Skip to content

Instantly share code, notes, and snippets.

@plasticine
Created January 22, 2015 06:32
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 plasticine/460a757d5337cfb3e45a to your computer and use it in GitHub Desktop.
Save plasticine/460a757d5337cfb3e45a to your computer and use it in GitHub Desktop.
Command line tool to convert video files to GIF
#!/usr/bin/env bash +x
#
# Compress video files into GIFs.
#
# Requirements:
# - ffmpeg
# - imagemagick
# - terminal-notifier
# - gifsicle
#
# Installing requirements:
# brew install ffmpeg imagemagick terminal-notifier gifsicle
set -eo pipefail
gifsicle_bin="/opt/boxen/homebrew/bin/gifsicle"
notifier_bin="/opt/boxen/homebrew/bin/terminal-notifier"
ffmpeg_bin="/opt/boxen/homebrew/bin/ffmpeg"
convert_bin="/opt/boxen/homebrew/bin/convert"
tmpdir=$(mktemp -d /tmp/jiffy.XXXXXXX)
notify() {
$notifier_bin -title "Jiffy" -subtitle "$1" -message "$2"
}
dump() {
$ffmpeg_bin -i "$1" -r 10 -vcodec png "$tmpdir/frame-%05d.png"
}
convert() {
$convert_bin -verbose +dither -layers Optimize -resize 600x600 "$tmpdir/frame*.png" "$tmpdir/output.gif"
}
compress() {
$gifsicle_bin --colors 128 --delay=5 --loop --optimize=4 --output="$tmpdir/output.gif" "$tmpdir/output.gif"
}
cleanup() {
rm -rf "$tmpdir"
}
main() {
trap cleanup EXIT
local input_path="$1"
local output_path="$1.gif"
{
time(
notify "Converting to GIF..." "$input_path"
dump $input_path
convert
compress
notify "All done!" "$input_path"
mv "$tmpdir/output.gif" "$output_path"
)
} 2>&1
}
main $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment