Opened 7 years ago

Closed 7 years ago

#6292 closed defect (fixed)

overlay filter shortest doesn't work and ffmpeg hangs if 2nd input is longer

Reported by: Gyan Owned by:
Priority: important Component: avfilter
Version: git-master Keywords: overlay regression
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


Setting shortest=1 in the overlay filter doesn't work. If the main input is longer, the overlay runs till the end of that video. If the secondary input is longer, whether it's a video or a looped single image, encoding proceeds till the EOF of the main input but FFmpeg doesn't exit. Doing a soft exit works and the output file is valid (tested with MP4 output). However, this is not a practical option when processing videos in bulk. Can't use output option -shortest as workaround if there are no other streams being muxed (or they are shorter).

Tested with multiple MP4/MOV inputs as main video. Tested with multiple images and couple of MP4/MOVs as secondary input.

Running git bisect gets

0ff5567a30be6d7c804e95997ae282d6bacd76c3 is the first bad commit
commit 0ff5567a30be6d7c804e95997ae282d6bacd76c3
Author: Nicolas George <>
Date:   Fri Dec 23 21:39:46 2016 +0100

    lavfi/buffersrc: push the frame deeper if requested.

    Reduce peak memory consumption with ffmpeg in certain cases.

:040000 040000 1495a0350e1af2b72abb35ce112ee6fd82371a75 bd8d282f75ad23eab19a3fb003574e0090aaed78 M  libavfilter
C:\avutils\ffmpeg-stock (HEAD detached at 0ff5567)
λ .\ffmpeg -i "t:\Handmade road bike. (promo video).mp4" -loop 1 -i t:\text.png -filter_complex "[0][1]overlay=x='(W-w)/2':y='H-h-30':shortest=1" -c:v mpeg4 -c:a aac -b:a 64k -movflags +faststart -f mp4 t:\out.mp4
ffmpeg version 3.2.git Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 6.3.0 (x86_64-posix-sjlj-rev1, Built by MinGW-W64 project)
  configuration: --disable-ffplay --disable-ffprobe --disable-ffserver --disable-hwaccels --disable-devices --disable-encoders --enable-encoder=mpeg4 --enable-encoder=aac --disable-demuxers --enable-demuxer=mov --enable-demuxer=image_png_pipe --disable-muxers --enable-muxer=mp4
  libavutil      55. 43.100 / 55. 43.100
  libavcodec     57. 70.100 / 57. 70.100
  libavformat    57. 61.100 / 57. 61.100
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 68.100 /  6. 68.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 't:\Handmade road bike. (promo video).mp4':
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.40.101
  Duration: 00:00:15.74, start: 0.000000, bitrate: 2711 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709/unknown/bt709), 1920x1080 [SAR 1:1 DAR 16:9], 2508 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 200 kb/s (default)
      handler_name    : SoundHandler
Input #1, png_pipe, from 't:\text.png':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Video: png, rgba(pc), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc
File 't:\out.mp4' already exists. Overwrite ? [y/N] y
Output #0, mp4, to 't:\out.mp4':
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.61.100
    Stream #0:0: Video: mpeg4 ( [0][0][0] / 0x0020), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 25 fps, 12800 tbn, 25 tbc (default)
      encoder         : Lavc57.70.100 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
    Stream #0:1(und): Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, fltp, 64 kb/s (default)
      handler_name    : SoundHandler
      encoder         : Lavc57.70.100 aac
Stream mapping:
  Stream #0:0 (h264) -> overlay:main (graph 0)
  Stream #1:0 (png) -> overlay:overlay (graph 0)
  overlay (graph 0) -> Stream #0:0 (mpeg4)
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[mp4 @ 000000000033a5a0] Starting second pass: moving the moov atom to the beginning of the file
frame=  393 fps= 32 q=31.0 Lsize=    2545kB time=00:00:15.72 bitrate=1326.3kbits/s speed=1.27x
video:2409kB audio:126kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.398423%
[aac @ 000000000332f3c0] Qavg: 317.130
Exiting normally, received signal 2.

Change History (9)

comment:1 by Gyan, 7 years ago

Priority: normalimportant
Summary: overlay filter's shortest=1 doesn't take effect.overlay filter shortest doesn't work and ffmpeg hangs if 2nd input is longer

comment:2 by Carl Eugen Hoyos, 7 years ago

Component: undeterminedavfilter
Keywords: regression added

comment:3 by Carl Eugen Hoyos, 7 years ago

Keywords: overlay added

comment:4 by Gyan, 7 years ago

shortest=1 exhibits the same behaviour with the haldclut, hstack and vstack filters. The blend filter shows the same bug if the first input (the A or top video) is the shorter stream. If the 2nd input is shorter, ffmpeg displays "Error while filtering" but otherwise exits normally.

comment:5 by Gyan, 7 years ago

Still reproducible, as of N-85722-gd535e0c140

Any chance for a fix or a revert? Thanks.

comment:6 by Elon Musk, 7 years ago

Resolution: fixed
Status: newclosed

Relevant commit was reverted.

comment:7 by Gyan, 7 years ago

Resolution: fixed
Status: closedreopened

comment:8 by Gyan, 7 years ago

Since 1daacba9 reverts the revert, I'm reopening this to accurately track status.

comment:9 by Elon Musk, 7 years ago

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.