videoffmpegoverlaypts

ffmpeg delay video in overlay


I am trying to overlay 2 videos, and one of them (the one on the "bottom"), I want to delay the start of (let's say by 2 seconds).

So, either hold the first frame for the duration of the delay, or have black frames for the duration of the delay. I have no preference as to which.

Here is what I tried based on this similar question: https://superuser.com/questions/734234/delayed-video-overlay-using-ffmpeg

ffmpeg
-i video_top
-i video_bottom
-filter_complex
"[0:v]trim=start='00\:04\:17.8':end='00\:04\:32.8',setpts=PTS-STARTPTS, scale=-1:'ih-ih*.5':eval=frame[v0];
[0:a]atrim=start='00\:04\:17.8':end='00\:04\:32.8',asetpts=PTS-STARTPTS[a0];
[1:v]setpts=PTS-STARTPTS+2/TB, format=yuva420p[v1];
[v1][v0]overlay=y=(main_h-overlay_h)*.074:format=yuv444:shortest=0:alpha='straight',format=yuv420p[out]"
-map [out] -map [a0] -vcodec libx264 testing_14.mp4

However, the result of this is that BOTH videos freeze the first frame for the delayed duration (of 2 seconds in this case). I have tried a bunch of alternative options, including

Nothing seems to work.


Solution

  • Use the tpad filter. During the delay you can either clone the first frame or show a solid color. Simplified examples:

    Clone 1st frame:

    ffmpeg -i background.mp4 -i front.mp4 -filter_complex "[0]tpad=start_duration=2:start_mode=clone[bg];[bg][1]overlay" output.mp4
    

    Show solid color:

    ffmpeg -i background.mp4 -i front.mp4 -filter_complex "[0]tpad=start_duration=2:start_mode=add:color=black[bg];[bg][1]overlay" output.mp4