'FFMpeg Add multiple Gifs/Watermarks to a video

I'm trying to add various Gifs/Watermarks to a video, but I'm having a problem getting it to work properly.

We're assuming the video is 60 seconds long and I'm adding one Gif image. The output looks correct, the sound is on, the gif animates, and the video doesn't stop. here is the code:

            add("-i")
            add("inputVideo.mp4")
            add("-stream_loop")
            add("-1")
            add("-i")
            add("gif_1.gif")
            add("-filter_complex")
            add("[0][1]overlay=x=18:y=461:shortest=1[out]) 
            add("-map")
            add("[out]")
            add("-map")
            add("0:a?") 
            add("-qscale:v")
            add("1")
            add("-preset")
            add("ultrafast")
            add("outputVideo.mp4")

When I try to add multiple GIFs, the video plays and the sound is on, one GIF animates, but the rest of the GIFs finish animating very early. this is the code

            add("-i")
            add("inputVideo.mp4")
            add("-stream_loop")
            add("-1")
            add("-i")
            add("gif_1.gif")
            add("-i")
            add("gif_2.gif")
            add("-i")
            add("gif_3.gif")
            add("-filter_complex")
            add("[0][1]overlay=x=47:y=106:shortest=1[t1];[t1][2]overlay=x=551:y=1190[t2];[t2][3]overlay=x=-82:y=1279[out]) 
            add("-map")
            add("[out]")
            add("-map")
            add("0:a?") 
            add("-qscale:v")
            add("1")
            add("-preset")
            add("ultrafast")
            add("outputVideo.mp4")

What can I do to have all random GIFs added to animate while the video is playing for the full 60 seconds?



Solution 1:[1]

Use pattern matching feature of image2 format

Instead of

-stream_loop -1 -i gif_1.gif -i gif_2.gif -i gif_3.gif

try

-framerate 1 -i gif_%d.gif

This will sequentially show gif_1.gif, gif_2.gif, gif_3.gif etc., 1 second apart. To change the display duration, set -framerate to 1/duration (so 0.5 for 2 seconds, 0.1 for 10 seconds, etc.)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kesh