Converting an .mp4 to a .gif using ffmpeg

- Posted in productivity workflow

Today I was converting an mp4 video to a gif and I figured I’d document some commands that helped in the process. I used ffmpeg to do this. You can install it on Mac or Linux using homebrew:

brew install ffmpeg

For optimal quality, generate a color pallette based on a timestamp in the video:

ffmpeg -ss 00:00:00 -t 1 -i video.mp4 -filter_complex "[0:v] palettegen" palette.png  -frames:v 1

This will generate a palette.png in the local folder. Now you can use that, to generate a gif:

ffmpeg -i video.mp4 -i palette.png  -r 30 'final-gif.gif' -filter_complex "paletteuse"

The command takes an mp4 and the generated pallette.png as inputs, as well as a framerate (30 in this case) via the r argument.

Leave a Reply

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