#!/bin/sh
if [ $# -lt 2 ] ; then
    echo "Usage: $0 <videofile> <start> [<end>]"
    exit 1
fi
if [ ! -e "$1" ] ; then
    echo "$0: No such file $1"
    exit 1
fi
if [ "$3" = "" ] ; then
    OPTIONS="-ss $2"
else
    OPTIONS="-ss $2 -t $3"
fi

output=`echo $1 | sed 's/^\(.\+\)\.\([^.]\+\)/\1_cut.\2/'`
rm -f "$output"
# if only video should be copied but audio dropped
# avconv -i "$1" $OPTIONS -vcodec copy "$output"
avconv -i "$1" $OPTIONS -codec copy "$output"
touch -r "$1" "$output"

exit
