14

I want to overlay multiple images (Say 5) in a 120 second video at specified intervals , like, between 3-7 seconds overlay image 1. Is is it possible without splitting the video in multiple parts?

hack
  • 1,403
  • 2
  • 14
  • 20

2 Answers2

26

Basic method is

ffmpeg -i video -i image1 -i image2 -i image3
 -filter_complex
    "[0][1]overlay=x=X:y=Y:enable='between(t,23,27)'[v1];
     [v1][2]overlay=x=X:y=Y:enable='between(t,44,61)'[v2];
     [v2][3]overlay=x=X:y=Y:enable='gt(t,112)'[v3]"
-map "[v3]" -map 0:a  out.mp4

The last image will be overlaid from t=112 seconds till end of video.

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • Thanks. It is working. But there is a visible difference in quality of the video generated as output. – hack Mar 22 '17 at 08:48
  • 1
    Insert `-crf 18` after the filter the complex. I assume you have libx264 in your ffmpeg build. – Gyan Mar 22 '17 at 09:30
  • if i have a single image to be overlapped at multiple intervals, will i have to specify it in input multiple times? – hack Mar 22 '17 at 15:06
  • No. Just reuse the same input pad e.g. `[1]`. – Gyan Mar 22 '17 at 15:09
  • Hi. In this command, can we specify the input images to be overlayed in a text file? The final command getting generated is very very long. I have already put the complex filters in a script. – hack Mar 30 '17 at 04:24
  • It should be possible. – Gyan Mar 30 '17 at 04:51
  • Thanks. How to specify input pad in this case? Like i have 3 image path in a text file, how can we tell that overlay 1st image for these much seconds, 2nd for these seconds? – hack Mar 30 '17 at 04:59
  • I am also doing the same, however my need is to be millisecond precise. There i find it hard to see precise timing in image overlay. Do you have any suggestion for me? Please see my post https://stackoverflow.com/questions/45818266/precise-image-overlay-over-video-using-ffmpeg – Sunny Tambi Aug 22 '17 at 12:56
  • @Mulvya by using this command all images will appear 23 to 27(image1) after 27 second image1 disable and image2(44 to 61) enable and then disable at 61 sec and so on am i right? but in my case after showing first image other images can not visible – ND1010_ Mar 19 '18 at 11:00
  • Post a new Q with your full command and console output at SuperUser. – Gyan Mar 19 '18 at 11:42
  • hey @Mulvya i have asked question Link[https://stackoverflow.com/questions/49363053/ffmpeg-overlay-multipe-videos-over-video-at-specified-interval-of-time] – ND1010_ Mar 19 '18 at 12:35
2

The following code is working to create a video with multiple overlay images with specified duration.

ffmpeg -i video -i image1 -i image2 -i image3 
-filter_complex
"[0][1]overlay=y=H-h:enable='between(t,2,4)'[v1];
 [v1][2]overlay=y=H-h:enable='between(t,6,8)'[v2];
 [v2][3]overlay=y=H-h:enable='between(t,8,10)'[v3]"
-map "[v3]" outputVideo.mp4
Thomas Kekeisen
  • 4,355
  • 4
  • 35
  • 54
Puratchi
  • 29
  • 3