Added new check for VOBs that have bad length protection.
[rip_dvd/.git] / rip_dvd
diff --git a/rip_dvd b/rip_dvd
index 879920bc1785ef8712e46ab7de79907181bdc903..8919900b63a2cf9a5a6771f071da471d760f97ec 100755 (executable)
--- a/rip_dvd
+++ b/rip_dvd
@@ -65,6 +65,7 @@ typeset -i custom_video_bitrate=0
 typeset -i custom_audio_bitrate=0
 typeset -i custom_audio_2ch=0
 typeset -i custom_audio_6ch=0
+typeset -i minimum_feature_title_length=10
 
 ##############################################################################
 # Local Machine Settings:
@@ -985,7 +986,7 @@ function create_main_vob_with_mplayer {
   # check to make sure we didn't detect an mplayer dumpstream incompatibility earlier
   if [ $mplayer_dumpstream_incompatibility -eq 1 ]; then
     msg="-E- We detected an mplayer dumpstream incompatibility earlier."
-    msg="$msg We also detected another condition that requires us to use dumpstream. "
+    msg="$msg We also detected a condition that may require you to use dumpstream. "
     msg="$msg\n    Unable to rip this DVD in the mode you requested."
     fatal_and_exit "$msg"
   fi
@@ -1249,9 +1250,21 @@ function calculate_bitrate_from_target_size {
   # determine what our bitrate needs to be if a target size was specified instead
   if [ $target_size -ne 0 ] && [ $custom_video_bitrate -eq 0 ]; then
     vob_length=`mplayer -identify -v "$vobfile" -endpos 0 2>&1 | grep ID_LENGTH | awk -F '=' '{ print $2 }' | awk -F '.' '{ print $1 }'`
-    ((target_video_bitrate = (target_size * 1024 * 8) / vob_length ))
-    custom_video_bitrate=1
-    echo "   With a given target size of $target_size MB, the estimated bit rate will need to be $target_video_bitrate kbits/sec" | tee -a "$logfile"
+    ((min_length = minimum_feature_title_length * 60))
+    if [[ $vob_length -gt $min_length ]]; then 
+      ((target_video_bitrate = (target_size * 1024 * 8) / vob_length ))
+      custom_video_bitrate=1
+      echo "   With a given target size of $target_size MB, the estimated bit rate will need to be $target_video_bitrate kbits/sec" | tee -a "$logfile"
+    else
+      echo "-W- Unable to determine the real length of this DVD feature title." | tee -a "$logfile"
+      echo "    A target bitrate from the target_size requested will not be set." | tee -a "$logfile"
+      echo "    If using handbrake, only the target_size will be passed to the encoder." | tee -a "$logfile" 
+      echo "    If using mencoder, the target_size will be entirely disregarded." | tee -a "$logfile"
+      echo "    You may need to rerun with the -b option with a target bitrate to get the desired size." | tee -a "$logfile"
+      if [[ $encoder -ne "handbrake" ]] || [[ "$profile" =~ "xvid" ]]; then
+        fatal_and_exit "-E- You'll need rip this DVD with the handbrake encoder and an MP4 type profile to get a good rip."
+      fi
+    fi
   fi
 }
 
@@ -1353,6 +1366,20 @@ function check_for_mplayer_dumpstream_incompatibility {
     fi
     [[ -e "$dumplog" ]] && rm -f $dumplog
   fi
+
+  # There is another form of protection that causes the mplayer dumpstream to fail.
+  # The resulting VOB file looks complete, but has something in it that causes mplayer/mencoder 
+  # to be unable to encode it since it thinks the entire VOB is only a few minutes long in length.
+  # Using HandBrake with an MP4 type profile can work around this, but mencoder or Handbrake with XVID profile won't.
+  vob_length=`mplayer -identify -v "$vobfile" -endpos 0 2>&1 | grep ID_LENGTH | awk -F '=' '{ print $2 }' | awk -F '.' '{ print $1 }'`
+  ((min_length = minimum_feature_title_length * 60))
+  if [[ $vob_length -lt $min_length ]]; then 
+    if [[ $encoder -ne "handbrake" ]] || [[ "$profile" =~ "xvid" ]]; then
+      echo "-E- The main feature title that was ripped from the DVD has an invalid movie length." | tee -a "$logfile"
+      echo "    You'll need rip this DVD with the handbrake encoder and an MP4 type profile instead." | tee -a "$logfile"
+      mplayer_dumpstream_incompatibility=1
+    fi
+  fi
 }
 
 function fill_mythvideo_metadata {