2019-07-11 15:08:19 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
if [ $# -ne 3 ]; then
|
|
|
|
echo -e "\033[31;1merror:\033[0m this script expects three arguments, the file, the starting time and the duration."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-12-06 11:45:04 +01:00
|
|
|
if [ ! -f "$1" ]; then
|
2019-07-11 15:08:19 +02:00
|
|
|
echo -e "\033[31;1merror:\033[0m couldn't open $1: no such file."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
palette_dir=$(mktemp -d)
|
|
|
|
|
2023-11-07 14:26:22 +01:00
|
|
|
ffmpeg -y -ss $2 -to $3 -i $1 \
|
2021-04-21 14:55:45 +02:00
|
|
|
-vf fps=30,scale=320:-1:flags=lanczos,palettegen $palette_dir/palette.png > /dev/null 2>&1
|
2019-07-11 15:08:19 +02:00
|
|
|
|
2023-11-07 14:26:22 +01:00
|
|
|
ffmpeg -ss $2 -to $3 -i $1 -i $palette_dir/palette.png -filter_complex \
|
|
|
|
"fps=30,scale=640:-1:flags=lanczos[x];[x][1:v]paletteuse" -y output.gif > /dev/null 2>&1
|
2019-07-11 15:08:19 +02:00
|
|
|
|
|
|
|
rm -rf $palette_dir
|