Created
April 28, 2022 16:04
-
-
Save nicksieger/b73e5934950cc3d71191c755f1ff8fef to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# | |
# Convert a .mov or .mp4 to a .gif using ffmpeg and gifsicle. | |
# | |
# Tools install: https://gist.github.com/dergachev/4627207#installation | |
# | |
# Sources: | |
# 1. https://discovergrid.com/animated-gif-with-ffmpeg-palettegen/ | |
# Use ffmpeg with a generated palette to map colors better | |
# 2. https://gist.github.com/dergachev/4627207 | |
# Gifsicle usage | |
# 3. https://www.robinstewart.com/blog/2018/10/adding-a-delay-to-the-end-of-an-animated-gif/ | |
# Add a delay at the end of the movie | |
# usage: $0 [-f FPS] .mov files... | |
getopts 'f:' fps | |
if [ "$fps" -a "$fps" != '?' ]; then | |
fps=$OPTARG | |
else | |
fps=10 | |
fi | |
while [ $OPTIND -gt 1 ]; do | |
shift | |
OPTIND=$[ $OPTIND - 1 ] | |
done | |
while [ "$1" ]; do | |
f=$1 | |
p=${f/.mov/}.palette.png | |
g=${f/.mov/.gif} | |
ffmpeg -y -i $f -vf fps=$fps,palettegen $p | |
ffmpeg -y -i $f -i $p -filter_complex "fps=$fps[x];[x][1:v]paletteuse" -f gif - \ | |
| gifsicle -d3 "#0--2" -d200 "#-1" -O2 > $g | |
rm $p | |
shift | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment