--- /dev/null
+#! /bin/sh
+
+if [ -z "$1" ]; then
+ echo "Usage: [vcodec=s] [vbitrate=n] [vscale=s] [aid=n] [acodec=s] [abitrate=n] [ascale=s] [pass=n] $0 input.avi [-ffmpeg_options]"
+ exit 1
+fi
+
+if [ -z "$vcodec" ]; then
+ vcodec=mpeg4
+else
+ vcodec="$vcodec"
+fi
+
+if [ -z "$vbitrate" ]; then
+ vbitrate=1600k
+else
+ vbitrate="$vbitrate"
+fi
+
+if [ -n "$vscale" ]; then
+ vscale="-s $vscale"
+fi
+
+if [ -z "$acodec" ]; then
+ acodec=libmp3lame
+else
+ acodec="$acodec"
+fi
+
+if [ -z "$abitrate" ]; then
+ abitrate=256k
+else
+ abitrate="$abitrate"
+fi
+
+if [ -z "$pass" ]; then
+ pass=1
+else
+ pass="$pass"
+fi
+
+input="$1"
+shift
+
+if [ "$pass" -eq 1 ]; then
+ exec ffmpeg -i "$input" -f avi -c:v "$vcodec" -b:v "$vbitrate" -g 300 -bf 2 -c:a "$acodec" -b:a "$abitrate" "$@" output.avi
+
+elif [ "$pass" -eq 2 ]; then
+ ffmpeg -pass 1 -i "$input" -f avi -c:v "$vcodec" -b:v "$vbitrate" -g 300 -bf 2 -an -f rawvideo -y /dev/null "$@" &&
+ exec ffmpeg -pass 2 -i "$input" -f avi -c:v "$vcodec" -b:v "$vbitrate" -g 300 -bf 2 -c:a "$acodec" -b:a "$abitrate" "$@" output.avi
+
+else
+ echo "Can only do 1 or 2 passes." >&2
+ exit 1
+fi