X-Git-Url: http://git.pippins.net/embedvideo/.git/static/gitweb.js?a=blobdiff_plain;f=rip_dvd;h=879920bc1785ef8712e46ab7de79907181bdc903;hb=774cd5372cab8e9265d62cc5e07ce707578cfa89;hp=aa4b13ba6ae64c2dac4186e9b02df8ea85ce0637;hpb=27cd43baa5583cd66597cc68bf2de2782fb780e1;p=rip_dvd%2F.git diff --git a/rip_dvd b/rip_dvd index aa4b13b..879920b 100755 --- a/rip_dvd +++ b/rip_dvd @@ -3,7 +3,7 @@ # Author: Alan J. Pippin (apippin@pippins.net) # Date: 05/17/2009 # - REV=2.0 + REV=2.3 # # Description: This script wraps a number of linux utilities to # create a recipe for ripping protected DVDs, circumventing @@ -15,15 +15,8 @@ # Known Issues/Limitations: # - Mirror mode is always done in ISO mode # -# Package Dependencies (apt-get install these for example): -# lsdvd dvdauthor gddrescue dvdbackup tovid mencoder mplayer genisoimage libdvdcss2 -# -# Specific Executable (program) Dependencies (must be found in $PATH): -# volname makexml lsdvd dvdauthor gddrescue dvdbackup mencoder mplayer mkisofs HandBrakeCLI -# -# Optional Dependencies: -# lookup imdb info/posters for mythvideo: http://www.mythtv.org/wiki/Fill_mythvideo_metadata.pl -# +# See the README file for information about the dependencies +# this script has. ############################################################################################## # Global Variables @@ -60,13 +53,18 @@ typeset -i make_final_dest_comp=0 typeset -i errors=0 typeset -i show_usage=0 typeset -i mirror_mode=0 -typeset -i target_bitrate=2000 +typeset -i target_video_bitrate=2000 +typeset -i target_audio_bitrate=224 typeset -i target_size=0 typeset -i audio_2ch=0 typeset -i audio_6ch=1 typeset -i invalid_feature_title=0 typeset -i feature_title_override=0 typeset -i mplayer_dumpstream_incompatibility=0 +typeset -i custom_video_bitrate=0 +typeset -i custom_audio_bitrate=0 +typeset -i custom_audio_2ch=0 +typeset -i custom_audio_6ch=0 ############################################################################## # Local Machine Settings: @@ -102,15 +100,16 @@ fi ############################################################################################## # Command line processing ############################################################################################## -while (($#)) && getopts 162wmvifkzx:ht:n:d:b:s:t:a:p:e:j:l:r: opt "$@" +while (($#)) && getopts 162wmvifkzx:ht:n:d:b:B:s:t:a:p:e:j:l:r: opt "$@" do case $opt in (n) dvdname=$OPTARG;; (d) dest=$OPTARG;; - (b) target_bitrate=$OPTARG;; + (b) target_video_bitrate=$OPTARG; custom_video_bitrate=1;; + (B) target_audio_bitrate=$OPTARG; custom_audio_bitrate=1;; (s) target_size=$OPTARG;; - (2) audio_2ch=1;; - (6) audio_6ch=1;; + (2) audio_2ch=1; custom_audio_2ch=1;; + (6) audio_6ch=1; custom_audio_6ch=1;; (1) force_onepass_mode=1;; (v) make_final_dest_vob=1;; (i) make_final_dest_iso=1;; @@ -170,7 +169,8 @@ function usage() { echo >&2 " -e Specify the encoder to use to make the compressed file (valid encoders=mencoder|handbrake) (default=handbrake if found)" echo >&2 " You must also specify the target size or bitrate using the '-s' or '-b' options with xvid profiles" echo >&2 " -s Set the target size of the compressed file in MB (ex: 700, 1000, etc)" - echo >&2 " -b Set the bitrate desired in the compressed file in kbits/sec (ex: 1500, 2000 (default), etc)" + echo >&2 " -b Set the video bitrate desired in the compressed file in kbits/sec (ex: 1500, 2000 (default), etc)" + echo >&2 " -B Set the audio bitrate desired in the compressed file in kbits/sec (ex: 96, 128, 160, 224 (default), 300, etc)" echo >&2 " -a Specify the width x height aspect ratio to scale the DVD to (only used in -z mode)" echo >&2 " If only the width is given, it will autoset the height to a value which preserves the aspect ratio" echo >&2 " The default behavior is autoaspect mode, which preserves the original aspect, with no scaling being done" @@ -216,7 +216,7 @@ if ([ $target_size -ne 0 ] || [ "$aspect" != "" ]) && [ $make_final_dest_comp -n usage fi -if [ $target_bitrate -eq 0 ] && [ $target_size -eq 0 ] && [ $make_final_dest_comp -eq 1 ]; then +if [ $target_video_bitrate -eq 0 ] && [ $target_size -eq 0 ] && [ $make_final_dest_comp -eq 1 ]; then echo "-E- You must specify a bitrate in compressed file mode. You must specify '-b' or '-s' when using '-z'" | tee -a $logfile usage fi @@ -278,6 +278,8 @@ fi [[ ! -x `which makexml` ]] && echo "-E- missing dependency: makexml" && exit [[ ! -x `which dvdauthor` ]] && echo "-E- missing dependency: dvdauthor" && exit [[ ! -x `which mkisofs` ]] && echo "-E- missing dependency: mkisofs" && exit +[[ -n "$handbrake_xvid" ]] && [[ ! -x `which $handbrake_xvid` ]] && echo "-E- missing handbrake xvid encoder, set in rip_dvd.conf to: $handbrake_xvid" && exit +[[ -n "$handbrake_mp4" ]] && [[ ! -x `which $handbrake_mp4` ]] && echo "-E- missing handbrake mp4 encoder, set in rip_dvd.conf to: $handbrake_mp4" && exit [[ "$encoder" == "handbrake" ]] && [[ "$profile" =~ "xvid" ]] && [[ ! -x `which $handbrake_xvid` ]] && echo "-E- missing encoder: $handbrake_xvid" && exit [[ "$encoder" == "handbrake" ]] && [[ "$profile" =~ "mp4" ]] && [[ ! -x `which $handbrake_mp4` ]] && echo "-E- missing encoder: $handbrake_mp4" && exit [[ "$encoder" == "handbrake" ]] && [[ "$profile" =~ "ip" ]] && [[ ! -x `which $handbrake_mp4` ]] && echo "-E- missing encoder: $handbrake_mp4" && exit @@ -472,6 +474,8 @@ function encode_vob_file_handbrake { typeset filetype="" typeset handbrake_audio_opts="" typeset hb_profile="" + typeset SIZE="" + typeset AUDIO_BITRATE="" # Set a variable that we will use later to determine if we found a handler for $profile or not typeset -i found_profile=0 @@ -484,8 +488,14 @@ function encode_vob_file_handbrake { # Set our DRC option DRC="-D $drc" - # Check the global force_onepass_mode. If it is set, change our variables appropriately - # to force 1-pass encoding across all profiles. + if [ $target_size -ne 0 ]; then + SIZE="-S $target_size" + fi + + if [ $custom_audio_bitrate -eq 1 ]; then + AUDIO_BITRATE="-B $target_audio_bitrate" + fi + if [ $force_onepass_mode -eq 1 ]; then PASSES="" fi @@ -503,7 +513,7 @@ function encode_vob_file_handbrake { # Very High Quality (16fps) if [ "$profile" == "xvidvhq" ]; then handbrake_opts[0]="-f avi" - handbrake_opts[1]="-b $target_bitrate" + handbrake_opts[1]="-b $target_video_bitrate" handbrake_opts[2]="-e xvid" handbrake_opts[3]="-T" handbrake_opts[4]="-5" @@ -512,7 +522,7 @@ function encode_vob_file_handbrake { # High Quality (20fps) if [ "$profile" == "xvidhq" ]; then handbrake_opts[0]="-f avi" - handbrake_opts[1]="-b $target_bitrate" + handbrake_opts[1]="-b $target_video_bitrate" handbrake_opts[2]="-e ffmpeg" handbrake_opts[3]="-T" handbrake_opts[4]="-5" @@ -520,7 +530,7 @@ function encode_vob_file_handbrake { # Fast (28fps) if [ "$profile" == "xvid" ]; then handbrake_opts[0]="-f avi" - handbrake_opts[1]="-b $target_bitrate" + handbrake_opts[1]="-b $target_video_bitrate" handbrake_opts[2]="-e ffmpeg" handbrake_opts[3]="-T" fi @@ -533,6 +543,17 @@ function encode_vob_file_handbrake { final_output_file="$dest/$dvdname.mp4" PASSES="" + # Handle custom parameter overrides + if [ $custom_video_bitrate == 1 ]; then + handbrake_opts[0]="-b $target_video_bitrate" + fi + if [ $custom_audio_2ch == 0 ]; then + audio_2ch=0 + fi + if [ $custom_audio_6ch == 0 ]; then + audio_6ch=0 + fi + # Very High Quality if [ "$profile" == "mp4vhq" ]; then profile="hb_High_Profile" @@ -554,14 +575,26 @@ function encode_vob_file_handbrake { final_output_file="$dest/$dvdname.mp4" PASSES="" + # Handle custom parameter overrides + if [ $custom_video_bitrate == 1 ]; then + handbrake_opts[0]="-b $target_video_bitrate" + fi + if [ $custom_audio_2ch == 0 ]; then + audio_2ch=0 + fi + if [ $custom_audio_6ch == 0 ]; then + audio_6ch=0 + fi + # iphone if [ "$profile" == "iphone" ]; then - profile="hb_iPhone" + profile="hb_iPhone_&_iPod_Touch" fi # ipod if [ "$profile" == "ipod" ]; then profile="hb_iPod" fi + fi # Predefined Handbrake Profile Handling @@ -570,6 +603,17 @@ function encode_vob_file_handbrake { handbrake_cli="$handbrake_mp4" final_output_file="$dest/$dvdname.mp4" PASSES="" + + # Handle custom parameter overrides + if [ $custom_video_bitrate == 1 ]; then + handbrake_opts[0]="-b $target_video_bitrate" + fi + if [ $custom_audio_2ch == 0 ]; then + audio_2ch=0 + fi + if [ $custom_audio_6ch == 0 ]; then + audio_6ch=0 + fi # extract the HandBrake Profile name from $profile hb_profile=`echo "$profile" | sed 's/hb_//g' | sed 's/_/ /g'` @@ -610,8 +654,12 @@ function encode_vob_file_handbrake { handbrake_cmd_line_opts="$handbrake_cmd_line_opts $PASSES" handbrake_cmd_line_opts="$handbrake_cmd_line_opts $DRC" handbrake_cmd_line_opts="$handbrake_cmd_line_opts $SCALE" + handbrake_cmd_line_opts="$handbrake_cmd_line_opts $SIZE" + handbrake_cmd_line_opts="$handbrake_cmd_line_opts $AUDIO_BITRATE" # Execute the handbrake command to encode the video + # I have to copy-n-paste the code below to handle the 2 conditions, 1) hb_profile (mp4) 2) no hb_profile (xvid) + # The problem is the -Z "$hb_profile" option. I have to quote the "$hb_profile" due to spaces in it, forcing me to call it out explicity. if [ -n "$hb_profile" ]; then echo -e "\n Encoding: $handbrake_cli -i \"$vobfile\" -o \"$final_output_file\" -Z \"$hb_profile\" $handbrake_cmd_line_opts $handbrake_audio_opts $handbrake_video_encoder_opts >> $encodelog 2>&1" >> "$logfile" $handbrake_cli -i "$vobfile" -o "$final_output_file" -Z "$hb_profile" $handbrake_cmd_line_opts $handbrake_audio_opts $handbrake_video_encoder_opts >> $encodelog 2>&1 @@ -665,7 +713,7 @@ function encode_vob_file_mencoder { # Very High Quality (16fps) if [ "$profile" == "xvidvhq" ]; then - video_encoder_opts[0]="bitrate=$target_bitrate" + video_encoder_opts[0]="bitrate=$target_video_bitrate" video_encoder_opts[1]="threads=$mencoder_threads" video_encoder_opts[2]="chroma_opt" video_encoder_opts[3]="vhq=4" @@ -675,7 +723,7 @@ function encode_vob_file_mencoder { fi # High Quality (20fps) if [ "$profile" == "xvidhq" ]; then - video_encoder_opts[0]="bitrate=$target_bitrate" + video_encoder_opts[0]="bitrate=$target_video_bitrate" video_encoder_opts[1]="threads=$mencoder_threads" video_encoder_opts[2]="chroma_opt" video_encoder_opts[3]="vhq=2" @@ -685,7 +733,7 @@ function encode_vob_file_mencoder { fi # Fast (28fps) if [ "$profile" == "xvid" ]; then - video_encoder_opts[0]="bitrate=$target_bitrate" + video_encoder_opts[0]="bitrate=$target_video_bitrate" video_encoder_opts[1]="threads=$mencoder_threads" video_encoder_opts[2]="vhq=0" video_encoder_opts[3]="turbo" @@ -705,7 +753,7 @@ function encode_vob_file_mencoder { mencoder_audioch_opts[2]="" else # These options produce good 2 channel audio for linux and windows (including the internal mythvideo player) - mencoder_audio_opts="-oac mp3lame -lameopts cbr:br=$audio_bitrate" + mencoder_audio_opts="-oac mp3lame -lameopts cbr:br=$target_audio_bitrate" mencoder_audioch_opts[0]="" fi @@ -732,7 +780,7 @@ function encode_vob_file_mencoder { mencoder_output_opts="-ofps 30000/1001 -sws 9 -of lavf -lavfopts format=mp4" mencoder_video_filter_opts="-vf harddup$CROP$SCALE"; mencoder_video_encoder_opts="-ovc x264 -x264encopts $pass_opt" - video_encoder_opts[0]="bitrate=$target_bitrate" + video_encoder_opts[0]="bitrate=$target_video_bitrate" video_encoder_opts[1]="threads=$mencoder_threads" video_encoder_opts[2]="vbv_maxrate=1500" video_encoder_opts[3]="vbv_bufsize=2000" @@ -749,7 +797,7 @@ function encode_vob_file_mencoder { mencoder_video_encoder_opts="$mencoder_video_encoder_opts:$OPTS" done - mencoder_audio_opts="-oac faac -faacopts mpeg=4:object=2:br=$audio_bitrate:raw" + mencoder_audio_opts="-oac faac -faacopts mpeg=4:object=2:br=$target_audio_bitrate:raw" mencoder_audioch_opts[0]="-channels 2 -srate 48000" fi @@ -1053,18 +1101,19 @@ function get_audio_track_from_vob { # extract the audio streams in the vob #ffmpeg -i "$vob" > $aidcheck 2>&1 - $handbrake_cli --stop-at 0 -i "$vob" -o /dev/null -v 100 > $aidcheck 2>&1 + $handbrake_cli --stop-at duration:1 -i "$vob" -o /dev/null -v 100 > $aidcheck 2>&1 # find the stream that matches our aid #stream=`grep "Stream.*\[0x$aid_hex\]" $aidcheck` - stream=`grep "scan: audio" $aidcheck | grep -n "" | grep "scan: audio 0x$aid_hex"` + #stream=`grep "scan: audio" $aidcheck | grep -n "" | grep "scan: audio 0x$aid_hex"` + stream=`grep "add_audio_to_title:" $aidcheck | grep -n "" | grep "add_audio_to_title:.* stream 0x$aid_hex"` # extract the track number that handbrake uses #track=`expr match "$stream" '.*#[0-9]\.\([0-9]*\)'` track=`expr match "$stream" '^\([0-9]*\):'` if [ -n "$track" ]; then - echo "-> Setting the audio ID to $aid. Setting the audio track to $track." | tee -a "$logfile" + echo " Setting the audio ID to $aid. Setting the audio track to $track." | tee -a "$logfile" fi } @@ -1198,10 +1247,11 @@ function check_vob_for_a52_crc_errors { 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 ]; then + 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_bitrate = (target_size * 1024 * 8) / vob_length )) - echo " With a given target size of $target_size MB, the estimated bit rate will need to be $target_bitrate kbits/sec" + ((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" fi }