Created
May 22, 2020 17:46
Converts videos to gifs using ffmpeg. It creates a color palette to keep gif sizes low; hard-coded 15fps.
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 | |
if [[ "$#" -ne 2 ]]; then | |
echo "Usage: to-gif.sh <input video> <output gif>" | |
exit 1 | |
fi | |
set -ex | |
# Generate a palette to cut down on space | |
PALETTE_PNG="/tmp/$(openssl rand -hex 4).png" | |
ffmpeg -hide_banner -loglevel warning -i "${1}" -vf fps=15,scale=320:-1:flags=lanczos,palettegen "${PALETTE_PNG}" | |
# Apply palette | |
ffmpeg -hide_banner -loglevel warning -i "${1}" -i "${PALETTE_PNG}" -filter_complex "fps=15,scale=-1:-1:flags=lanczos[x];[x][1:v]paletteuse" "${2}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment