Converting an .mp4 to a .gif using ffmpeg
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 ffmpegFor 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 1This 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.
As the founder of Obra Studio, Johan's mission is to help software companies get to the next design level. He’s forever looking for the perfect balance between aesthetics and usability.