Created
February 15, 2023 13:43
-
-
Save sholloway/67ee75125cc614b584284f182b2ff3b3 to your computer and use it in GitHub Desktop.
This script converts a Quicktime MOV file into an animated 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
############################################################################### | |
# This script converts a Quicktime MOV file into an animated GIF. | |
# Based on: https://abitawake.com/news/articles/how-we-make-gifs-for-twitter | |
# | |
# Dependencies | |
# - ffmpeg | |
# - gifsicle | |
# | |
# Usage | |
# ./mov_to_gif.sh a_movie.mov new_gif.gif | |
############################################################################### | |
mov_to_gif(){ | |
INPUT=$1 | |
PALLET=/tmp/palette.png | |
GIF_OUTPUT="animation.gif" | |
FINAL_OUTPUT=$2 | |
RESIZED_MOV=/tmp/resized.mov | |
echo "#######################################################################" | |
echo "Generating a 256 color pallet." | |
echo "#######################################################################" | |
ffmpeg -i $INPUT -vf "fps=30,palettegen=stats_mode=diff" -y $PALLET | |
echo "#######################################################################" | |
echo "Resizing to 480P" | |
echo "#######################################################################" | |
ffmpeg -i $INPUT -vf scale=-2:480 $RESIZED_MOV | |
echo "#######################################################################" | |
echo "Creating the animated gif" | |
echo "#######################################################################" | |
# generate the gif at the set width | |
#-vf scale=480:-1 | |
# -lavfi graph_description create a complex filtergraph | |
ffmpeg -i $RESIZED_MOV -i $PALLET -lavfi "fps=10 [x]; [x][1:v] paletteuse=dither=none" -y $GIF_OUTPUT | |
echo "#######################################################################" | |
echo "Optimize the Gif" | |
echo "#######################################################################" | |
gifsicle -O3 $GIF_OUTPUT -o $FINAL_OUTPUT | |
echo "#######################################################################" | |
echo "Done!" | |
echo "#######################################################################" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment