#!/bin/bash usage="usage: anithumb.sh -i input -o output -s video_size (example: 320x240) [-f start_frame | Default: 0] [-r N between frames| Default:every 15 frames] [-n number_of_frames | Default: 10] [-v video codec | Default: divx5] [-a audio codec | Default: null]"; while getopts ":i:o:s:f:r:n:v:a:h" options; do case $options in i ) input=$OPTARG;; o ) output=$OPTARG;; s ) size=$OPTARG;; f ) frame=$OPTARG;; r ) framerate=$OPTARG;; n ) numframes=$OPTARG;; v ) video=$OPTARG;; a ) audio=$OPTARG;; h ) echo $usage;; \? ) echo $usage exit 1;; * ) echo $usage exit 1;; esac done if [ $# == 0 ] ; then echo $usage; exit 1; fi if [ ! $input ] || [ ! $output ] || [ ! $size ] ; then echo $usage; exit 1; fi if [ ! $numframes ]; then numframes=10; fi if [ ! $framerate ]; then framerate=15; fi if [ ! $frame ]; then frame=0; echo "Start frame not defined; Using frame 0"; fi if [ ! $video ]; then video="divx5" fi if [ ! $audio ]; then audio="null" fi COUNTER=1 sframe=$frame newstring="" while [ $COUNTER -le $numframes ]; do let frame=sframe+framerate*COUNTER let nframe=frame+1 c="$frame-$nframe" newstring="$newstring,$c"; let COUNTER=COUNTER+1 done total_frames=`echo $newstring | cut -c 2-`; cur_dir=$PWD mkdir /tmp/anithumb transcode -i $input -x $video,$audio -y jpg -g $size -c $total_frames -o /tmp/anithumb/thumb cd /tmp/anithumb for i in thumb* ; do j=`echo $i | sed 's/jpg/gif/'` echo "Converting $i to $j..."; convert $i -resize 50% $j done echo "Creating animated GIF..." convert -delay 15 -loop 0 thumb*.gif $cur_dir/$output rm -rf /tmp/anithumb echo "Done!";