.dotfiles/.local/bin/best-gif.sh

49 lines
848 B
Bash
Raw Normal View History

#!/bin/sh
fps="fps=24"
scale="scale=1080:-1:flags=lanczos"
usage() {
echo "Usage: $0 [-i <string>] [-s <integer>] [-r <integer>]"
echo "Options:"
echo " i input file"
echo " s width of the resulting gif"
echo " r frame rate of the resulting gif"
}
while getopts "s: r: i: h" args; do
case "$args" in
i)
file_name=${OPTARG}
;;
s)
echo $OPTARG
if [[ $OPTARG =~ ^[0-9]+$ ]]; then
scale="scale=${OPTARG}:-1:flags=lanczos"
else
echo "Error: -s expects an integer." >&2
exit 1
fi
;;
r)
if [[ $OPTARG =~ ^[0-9]+$ ]]; then
rate="fps=${OPTARG}"
else
echo "Error: -r expects an integer." >&2
exit 1
fi
;;
h | * | \?)
usage
exit
;;
esac
done
if [ $OPTIND -eq 1 ]; then
usage
exit
fi
ffmpeg -i $file_name.mp4 -vf "${fps},${scale},split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" $file_name.gif