So, you’ve spent countless hours crafting a video in your favourite video software and it looks amazing. The only step left is making a GIF file. Sounds like the easiest part, right? But this is where all the fun begins.
There are a couple of ways to get this done – you can use online converters, Photoshop, or some other speciality tools.
These options are all fine, but let’s get down to some serious business.
FFmpeg is a command line tool that is a complete cross-platform solution to record, convert and stream audio and video.
You will need some knowledge of the command line or terminal to do this – but if you don’t , don’t worry, I’ve got you covered. Just follow along with the instructions.
In this example I will be using FFmpeg on Windows to convert a sample video to a GIF.
You can download a Windows build of FFmpeg from Zeranoe.
All builds require at least Windows 7. After downloading the zip file extract, it to your computer.
Navigate to the folder where you extracted the FFmpeg build and open the
bin folder. This is the folder that contains the FFmpeg executable that we will be using to convert the video to a GIF.
Find the video you want to convert and move it into the
The size, dimensions and FPS of your input video will determine the output size of your GIF.
The video example I’m using has a width of 480px and a height of 270px and a framerate of 24. This will match the output size of my GIF.
bin folder hold the Shift key and press right click, and select “Open PowerShell window here”.
This will open the PowerShell terminal in the bin folder that contains the FFmpeg executable that we will be using to convert the video to a GIF.
We generate a colour palette from the video to be used to generate a high quality GIF from our video.
Run the following command in your terminal to generate a colour palette file:
.\ffmpeg.exe -i example.mp4 -vf "fps=12,scale=480:-2:flags=lanczos,palettegen" palette.png
Here’s an explanation of the options used in the above command. You can look up the available commands for FFmpeg on the official FFmpeg Documentation.
example.mp4 is the video file you want to convert
fps is the frame rate you need in your GIF. I use half of the frame rate of the input video.
scale explicitly asks FFMPEG to resize the video
palette.png is your output palette file
Now we are ready to convert the video to a GIF.
Run the following command in your terminal to convert the video to a GIF.
.\ffmpeg.exe -i example.mp4 -i palette.png -filter_complex "fps=12,scale=480:-2:flags=lanczos[x],[x][1:v]paletteuse" output.gif
Here’s an explanation of the options used in the above command.
example.mp4 is the same input file we used for color palette generation
palette.png is the result of the previous step
fps should stay the same
output.gif is our output GIF
Here’s our result:
The file size comes to just below 10 MB. This is pretty good for a GIF that is 8 seconds long.
You can always go ahead and tweak the FPS and repeat steps 4 and 5 to get a smaller file size.
I hope this has been a useful breakdown of how to use FFmpeg to convert a video to a GIF.