1

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]trim=duration=5[0_trim0];
[0_trim0]scale=width=1280:height=-1[0_scale1];
[0_scale1]setsar=sar=1[0_setsar2];
[0_setsar2]crop=out_w=1280:out_h=720:x=0:y=(in_h - 720) / 2[0_setsar2_crop0];
[0_setsar2_crop0]setsar=sar=1[0_setsar3];
[0_setsar3]split=2[fl0_r0][fl0_r1];
[1]trim=duration=2[1_trim0];
[1_trim0]scale=width=1280:height=-1[1_scale1];
[1_scale1]setsar=sar=1[1_setsar2];
[1_setsar2]crop=out_w=1280:out_h=720:x=0:y=(in_h - 720) / 2[1_setsar2_crop0];
[1_setsar2_crop0]setsar=sar=1[1_setsar3];
[1_setsar3]split=2[fl1_r0][fl1_r1];
[fl0_r0]setpts=PTS-STARTPTS[fl0_r0_];
[fl1_r0]setpts=PTS-STARTPTS[fl1_r0_];
[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];
[tr0_overlay]trim=duration=5[tr0];
[fl0_r1][tr0][fl1_r1]concat=n=3:v=1[vt]
-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...

0

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

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.