ffmpeg overlay video on another video in specific time

3

1

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

BOB

Posted 2016-05-30T15:42:54.080

Reputation: 33

Answers

2

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

Gyan

Posted 2016-05-30T15:42:54.080

Reputation: 21 016

Thanks @Mulvya that's works fine but there is another problem founded if i overlay the video from 00:00 to 00:05 that's works fine but if i choose another time such as 00:10 to 00:15 it's overlay the last frame only from the top video, so how we can solve this issue – BOB – 2016-05-30T22:48:07.623

I think that's happen because the both video start play at 00:00 and the top video appears only at the specific time so i need to make the top video start playing at 00:10 not at 00:00 – BOB – 2016-05-30T22:48:23.093

hey bro, can i overlay more than one video in specific time with the same way? i'm search about it but i didn't find a good way to solve this issue – BOB – 2016-06-02T09:55:03.477

Add another overlay filter, where first input is the output of the previous overlay filter e.g. [out][2:v]overlay[out2] – Gyan – 2016-06-03T05:56:49.737

Thanks bro, i understand this solution, but can i do it in one command? – BOB – 2016-06-07T21:02:17.507