Ffmpeg overlay video on another video in specific time

ffmpegoverlayvideovideo conversion

I have video with duration 01:30 min and i have another video with duration 00:50 sec i want to overlay the second video on the top of the first video at 00:45 to 00:50

i'm trying to use this command but it doesn't work

ffmpeg -i D:\ffmpeg\base_video.mp4 -i D:\ffmpeg\top_video.avi  -filter_complex "[0:0][1:0]overlay[out]" -shortest -map [out] -map 0:1 -pix_fmt yuv420p -c:a copy -c:v libx264 -crf 18  D:\ffmpeg\final_video.mp4

any suggestions please?

Thanks

Best Answer

  • You have to use the enable option:

    ffmpeg -i D:\ffmpeg\base_video.mp4 -i D:\ffmpeg\top_video.avi  -filter_complex \
            "[0:0][1:0]overlay=enable='between(t\,45,50)'[out]" \
           -shortest -map [out] -map 0:1 \
           -pix_fmt yuv420p -c:a copy -c:v libx264 -crf 18  D:\ffmpeg\final_video.mp4
    

    To delay the start of the top video, use the setpts filter.

    ffmpeg -i D:\ffmpeg\base_video.mp4 -i D:\ffmpeg\top_video.avi  -filter_complex \
            "[1]setpts=PTS-STARTPTS+10/TB[top];
            [0:0][top]overlay=enable='between(t\,10,15)'[out]" \
           -shortest -map [out] -map 0:1 \
           -pix_fmt yuv420p -c:a copy -c:v libx264 -crf 18  D:\ffmpeg\final_video.mp4
    
  • Related Question