Create a Short Animated GIF from Any Video File

happy-kitten

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:

Download a Windows build of Zeranoe FFmpeg

Download a Windows build of Zeranoe FFmpeg

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 ffmpeg.exe located in the ffmpeg\bin subfolder to wherever the video file you want to convert is located.

Then launch Command Prompt via Start > All Programs > Accessories.

In the Command Prompt window, first navigate to the location of the video files and ffmpeg.exe (using the cd command), then type and enter the following command:

The above command simply converts the whole original MP4 video file to an animated GIF.

Tip

Only convert whole video files, if they are short. Otherwise, the resulting animated GIFs will be extremely large in file size.

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:

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:

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:

The additional -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:

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:

And the very last thing I did was to try and reduce the quality of the output GIF a bit:

However, the -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.

The Results

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.

Pretty cool!

Liked this post?

Subscribe to our newsletter to receive early notification of new posts and deals:

Next Post »« Previous Post

Leave a Reply

Your email address will not be published. Required fields are marked *