Skip to content

Instantly share code, notes, and snippets.

@meowgorithm
Created September 29, 2022 13:59
Show Gist options
  • Save meowgorithm/5bd66009db266adcbc378c2a75084bc3 to your computer and use it in GitHub Desktop.
Save meowgorithm/5bd66009db266adcbc378c2a75084bc3 to your computer and use it in GitHub Desktop.
Small GIFs with ffmpeg and bash
#!/usr/bin/env bash
function makeGIF {
local input="$1"
local framerate="$2"
local width="$3"
local basename="$4"
local maxColors="$5"
# GIFs of 60fps videos have to be 50fps
if [[ $framerate == "60" ]]; then
framerate=50
fi
if [[ $maxColors == "" ]]; then
maxColors=256
fi
ffmpeg \
-framerate $framerate \
-i $input \
-vf "fps=$framerate,scale=$width:-1:flags=lanczos,split[s0][s1];[s0]palettegen=max_colors=${maxColors}[p];[s1][p]paletteuse" \
"$basename".gif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment