Make bin/mov2gif more reliable + refactor
This commit is contained in:
parent
15f8287ac3
commit
5059f3bb18
37
bin/mov2gif
37
bin/mov2gif
|
@ -1,14 +1,37 @@
|
||||||
#!/bin/sh
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
if [ ! -f "$1" ]; then
|
usage() { echo "Usage: $0 [-f <fps>] [-o <output-dest>] [-h]"; }
|
||||||
>&2 echo "Movie file doesn't exist!"
|
|
||||||
|
if [[ $# = 0 ]]; then
|
||||||
|
>&2 echo "No movie file specified"
|
||||||
|
exit
|
||||||
|
elif [[ ! -f "$1" ]]; then
|
||||||
|
>&2 echo "$1 does not exist"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
palette="/tmp/palette.png"
|
fps=30
|
||||||
flags="fps=${4:-10},scale=${3:-640}:-1:flags=lanczos"
|
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"
|
palette="$(mktemp)"
|
||||||
ffmpeg -v warning -i "$1" -i "$palette" -lavfi "$flags [x]; [x][1:v] paletteuse" -y "$2"
|
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"
|
[ -f "$palette" ] && rm -f "$palette"
|
||||||
|
|
Loading…
Reference in a new issue