Skip to content

Instantly share code, notes, and snippets.

@jamesknelson jamesknelson/README.md
Last active Oct 3, 2019

Embed
What would you like to do?
Convert a video into a gif

A 4-line shell script to convert your movies into gifs. Defaults to 10fps, 700px wide.

WIDTH=420 FPS=12 togif input.mov

You'll need to have ffmpeg installed -- on mac, you can do this with brew:

brew install ffmpeg

Assuming you have /usr/local/bin in your path, you can install the script by copying/pasting this into your shell:

cat >> /usr/local/bin/togif <<EOL
FILENAME="\${1%.*}"
WIDTH=\${WIDTH:-700}
FPS=\${FPS:-12}
ffmpeg -i \$1 -filter_complex "[0:v] fps=\$FPS,scale=\$WIDTH:-1,split [a][b];[a] palettegen [p];[b][p] paletteuse" \$FILENAME.gif
EOL
chmod +x /usr/local/bin/togif

For details on how this works, see:

https://engineering.giphy.com/how-to-make-gifs-with-ffmpeg/

FILENAME="${1%.*}"
WIDTH=${WIDTH:-700}
FPS=${FPS:-12}
ffmpeg -i $1 -filter_complex "[0:v] fps=$FPS,scale=$WIDTH:-1,split [a][b];[a] palettegen [p];[b][p] paletteuse" $FILENAME.gif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.