4

I want to overlay one video onto another, but with a delayed appearance. I have:

  • source1.mp4 which is of duration 20 sec.
  • source2.mp4 which is of duration 5 sec.

I want to create a final output in which source2.mp4 overlaps source1.mp4 from 00:00:07 to 00:00:12. How can I achieve this?

I have tried the following commands, but none of these serve what I want:

ffmpeg -i source1.mp4 -itsoffset 7 -i source2.mp4 -map 0:0 -map 1:1 -c copy -y output.mp4

ffmpeg -itsoffset 7 -i source2.mp4 -i source1.mp4 -filter_complex 'overlay=0:0' output.mp4

ffmpeg -i source1.mp4 -i source2.mp4 -filter_complex "overlay" -strict -2 output.mp4
1
  • I asked this on both sites because it was confusing whether or not it is a programming related question. However I have still not received any answer on either site for this question.
    – alter
    Commented Mar 29, 2014 at 12:46

1 Answer 1

6

To do this, you need the latest FFmpeg version (2.2). So you should run a command like

ffmpeg -i sample1.mp4 -i sample2.mp4 -filter_complex "[0:v]setpts=PTS-STARTPTS[v0];[1:v]setpts=PTS-STARTPTS+7/TB[v1];[v0][v1]overlay=eof_action=pass[out1]" -map [out1]  /tmp/final.mp4

The trick is to set PTS for the second video to +7 seconds (PTS-STARTPTS+7/TB) and then just overlay the two streams.

2
  • 1
    When I try this approach, both videos end up being delayed, holding on the start frame until 7 seconds go by. Shouldn't this only have such an effect on the 2nd video input, and not both video inputs?
    – Sam
    Commented Aug 3, 2020 at 21:08
  • @Sam setpts more often than not does not work as intended. Use -itsoffset instead for example as described at superuser.com/questions/1595428
    – Davide
    Commented Apr 15 at 3:41

You must log in to answer this question.

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