Search code examples
ffmpeganimated-gif

gifs not loops in ffmpeg movie filter


I have a gif that loops infinite(loop.gif). I want to overlay this gif to top left corner of video.mpg. So I am using this code to make this:

ffmpeg -i video.mpg -vf "movie=loop.gif [logo]; [in][logo] overlay=10:10 [out]" -vcodec mpeg2video out.mpg

The problem is; gif loops only 1 time and last frame of the gif showing until end of video.mpg.

How can I loop this gif continuously?


Solution

  • Use the -ignore_loop option from the GIF demuxer:

    ffmpeg -i video.mp4 -ignore_loop 0 -i loop.gif -filter_complex "[0:v][1:v]overlay=10:10:shortest=1" output.mp4
    
    • See the GIF demuxer documentation or run ffmpeg -h demuxer=gif for more options.
    • No need to use the movie source filter.
    • This example uses the shortest option in the overlay filter. Otherwise the encoding will run indefinitely due to the looping GIF.