ffmpeg commands:
Run this command so that ffmpeg can figure out a good palette:
ffmpeg -y -i foo.mp4 -vf fps=30,scale=320:-1:flags=lanczos,palettegen palette.png
Run this command to convert the mp4 file into gif:
ffmpeg -y -i foo.mp4 -i palette.png -filter_complex "fps=30,scale=320:-1:flags=lanczos[x];[x][1:v]paletteuse" foo.gif
You might want to tweak the fps and scale. Smaller for either will result in better file size.
Making a simple alias function
You can also create an alias function like this. I added it to my .bashrc
or .bash_profile
:
function makegif { ffmpeg -y -i $1 -vf fps=30,scale=320:-1:flags=lanczos,palettegen palette.png ffmpeg -y -i $1 -i palette.png -filter_complex "fps=30,scale=320:-1:flags=lanczos[x];[x][1:v]paletteuse" $1.gif}
And then just makegif foo
Note: You'll need ffmpeg of course. Get it here https://www.ffmpeg.org/download.html or brew install ffmpeg