Skip to content

Instantly share code, notes, and snippets.

@jkimbo
Last active June 7, 2016 00:34
Show Gist options
  • Save jkimbo/0496077d32433023b651 to your computer and use it in GitHub Desktop.
Save jkimbo/0496077d32433023b651 to your computer and use it in GitHub Desktop.

Requirements

~> brew install ffmpeg
~> brew install imagemagick

Usage

~> gifit ~/Desktop/pull-refresh.mov

pull-refresh.gif should now be in ~/Desktop

To change the gif size use the -s param.

~> gifit -s 800 ~/Desktop/pull-refresh.mov
#!/usr/bin/env bash
# vim: set filetype=sh:
#
# Credit: https://gist.github.com/henriquea/6dac86ed357e036a1dd4
#
set -e
PROGRAM="${0##*/}"
show_help() {
cat <<_EOF
Usage:
$PROGRAM <MOV_FILE> [-s SCALE]
_EOF
}
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
TEMP_DIR=`mktemp -d -t gifit`
SCALE=400
while getopts "h?s:" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
s) SCALE=$OPTARG
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
ffmpeg -i "$1" -vf scale=$SCALE:-1 -r 10 $TEMP_DIR/gif%3d.png
FILENAME=${1##*/}
DIR=`dirname $1`
convert \
-delay 8 \
-dither none \
-coalesce \
-layers optimize \
-depth 8 \
-colors 128 \
-loop 0 \
$TEMP_DIR/gif*.png \
"$DIR/${FILENAME%.*}.gif"
rm -rf $TEMP_DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment