如果你的字幕文件名为“Hi, y'all.srt”,如何为 FFmpeg 正确转义?逗号可以用反斜杠转义,但无论我尝试什么技巧,我都无法使引用起作用!
$ ffmpeg -vf subtitles="Hi\, y\\\'all.srt" -t 1 -f null -
ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 8.1.0 (clang-802.0.42)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-libass --enable-libmp3lame --enable-libx264 --enable-libx265 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-vda
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libavresample 3. 5. 0 / 3. 5. 0
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
[Parsed_subtitles_0 @ 0x7fba7af36080] Shaper: FriBidi 0.19.7 (SIMPLE) HarfBuzz-ng 1.4.8 (COMPLEX)
[Parsed_subtitles_0 @ 0x7fba7af36080] Unable to open Hi, yall.srt
[AVFilterGraph @ 0x7fba7ad05d60] Error initializing filter 'subtitles' with args 'Hi, y\all.srt'
Error reinitializing filters!
Failed to inject frame into filter network: No such file or directory
Error while processing the decoded data for stream #0:0
Conversion failed!
在 Windows 7 上,这有效:
subtitles="Hi\, y\\\'all.srt"
我知道这是一个老问题,但我想在这里发布答案,因为我遇到了类似的问题并找到了解决方法。这是在 Windows 8.1 中测试的。
解决方法是先使用 ffmpeg 喜欢的名称创建一个指向文件的符号链接,然后使用它。
例如。
mklink input.mkv "my file with [strange] characters.mkv"
然后你可以将它与 ffmpeg 一起使用,如下所示:
ffmpeg -i input.mkv -vf subtitles=input.mkv -y output.mp4
这也适用于 .srt 文件。
ffmpeg 似乎存在一个错误,如果您在字幕过滤器中使用包含特殊字符的文件,ffmpeg 将找不到该文件。我有一组想要刻录字幕的文件,但它们的文件名中都有特殊字符(方括号)。我可以重命名所有文件,并删除特殊字符,但这似乎很痛苦,我宁愿找到一种不关心源文件如何命名的方法。我能找到的最好的解决方法是只创建一个到文件本身的符号链接,并在符号链接上调用 ffmpeg 。如果我要迭代许多文件,我所需要做的就是将符号链接更改为下一个文件。
假设您在 D:\Videos 文件夹中有一个名为 subtitle's.srt 的文件,您可以像这样转义它
"subtitles='D\:\\Videos\\subtitle'\\\''s.srt'"
。
示例:
ffmpeg.exe -in file.mkv -c:a copy -c:v libx264 -crf 20 -pix_fmt yuv420p -map 0:v:0 -map 0:a:0 -vf "subtitles='D\:\\Videos\\subtitle'\\\''s.srt':si=0" file.mp4
这是在 Windows 10 上测试的。
这是我为 Bash 准备的东西。
$ ls
'file with spaces : colons : , commas, %percents%, '\'' single and "double"'\'' quotes, and \ backslashes\.mp4'
以下调用将起作用:
i=*; e=${i//\\/\\\\\\\\}; e=${e//:/\\\\:}; e=${e//,/\\,}; e=${e//\'/\\\\\\\'}; ffmpeg -i "${i}" -vf "subtitles=${e}:si=8" "out.mp4"