From 5059f3bb18ae032c35af92cc8f4e98f429584113 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 9 Nov 2016 03:38:26 +0100 Subject: [PATCH] Make bin/mov2gif more reliable + refactor --- bin/mov2gif | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) 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"