Instantly share code, notes, and snippets.

@vmrob vmrob/convert.sh
Created Jun 18, 2014

Embed
What would you like to do?
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