带有链式过滤器的 ffmpeg 命令

带有链式过滤器的 ffmpeg 命令

我是 ffmpeg 和这个论坛的新手,我需要创建一些复杂的(至少对我来说)动画。请原谅我的英语或解释不好。

我正在使用 ffmpeg 版本 4.4

输入:

  • img1.jpeg(将循环 14 秒)
  • img2.jpeg(将循环 14 秒)
  • fade in第一个视频(由 img1.jpeg 创建,时长 14 秒)将以0 帧到 25 帧的滤镜开始
  • xfade在循环图像 1 和循环图像 2 之间应用的过滤器
  • smartblur从第 4 秒开始,持续到第 20 秒
  • 白色透明drawbox(不透明度 0.3)显示从第 5 秒到第 20 秒
  • audio.mp3 在后台添加,末尾带有 -shortest 标志
  • 最终视频的帧速率被强制为 25-r 25

输出:

  • 带有滤镜和背景音频的最终视频

我的命令:

ffmpeg -loop 1 -t 14 -i img1.jpeg -loop 1 -t 14 -i img2.jpeg -filter_complex "[0][1]xfade=transition=fade:duration=1:offset=13[video];[video]fade=in:0:25[video];[video]smartblur=5:1:0:enable='between(t,4,20)'[video];[video]drawbox=x=0:y=20:w=iw:h=ih-40:[email protected]:t='fill':enable='between(t,5,20)'" -i audio.mp3 -shortest -pix_fmt yuv420p -r 25 -s 848x480 video.mp4 -y

完整的ffmpeg命令日志:

time ffmpeg -loop 1 -t 14 -i 57ac8b5655e926a994d57857f92dcffa.jpeg -loop 1 -t 14 -i b53dc57419455354319c1cfb1b047924.jpeg -filter_complex "[0][1]xfade=transition=fade:duration=1:offset=13[video];[video]fade=in:0:25[video];[video]smartblur=5:1:0:enable='between(t,4,20)'[video];[video]drawbox=x=0:y=20:w=iw:h=ih-40:[email protected]:t='fill':enable='between(t,5,20)'" -i a950b90762b39d6dae38c9d06f8cf1d3.mp3 -shortest -pix_fmt yuv420p -r 25 -s 848x480 video.mp4 -y
ffmpeg version 4.4 Copyright (c) 2000-2021 the FFmpeg developers
built with Apple clang version 12.0.0 (clang-1200.0.32.29)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.4_1 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
libavutil      56. 70.100 / 56. 70.100
libavcodec     58.134.100 / 58.134.100
libavformat    58. 76.100 / 58. 76.100
libavdevice    58. 13.100 / 58. 13.100
libavfilter     7.110.100 /  7.110.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  9.100 /  5.  9.100
libswresample   3.  9.100 /  3.  9.100
libpostproc    55.  9.100 / 55.  9.100
Input #0, image2, from '57ac8b5655e926a994d57857f92dcffa.jpeg':
Duration: 00:00:00.04, start: 0.000000, bitrate: 31104 kb/s
Stream #0:0: Video: mjpeg (Progressive), yuvj444p(pc, bt470bg/unknown/unknown), 640x480 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #1, image2, from 'b53dc57419455354319c1cfb1b047924.jpeg':
Duration: 00:00:00.04, start: 0.000000, bitrate: 34629 kb/s
Stream #1:0: Video: mjpeg (Progressive), yuvj444p(pc, bt470bg/unknown/unknown), 640x480 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #2, mp3, from 'a950b90762b39d6dae38c9d06f8cf1d3.mp3':
Metadata:
    encoder         : Lavf58.20.100
Duration: 00:00:27.59, start: 0.025057, bitrate: 64 kb/s
Stream #2:0: Audio: mp3, 44100 Hz, stereo, fltp, 64 kb/s
    Metadata:
    encoder         : Lavc58.35
Stream mapping:
Stream #0:0 (mjpeg) -> xfade:main (graph 0)
Stream #1:0 (mjpeg) -> xfade:xfade (graph 0)
drawbox (graph 0) -> Stream #0:0 (libx264)
Stream #2:0 -> #0:1 (mp3 (mp3float) -> aac (native))
Press [q] to stop, [?] for help
[swscaler @ 0x7f8600008000] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x7f8600018000] deprecated pixel format used, make sure you did set range correctly
[libx264 @ 0x7f862c029e00] using SAR=40/53
[libx264 @ 0x7f862c029e00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7f862c029e00] profile High, level 3.0, 4:2:0, 8-bit
[libx264 @ 0x7f862c029e00] 264 - core 161 r3049 55d517b - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=15 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'video.mp4':
Metadata:
    encoder         : Lavf58.76.100
Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt470bg/unknown/unknown, progressive), 848x480 [SAR 40:53 DAR 4:3], q=2-31, 25 fps, 12800 tbn (default)
    Metadata:
    encoder         : Lavc58.134.100 libx264
    Side data:
    cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s
    Metadata:
    encoder         : Lavc58.134.100 aac
