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.

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.