+# encode the vob file into a compressed file format using handbrake
+function encode_vob_file_handbrake {
+
+ # declare some globals
+ typeset handbrake_cli=""
+ typeset handbrake_video_encoder_opts=""
+ typeset filetype=""
+ typeset handbrake_audio_opts=""
+
+ # Set a variable that we will use later to determine if we found a handler for $profile or not
+ typeset -i found_profile=0
+
+ # For a given profile, to override the 2 pass behavior to be single pass,
+ # simply set the PASSES variable below to "2" instead of "1 2" inside your profile handler.
+ # It indicates which PASS numbers to loop over. PASSES="2" means just do pass 2 => single pass mode.
+ PASSES="-2"
+
+ # Check the global force_onepass_mode. If it is set, change our variables appropriately
+ # to force 1-pass encoding across all profiles.
+ if [ $force_onepass_mode -eq 1 ]; then
+ PASSES=""
+ fi
+
+ # XVID profile
+ if [[ "$profile" =~ "xvid" ]]; then
+ found_profile=1
+ handbrake_cli="$handbrake_xvid"
+ final_output_file="$dest/$dvdname.avi"
+ filetype="avi"
+
+ # Very High Quality (16fps)
+ if [ "$profile" == "xvidvhq" ]; then
+ handbrake_opts[0]="-f avi"
+ handbrake_opts[1]="-b $target_bitrate"
+ handbrake_opts[2]="-e ffmpeg"
+ handbrake_opts[3]="-T"
+ handbrake_opts[4]="-5"
+ handbrake_opts[5]="-8"
+ fi
+ # High Quality (20fps)
+ if [ "$profile" == "xvidhq" ]; then
+ handbrake_opts[0]="-f avi"
+ handbrake_opts[1]="-b $target_bitrate"
+ handbrake_opts[2]="-e ffmpeg"
+ handbrake_opts[3]="-T"
+ handbrake_opts[4]="-5"
+ fi
+ # Fast (28fps)
+ if [ "$profile" == "xvid" ]; then
+ handbrake_opts[0]="-f avi"
+ handbrake_opts[1]="-b $target_bitrate"
+ handbrake_opts[2]="-e ffmpeg"
+ handbrake_opts[3]="-T"
+ fi
+ fi
+
+ # MP4 profile
+ if [[ "$profile" =~ "mp4" ]]; then
+ found_profile=1
+ handbrake_cli="$handbrake_mp4"
+ final_output_file="$dest/$dvdname.mp4"
+ PASSES=""
+
+ # Very High Quality
+ if [ "$profile" == "mp4vhq" ]; then
+ profile="hb_High_Profile"
+ fi
+ # High Quality
+ if [ "$profile" == "mp4hq" ]; then
+ profile="hb_Normal"
+ fi
+ # Fast
+ if [ "$profile" == "mp4" ]; then
+ profile="hb_Classic"
+ fi
+ fi
+
+ # iphone and ipod MP4 profiles
+ if [ "$profile" == "iphone" ] || [ "$profile" == "ipod" ]; then
+ found_profile=1
+ handbrake_cli="$handbrake_mp4"
+ final_output_file="$dest/$dvdname.mp4"
+ PASSES=""
+
+ # iphone
+ if [ "$profile" == "iphone" ]; then
+ profile="hb_iPhone"
+ fi
+ # ipod
+ if [ "$profile" == "ipod" ]; then
+ profile="hb_iPod"
+ fi
+ fi
+
+ # Predefined Handbrake Profile Handling
+ if [[ "$profile" =~ "hb" ]]; then
+ found_profile=1
+ handbrake_cli="$handbrake_mp4"
+ final_output_file="$dest/$dvdname.mp4"
+ PASSES=""
+
+ # extract the HandBrake Profile name from $profile
+ hb_profile=`echo "$profile" | sed 's/hb_//g' | sed 's/_/ /g'`
+ handbrake_opts[0]="-Z \"$hb_profile\""
+ fi
+
+ # Make sure we found a handler for the given profile
+ if [ $found_profile -eq 0 ]; then
+ fatal_and_exit "-E- Unable to find a profile handler for profile: $profile"
+ fi
+
+ # setup our audio option
+ if [ $audio_2ch -eq 1 ] && [ $audio_6ch -eq 1 ]; then
+ handbrake_audio_opts="-E faac,ac3 -6 dpl2,6ch"
+ fi
+ if [ $audio_6ch -eq 1 ]; then
+ handbrake_audio_opts="-E ac3 -6 6ch"
+ fi
+ if [ $audio_2ch -eq 1 ]; then
+ handbrake_audio_opts="-E faac -6 dpl2"
+ fi
+
+ # Convert our array of opts into a string
+ for OPTS in "${video_encoder_opts[@]}"; do
+ handbrake_video_encoder_opts="$handbrake_video_encoder_opts:$OPTS"
+ done
+ if [ -n "$handbrake_video_encoder_opts" ]; then
+ handbrake_video_encoder_opts="-x $handbrake_video_encoder_opts"
+ fi
+ for OPTS in "${handbrake_opts[@]}"; do
+ handbrake_cmd_line_opts="$handbrake_cmd_line_opts $OPTS"
+ done
+
+ # Execute the handbrake command to encode the video
+ echo -e "\n Encoding: $handbrake_cli -i \"$vobfile\" -o \"$final_output_file\" $handbrake_cmd_line_opts $handbrake_audio_opts $handbrake_video_encoder_opts $PASSES >> $encodelog 2>&1" >> "$logfile"
+ $handbrake_cli -i "$vobfile" -o "$final_output_file" $handbrake_cmd_line_opts $handbrake_audio_opts $handbrake_video_encoder_opts $PASSES >> $encodelog 2>&1
+ handbrake_retval=$?
+ if [ $handbrake_retval != 0 ]; then
+ fatal_and_exit "-E- Unhandled handbrake error"
+ fi
+
+ # Concatenate the encode log to our main log file, greping out unwanted lines
+ cat $encodelog | grep -v "Encoding" >> "$logfile"
+ cat $encodelog | grep "Encoding:" | sed 's/\r/\n/g' | grep "Encoding:" | grep "ETA" | head -1 >> "$logfile"
+ cat $encodelog | grep "Encoding:" | sed 's/\r/\n/g' | grep "Encoding:" | grep "ETA" | tail -1 >> "$logfile"
+}
+
+# encode the vob file into a compressed file format using mencoder
+function encode_vob_file_mencoder {