Skip to content

Instantly share code, notes, and snippets.

@riccardobl
Last active February 4, 2016 17:24
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 riccardobl/a0a07a94e32e11e84df7 to your computer and use it in GitHub Desktop.
Save riccardobl/a0a07a94e32e11e84df7 to your computer and use it in GitHub Desktop.
Convert a video to a gif file.
#!/bin/bash
#
# Usage: video2gif myvideo.mp4
#
temp_dir=/tmp/video2gif-`tr -dc A-Za-z0-9 < /dev/urandom | head -c 8`
echo "Using temp directory $temp_dir"
mkdir "$temp_dir"
ffmpeg -i "$1" -r 15 -vf scale=-1:-1 "$temp_dir/frame-%04d.gif"
convert -delay 1x15 -loop 0 "$temp_dir/frame-*.gif" "$temp_dir/animation.gif"
mv "$temp_dir/animation.gif" "$1.gif"
rm -Rf "$temp_dir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment