Convert an mp4 video to an animated gif with Ffmpeg

26 June 2025

Convert an mp4 video to an animated gif with Ffmpeg

If you want to convert an mp4 video file in to an animated gif, all you have to do is a quick search, and your search engine will show you a ton of websites that can do this for you. Many websites out there offer this service for free, which is great of course, but I always find there to be certain limitations that I don't care for much. Often the output file is of a lower resolution, or it can only be a couple of seconds long, or it has added a watermark that ruins the gif completely. What if I told you that you can use a really simple command for Ffmpeg to convert your video to gif, without any of the hassle? There are different ways to create a gif from our mp4, and I'll start by showing the quick and dirty way first. Be aware that the results of this first method are often not as good as you might be expecting.

ffmpeg -i input.mp4 -vf "fps=25,scale=iw:ih" output.gif

This pretty much speaks for itself right? Simply replace input.mp4 with the filename of your video file. Be aware that you will need to add "" to the filename when the filename contains any spaces. Optionally you can specify the filename for the gif file. Like I mentioned earlier, the results of this method may vary, and not up to your wishes.

This next method is a lot better, and you should use this one in nearly all situations. It does add an extra step, but that shouldn't be a reason not to use this method.

ffmpeg -i input.mp4 -vf "fps=25,scale=iw:ih:flags=lanczos,palettegen" palette.png

This extracts the color palette from the source mp4 file, stores it in a .png file, so it can be used as input to create a much better gif in the end. Once it has created the png file, you can proceed to this next step shown below.

ffmpeg -i input.mp4 -i palette.png -filter_complex "fps=25,scale=iw:ih:flags=lanczos[x];[x][1:v]paletteuse" output.gif

Note that we added the palette png we just created to the input variables. This method may take a second or two longer, but the results are certainly worth it. Give it a try yourself, you'll be amazed by how much this improves the quality of the gif.

These two images really show the difference in quality. It can best be noticed when you take a close look at the background.

Pick a star to rate this
Table of Contents

Leave a Reply

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

Unrelated Content

26 June 2025
Why Self-Hosting Your Livestream Is Safer, Cheaper, and More Flexible Than Commercial Platforms

With livestreaming more popular than ever, platforms like YouTube Live, Twitch, Vimeo, and Facebook Live have become household names. But are they really the best option for everyone? If you're a tech-savvy creator, a privacy-conscious broadcaster, or someone who just wants full control, self-hosting your own livestream server might be a better choice. In this […]

READ MORE
27 November 2020
Motivation behind this website

For every service that is offered for a lot of money on the internet, there's always a free or much cheaper alternative, especially if you embrace open-source software. For live-streaming this is also very much the case. We love that,

READ MORE
23 January 2021
Introduction to the new how-to article in the Knowledge Base.

I wrote a new guide on setting up your own live-stream server. Mostly due to your requests. I took the opportunity to simplify and shorten the guide a bit. If you follow this guide step by step, and use your brain a tiny bit, you'll be fine. This guide has so far been tested on […]

READ MORE
25 January 2021
Optimizing First-Frame Bitrate for HLS

When responding to an HLS request, the streaming server determines which video quality (i.e., ts file) the client will attempt to play before switching to a lower or higher quality video. This switch depends on available bandwidth and device type. Switching to the wrong quality first degrades the user experience considerably. For instance, sending a […]

READ MORE
25 January 2021
Adaptive Bit-rate Streaming

“What is adaptive streaming?” This question often leads to answers filled with technical terms like “HLS”, “MPEG-DASH”, “segments” and “codec“. This article is written for people who need to understand the principles, but don’t need to actually implement the technology. If you are looking for specific technical information on adaptive streaming then I recommend you read up on it on this website and elsewhere.

READ MORE
2 February 2021
About Bradmax Video Player WordPress plugin

Let's talk about our favorite video player plugin for WordPress. Here are some reasons why Bradmax Player is our favorite. And below that are detailed instructions on how to set it up. Setting it up may at first seem a bit awkward, but it really isn't. First you must obviously install the Bradmax Player plugin […]

READ MORE
Copyright © 2025. 
All rights reserved.
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram