Skip to content

Instantly share code, notes, and snippets.

@jamesknelson
Last active August 20, 2022 22:21
Show Gist options
  • Save jamesknelson/caa15ba30c8ca7d2bfaebdf442101dc4 to your computer and use it in GitHub Desktop.
Save jamesknelson/caa15ba30c8ca7d2bfaebdf442101dc4 to your computer and use it in GitHub Desktop.
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