Skip to content

Instantly share code, notes, and snippets.

@fnando

fnando/giffy

Last active Jul 1, 2020
Embed
What would you like to do?
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