I'm getting desperate trying to figure out why ffmpeg overlay filter misbehaves

I have the following ffmpeg command

ffmpeg -loop 1 -r 60 -i ./tmp/tmp0.jpg -loop 1 -r 60 -i ./tmp/tmp1.jpg -y -filter_complex 
[0_setsar2]crop=out_w=1280:out_h=720:x=0:y=(in_h - 720) / 2[0_setsar2_crop0];
[1_setsar2]crop=out_w=1280:out_h=720:x=0:y=(in_h - 720) / 2[1_setsar2_crop0];
[fl0_r0_][fl1_r0_]overlay=x='if(lte(x, (main_w - overlay_w) / 2), -overlay_w + t / 5 * (overlay_w + (main_w - overlay_w) / 2), (main_w - overlay_w) / 2)'[tr0_overlay];
-map [vt] -acodec libmp3lame -r 60 -vcodec libx264 -f mp4 -pix_fmt yuv420p -preset fast -crf 20 ./tmp/output.mp4

(It's padded for better visibility)

What am I trying to do?

  1. show 1st image for 5 seconds(arbitrary number)
  2. slide 2nd image over 1st image from the left to the right for 5 seconds(arbitrary number, can be 1, can be 10 - should not depend on the length of 1st and 2nd input streams)
  3. show 2nd image for 2 seconds(arbitrary number)

What do I get?

I've tried various solutions, with this one 2nd image moves above 1st image just for the 1st second and then abruptly stops for the next 4 seconds after which instantly jumps to the end of animation

while ffmpeg spams lots of warning

frame=   98 fps=8.1 q=28.0 size=     144kB time=00:00:01.08 bitrate=1087.8kbits/
[Parsed_overlay_14 @ 0x30d6400] [framesync @ 0x30d64e8] Buffer queue overflow, d                                                                                                                                                    ropping

I suspect there is some issue with frames timelines, but so far I had no success If I add setpts filter 5*PTS - it works perfectly but I observe 5x frame drop(from 60 fps down to 12 fps) taken from: https://ffmpeg.org/ffmpeg-filters.html#Examples-88 (slow motion)

For some reason overlay filter works only with the 1st second of the video - no matter what I'm trying to do

I also tried to combine fps and setpts filter as a kind of weird hack - no success

ffmpeg version:

ffmpeg version N-76045-g97be5d4 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)

Probably I'm missing something obvious! Please help...


2 Answers 2


After ~8 hours of banging my head against the wall of ffmpeg, google and docs I finally found what to do(works with any sliding duration):

  1. setpts filter PTS*5-STARTPTS
  2. fps filter to correct fps to desired value after "stretching" the stream with setpts filter
  3. pass both streams to the fifo filter, this prevents ffmpeg from dropping frames

for some reason ffmpeg drops ANY frames above FRAME_RATE given to the overlay filter unless you manually pass them thru the fifo... i.e. at max you can pass 60 frames per second(if your fps is 60) or 12 frames at second for 5 seconds(60 frames in total = same as fps of the video)

bleh... I wish docs were better regarding such things


So, If i got you correctly.. You want images to slide over previous image after some duration.

This is how you can do it:

ffmpeg -loop 1 -i img01.png -loop 1 -i img02.png -loop 1 -i img03.png -loop 1 -i img04.png -i watermark_logo.png -filter_complex \ "[0:v]scale=412x684,setpts=PTS-STARTPTS[v0];\ [0:v]trim=duration=3,scale=412x684,setpts=PTS-STARTPTS,split[v1a][v1b];\ [1:v]trim=duration=3,scale=412x684,setpts=PTS-STARTPTS,split[v2a][v2b];\ [2:v]trim=duration=3,scale=412x684,setpts=PTS-STARTPTS,split[v3a][v3b];\ [3:v]trim=duration=3,scale=412x684,setpts=PTS-STARTPTS[v4];\ [4:v]setpts=PTS-STARTPTS[v5];\ [v0][v1a] overlay=x='0':shortest=1[vv0];\ [v1b][v2a] overlay=x='max(w-(tw/0.5),0)':shortest=1[vv1];\ [v2b][v3a] overlay=x='max(w-(tw/0.5),0)':shortest=1[vv2];\ [v3b][v4] overlay=x='max(w-(t*w/0.5),0)':shortest=1[vv3];\ [vv0][vv1][vv2][vv3] concat=n=4:v=1:a=0 [video];\ [video][v5] overlay=main_w-80:main_h-80 [finalvid]" -i audio.mp3 -map "[finalvid]" -map 5:0 -t 20 output.mp4

filter breakdown:
- create v0,v1a,v1b... from input images
- overlay v1a on v0, v2a on v1b.. so on
- concat all overlay and generate video
- overlay video with water_mark
- map audio with finalVid

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .