Quantcast
Channel: How do I convert a video to GIF using ffmpeg, with reasonable quality? - Super User
Viewing all articles
Browse latest Browse all 19

Answer by Aphex for How do I convert a video to GIF using ffmpeg, with reasonable quality?

$
0
0

ffmpeg commands:

  1. 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
  2. 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


Viewing all articles
Browse latest Browse all 19

Trending Articles