如何使用缩放、填充和叠加操作来加速复杂的过滤?

如何使用缩放、填充和叠加操作来加速复杂的过滤?

我想拍摄一段视频,将其缩放到其宽度减去所添加图像的宽度,然后将该图像的宽度添加为填充并在该空间中叠加图像。我有一个有效的命令,但它非常慢。

ffmpeg -i "i.ts" -i img.png -filter_complex "[0]scale=iw-300:-2[vid],[vid]pad=iw+300:ih[padvid],[padvid][1]overlay=x=W-w:y=0" -c:v h264 -c:a copy o.ts

我使用是-c:v h264因为 pad 过滤器将 h264 视频编解码器更改为 mpeg2video,这大大降低了视频质量。

那么,是否有可能以某种方式加快速度?

不带编解码器参数的日志。

ffmpeg -i "i.ts" -i img1.png -filter_complex "[0]scale=iw-280:-2[vid],[vid]pad=iw+280:ih[padvid],[padvid][1]overlay=x=W-w:y=0" -c:a copy o.ts
ffmpeg version 4.3.1-2020-11-02-full_build-www.gyan.dev Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 10.2.0 (Rev3, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, mpegts, from 'i.ts':
  Duration: 00:00:45.84, start: 2660.015000, bitrate: 8414 kb/s
  Program 1
    Stream #0:0[0x100]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, mono, fltp, 13 kb/s
    Stream #0:1[0x101]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 60 fps, 60 tbr, 90k tbn, 120 tbc
    Stream #0:2[0x102]: Data: timed_id3 (ID3  / 0x20334449)
Input #1, png_pipe, from 'img1.png':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Video: png, rgba(pc), 280x720 [SAR 3778:3778 DAR 7:18], 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:1 (h264) -> scale
  Stream #1:0 (png) -> overlay:overlay
  overlay -> Stream #0:0 (mpeg2video)
  Stream #0:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
Output #0, mpegts, to 'o.ts':
  Metadata:
    encoder         : Lavf58.45.100
    Stream #0:0: Video: mpeg2video (Main), yuv420p, 1920x922 [SAR 1844:1845 DAR 256:123], q=2-31, 200 kb/s, 60 fps, 90k tbn, 60 tbc (default)
    Metadata:
      encoder         : Lavc58.91.100 mpeg2video
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
    Stream #0:1: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, mono, fltp, 13 kb/s
frame= 2750 fps= 54 q=31.0 Lsize=   16219kB time=00:00:45.82 bitrate=2899.6kbits/s speed=0.892x
video:14541kB audio:809kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 5.664216%

带有编解码器参数。

ffmpeg -i "i.ts" -i img1.png -filter_complex "[0]scale=iw-280:-2[vid],[vid]pad=iw+280:ih[padvid],[padvid][1]overlay=x=W-w:y=0" -c:v h264 -c:a copy o.ts
ffmpeg version 4.3.1-2020-11-02-full_build-www.gyan.dev Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 10.2.0 (Rev3, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, mpegts, from 'i.ts':
  Duration: 00:00:45.84, start: 2660.015000, bitrate: 8414 kb/s
  Program 1
    Stream #0:0[0x100]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, mono, fltp, 13 kb/s
    Stream #0:1[0x101]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 60 fps, 60 tbr, 90k tbn, 120 tbc
    Stream #0:2[0x102]: Data: timed_id3 (ID3  / 0x20334449)
Input #1, png_pipe, from 'img1.png':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Video: png, rgba(pc), 280x720 [SAR 3778:3778 DAR 7:18], 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:1 (h264) -> scale
  Stream #1:0 (png) -> overlay:overlay
  overlay -> Stream #0:0 (libx264)
  Stream #0:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
[libx264 @ 00000261be2ef4c0] using SAR=1844/1845
[libx264 @ 00000261be2ef4c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
[libx264 @ 00000261be2ef4c0] profile High, level 4.2, 4:2:0, 8-bit
Output #0, mpegts, to 'o.ts':
  Metadata:
    encoder         : Lavf58.45.100
    Stream #0:0: Video: h264 (libx264), yuv420p, 1920x922 [SAR 1844:1845 DAR 256:123], q=-1--1, 60 fps, 90k tbn, 60 tbc (default)
    Metadata:
      encoder         : Lavc58.91.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) ([15][0][0][0] / 0x000F), 44100 Hz, mono, fltp, 13 kb/s
frame= 2750 fps= 11 q=-1.0 Lsize=    9868kB time=00:00:45.82 bitrate=1764.2kbits/s speed=0.187x
video:8321kB audio:809kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 8.093884%
[libx264 @ 00000261be2ef4c0] frame I:11    Avg QP:20.82  size:137506
[libx264 @ 00000261be2ef4c0] frame P:760   Avg QP:23.08  size:  7233
[libx264 @ 00000261be2ef4c0] frame B:1979  Avg QP:25.13  size:   763
[libx264 @ 00000261be2ef4c0] consecutive B-frames:  0.8%  8.8%  3.2% 87.3%
[libx264 @ 00000261be2ef4c0] mb I  I16..4: 13.0% 67.5% 19.5%
[libx264 @ 00000261be2ef4c0] mb P  I16..4:  0.2%  1.0%  0.0%  P16..4: 19.1%  3.3%  3.4%  0.0%  0.0%    skip:73.0%
[libx264 @ 00000261be2ef4c0] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8: 11.4%  0.1%  0.0%  direct: 0.0%  skip:88.5%  L0:38.1% L1:61.5% BI: 0.4%
[libx264 @ 00000261be2ef4c0] 8x8 transform intra:74.1% inter:74.2%
[libx264 @ 00000261be2ef4c0] coded y,uvDC,uvAC intra: 35.0% 46.2% 14.0% inter: 2.0% 2.3% 0.0%
[libx264 @ 00000261be2ef4c0] i16 v,h,dc,p: 58% 20%  8% 14%
[libx264 @ 00000261be2ef4c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 17%  9% 53%  3%  3%  3%  4%  3%  4%
[libx264 @ 00000261be2ef4c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 32% 17%  9%  6%  8%  7%  9%  5%  8%
[libx264 @ 00000261be2ef4c0] i8c dc,h,v,p: 62% 17% 17%  3%
[libx264 @ 00000261be2ef4c0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 00000261be2ef4c0] ref P L0: 66.9%  9.8% 17.9%  5.3%
[libx264 @ 00000261be2ef4c0] ref B L0: 84.0%  9.9%  6.1%
[libx264 @ 00000261be2ef4c0] ref B L1: 95.9%  4.1%
[libx264 @ 00000261be2ef4c0] kb/s:1487.18

答案1

用一个x264-preset

ffmpeg -i "i.ts" -i img1.png -filter_complex "[0]scale=iw-280:-2,pad=iw+280:ih[padvid],[padvid][1]overlay=x=W-w:y=0" -c:v libx264 -preset veryfast -c:a copy o.ts

相关内容