I have already written about how to create animated GIFs online and how to optimize animated GIFs for use on the web. But you can also create animated GIFs from any video file at home, for free, and without using any online tools.
What will you learn in this post?
I will show you:
- how to convert full videos to animated GIFs
- how to convert only parts of videos to animated GIFs
- how to change FFmpeg’s settings to compress the size of the output animated GIF
- how to convert animated GIFs to WebM format to save hard drive space
Converting Video Files to Animated GIFs
All you need is the free, open-source, and fantastic ffmpeg software package.
I use the portable version (called a static build) for Windows:
You will need to unpack FFmpeg’s files to a dedicated portable folder on your hard drive. I recommend using 7-zip for this job.
Next, you need to copy the executable file called
In the Command Prompt window, first navigate to the location of the video files and ffmpeg.exe (using the
ffmpeg -i input.mp4 ani.gif
The above command simply converts the whole original MP4 video file to an animated GIF.
Creating Animated GIFs from Specific Parts of Video Files
In reality, most people want to use only a small portion of the input video file and convert that to an animated GIF.
This can be achieved by adding further parameters to the above ffmpeg command:
ffmpeg -i input.mp4 -ss 202 -t 8.5 ani.gif
In this case I am only converting an 8.5 second long segment of the input MP4 file starting at 202 seconds (3 minutes and 22 seconds) into the file.
Alternatively, you can use the following variation of the command, in case you don’t want to convert the starting point to seconds:
ffmpeg -i input.mp4 -ss 3.22 -t 8.5 ani.gif
Reducing the Size of the Output GIF File
The original MP4 file I was converting was recorded at full HD resolution, i.e. 1920 × 1080 pixels. Thus, the resulting GIF file was extraordinarily large at more than 26 megabytes.
Therefore, I needed to reduce the file size of the GIF.
The first thing to do was to reduce the resolution of the GIF:
ffmpeg -i input.mp4 -y -s 640x360 -ss 202 -t 8.5 ani.gif
-y parameter tells ffmpeg to overwrite the currently existing ani.gif file.
This helped because the GIF’s file size was reduced to 10 megabytes. But that was still a bit much for me.
Next, I reduced the GIF’s framerate to 10 frames per second:
ffmpeg -i input.mp4 -y -r 10 -s 640x360 -ss 202 -t 8.5 ani.gif
This compressed the GIF’s size to less than 4.5 megabytes.
That was good enough for me — I managed to drive down the animated GIF’s file size by 83% without any noticeable loss of quality.
All GIFs are set to an infinite loop by default. To turn the looping off, use this command:
ffmpeg -i input.mp4 -y -r 10 -s 640x360 -ss 202 -t 8.5 -loop -1 ani.gif
And the very last thing I did was to try and reduce the quality of the output GIF a bit:
ffmpeg -i input.mp4 -y -q:v 30 -r 10 -s 640x360 -ss 202 -t 8.5 ani.gif
-q:v parameter has no effect on output GIFs, it only matters to video output formats such as MP4, MOV, AVI, WMV, and so on.
Convert the Animated GIF to WebM
To further optimize the file size, you can convert the animated GIF you just created to the WebM format.
The easiest way to do so is to use the online service called gfycat.com.
My animated GIF came in at less than 4.5 megabytes, yet the WebM version was only 1.6 megabytes. A further saving of 65% on the file size.
I estimate that the MP4 segment took up about 126 megabytes. So, the final GIF was a 96.4% reduction in file size. And the WebM was a 99% reduction in file size.
Liked this post?
Subscribe to our newsletter to receive early notification of new posts and deals: