the_earnest/dotfiles

function ffcut() {
	local error
	if [[ $# -ne 3 ]]; then 
		error="error: expected 3 arguments, found $#\nusage: ffcut input-file start-time end-time" 
	elif [[ ! -e "$1" ]]; then
		error="error: input file does not exist"
	fi
	if [[ -n "$error" ]]; then
		echo -e "$error"
		return 99
	fi
	name_no_ext=${1%.*}
	ext=${1##*.}
	ts_start=$(echo $2|tr ':.,' '___')
	ts_stop=$(echo $3|tr ':.,' '___')
	# or without tr, sth like:
	# ts_start=${2//:/_}
	# ts_stop=${3//:/_}
	outfile="$name_no_ext snip $ts_start to $ts_stop.$ext"
	echo output file: \"$outfile\"
	ffmpeg -hide_banner -loglevel error -ss $2 -to $3 -i "$1" -map 0 -c copy "$outfile"
	[[ $? -eq 0 ]] && echo OK
	return $?
}