delayed video overlay using ffmpeg

2

I am wanting 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 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

alter

Posted 2014-03-27T10:24:29.400

Reputation: 113

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 – 2014-03-29T12:46:48.070

Answers

5

To do this you need latest ffmpeg version (2.2). So you should run 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 second video to +7 sec (PTS-STARTPTS+7/TB) and then just overlay 2 streams.

ptQa

Posted 2014-03-27T10:24:29.400

Reputation: 1 599