2024-06-01 23:06:02 +03:00
|
|
|
#!/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
|
|
|
|
|
2024-12-13 11:23:48 +02:00
|
|
|
if [ $OPTIND -eq 1 ]; then
|
2024-06-01 23:06:02 +03:00
|
|
|
usage
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
ffmpeg -i $file_name.mp4 -vf "${fps},${scale},split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" $file_name.gif
|