frame=  675 fps=112 q=-1.0 Lsize=    1120kB time=00:00:26.98 bitrate= 340.1kbits/s speed=4.48x    
video:668kB audio:429kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.141831%
[libx264 @ 0x7f862c029e00] frame I:6     Avg QP:14.68  size: 50615
[libx264 @ 0x7f862c029e00] frame P:172   Avg QP:18.93  size:  2109
[libx264 @ 0x7f862c029e00] frame B:497   Avg QP:28.86  size:    34
[libx264 @ 0x7f862c029e00] consecutive B-frames:  1.6%  0.3%  0.9% 97.2%
[libx264 @ 0x7f862c029e00] mb I  I16..4: 18.3% 63.3% 18.4%
[libx264 @ 0x7f862c029e00] mb P  I16..4:  0.2%  1.3%  0.1%  P16..4:  6.1%  1.4%  1.1%  0.0%  0.0%    skip:89.8%
[libx264 @ 0x7f862c029e00] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.8%  0.0%  0.0%  direct: 0.0%  skip:99.2%  L0:24.9% L1:73.9% BI: 1.2%
[libx264 @ 0x7f862c029e00] 8x8 transform intra:69.9% inter:62.2%
[libx264 @ 0x7f862c029e00] coded y,uvDC,uvAC intra: 76.1% 81.2% 66.6% inter: 1.3% 2.0% 0.7%
[libx264 @ 0x7f862c029e00] i16 v,h,dc,p: 73%  8%  4% 15%
[libx264 @ 0x7f862c029e00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 22% 13%  6%  7%  6% 10%  7% 10%
[libx264 @ 0x7f862c029e00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 18%  8%  6% 10%  8% 13%  7% 10%
[libx264 @ 0x7f862c029e00] i8c dc,h,v,p: 51% 21% 15% 13%
[libx264 @ 0x7f862c029e00] Weighted P-Frames: Y:7.0% UV:6.4%
[libx264 @ 0x7f862c029e00] ref P L0: 81.4%  6.9% 11.4%  0.3%  0.0%
[libx264 @ 0x7f862c029e00] ref B L0: 92.6%  7.1%  0.2%
[libx264 @ 0x7f862c029e00] ref B L1: 95.2%  4.8%
[libx264 @ 0x7f862c029e00] kb/s:202.41
[aac @ 0x7f862c02ce00] Qavg: 188.226

real    0m6.225s
user    0m10.558s
sys 0m0.399s

问题: 作为这个神奇工具的新手,我该如何改进上面的命令以生成与现在完全相同的输出?我确信它不是最佳的,还有很多需要改进的地方。处理速度非常重要。

感谢您的任何帮助/想法!

答案1

您的命令看起来不错,而且您没有使用配置不佳的旧 ffmpeg。一些小建议:

库文件

您正在使用 libx264 进行编码,因此您可以添加-preset-crf选项来控制速度和质量,如FFmpeg 维基:H.264

视频工具箱和音频工具箱

因为您使用的是 iOS/macOS,所以您可以尝试 VideoToolbox 和 AudioToolbox。

添加-c:v h264_videotoolbox -c:a aac_at

它可能更快。我从未尝试过这些编码器,因为我没有所需的硬件。libx264 提供比 h264_videotoolbox 更高的比特率质量。aac_at 可能比内置的 FFmpeg AAC 编码器更好。

更多信息:ffmpeg -h encoder=h264_videotoolboxffmpeg -h encoder=aac_at

一切都在-filter_complex

旧版-pix_fmt-s选项是格式和比例过滤器的别名。使用过滤器,这样您就可以更好地控制在 中应用它们-filter_complex。因为您正在升级,所以比例过滤器应该放在最后,以便更快地进行处理(在这种情况下可能无关紧要,但这是一般建议)。

ffmpeg -y -loop 1 -t 14 -i img1.jpeg -loop 1 -t 14 -i img2.jpeg -i audio.mp3 -filter_complex "[0][1]xfade=transition=fade:duration=1:offset=13[video];[video]fade=in:0:25[video];[video]smartblur=5:1:0:enable='between(t,4,20)'[video];[video]drawbox=x=0:y=20:w=iw:h=ih-40:[email protected]:t='fill':enable='between(t,5,20)',format=yuv420p,scale=-2:480" -shortest video.mp4

我省略了,-r 25因为默认帧速率为图像分离器是 25。

相关内容