7 # 2002/09/21 Jürgen Hammelmann <juergen.hammelmann@gmx.de>
9 # Script: MPlayer Sources (DVD) to (S)VCD ripping and burning
16 # toolame (optionally)
19 for exe
in mplayer mpeg2enc mp2enc mplex yuvscaler
; do
20 if [ -z "`which $exe`" ]; then
21 echo "ERROR: $exe must be in your path $PATH!"
25 for exe
in vcdimager lame cdrdao yuvdenoise sox toolame normalize
; do
26 if [ -z "`which $exe`" ]; then
27 echo "WARNING: $exe is not found in your path $PATH!"
31 ################################################################################
33 # 2002/04/11 v0.1.0: first version
36 # - handles now multiple vcd's
37 # - support's mp3 audio as option
38 # - use of mp2enc/lame instead of toolame because of support
39 # of resampling and mp3
41 # - new option "-burnonly"
43 # - removes mpg file after mastering cd image
44 # (mplayer can read bin images!)
47 # - bugfixes / changes
50 # - new option "-norm"
54 # - "-norm" renamed to "-vnorm"
59 # - new option "-sync"
61 # - new option "-mpgonly"
64 # - tests now, if the commands are in path and give warnings
68 # - new options: "-sox", "-volume", "-toolame"
69 # - renamed "-mpg" to "-mpegsrc"
70 # - default cd size changed to 800mb
72 # - aspect ratio for vcd's, too
77 ################################################################################
79 # global config section, change them to your needs!
81 TMPDIR
="." # path to directory for creating temporary files, recommended 2-3GB space
83 CDDRV
="generic-mmc" # cdrdao: cdwriter driver
84 CDDEV
="--device 0,1,0" # or comment out and create link /dev/cdrecorder
85 # to your cdwriter dev
88 ################################################################################
93 ################################################################################
96 echo "Usage: $HOWCALLED <basename> [$HOWCALLED options] [mplayer options]"
98 echo " <basename> is used as basename of the resulting mpg/bin files."
100 echo "For mplayer options see mplayer help and manual."
102 echo "$HOWCALLED options:"
105 echo "-a <n> sets the aspect ratio (for SVCD):"
106 echo " 1 - 1:1 display"
107 echo " 2 - 4:3 display"
108 echo " 3 - 16:9 display"
109 echo " 4 - 2.21:1 display"
110 echo "-abr <n> output audio bitrate in kbs [224]."
111 echo "-asr <n> output audio sample rate in Hz [44100]."
112 echo "-blank cleans cd-rw before burning."
113 echo "-burnonly burn only the premastered <name>*.cue/<name>*.bin images."
114 echo "-cdsize <n> maximal size of cd images [800 = 80min raw cd]."
115 echo "-denoise denoises mpeg stream."
116 echo "-mp3 outputs audio in mp3 instead of mp2 format."
117 echo "-mpegsrc don't encode from source, multiplex/burn the "
118 echo " encoded mpg stream."
119 echo "-mpgonly do only encoding to mpeg 1/2 format."
120 echo "-noburn disables burning."
121 echo "-normalize use 'normalize'."
122 echo "-overburn enables overburning a cd."
123 echo "-pulldown enable pulldown mode in output."
124 echo "-ratio <s> output ratio size of frames, see yuvscaler (1)."
125 echo "-size <X>x<Y> sets output size of frames."
126 echo "-sox use sox for audio resampling."
127 echo "-svcdout encode to SVCD format [VCD default]."
128 echo "-sync <n> set the presentation timestamp offset of video"
129 echo " stream w.r.t. audio stream (video-audio) in mSec."
130 echo "-toolame use toolame instead of mp2enc."
131 echo "-v <volume> change amplitude (floating point); less than 1.0"
132 echo " decreases, greater than 1.0 increases. Use that only"
133 echo " together with sox!"
134 echo "-vbr <n> output video bitrate in kbs [VCD:1152, SVCD:2500]."
135 echo "-vfr <n> sets the frame-rate of the output-stream. Currently"
136 echo " only the standard MPEG rates are supported:"
138 echo " 1 - 24000.0/1001.0 (NTSC 3:2 pulldown converted FILM)"
139 echo " 2 - 24.0 (NATIVE FILM)"
140 echo " 3 - 25.0 (PAL/SECAM VIDEO / converted FILM)"
141 echo " 4 - 30000.0/1001.0 (NTSC VIDEO)"
143 echo " 6 - 50.0 (PAL FIELD RATE)"
144 echo " 7 - 60000.0/1001.0 (NTSC FIELD RATE)"
146 echo "-vnorm <p|n|s> sets the input video norm p, n or s:"
147 echo " forces the input stream to be treated as PAL|NTSC|SECAM"
148 echo " regardless of what the stream header might suggest."
149 echo "-w outputs in wide screen format 16:9."
153 echo "'$HOWCALLED teneriffa teneriffa.avi'"
154 echo "this creates a VCD from an avi file."
156 echo "'$HOWCALLED crazy dvd://3 -w':"
157 echo "encodes and burns dvd title 3 to VCD in 16:9."
159 echo "'$HOWCALLED carter dvd://1 -sid 0 -aid 128 -ss 3:00 -frames 1500 \\"
160 echo " -noburn -vnorm n -vfr 1':"
161 echo "this encodes 1500 frames of dvd title 1 with subtitle 0 and audio stream"
162 echo "128 starting from 3:00 with frame rate 29.97 fps and input video norm NTSC"
163 echo "and output frame rate 23.98 fps because of the 3:2 pulldown method in NTSC."
165 echo "'$HOWCALLED bj -size 640x272 -vf expand=640:480:0:104:0 \\"
166 echo " -cdsize 645 -noburn bj.avi'"
167 echo "this example above shows you, how to deal with movies which are not"
168 echo "created with aspect ratios of 4:3 or 16:9."
171 HOWCALLED
=`basename $0`
172 if [ $# -le 1 ]; then
190 # create a named pipe for video stream
213 mplexnorm
="-f $VCDMODE -m 1 -V -b 46"
225 while [ "$1"x
!= "x" ]; do
262 overburn
="--overburn"
298 -sid) # mplayer option: have to set vf expand, too!!!
299 sub
="-vf pp,expand=-1:-1:-1:-1:1 -sid $2"
332 mpegnorm
="-f $VCDMODE -b $vbr -B 260 -V 46"
333 if [ "$vnorm" = "SVCD" ]; then
334 [ $vbrset -eq 0 ] && vbr
=2500
335 mplexnorm
="-f $SVCDMODE -m 2 -V -b 230"
336 mpegnorm
="-f $SVCDMODE -b $vbr -B 260 -V 230"
340 # ratio overwrites wide sizing, size overwrites default frame size
341 [ -n "$ratio" ] && wide
="-M $ratio"
342 [ -n "$size" ] && size
="-O SIZE_$size"
344 # with mp3 audio set the default audio bitrate to 128 kbs
345 [ $mp3 -eq 1 -a $abrset -eq 0 ] && abr
=128
347 # audio sample rate in kHz
348 a
=$
(($a=$asr / 1000))
349 b
=$
(($b=$asr % 1000))
350 [ $b -le 9 ] && b
="00$b00"
351 [ $b -le 99 ] && b
="0$b00"
355 if [ $burnonly -eq 0 ]; then
357 if [ $mkstream -eq 1 ]; then
359 command="mplayer -noframedrop -vo yuv4mpeg -ao pcm:waveheader -v -osdlevel 0 $sub $params"
364 ($denoise < $VIDEO | \
365 yuvscaler
-v 0 $wide -O $vnorm $size $yuvin | \
366 mpeg2enc
-v 0 -s $mpegnorm $aratio -S $CDMAXSIZE -g 6 -G 15 -r 16 \
367 $pd $framerate $yuvin -4 2 -2 1 -o $NAME.mpv
) &
369 # wait for finishing the subprocesses
373 [ $norm -eq 1 ] && (echo "normalizing sound..."; normalize
$AUDIO)
375 # do resampling with sox
376 if [ $sox -ne 0 ]; then
377 echo "wait, do resampling with sox..."
378 sox
$AUDIO -v $volume -r $asr $NAME.wav resample
-qs
379 mv -f $NAME.wav
$AUDIO
382 if [ $toolame -ne 0 -a $mp3 -eq 0 ]; then
383 # do mp2 encoding with toolame
384 echo "wait, encoding to mp2 audio with toolame..."
385 toolame
-b $abr $AUDIO
386 mv -f `basename $AUDIO .wav`.mp2
$NAME.mpa
387 elif [ $toolame -eq 0 -a $mp3 -eq 0 ]; then
388 # mp2enc/lame can't read audiodump.wav directly from named pipe,
389 # we have to read the whole file.
390 echo "wait, encoding to mp2 audio with mp2enc..."
391 mp2enc
-b $abr -r $asr -o $NAME.mpa
< $AUDIO
392 elif [ $mp3 -ne 0 ]; then
393 echo "wait, encoding to mp3 audio with lame..."
394 lame
-b $abr --resample $kasr - $NAME.mpa
< $AUDIO
398 # remove wav file, won't need anymore!
402 [ -f $NAME.mpv
-a -f $NAME.mpa
] ||
exit 1
404 mplex
$mplexnorm $sync $NAME.mpv
$NAME.mpa
-o ${NAME}%d.mpg
406 # remove pipe, won't need anymore!
409 # should i create only the mpeg file?
410 [ $mpgonly -eq 1 ] && exit 0
413 for mpg
in ${NAME}*.mpg
; do
414 [ -f $mpg ] ||
exit 1
415 cue
="`basename $mpg .mpg`.cue"
416 bin
="`basename $mpg .mpg`.bin"
418 vcdimager
$imaget -c $cue -b $bin $mpg
419 [ -f $bin -a -f $cue ] && rm -f $mpg
422 # end of streaming/mastering
426 [ $burn -eq 0 ] && exit 0
428 for cue
in ${NAME}*.cue
; do
429 bin
="`basename $cue .cue`.bin"
430 [ -f $bin -a -f $cue ] ||
exit 1
432 echo "please insert a cd in your cdwriter, after a keypress we start:"
435 if [ $blank -eq 1 ]; then
436 cdrdao blank
--reload $CDDEV --driver $CDDRV --blank-mode minimal
438 cdrdao
write $overburn --reload $CDDEV --driver $CDDRV $cue