#!/bin/bash
preview=0 # Make a preview only
start=0:00:00 # Start position
endpos=5 # End position
fps=13 # Frame per second. The more the better.
output=movie.gif # Gif file name
scale=240:180 # Gif scale
video= # Video file name
test=0 # Wether output the command or run it
# mplayer filename [Name of video file]-ao null
# -ss 0:04:15 [Startposition h:mm:ss]
# -endpos 15 [duration of gif]
# -vo gif89a:fps=13 [frames per second]:output=animated.gif [Name of ouput file]
# -vf scale=240:180 [Dimensions of gif file]
#
# mplayer -ao null -ss 0:03:33 [Startposition h:mm:ss]
# -endpos 15 [duration of gif] filename.mpg [Name of video file]
#
while getopts v:s:e:f:o:c:pt opt; do
case ${opt} in
v)
video=${OPTARG}
if [[ ! -e $video ]]; then
echo "Can\'t access video: ${video}"
exit 1
fi
;;
s)
start=${OPTARG}
;;
e)
endpos=${OPTARG}
;;
f)
fps=${OPTARG}
;;
o)
out=${OPTARG}
;;
c)
scale=${OPTARG}
;;
p)
preview=1
;;
t)
test=1
;;
\?)
echo 'Missing argument'
exit 1
;;
esac
done
if [[ $video == '' ]]; then
echo "Usage ${0} -v movie.avi"
exit 1
fi
cmd="mplayer ${video} -ao null -ss ${start} -endpos ${endpos}"
if (($preview == 0)); then
cmd="$cmd -vo gif89a:fps=${fps}:output=${output} -vf scale=${scale}"
fi
if (($test)); then
echo $cmd
else
exec $cmd
fi