Skip to content

Instantly share code, notes, and snippets.

@shivakar
Created May 24, 2017 02:54
Show Gist options
  • Save shivakar/0cc1474f9716dfaf643cb62a9365957e to your computer and use it in GitHub Desktop.
Save shivakar/0cc1474f9716dfaf643cb62a9365957e to your computer and use it in GitHub Desktop.
Create GIF from a video using ffmpeg and gifsicle
#!/usr/bin/env bash
if [ $# -ne 2 ]; then
echo "$0 - Creates a GIF from a video using ffmpeg and gifsicle"
echo "Usage: $0 <input-filename> <output-filename>"
exit
fi
infile="${1}"
outfile="${2}"
# Check if input file exists
if [ ! -f ${infile} ]; then
echo "Input file - ${infile} - does not exist. Aborting..."
exit
fi
# Check if output file exists
if [ -f ${outfile} ]; then
echo "Output file - ${outfile} - already exists."
echo "Please delete output file before proceeding. Aborting..."
exit
fi
## Run the conversion
ffmpeg -i "${infile}" -pix_fmt rgb24 -r 5 -f gif - | gifsicle --optimize=3 > "${outfile}"
echo "Done with conversion."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment