Skip to content

Instantly share code, notes, and snippets.

@bradley219
Created December 13, 2018 07:17
Show Gist options
  • Save bradley219/41beed425edc0c86dc6be6612473f4d4 to your computer and use it in GitHub Desktop.
Save bradley219/41beed425edc0c86dc6be6612473f4d4 to your computer and use it in GitHub Desktop.
Convert a video file to high quality gif
#!/bin/bash
FPS=14
WIDTH=640
PALETTE=/tmp/palette.png
INPUT="$1"
OUTPUT="$2"
KEEP_PALETTE="$3"
if [ "$INPUT" == "" ] || [ "$OUTPUT" == ""]; then
echo "Usage: video2gif input_file output_file"
exit 1
fi
ffmpeg -i "$INPUT" -vf 'palettegen' "$PALETTE"
if [ $? -ne 0 ]; then
exit 1
fi
ffmpeg -i "$INPUT" -i "$PALETTE" -filter_complex "fps=$FPS,scale=$WIDTH:-1:flags=lanczos,paletteuse" "$OUTPUT"
if [ $? -ne 0 ]; then
if [ "$KEEP_PALETTE" == "" ]; then
rm "$PALETTE"
fi
exit 1
fi
if [ "$KEEP_PALETTE" == "" ]; then
rm "$PALETTE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment