Last active
July 31, 2019 20:52
-
-
Save KylePDavis/e5b4b0aae01b15fbd575b75c884ac027 to your computer and use it in GitHub Desktop.
Convert a movie to a reasonably high quality GIF
This file contains hidden or 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 | |
################################################################################ | |
# | |
# USAGE: | |
# ./convert_to_gif.sh MOVIE_FILE [MOVIE_FILE_2] | |
# | |
# ARGS: | |
# MOVIE_FILE - the name of the movie file | |
# | |
# ENV VAR SETTINGS: | |
# FPS - FPS of output (DEFAULT: 15) | |
# WIDTH - width of output (DEFAULT: -1 -- which means use aspect ratio) | |
# HEIGHT - height of output (DEFAULT: 400) | |
# DITHER - ffmpeg dither method (DEFAULT: none) | |
# | |
# EXAMPLES: | |
# ./convert_to_gif.sh ~/Desktop/*.mov | |
# WIDTH=200 HEIGHT=-1 FPS=20 ./convert_to_gif.sh ~/Desktop/*.mov | |
# | |
# GIST: | |
# https://gist.github.com/KylePDavis/e5b4b0aae01b15fbd575b75c884ac027 | |
# | |
################################################################################ | |
set -o errexit -o pipefail | |
FPS=${FPS:=15} | |
WIDTH=${WIDTH:=-1} | |
HEIGHT=${HEIGHT:=400} | |
DITHER=${DITHER:=none} # or maybe try: bayer:bayer_scale=2 | |
FFMPEG_FILTERS="fps=${FPS},scale=${WIDTH}:${HEIGHT}:flags=lanczos" | |
for FILE in "$@"; do | |
echo "# GENERATING TEMP PALLETE: $FILE ..." | |
ffmpeg -i "$FILE" -vf "$FFMPEG_FILTERS,palettegen" "$FILE.palette.png" | |
echo "# GENERATING GIF: $FILE ..." | |
ffmpeg -i "$FILE" -i "$FILE.palette.png" -filter_complex "$FFMPEG_FILTERS [x]; [x][1:v] paletteuse=dither=none" "$FILE.gif" | |
echo "# CLEANUP TEMP PALLETE: $FILE ..." | |
rm "$FILE.palette.png" | |
done | |
echo "# DONE!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment