Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate gif from avi using ffmpeg? [closed]

Tags:

ffmpeg

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?

like image 802
Marconi Avatar asked May 21 '11 02:05

Marconi


People also ask

How do I convert video to GIF using FFmpeg?

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.

Does FFmpeg support 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.


1 Answers

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.

like image 94
Tommy Strand Avatar answered Sep 24 '22 03:09

Tommy Strand