3 # (c) 2003 Vajna Miklos <mainroot@freemail.hu>
4 # divx2svcd for MPlayer
5 # distributed under GPL License
7 # simple utility that creates a SVCD from a video in an AVI container
9 # The newest version of this utility can be found at
10 # http://vmiklos.uw.hu/divx2svcd/divx2svcd
11 # MPlayer available at
12 # http://www.mplayerhq.hu/MPlayer/releases/MPlayer-1.0pre3try2.tar.bz2
15 #nobody cares about it :-)
18 - faster code by not re-mplexing one-cd-size or smaller videos
21 - needless for dumpvideo patch ;-)
24 - changed default bitrate to 1600 for better quality
25 - fix for burning more than one cd
26 - fix for wrong parameter help
32 - fixed bug, when there is no sub available
35 - support for burning the svcd with cdrecord
36 - lots of paranoid options for better quality from Denes Balatoni
39 - support for filenames including spaces
42 - support for checking all applications this script uses
46 - advanced detectation of movie aspect (mpeg4 codec, mpeg container)
49 - advanced vf options for movies with non-standard aspect
52 - checking for available sub
55 - support for tcmplex-panteltje
56 - support for libavcodec audio encoder
62 - almost totally rewritten from scratch
63 based on the idea of Denes Balatoni <pnis@coder.hu>
64 - support for toolame instead of mp2enc
65 - suppert for libavcodec mpeg2video codec instead of mpeg2enc
68 - support for tcmplex instead of mplex
85 Usage: `basename $0` input_avi [options]
88 -b|--bitrate xx bitrate of mp2 video stream [1375]
89 -s|--cdsize xx size of the cd we split the video to [795]
90 -w|--writecd enables burning [disable]
91 -d|--device xx scsi cd-recording device if you are using linux 2.4.x [0,0,0]
92 -c|--clean clean up svcd images you just created
93 -h|--help this help screen
98 #initializating constants
108 paraopts
='vrc_override=1,10,708:vqcomp=0.1:vratetol=10000000:vrc_buf_size=917:vrc_maxrate=2500:intra_matrix=8,9,12,22,26,27,29,34,9,10,14,26,27,29,34,37,12,14,18,27,29,34,37,38,22,26,27,31,36,37,38,40,26,27,29,36,39,38,40,48,27,29,34,37,38,40,48,58,29,34,37,38,40,48,58,69,34,37,38,40,48,58,69,79:inter_matrix=16,18,20,22,24,26,28,30,18,20,22,24,26,28,30,32,20,22,24,26,28,30,32,34,22,24,26,30,32,32,34,36,24,26,28,32,34,34,36,38,26,28,30,32,34,36,38,40,28,30,32,34,36,38,42,42,30,32,34,36,38,40,42,44'
111 echo "DivX2SvcD $version (C) 2003-2004 Vajna Miklos"
118 which bc >/dev
/null
2>&1
119 bcbin
=`which bc 2>/dev/null`
122 ERROR: Can't find bc. You can download it at
123 ftp://ftp.ibiblio.org/pub/gnu/bc/bc-1.06.tar.gz
128 #checking for vcdimager
129 which vcdimager
>/dev
/null
2>&1
130 bcbin
=`which vcdimager 2>/dev/null`
133 ERROR: Can't find vcdimager. You can download it at http://www.vcdimager.org
134 /pub/vcdimager/vcdimager-0.7_UNSTABLE/vcdimager-0.7.14.tar.gz
139 #checking which mplex utility we have to use
140 which tcmplex-panteltje
>/dev
/null
2>&1
142 tcp_path
=`which tcmplex-panteltje 2>&1`
146 which tcmplex
>/dev
/null
2>&1
148 tc_path
=`which tcmplex 2>&1`
153 if [ -x $tcp_path ]; then
154 tcbin
=tcmplex-panteltje
156 elif [ -x $tc_path ]; then
161 ERROR: Can't find any sutable mplex utility. You can download
162 tcmplex-panteltje at http://sunsite.rediris.es/
163 sites2/ibiblio.org/linux/apps/video/tcmplex-panteltje-0.3.tgz
170 if [ $# -le 0 ]; then
171 echo "Missing parameter!"
182 echo "Missing parameter!"
187 input
=`echo $1 |sed 's/\\ / /'`
188 if [ "$input" == "`basename "$input"`" ]; then
191 nev
=`basename "$input" .avi`
196 while [ "$1"x
!= "x" ]; do
224 #checking for cd-recording device
225 if [ "$burning" == 1 ]; then
226 echo -n "Searching for cdrecorder device... "
228 if [ `uname -r |cut -d '.' -f 2` == 4 ]; then
232 elif [ `uname -r |cut -d '.' -f 2` == 6 ]; then
234 if [ -e /dev
/cdrecorder
]; then
235 dev
='dev=/dev/cdrecorder'
236 echo "/dev/cdrecorder"
239 ERROR: Device file /dev/cdrecorder not found. Please link your
240 cd-recording device to /dev/cdrecorder!
241 Example: 'cd /dev; ln -s hdc cdrecorder'
247 ERROR: Linux 2.4 or 2.6 series not found. You can download it at
248 http://www.kernel.org/ ;-)
253 #checking for cdrecord
254 which cdrecord
>/dev
/null
2>&1
255 cdrbin
=`which cdrecord 2>/dev/null`
258 ERROR: Can't find cdrecord. You can download it at
259 ftp://ftp.berlios.de/pub/cdrecord/alpha/cdrtools-2.01a20.tar.gz
262 else #checking for version >= 2.01a14
263 echo -n "Checking for cdrecord version >= 2.01a14... "
264 $cdrbin cuefile
=a
2>&1 |
grep 'Bad Option' >/dev
/null
2>&1
265 if [ "$?" == 0 ]; then
267 ERROR: Can't find cdrecord version >= 2.01a14. You can download it at
268 ftp://ftp.berlios.de/pub/cdrecord/alpha/cdrtools-2.01a20.tar.gz
271 echo "`$cdrbin -version |cut -d ' ' -f 2`"
276 #checking for sub avariable
278 if [ -f "$nev.sub" ]; then
284 if [ "x$subopts" == "x" ]; then
290 #checking for what height needed
291 inputwidth
=`mplayer -vo null -ao null "$input" -frames 1 2>/dev/null |grep '=>'|cut -d ' ' -f 5|cut -d x -f 1`
292 inputheight
=`mplayer -vo null -ao null "$input" -frames 1 2>/dev/null |grep '=>'|cut -d ' ' -f 5|cut -d x -f 2`
293 svcdaspect
=`echo -e "scale=10\n1.596/($inputwidth/$inputheight)"|bc /dev/stdin`
294 height
=`echo -e "scale=10\n$svcdaspect*480"|bc /dev/stdin|cut -d . -f 1`
296 #checking for ratios less than 1.33
297 istoohigh
=`expr $height \> 577`
298 if [ "$istoohigh" = 1 ]; then
302 #find out the vf options
303 if [ "$height" = 576 ]; then
304 vfopts
='-vf scale=480:576'
306 #-vf processes filters in reverse order
307 exy
=`echo -e "scale=10\n(576-$height)/2"|bc /dev/stdin|cut -d . -f 1`
308 vfopts
="-vf scale=480:$height,expand=480:576:0:$exy:1"
309 echo "Using filter options: '$vfopts'"
312 #finish displaying informations
313 if [ "$burning" == 1 ]; then
317 Please insert a blank cd in your cdwriter.
318 (If you are using a rewritable media,
319 don't forgot to blank it before using divx2svcd.)
320 Press any key when your are ready.
328 mencoder
-ofps 25 -oac lavc
"$input" -ovc lavc
-lavcopts vcodec
=mpeg2video
:vbitrate
=$bitrate:acodec
=mp2
:abitrate
=128:keyint
=25:aspect
=4/3:$paraopts -o "${nev}2.avi" -srate 44100 -of mpeg
-channels 2 $vfopts $subs "$subopts"
330 videosize
=`$ls -l "${nev}2.avi"|tr -s ' '|cut -d ' ' -f5`
331 if ! [ `echo $(( $cdsize*1048576 < $videosize ))` == "1" ]; then
332 #video is smaller, than $cdsize
333 mv ${nev}2.avi
${nev}00.mpg
336 mplayer
-dumpvideo -dumpfile "$nev.m2v" "${nev}2.avi"
337 mplayer
-dumpaudio -dumpfile "$nev.mp2" "${nev}2.avi"
339 echo "maxFileSize = $cdsize" > template
340 $tcbin -i "$nev.m2v" $tcopt "$nev.mp2" -o "$nev.mpg" -m s
-F template
342 rm "$nev.m2v" "$nev.mp2"
347 nev2
=`basename "$i" .mpg`
349 vcdimager
-t svcd
-c "$nev2.cue" -b "$nev2.bin" "$i"
351 if [ "$burning" == 1 ]; then
352 if [ "$firstcd" != 1 ]; then
355 Please insert an another blank cd in your cdwriter.
356 Press any key when your are ready.
362 $cdrbin -v -dao $dev speed
=12 gracetime
=2 driveropts
=burnfree
-eject cuefile
="$nev2.cue"
365 if [ "$cleaning" == 1 ]; then
366 rm -f "$nev2.cue" "$nev2.bin"