2016-11-08 18:38:26 -08:00
|
|
|
#!/usr/bin/env bash
|
2016-05-31 21:26:43 -07:00
|
|
|
|
2016-11-08 18:38:26 -08:00
|
|
|
usage() { echo "Usage: $0 [-f <fps>] [-o <output-dest>] [-h]"; }
|
|
|
|
|
2016-11-10 09:39:08 -08:00
|
|
|
if (($# == 0)); then
|
2016-11-08 18:38:26 -08:00
|
|
|
>&2 echo "No movie file specified"
|
|
|
|
exit
|
2016-11-10 09:39:08 -08:00
|
|
|
elif [[ ! -f $1 ]]; then
|
2016-11-08 18:38:26 -08:00
|
|
|
>&2 echo "$1 does not exist"
|
2016-05-31 21:26:43 -07:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2016-11-08 18:38:26 -08:00
|
|
|
fps=30
|
|
|
|
src="$1"
|
2016-11-10 09:39:08 -08:00
|
|
|
dest="${${src##*/}%.mov}.gif"
|
|
|
|
while getopts hf:o: opt; do
|
|
|
|
case $opt in
|
2016-11-08 18:38:26 -08:00
|
|
|
-f) fps="$OPTARG" ;;
|
|
|
|
-o) dest="$OPTARG" ;;
|
|
|
|
-h) usage
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
:) >&2 echo "$OPTARG requires an argument"
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
palette="$(mktemp)"
|
|
|
|
flags="fps=${fps}"
|
2016-05-31 21:26:43 -07:00
|
|
|
|
2016-11-08 18:38:26 -08:00
|
|
|
ffmpeg -v warning -i "$src" -vf "$flags,palettegen" -y "$palette"
|
|
|
|
ffmpeg -v warning -i "$src" -i "$palette" -lavfi "$flags [x]; [x][1:v] paletteuse" -y "$dest"
|
2016-05-31 21:26:43 -07:00
|
|
|
|
2016-11-10 09:39:08 -08:00
|
|
|
[[ -f $palette ]] && rm -f "$palette"
|