How to generate gif from avi using ffmpeg?

Ffmpeg

Ffmpeg Problem Overview


I'm trying to extract a part of a video into an animated gif using the following command:

ffmpeg -i video.avi -t 5 out.gif

It generates an animated gif but the quality is insane. However when I generate gif image using:

ffmpeg -i video.avi -t 10 out%d.gif

It generates acceptable quality of gif images. How can i generate animated gif using the first command but the same quality as the second command?

Ffmpeg Solutions


Solution 1 - Ffmpeg

I had a similar problem trying to generate high quality animated gif from a series of images extracted from a movie.

For some reasons the animated gif generated with ffmpeg only contains 103 colors assumable using a fixed 256 level system color palette resulting in horrific result. My solution was instead

ffmpeg -i video.avi -t 10 out%02d.gif

then

gifsicle --delay=10 --loop *.gif > anim.gif

Quality is then quite good. You can find gifsicle here

Edit: Updated the post to reflect Alex Kahn's suggestions.

Solution 2 - Ffmpeg

I haven't made an animated GIF before but you might try using the bit-rate parameter to specify quality, in spite of it being an image (and presumably having no rate). Thumbnail quality responds to the -b parameter. If by insane, you mean, "insanely bad," you can specify a very high bitrate and bitrate tolerance (not sure if you're using vbr or cbr source). (or do the opposite if you mean it's too good and you want to limit size)

'-b', '10000000','-bt', '20000000'

Alternatively, you could also change the dimensions using the -s parameter, which will take an ordinary looking representation of the dimensions like "1920X1200".

It really depends on the bitrate and compression of your source material and what you hope the gif will be like. Maybe consider providing more info than "insane," but I imagine this will give you a good start either way. Good luck

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMarconiView Question on Stackoverflow
Solution 1 - FfmpegTommy StrandView Answer on Stackoverflow
Solution 2 - FfmpegProfaneView Answer on Stackoverflow