diff --git a/bin/mov2gif b/bin/mov2gif index aaece5a2..5b763c0e 100755 --- a/bin/mov2gif +++ b/bin/mov2gif @@ -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 ] [-o ] [-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"