#!/bin/sh rate=5 scale="scale=-1:-1:flags=lanczos" usage() { echo "Usage: $0 [-i ] [-s ] [-r ]" echo "Options:" echo " i input file" echo " s width of the resulting gif" echo " r frame rate of the resulting gif" } while getopts "s: r: i: h" args; do case "$args" in i) file_name=${OPTARG} ;; s) echo $OPTARG if [[ $OPTARG =~ ^[0-9]+$ ]]; then scale="scale=${OPTARG}:-1:flags=lanczos" else echo "Error: -s expects an integer." >&2 exit 1 fi ;; r) if [[ $OPTARG =~ ^[0-9]+$ ]]; then rate=${OPTARG} else echo "Error: -r expects an integer." >&2 exit 1 fi ;; h | * | \?) usage exit ;; esac done if [ $OPTIND -eq 1 ]; then usage exit fi ffmpeg -r ${rate} -i ${file_name}-%d.jpg -vf "${scale}" ${file_name}.gif