#!/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"
# mencoder "$1" -nosound -ovc copy $OPTIONS -o "$output"
ffmpeg -i "$1" $OPTIONS -vcodec copy "$output"
touch -r "$1" "$output"

exit

#  In case of problems try:
avconv -i problematic_video -c:v copy -y good_video.mp4
