#!/bin/sh

usage()
{
	# Title
	echo "Title: Flash FLV Dual Pass (FFMPEG)"

	# Usable?
	which ffmpeg> /dev/null
	[ $? -eq 0 ] && echo Status: Active || echo Status: Inactive

	# Type
	echo Flags: double-pass file-producer

	# Profiles
	echo "Profile: Broadband Quality (320x240, 564Kbps)"
	echo "Profile: Low Quality (320x240, 15fps, 128Kbps)"
}

execute()
{
	# Arguments
	normalisation="$1"
	length="$2"
	profile="$3"
	file="$4"
	pass="$6"
	[ "x$file" = "x" ] && file="kino_export_"`date +%Y-%m-%d_%H.%M.%S`

	# Determine info arguments
	size=`[ "$normalisation" = "pal" ] && echo 352x288 || echo 352x240`
	hq=""
	[ $pass -eq "2" ] && hq="-deinterlace -hq"
	

	# Run the command
	case "$profile" in 
		"0" ) 	ffmpeg -f dv -i pipe: -pass $pass -passlogfile "$file" $hq \
			-r "$normalisation" -b 500 -ac 2 -ab 64 -s 320x240 -aspect 4:3 \
			-ar 44100 -y "$file".flv ;;
		"1" ) 	ffmpeg -f dv -i pipe: -pass $pass -passlogfile "$file" $hq \
			-r 15.0 -b 80 -ac 1 -ab 48 -s 320x240 -aspect 4:3 \
			-ar 22050 -y "$file".flv ;;
	esac
	if [ $pass -eq "2" ]; then
		rm -f "$file-0.log"
	fi
}

[ "$1" = "--usage" ] || [ -z "$1" ] && usage "$@" || execute "$@"
