为什么 ffmpeg 在 filter_complex 中调用颜色时永远不会结束?

为什么 ffmpeg 在 filter_complex 中调用颜色时永远不会结束?

我正在尝试按照以下示例之一向现有视频添加简单的颜色叠加http://www.ffmpeg.org/ffmpeg-filters.html#Examples-55(见示例在主视频顶部添加透明颜色层

我在使用以下命令时遇到了奇怪的行为:

ffmpeg.exe -i input.mov -filter_complex "[email protected]:size=1024x768 [over]; /
[0][over] overlay" output.mkv

ffmpeg 生成看起来正常的输出(如下),然后在同一帧上重复工作日志。这种情况会无限期地持续下去。如果我按下 Ctrl-C,工作就会恢复,ffmpeg 会完成任务并生成输出文件(带有覆盖)。

我的调用有问题吗color

输出:

ffmpeg version N-71182-g5cba529 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.9.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --
enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-l
ibilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enab
le-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --en
able-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --ena
ble-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc
 --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enabl
e-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --ena
ble-decklink --enable-zlib
  libavutil      54. 21.100 / 54. 21.100
  libavcodec     56. 32.100 / 56. 32.100
  libavformat    56. 27.100 / 56. 27.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 13.101 /  5. 13.101
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 537199360
    compatible_brands: qt
    creation_time   : 2010-04-05 17:03:23
  Duration: 00:00:06.00, start: 0.000000, bitrate: 9491 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709)
, 1280x720, 9482 kb/s, 25 fps, 25 tbr, 600 tbn, 1200 tbc (default)
    Metadata:
      creation_time   : 2010-04-05 17:03:23
      handler_name    : Apple Alias Data Handler
      encoder         : H.264
[libx264 @ 00000000003bd600] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
AVX
[libx264 @ 00000000003bd600] profile High, level 3.1
[libx264 @ 00000000003bd600] 264 - core 146 r2538 121396c - H.264/MPEG-4 AVC cod
ec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 r
ef=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_pski
p=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 deci
mate=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=2
5 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.6
0 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, matroska, to 'output.mkv':
  Metadata:
    major_brand     : qt
    minor_version   : 537199360
    compatible_brands: qt
    encoder         : Lavf56.27.100
    Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv420p, 1280x720, q
=-1--1, 25 fps, 1k tbn, 25 tbc (default)
    Metadata:
      encoder         : Lavc56.32.100 libx264
Stream mapping:
  Stream #0:0 (h264) -> overlay:main
  overlay -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
frame=   60 fps=0.0 q=28.0 size=      46kB time=00:00:00.32 bitrate=1185.4kbits/
frame=   90 fps= 87 q=28.0 size=     520kB time=00:00:01.52 bitrate=2804.9kbits/
frame=  121 fps= 78 q=28.0 size=    1059kB time=00:00:02.76 bitrate=3142.4kbits/
Past duration 0.999992 too large

问题就出在这里。我在其他 filter_complex 调用中收到了“Past duration X too large”消息,但它们都成功完成了。

frame=  151 fps= 74 q=28.0 size=    1460kB time=00:00:03.96 bitrate=3020.1kbits/
frame=  151 fps= 59 q=28.0 size=    1460kB time=00:00:03.96 bitrate=3020.1kbits/
frame=  151 fps= 50 q=28.0 size=    1460kB time=00:00:03.96 bitrate=3020.1kbits/
frame=  151 fps= 43 q=28.0 size=    1460kB time=00:00:03.96 bitrate=3020.1kbits/
frame=  151 fps= 37 q=28.0 size=    1460kB time=00:00:03.96 bitrate=3020.1kbits/
frame=  151 fps= 32 q=-1.0 Lsize=    2011kB time=00:00:05.96 bitrate=2764.6kbits
/s dup=0 drop=754

这里它从第 151 帧开始重复。过了一会儿,我按下 Ctrl-C,ffmpeg 继续......

video:2009kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing
overhead: 0.092920%
[libx264 @ 00000000003bd600] frame I:1     Avg QP:17.97  size:  6988
[libx264 @ 00000000003bd600] frame P:99    Avg QP:21.11  size: 18745
[libx264 @ 00000000003bd600] frame B:51    Avg QP:22.49  size:  3809
[libx264 @ 00000000003bd600] consecutive B-frames: 45.0% 17.2% 37.7%  0.0%
[libx264 @ 00000000003bd600] mb I  I16..4: 26.1% 64.4%  9.6%
[libx264 @ 00000000003bd600] mb P  I16..4:  3.5%  7.1%  1.3%  P16..4: 24.6%  9.6
%  6.7%  0.0%  0.0%    skip:47.1%
[libx264 @ 00000000003bd600] mb B  I16..4:  0.4%  0.6%  0.1%  B16..8: 22.7%  2.6
%  1.1%  direct: 3.9%  skip:68.7%  L0:38.2% L1:50.7% BI:11.0%
[libx264 @ 00000000003bd600] 8x8 transform intra:59.8% inter:51.6%
[libx264 @ 00000000003bd600] coded y,uvDC,uvAC intra: 21.0% 33.2% 17.3% inter: 1
1.8% 17.7% 10.4%
[libx264 @ 00000000003bd600] i16 v,h,dc,p: 41% 16%  8% 35%
[libx264 @ 00000000003bd600] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 30% 13% 43%  2%  3%
 3%  2%  2%  2%
[libx264 @ 00000000003bd600] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 17% 26%  4%  8%
 8%  6%  5%  5%
[libx264 @ 00000000003bd600] i8c dc,h,v,p: 65% 17% 15%  2%
[libx264 @ 00000000003bd600] Weighted P-Frames: Y:1.0% UV:0.0%
[libx264 @ 00000000003bd600] ref P L0: 63.7% 15.8% 15.0%  5.4%  0.0%
[libx264 @ 00000000003bd600] ref B L0: 81.8% 16.5%  1.7%
[libx264 @ 00000000003bd600] ref B L1: 92.5%  7.5%
[libx264 @ 00000000003bd600] kb/s:2724.49
Received signal 2: terminating.

答案1

overlay筛选有一个shortest选项:

如果设置为1,则在最短输入终止时强制输出终止。默认值为0

例子:

ffmpeg -i input -filter_complex "color[c];[0:v][c]overlay=shortest=1" output

shortest需要使用,因为color持续时间是不确定的(除非您使用该d选项)。

答案2

根据给出的示例,您的覆盖语法是正确的,但是,像这样调用它将无限重复,正如您所注意到的。您需要包含以下选项repeatlast=0

重复最后

如果设置为 1,则强制过滤器在主输入上绘制最后一个覆盖帧,直到流结束。值为 0 会禁用此行为。默认值为 1

因此你的命令变成:

ffmpeg.exe -i input.mov -filter_complex "[email protected]:size=1024x768 [over]; /
[0][over] overlay=repeatlast=0" output.mkv

(使用示例文件测试)

顺便说一句,我认为这并不完全直观,因为很明显您的流即将结束(这就是帧开始丢失的原因)。我不确定为什么它不会默认结束,除非它正在等待颜色生成的结束(没有持续时间)?抛开猜测,该命令现在应该可以工作了。

相关内容