Skip to content

Instantly share code, notes, and snippets.

@raydog
Last active August 26, 2016 00:31
Show Gist options
  • Save raydog/6c2f38df53d0c8eb03ef7f993e1ffef8 to your computer and use it in GitHub Desktop.
Save raydog/6c2f38df53d0c8eb03ef7f993e1ffef8 to your computer and use it in GitHub Desktop.
Converts a mov file (most video formats actually) into a reasonable gif
#!/bin/bash
if [ -z "$1" ] ; then
echo "Usage: $0 <mov_file>"
exit 1
fi
MOVFILE="$1"
GIFFILE="$(basename "$MOVFILE" .mov).gif"
TEMPDIR="$(mktemp -d)"
echo "============================"
echo "INPUT: $MOVFILE"
echo "OUTPUT: $GIFFILE"
echo "TEMP: $TEMPDIR"
echo "============================"
LOGLVL="-v warning"
PALETTE="$TEMPDIR/palette.png"
FILTERS="fps=10,scale=640:-1:flags=lanczos"
echo "[ Creating palette ]"
ffmpeg $LOGLVL -i "$MOVFILE" -vf $FILTERS,palettegen -y "$PALETTE"
echo "[ Compiling video ]"
ffmpeg $LOGLVL -i "$MOVFILE" -i "$PALETTE" -lavfi "$FILTERS [out]; [out][1:v] paletteuse" -y "./$GIFFILE"
ls -lh "./$GIFFILE"
rm -rf "$TEMPDIR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment