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?
Converting a Part of the Video-ss tells FFmpeg to seek x seconds into the input file. -t tells FFmpeg to read in y seconds of the input video and then stop. For example, the command below will trim 1.8 seconds from 00:23 ↗ of the video and convert it to a GIF.
By default, FFmpeg uses a generic 256 color palette for every gif encoding. As a result, the output we get after converting the video is suboptimal. However, we can use FFmpeg itself to generate a custom palette of 256 colors created specifically for our video.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With