3

How do I convert animated gifs to mp4s that loop?

This command successfully converts the gifs to mp4s, but the loop doesn't appear to work:

for i in *.gif; do ffmpeg -f gif -i "$i" -loop 0 "0output$i.mp4"; done

When I play the resulting mp4s in SMPlayer it will only loop if I set SMPlayer to repeat, but then SMplayer has a jitter between repeats so it doesn't repeat smoothly.

5 Answers 5

3

You can make a looping GIF by setting a bit in the header of the file (been doing that since 1989), but there is no such facility that I know of in the .mp4 files. For them looping is controlled via an additional, player dependent, file.

The absence of that also is the reason why you don't have any looping .mp4 on YouTube.

1

You cannot loop .mp4 files, but as a workaround you can use e.g. -loop 5 to multiply the animation in the resulting .mp4 file 5 times. This will result in 5 times bigger file, but you will not have any jitter between these 5 animations.

1

I would just convert the gif to a MP4 FIRST and then loop it about 100 times. The basic idea is the same but from the obvious approach it does not seem to work that well to feed multiple gif animations in the transcoder. Instead of doing that just convert one and then repeat the results as many times as needed.

1

First, convert the GIF into a [high-quality] video

ffmpeg -i anim.gif -crf 12 -pix_fmt yuv420p anim-single.mp4

Then, make a new video with multiple loops of the single

ffmpeg -i anim-single.mp4 -filter_complex "loop=120:9999" anim-final.mp4

Tested today in ffmpeg version 4.1.3

1

Found this while looking for a way to loop multiple gifs in a set order. If you don't mind telling it how many seconds you want it to loop for

ffmpeg -ignore_loop 0 -t 50 -i giphy.gif -pix_fmt yuv420p output.mp4

Where -t 50, 50 is the number of seconds long the video will be.

You must log in to answer this question.

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