--- /dev/null
+#!/bin/bash
+
+#set -x
+#set -e
+#set -n
+
+
+SCALE="1280:-3"
+#SCALE="800:-3"
+#SCALE="480:-3"
+#SCALE=
+
+BITRATE=1600
+#BITRATE=800
+
+# gegen Uhrzeiger drehen
+#ROTATE=2
+# im Uhrzeiger drehen
+#ROTATE=1
+# nicht drehen
+ROTATE=
+
+TITLE="Westworld - s01e02 - Das wahre Selbst, german dubbed, 720p"
+
+#----------------------
+
+VF=""
+if [[ -n "${SCALE}" ]] ; then
+ VF="scale=${SCALE}"
+fi
+
+if [[ -n "${ROTATE}" ]] ; then
+ if [[ -z "${VF}" ]] ; then
+ VF="rotate=${ROTATE}"
+ else
+ VF="${VF},rotate=${ROTATE}"
+ fi
+fi
+
+if [[ -n "${VF}" ]] ; then
+ VF="-vf ${VF}"
+fi
+
+cleanup() {
+ trap - EXIT TERM HUP INT
+ rm -vf divx2pass.log || true
+ rm -vf frameno.avi || true
+}
+
+trap cleanup EXIT TERM HUP INT
+
+OLD="$1"
+shift
+
+NEW="$1"
+shift
+
+if [[ -z "${OLD}" ]]; then
+ echo "No movie to convert given." >&2
+ exit 1
+fi
+
+if [[ ! -f "${OLD}" ]]; then
+ echo "File '${OLD}' doesn't exists." >&2
+ exit 1
+fi
+
+if [[ -z "${NEW}" ]]; then
+ OLD_STEM=$( echo "${OLD}" | sed -e 's/\.\(mov\|avi\|mp4\|mkv\)$//i' )
+ if [[ "${OLD}" == "${OLD_STEM}" ]] ; then
+ echo "File '${OLD}' seems not to be a Quicktime, Mpeg, Matroska or AVI movie." >&2
+ exit 1
+ fi
+ NEW_EXT="avi"
+ NEW="${OLD_STEM}.${NEW_EXT}"
+ i=0
+ while [[ -e "${NEW}" ]] ; do
+ NEW_EXT="new.${i}.avi"
+ NEW="${OLD_STEM}.${NEW_EXT}"
+ i=$(( $i + 1 ))
+ done
+else
+ if [[ -e "${NEW}" ]]; then
+ echo "Target '${NEW}' aleady exists." >&2
+ exit 1
+ fi
+fi
+
+echo
+echo '##############################################################'
+echo "[$(date)]: Converting '${OLD}' -> '${NEW}' ..."
+echo
+
+echo "-----------------------------"
+echo "[$(date)]: Step 1: Audio converting"
+cmd="mencoder \"${OLD}\" -of avi -ovc frameno -oac mp3lame -lameopts vbr=3 ${VF} -o frameno.avi"
+echo "${cmd}"
+echo
+eval ${cmd}
+
+echo
+echo "-----------------------------"
+echo "[$(date)]: Step 2: converting to XVID pass 1"
+cmd="mencoder \"${OLD}\" -of avi -o /dev/null -oac mp3lame -ovc xvid -xvidencopts pass=1 -lameopts vbr=3 ${VF}"
+echo "${cmd}"
+echo
+eval ${cmd}
+
+cmd="mencoder \"${OLD}\" -of avi -o \"${NEW}\""
+cmd+=" -oac mp3lame -ovc xvid "
+if [[ -n "${TITLE}" ]] ; then
+ cmd+=" -info name=\"${TITLE}\""
+fi
+cmd+=" -xvidencopts pass=2:bitrate=${BITRATE} -lameopts vbr=3 ${VF}"
+
+echo
+echo "-----------------------------"
+echo "[$(date)]: Step 3: converting to XVID pass 2"
+cmd="mencoder \"${OLD}\" -of avi -o \"${NEW}\" -oac mp3lame -ovc xvid -xvidencopts pass=2:bitrate=${BITRATE} -lameopts vbr=3 ${VF}"
+echo "${cmd}"
+echo
+eval ${cmd}
+
+echo
+echo "-----------------------------"
+echo "[$(date)]: Ready."
+
+
+exit 0
+
+# vim: ts=4 expandtab