Created
December 13, 2018 07:17
-
-
Save bradley219/41beed425edc0c86dc6be6612473f4d4 to your computer and use it in GitHub Desktop.
Convert a video file to high quality gif
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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