Last active
May 12, 2017 10:23
-
-
Save vincentorback/03545313dd094e7d91cb706c9016cf91 to your computer and use it in GitHub Desktop.
Make 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
# Usage: | |
# <movie_file> <start_time> <duration> <output_name> | |
# ./makegif.sh movie.mp4 00:00 10 output.gif | |
# | |
# Check if ffmpeg is installed | |
if ! which ffmpeg >/dev/null; then | |
printf "\n\033[0;31mYou need to install ffmpeg to use this! Visit: https://ffmpeg.org/download.html\033[0m\n\n" | |
exit 1 | |
fi | |
start_time=$2 | |
duration=$3 | |
filters="fps=30,scale=500:-1:flags=lanczos" | |
timestamp=$(date +%s) | |
palette=$timestamp"_palette.png" | |
# Create color palette based on video | |
echo 1/4 Creating color palette... | |
ffmpeg -v warning -ss $start_time -t $duration -i $1 -vf "$filters,palettegen=stats_mode=diff" -y $palette | |
echo 2/4 Creating gif... | |
ffmpeg -v warning -ss $start_time -t $duration -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $4 | |
echo 3/4 Remove palette file... | |
rm $palette | |
if which gifsicle >/dev/null; then | |
echo 3.5/4 Optimize gif... | |
gifsicle -O3 $4 -o $4 | |
fi | |
echo 4/4 $4 created! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment