How to generate gif from avi using ffmpeg? [closed

2019-01-20 23:31发布

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
2条回答
Juvenile、少年°
2楼-- · 2019-01-21 00:03

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

查看更多
放我归山
3楼-- · 2019-01-21 00:17

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.

查看更多
登录 后发表回答