Windows系统下FFmpeg转换后文件名特殊字符为何变更?
Windows 11下FFmpeg转换FLAC到Opus时文件名特殊字符编码异常问题
在Windows 11系统中运行Python脚本,遍历采用UTF-16编码的FLAC音乐文件库,目标是创建结构完全一致的Opus格式镜像库。脚本调用FFmpeg执行格式转换,但转换后文件名中的特殊字符(如示例中的Ü和ø)会变为视觉相近但编码不同的字符——例如原文件名为06 xXXi_wud_nvrstøp_ÜXXx.flac,转换后文件名看似相同,但实际编码已从原Unicode U+0125、U+01410变为U+0334。
由于脚本通过判断文件名是否存在来决定是否转换,这种字符编码的差异导致每次运行脚本时,都会重复删除并重建同一批文件。
转换函数代码
def convert_file(pool, top, file): fullPath = os.path.join(top, file) # Pass count=1 to str.replace() just in case .flac is in the song # title or something. newPath = fullPath.replace(src_dir, dest_dir, 1) newPath = newPath.replace(".flac", ".opus", 1) if os.path.isfile(newPath): return None else: print("{} does not exist".format(newPath)) cvt = [ "Ffmpeg", "-v", "debug", "-i", fullPath, "-c:a", "libopus", "-b:a", "96k", newPath] print(cvt) return ( fullPath, pool.apply_async(subprocess.run, kwds={ "args": cvt, "check": True, "stdin": subprocess.DEVNULL}))
补充信息
- 脚本通过无特殊配置的
os.walk获取文件路径参数 - 已验证直接在CMD中执行FFmpeg转换命令也会出现该字符编码变更问题,因此问题根源不在Python代码层面
内容的提问来源于stack exchange,提问作者GeneralTully
相关产品推荐
相关产品推荐

