Why does ffmpeg never end when invoking color in a filter_complex?

1

I am trying to add a simple color overlay to an existing video, following one of the examples at http://www.ffmpeg.org/ffmpeg-filters.html#Examples-55 (see the example Add a transparent color layer on top of the main video)

I am getting strange behavior with the following command:

ffmpeg.exe -i input.mov -filter_complex "color=c=red@.3:size=1024x768 [over]; /
[0][over] overlay" output.mkv

ffmpeg generates normal-looking output (below) then repeated logs of work on the same frame. This continues indefinitely. If I hit Ctrl-C, work resumes, ffmpeg completes the task and the output file is generated (with the overlay).

Is there something wrong with my color invocation?

Output:

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

This is where the problem starts. I get the "Past duration X too large" message with other filter_complex invocations, but they complete successfully.

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

Here it has started repeating on frame 151. After a while I hit Ctrl-C, and ffmpeg continues...

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.

david.libremone

Posted 2015-07-03T07:28:57.800

Reputation: 1 128

Answers

3

The overlay filter has a shortest option:

If set to 1, force the output to terminate when the shortest input terminates. Default value is 0.

Example:

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

Usage of shortest is needed because the color duration is indefinite (unless you use the d option).

llogan

Posted 2015-07-03T07:28:57.800

Reputation: 31 929

0

Your syntax for the overlay is correct as per the example given, however invoked like that it will repeat indefinitely as you note. You will need to include the repeatlast=0 option:

repeatlast

If set to 1, force the filter to draw the last overlay frame over the main input until the end of the stream. A value of 0 disables this behavior. Default value is 1

So your command becomes:

ffmpeg.exe -i input.mov -filter_complex "color=c=red@.3:size=1024x768 [over]; /
[0][over] overlay=repeatlast=0" output.mkv

(tested with example files)

Incidentally, I don't think this is entirely intuitive, as clearly your stream is ending (which is why frames start getting dropped). I'm not sure why it doesn't end by default, unless it is waiting for the end of the color generation (which doesn't have a duration)? Speculation aside, the command should now work.

bertieb

Posted 2015-07-03T07:28:57.800

Reputation: 6 181