#!/usr/bin/env mksh # Make a video clip from a larger video usage() { if [ -n "$1" ] ; then echo "$1" >&2 fi echo "usage: $0 to-clip start-time end-time clipname" >&2 echo "example:" >&2 echo " $0 ToClip.mkv 00:15:00.0 00:15:30.0 sickflips" >&2 exit 1 } die() { echo "err: $1" >&2 exit 1 } origfile=$1 starttime=$2 endtime=$3 clipname=$4 if [ -z "$origfile" ] || [ -z "$starttime" ] || [ -z "$endtime" ] || [ -z "$clipname" ] then usage fi if ! [ -f "$origfile" ] ; then usage "$origfile doesn't exist!" fi duration=$(( $(gdate -d "$endtime" "+%s") - $(gdate -d "$starttime" "+%s") )) || usage "Couldn't get clip duration" [ "$duration" -gt 0 ] || usage "end-time should be after start-time" strduration="$(gdate -ud "@${duration}" "+%H:%M:%S.%N" | cut -c-10)" if [ -n "$SUBSFILE" ] ; then ffmpeg -ss "$starttime" -copyts -i "$origfile" -ss "$starttime" -t "$strduration" -c:v libx264 -c:a mp3 -ac 2 -vf subtitles="$SUBSFILE" "$clipname.mp4" else ffmpeg -ss "$starttime" -i "$origfile" -t "$strduration" \ -c:v libx264 -c:a mp3 $FFMPEG_PARAM -ac 2 \ "$clipname.mp4" fi