diff --git a/dvd2divx b/dvd2divx index 4ba63f5..a5be79b 100755 --- a/dvd2divx +++ b/dvd2divx @@ -5,9 +5,9 @@ # (C) 2004-2009 Arnaud G. Gibert #----------------------------------------------------------------------------------------------------------------------------------- # $RCSfile: dvd2divx,v $ -# $Revision: 1.12 $ +# $Revision: 1.13 $ # $Name: $ -# $Date: 2010/02/17 11:01:10 $ +# $Date: 2010/11/24 07:58:02 $ # $Author: agibert $ #----------------------------------------------------------------------------------------------------------------------------------- @@ -32,10 +32,10 @@ # Usage exemple #----------------------------------------------------------------------------------------------------------------------------------- # #!/bin/bash -# # divx_root divx_title input dvd_device dvd_title chapter angle alang slang audio abr asrate stereo volume sub video vcodec vqual vbr crop xsize aspect deint threads vopts +# # divx_root divx_title input buf_type dvd_device dvd_title chapter angle alang slang audio abr asrate stereo volume sub video vcodec vqual vbr crop xsize aspect deint threads vopts # #--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -# dvd2divx cobra 1 dbo /dev/cdrom1 10 1- 1 fr - - - - - - - - - - - - - - - - -# dvd2divx cobra 1 b - - - - - - fvp 128 - n 10 - 2a xvid 3 1000 - 480 4/3 y 4 cartoon +# dvd2divx cobra 1 dbo c /dev/cdrom1 10 1- 1 fr - - - - - - - - - - - - - - - - +# dvd2divx cobra 1 b - - - - - - - fvp 128 - n 10 - 2a xvid 3 1000 - 480 4/3 y 4 cartoon @@ -43,31 +43,32 @@ divx_root=${1} # divx_title=${2} # #------------------------------------------------------------------------------ input=${3} # d|db|dbo|b (d: read directly from disk | db: bufferize and continue | dbo: bufferize only | b: read from a preexisting buffer) -dvd_device=${4} # -|/dev/dvd|... -title=${5} # -chapter=${6} # -angle=${7} # -alang=${8} # -|en|fr|...|0|1|... (lang or id) -slang=${9} # -|en|fr|...|0|1|... (lang or id) +buf_type=${4} # c|u (c: compresed | u: uncompressed) +dvd_device=${5} # -|/dev/dvd|... +title=${6} # +chapter=${7} # +angle=${8} # +alang=${9} # -|en|fr|...|0|1|... (lang or id) +slang=${10} # -|en|fr|...|0|1|... (lang or id) #------------------------------------------------------------------------------ -audio=${10} # ap|avp|fvp|n (ap: compress audio during audio pass | avp: compress audio during all video pass | fvp: compress audio during final video pass | no: use input audio stream) -abr=${11} # -asrate=${12} # -|xxx (resample audio) -stereo=${13} # y|n -volume=${14} # -|... (volume gain) +audio=${11} # ap|avp|fvp|n (ap: compress audio during audio pass | avp: compress audio during all video pass | fvp: compress audio during final video pass | no: use input audio stream) +abr=${12} # xxx (audio bit rate) +asrate=${13} # -|xxx (resample audio) +stereo=${14} # y|n +volume=${15} # -|a/xx|yy (-: no volume change | a: auto normalize at -xx db | add yy db) #------------------------------------------------------------------------------ -sub=${15} # -|f|o (-: no subtitles | f: file subtitles | o: OSD subtitles) +sub=${16} # -|f|o (-: no subtitles | f: file subtitles | o: OSD subtitles) #------------------------------------------------------------------------------ -video=${16} # 1|2a|2s|n (1: compress video in 1 pass | 2a: compress video in 2 assymetric passes | 2s: compress video in 2 symetric passes | no: use input video stream) -vcodec=${17} # -|lavc|xvid|x264 -vquality=${18} # 0|1|2|3 (0: realtime | 1: fast | 2: High quality | 3: very high quality) -vbr=${19} # -crop=${20} # -|width:height:x:y -xsize=${21} # -|... -aspect=${22} # -|4/3|16/9|... -deint=${23} # y|n -threads=${24} # -|1.. -vopts=${25} # -|... # other vcodec options +video=${17} # 1|2a|2s|n (1: compress video in 1 pass | 2a: compress video in 2 assymetric passes | 2s: compress video in 2 symetric passes | no: use input video stream) +vcodec=${18} # -|lavc|xvid|x264 +vquality=${19} # 0|1|2|3 (0: realtime | 1: fast | 2: high quality | 3: very high quality) +vbr=${20} # xxx (video bit rate) +crop=${21} # -|width:height:x:y +xsize=${22} # -|... +aspect=${23} # -|4/3|16/9|... +deint=${24} # y|n +threads=${25} # -|1.. +vopts=${26} # -|... # other vcodec options #----------------------------------------------------------------------------------------------------------------------------------- @@ -78,7 +79,7 @@ tmp_name=../$divx_root-$divx_title.vob out_name=../$divx_root-$divx_title echo "DivX: [$divx_name] title: ($title)" -echo "Input: [$input] device: [$dvd_device] title: ($title) chapter: ($chapter) angle: ($angle) alang: ($alang) slang: ($slang)" +echo "Input: [$input] buf type: [$buf_type] device: [$dvd_device] title: ($title) chapter: ($chapter) angle: ($angle) alang: ($alang) slang: ($slang)" echo "Audio: [$audio] abr: ($abr) asrate: ($asrate) stereo: ($stereo) volume: (${volume})" echo "Sub: [$sub]" echo "Video: [$video] vcodec: [$vcodec] vquality: [$vquality] vbr: ($vbr) crop: ($crop) xsize: ($xsize) aspect: ($aspect) deint: ($deint) threards: ($threads) vopts: [${vopts}]" @@ -91,6 +92,16 @@ echo "Video: [$video] vcodec: [$vcodec] vquality: [$vquality] vbr: ($vbr) shopt -s extglob +if [ "$buf_type" == "u" ] +then + audio_buf_opt="-oac pcm" + video_buf_opt="-ovc raw" +else + audio_buf_opt="-oac copy" + video_buf_opt="-ovc copy" +fi + + if [ "$dvd_device" != "-" ] then device_opt="-dvd-device $dvd_device" @@ -159,6 +170,8 @@ esac + + #----------------------------------------------------------------------------------------------------------------------------------- # Audio Setup #----------------------------------------------------------------------------------------------------------------------------------- @@ -177,43 +190,6 @@ else stereo_mode=3 fi -if [ "${volume}" == "-" ] -then - vol_opt="" -else - vol_opt="-af-add volume=$volume:0" -fi - -audio_comp_opt="-oac mp3lame -lameopts cbr:br=$abr:aq=0:mode=$stereo_mode $aresample $vol_opt" -audio_copy_opt="-oac copy" - -if [ "$audio" != "n" ] -then - if [ "$video" == "1" ] - then - audio_opt1="$audio_comp_opt" - else - if [ "$video" != "n" ] - then - if [ "$audio" == "avp" ] - then - audio_opt1="$audio_comp_opt" - audio_opt2="$audio_comp_opt" - else - if [ "$audio" == "fvp" ] - then - audio_opt1="$audio_copy_opt" - audio_opt2="$audio_comp_opt" - fi - fi - else - audio_opt1="$audio_comp_opt" - fi - fi -else - audio_opt1="$audio_copy_opt" - audio_opt2="$audio_copy_opt" -fi @@ -221,8 +197,6 @@ fi # Video Setup #----------------------------------------------------------------------------------------------------------------------------------- -gen_opt="" - video_lavc_header_11="-ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$vbr" video_lavc_header_21="-ovc lavc -lavcopts vcodec=mpeg4:vpass=1:vbitrate=$vbr" video_lavc_header_22="-ovc lavc -lavcopts vcodec=mpeg4:vpass=2:vbitrate=$vbr" @@ -245,10 +219,14 @@ video_x264_header_11="-ovc x264 -x264encopts bitrate=$vbr" video_x264_header_21="-ovc x264 -x264encopts pass=1:bitrate=$vbr" video_x264_header_22="-ovc x264 -x264encopts pass=2:bitrate=$vbr" -video_x264_body_0="" -video_x264_body_1="subq=4:bframes=2:b_pyramid:weight_b" -video_x264_body_2="subq=5:8x8dct:frameref=2:bframes=3:b_pyramid:weight_b" -video_x264_body_3="subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid:weight_b" +video_x264_body_0="bframes=0" +#video_x264_body_0="b_pyramid=1" +video_x264_body_1="subq=4:bframes=2:bframes=0" +#video_x264_body_1="subq=4:bframes=2:b_pyramid=1:weight_b" +video_x264_body_2="subq=5:8x8dct:frameref=2:bframes=0" +#video_x264_body_2="subq=5:8x8dct:frameref=2:bframes=3:b_pyramid=1:weight_b" +video_x264_body_3="subq=9:partitions=all:8x8dct:me=umh:me_range=64:frameref=6:bframes=0" +#video_x264_body_3="subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid:weight_b" @@ -287,12 +265,19 @@ fi if [ "$aspect" == "-" ] then - video_opt1=$video_opt1":autoaspect" - video_opt2=$video_opt2":autoaspect" + if [ "$vcodec" != "x264" ] + then + video_opt1=$video_opt1":autoaspect" + video_opt2=$video_opt2":autoaspect" + fi else - video_opt1=$video_opt1":aspect=$aspect" - video_opt2=$video_opt2":aspect=$aspect" - gen_opt="${gen_opt} -force-avi-aspect ${aspect}" + glob_opt="-force-avi-aspect ${aspect}" + + if [ "$vcodec" != "x264" ] + then + video_opt1=$video_opt1":aspect=$aspect" + video_opt2=$video_opt2":aspect=$aspect" + fi fi if [ "$threads" != "-" ] @@ -328,6 +313,8 @@ echo "Cleanup..." + + #----------------------------------------------------------------------------------------------------------------------------------- # Bufferizing #----------------------------------------------------------------------------------------------------------------------------------- @@ -335,7 +322,7 @@ echo "Cleanup..." if [ "$input" != "d" ] && [ "$input" != "b" ] then echo "Bufferizing..." - mencoder $read_opt1 -oac copy -ovc copy -o $tmp_name >$out_name.1.log 2>&1 + mencoder $read_opt1 $audio_buf_opt $video_buf_opt -o $tmp_name >$out_name.1.log 2>&1 if [ "$input" == "dbo" ] then @@ -348,7 +335,68 @@ fi #----------------------------------------------------------------------------------------------------------------------------------- -# Video Compression +# Audio Volume Setup +#----------------------------------------------------------------------------------------------------------------------------------- + +if [ "${volume}" == "-" ] +then + vol_opt="" +else + if [ "${volume/\/*/}" == "a" ] + then + vol_max="$(mencoder $read_opt2 -af-add stats -oac pcm -ovc copy -o /dev/null | grep "stats: max_volume:" | sed -e 's/.*-//' -e 's/ dB.*//')" + vol_opt="-af-add volume=$((${vol_max} - ${volume/*\//})):0" + echo "[${vol_max}] - [${volume/*\//}]" + else + vol_opt="-af-add volume=$volume:0" + fi +fi + + + + + +#----------------------------------------------------------------------------------------------------------------------------------- +# Audio Final Setup +#----------------------------------------------------------------------------------------------------------------------------------- + +audio_comp_opt="-oac mp3lame -lameopts cbr:br=$abr:aq=0:mode=$stereo_mode $aresample ${vol_opt}" +audio_copy_opt="-oac copy" + +if [ "$audio" != "n" ] +then + if [ "$video" == "1" ] + then + audio_opt1="$audio_comp_opt" + else + if [ "$video" != "n" ] + then + if [ "$audio" == "avp" ] + then + audio_opt1="$audio_comp_opt" + audio_opt2="$audio_comp_opt" + else + if [ "$audio" == "fvp" ] + then + audio_opt1="$audio_copy_opt" + audio_opt2="$audio_comp_opt" + fi + fi + else + audio_opt1="$audio_comp_opt" + fi + fi +else + audio_opt1="$audio_copy_opt" + audio_opt2="$audio_copy_opt" +fi + + + + + +#----------------------------------------------------------------------------------------------------------------------------------- +# Audio / Video Compression #----------------------------------------------------------------------------------------------------------------------------------- if [ "$video" != "n" ] @@ -356,18 +404,18 @@ then if [ "$video" == "1" ] then echo "Compressing DivX..." - mencoder $read_opt2 $gen_opt $audio_opt1 $video_opt1 $vf_opt -o $divx_name >$out_name.3.log 2>&1 + mencoder $read_opt2 $audio_opt1 $video_opt1 $vf_opt $glob_opt -o $divx_name >$out_name.3.log 2>&1 else echo "Compressing DivX pass 1..." - mencoder $read_opt2 $gen_opt $audio_opt1 $video_opt1 $vf_opt -o /dev/null >$out_name.3.log 2>&1 + mencoder $read_opt2 $audio_opt1 $video_opt1 -o /dev/null >$out_name.3.log 2>&1 echo "Compressing DivX pass 2..." - mencoder $read_opt2 $gen_opt $audio_opt2 $video_opt2 $vf_opt -o $divx_name >$out_name.4.log 2>&1 + mencoder $read_opt2 $audio_opt2 $video_opt2 $vf_opt $glob_opt -o $divx_name >$out_name.4.log 2>&1 fi else if [ "$audio" == "ap" ] then echo "Compressing DivX audio..." - mencoder $read_opt2 $gen_opt $audio_opt1 -ovc copy -o $divx_name >$out_name.3.log 2>&1 + mencoder $read_opt2 $audio_opt1 -ovc copy $glob_opt -o $divx_name >$out_name.2.log 2>&1 fi fi