我正在尝试使用 drawtext 在视频上添加多个类似字幕的文本。当我有 1 或 2 个 drawtext 参数时它会起作用,如下所示:
在职的:
ffmpeg -i outa.mp4 -vf "[in]drawtext=fontfile=fonts/BebasNeue-Regular.otf:fontsize=60: fontcolor=white:x=20: y=500:text='My real fear is that':enable='between(t,5,10)',drawtext=fontfile=fonts/BebasNeue-Regular.otf:fontsize=60: fontcolor=white:x=0: y=500:text='the truth of the matter is people':enable='between(t,11,20)'[out]" output.mp4
但是当我尝试添加多个 drawtext 选项时,出现错误并且转换失败。
请参阅下面的尝试,然后查看失败转换的输出。任何朝着正确方向迈出的举措都将不胜感激。
**仅供参考:我也尝试直接刻录 SRT 文件,但样式选项有限,因此我避免这样做,而是使用 drawtext。
试图:
ffmpeg -i outa.mp4 -vf "[in]drawtext=fontfile=fonts/BebasNeue-Regular.otf:fontsize=40: fontcolor=white:x=20: y=500:text='My real fear is that they\\\'re going to invent a ':enable='between(t,0,4)';drawtext=fontfile=fonts/BebasNeue-Regular.otf:fontsize=40: fontcolor=white:x=20: y=500:text='better eye for blind people . And when they do ':enable='between(t,4,9)';drawtext=fontfile=fonts/BebasNeue-Regular.otf:fontsize=40: fontcolor=white:x=20: y=500:text=', like Look how amazing this is . We\\\'ve given ':enable='between(t,8,11)';drawtext=fontfile=fonts/BebasNeue-Regular.otf:fontsize=40: fontcolor=white:x=20: y=500:text='blind people the ability to see again , too possum ':enable='between(t,11,13)';drawtext=fontfile=fonts/BebasNeue-Regular.otf:fontsize=40: fontcolor=white:x=20: y=500:text='. But now they also have all these other features ':enable='between(t,13,16)';drawtext=fontfile=fonts/BebasNeue-Regular.otf:fontsize=40: fontcolor=white:x=20: y=500:text='that you don\\\'t have with your regular eyes . Let ':enable='between(t,16,17)';drawtext=fontfile=fonts/BebasNeue-Regular.otf:fontsize=40: fontcolor=white:x=20: y=500:text='us scooped those bad boys . ':enable='between(t,17,18)'[out]" aoutput.mp4
转换失败后我在终端上得到的输出:
ffmpeg -i outa.mp4 -vf "[in]drawtext=fontfile=fonts/BebasNeue-Regular.otf:fontsize=40: fontcolor=white:x=20: y=500:text='My real fear is that they\\\'re going to invent a ':enable='between(t,0,4)';drawtext=fontfile=fonts/BebasNeue-Regular.otf:fontsize=40: fontcolor=white:x=20: y=500:text='better eye for blind people . And when they do ':enable='between(t,4,9)';drawtext=fontfile=fonts/BebasNeue-Regular.otf:fontsize=40: fontcolor=white:x=20: y=500:text=', like Look how amazing this is . We\\\'ve given ':enable='between(t,8,11)';drawtext=fontfile=fonts/BebasNeue-Regular.otf:fontsize=40: fontcolor=white:x=20: y=500:text='blind people the ability to see again , too possum ':enable='between(t,11,13)';drawtext=fontfile=fonts/BebasNeue-Regular.otf:fontsize=40: fontcolor=white:x=20: y=500:text='. But now they also have all these other features ':enable='between(t,13,16)';drawtext=fontfile=fonts/BebasNeue-Regular.otf:fontsize=40: fontcolor=white:x=20: y=500:text='that you don\\\'t have with your regular eyes . Let ':enable='between(t,16,17)';drawtext=fontfile=fonts/BebasNeue-Regular.otf:fontsize=40: fontcolor=white:x=20: y=500:text='us scooped those bad boys . ':enable='between(t,17,18)'[out]" aoutput.mp4
ffmpeg version N-48288-g3b23eb283a-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg
libavutil 56. 26.100 / 56. 26.100
libavcodec 58. 47.102 / 58. 47.102
libavformat 58. 26.101 / 58. 26.101
libavdevice 58. 6.101 / 58. 6.101
libavfilter 7. 48.100 / 7. 48.100
libswscale 5. 4.100 / 5. 4.100
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'outa.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.26.101
Duration: 00:03:25.92, start: 0.000000, bitrate: 147 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc), 810x660, 12 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[drawtext @ 0x650edc0] [Eval @ 0x7fffcb9196b0] Missing ')' or too many args in 'between(t'
[drawtext @ 0x650edc0] Error when evaluating the expression 'between(t' for enable
[AVFilterGraph @ 0x650b9c0] Error initializing filter 'drawtext' with args 'fontfile=fonts/BebasNeue-Regular.otf:fontsize=40: fontcolor=white:x=20: y=500:text=My real fear is that they\\re going to invent a :enable=between(t'
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0
[aac @ 0x5e11e40] Qavg: 11771.192
[aac @ 0x5e11e40] 2 frames left in the queue on closing
我该如何避免这个错误?提前致谢!任何步骤都将不胜感激。