Make bin/mov2gif more reliable + refactor

This commit is contained in:
Henrik Lissner 2016-11-09 03:38:26 +01:00
parent 15f8287ac3
commit 5059f3bb18

View file

@ -1,14 +1,37 @@
#!/bin/sh
#!/usr/bin/env bash
if [ ! -f "$1" ]; then
>&2 echo "Movie file doesn't exist!"
usage() { echo "Usage: $0 [-f <fps>] [-o <output-dest>] [-h]"; }
if [[ $# = 0 ]]; then
>&2 echo "No movie file specified"
exit
elif [[ ! -f "$1" ]]; then
>&2 echo "$1 does not exist"
exit
fi
palette="/tmp/palette.png"
flags="fps=${4:-10},scale=${3:-640}:-1:flags=lanczos"
fps=30
src="$1"
dest="${$(basename $src)%.mov}.gif"
while getopts hf:o: opt
do
case "$opt" in
-f) fps="$OPTARG" ;;
-o) dest="$OPTARG" ;;
-h) usage
exit
;;
:) >&2 echo "$OPTARG requires an argument"
usage
exit 1
;;
esac
done
ffmpeg -v warning -i "$1" -vf "$flags,palettegen" -y "$palette"
ffmpeg -v warning -i "$1" -i "$palette" -lavfi "$flags [x]; [x][1:v] paletteuse" -y "$2"
palette="$(mktemp)"
flags="fps=${fps}"
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"
[ -f "$palette" ] && rm -f "$palette"