Skip to content

Instantly share code, notes, and snippets.

@fnando
Last active July 1, 2020 02:30
  • Star 17 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fnando/5710396 to your computer and use it in GitHub Desktop.
Export video files as GIF
#!/usr/bin/env bash
if [[ ! -f "$1" ]]; then
echo "=> Movie file not found"
exit 1
fi
tempfile=/tmp/output.gif
rm -f $tempfile
echo "=> Converting $1 to GIF"
ffmpeg -i "$1" -pix_fmt rgb24 "$tempfile" > /tmp/giffy.log 2>&1
if [[ ! -f "$tempfile" ]]; then
echo "=> Error while converting $1 to GIF"
echo "=> Check the file /tmp/giffy.log"
exit 1
fi
filename=$(basename "$1")
filename="${filename%.*}"
dir=$(dirname "$1")
output="$dir/$filename.gif"
echo "=> Exporting optimized GIF to $output"
convert -layers Optimize "$tempfile" "$output" > /tmp/giffy.log 2>&1
if [[ ! -f "$output" ]]; then
echo "=> Error while exporting $output"
echo "=> Check the file /tmp/giffy.log"
exit 1
fi
rm $tempfile
echo "=> Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment