How To Create Animated GIFs With FFmpeg

Learn to install and use this free video converter

Erik-Jan van Baaren
Feb 20 · 4 min read
Photo by Tim Mossholder on Unsplash

I use animated GIFs in my articles to show commands at work in my terminal, see here for an example. The beauty of an animated GIF is that it is embeddable on a webpage like any other image. There are no plugins or video tags needed, so it works on many devices and platforms.

If you want to teach or show your readers something, and don’t want to resort to YouTube to host a video of it, consider an animated GIF. Just keep in mind that animated GIFs are not the most efficient at storing video, so the file size can grow very quickly if you’re not taking the proper precautions.

So how do you create an animated GIF? You can find a plethora of video converters out there. I abandoned all these programs for an open-source and free tool called FFmpeg. FFmpeg is actually at the core of many video tools and websites.

The name is anything but attractive. That it is a command-line tool might put off even more people. But it’s not that difficult, and I’m convinced you can be up and running with FFmpeg by the end of this tutorial!

What is FFmpeg?

“FFmpeg is the leading multimedia framework, able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created. It supports the most obscure ancient formats up to the cutting edge. No matter if they were designed by some standards committee, the community or a corporation.”

Nothing about the above statement is a lie or exaggerated marketing speech. FFmpeg is in fact that awesome and feature-rich.

I’ll take a non-linear approach here and first show you what you can do with FFmpeg. If that convinces you, I’ll help you with the installation at the end of this article.

How to create animated GIFs

Windows 10 also includes a way to record your screen, read more about it here. On Linux, you can use a tool like Kazam or SimpleScreenRecorder.

While writing this article, I created a small video of myself typing. It resulted in an 887K MOV file. I converted that to a GIF:

ffmpeg -i me-writing.gif

Now that’s not too complicated, right? The -i option stands for “input file”. FFmpeg detected the input type and guessed the requested output format based on the extension .gif.

The result is a 387K GIF file. That’s not bad. We can reduce the file size even more by reducing the frame rate to 4 frames per second, which is enough for a simple video with very little action:

ffmpeg -i -r 4 me-writing-r4.gif

As you may have guessed, -r means “frame rate”. The result is a 146K file. Now we’re getting somewhere! We can reduce it further, with some down-scaling:

ffmpeg -i -r 4 -vf scale=640:-1 me-writing-r4–640.gif

We scaled the video to a width of 640. FFmpeg calculates the height for us because we entered -1. It will keep the aspect ratio of the original video.

Our file is now 110K. Not bad! We went from an 887K video to a 110K animated GIF, without losing information. Here’s the result:

It’s me, writing this article!

You now have the basics to create animated GIFs and make your articles stand out! You can play with the parameters to find the sweet spot for the video you made. A frame rate of 4 will not work for everything, but perhaps 8 is enough to get the point across and still reduce your file considerably.

Installing FFmpeg


brew install ffmpeg




  • Capture only that which is necessary to get the point across. The smaller the area, the smaller your GIF will be
  • Reduce the frame rate as much as possible
  • Rescale to video to smaller dimensions

The Startup

Medium's largest active publication, followed by +609K people. Follow to join our community.

Erik-Jan van Baaren

Written by

A writer at heart and software/data engineer by profession. Subscribe to my low-volume newsletter at

The Startup

Medium's largest active publication, followed by +609K people. Follow to join our community.

More From Medium

More from The Startup

More from The Startup

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade