The Meowgorithm Dotfiles, Collectors’ Edition
#!/bin/bash
set -euo pipefail
set -x
# If ffmpeg is not installed, exit with an error message
if ! command -v ffmpeg &>/dev/null; then
printf "Can't find ffmpeg. Please install it (or check your path).\n"
exit 1
fi
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 \
-i "$input" \
-framerate "$framerate" \
-vf "fps=$framerate,scale=$width:-1:flags=lanczos,split[s0][s1];[s0]palettegen=max_colors=${maxColors}[p];[s1][p]paletteuse" \
"${basename}.gif"
}
function makeMP4 {
local input=$1
local framerate=$2
local width=$3
local basename=$4
ffmpeg \