Skip to content

Instantly share code, notes, and snippets.

@vmrob
Created June 18, 2014 22:03
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 vmrob/27e4de2295c253edb7b3 to your computer and use it in GitHub Desktop.
Save vmrob/27e4de2295c253edb7b3 to your computer and use it in GitHub Desktop.
Converts a video to a gif
#!/bin/bash -e
# Converts a video to a gif
if [ "$#" -ne 2 ]; then
echo "usage: ${0##*/} [input video] [output gif]"
exit 1
fi
VIDEO=$1
GIF=$2
# finds width and height of $VIDEO expressed as 123x456
WIDTH_HEIGHT=$(ffprobe -loglevel warning -show_streams $VIDEO | grep -e "width\|height" | sed -E 's/(width|height)=//g' | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/x/g')
# converts the video
ffmpeg -i $VIDEO -s $WIDTH_HEIGHT -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > $GIF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment