Skip to content

Instantly share code, notes, and snippets.

@JamesMcMahon
Forked from imkevinxu/vidtogif.sh
Last active June 17, 2016 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesMcMahon/c16b421afa539f8f1322708b3b8a8e02 to your computer and use it in GitHub Desktop.
Save JamesMcMahon/c16b421afa539f8f1322708b3b8a8e02 to your computer and use it in GitHub Desktop.
Convert an animated video to gif from http://chrismessina.me/b/13913393/mov-to-gif
#!/usr/bin/env bash
#
# Convert an animated video to gif
# Works best for videos with low color palettes like Dribbble shots
#
# @param $1 - video file name like `animation.mov`
# @param @optional $2 - resize parameter as widthxheight like `400x300`
#
# Example: vidtogif animation.mov 400x300
# Requirements: ffmpeg and gifsicle. Can be downloaded via homebrew
#
# http://chrismessina.me/b/13913393/mov-to-gif
basename=$(basename "$1")
filename="${basename%.*}"
if [ -n "$1" ]
then
mkdir pngs gifs
ffmpeg -i "$1" -r 10 pngs/frame_%04d.png
sips -s format gif pngs/*.png --out gifs/
cd gifs
if [ -z "$2" ]
then
gifsicle *.gif --optimize=3 --delay=3 --loopcount > ../$filename.gif
else
gifsicle *.gif --optimize=3 --delay=3 --loopcount --resize "$2" > ../$filename.gif
fi
cd ..
rm -rf pngs gifs
else
echo "Use video file as first parameter"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment