Move printing of ID_AID_???_LANG to ts_add_stream instead of ts_detect_streams.
[mplayer/glamo.git] / TOOLS / divx2svcd.sh
blob4192e0f782261532c7943ca6199bfdfcf35d5655
1 #!/bin/bash
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
14 ###changelog###
15 #nobody cares about it :-)
16 cat >/dev/null <<EOF
17 0.5.1
18 - faster code by not re-mplexing one-cd-size or smaller videos
20 0.5.0
21 - needless for dumpvideo patch ;-)
23 0.4.9
24 - changed default bitrate to 1600 for better quality
25 - fix for burning more than one cd
26 - fix for wrong parameter help
28 0.4.8
29 - small fixes
31 0.4.7
32 - fixed bug, when there is no sub available
34 0.4.6
35 - support for burning the svcd with cdrecord
36 - lots of paranoid options for better quality from Denes Balatoni
38 0.4.5
39 - support for filenames including spaces
41 0.4.4
42 - support for checking all applications this script uses
43 - this changelog
45 0.4.3
46 - advanced detectation of movie aspect (mpeg4 codec, mpeg container)
48 0.4.2
49 - advanced vf options for movies with non-standard aspect
51 0.4.1
52 - checking for available sub
54 0.4.0
55 - support for tcmplex-panteltje
56 - support for libavcodec audio encoder
58 0.3.1-0.3.2
59 - small fixes
61 0.3
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
67 0.2
68 - support for tcmplex instead of mplex
70 0.1rc2-rc4
71 - small bugfixes
73 0.1rc1
74 - initial release
76 EOF
79 ###preparing###
80 #help
82 usage()
84 cat <<EOF
85 Usage: `basename $0` input_avi [options]
87 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
94 EOF
98 #initializating constants
99 version='0.5.1'
100 bitrate=1375
101 cdsize=795
102 burning=0
103 cleaning=0
104 dev4='0,0,0'
105 firstcd=1
107 #paranoid options
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'
110 #header
111 echo "DivX2SvcD $version (C) 2003-2004 Vajna Miklos"
112 echo
114 #checking for ls
115 ls=`which ls`
117 #checking for bc
118 which bc >/dev/null 2>&1
119 bcbin=`which bc 2>/dev/null`
120 if [ $? != 0 ]; then
121 cat <<EOF
122 ERROR: Can't find bc. You can download it at
123 ftp://ftp.ibiblio.org/pub/gnu/bc/bc-1.06.tar.gz
125 exit 1
128 #checking for vcdimager
129 which vcdimager >/dev/null 2>&1
130 bcbin=`which vcdimager 2>/dev/null`
131 if [ $? != 0 ]; then
132 cat <<EOF
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
136 exit 1
139 #checking which mplex utility we have to use
140 which tcmplex-panteltje >/dev/null 2>&1
141 if [ $? = 0 ]; then
142 tcp_path=`which tcmplex-panteltje 2>&1`
143 else
144 tcp_path="x"
146 which tcmplex >/dev/null 2>&1
147 if [ $? = 0 ]; then
148 tc_path=`which tcmplex 2>&1`
149 else
150 tc_path="x"
153 if [ -x $tcp_path ]; then
154 tcbin=tcmplex-panteltje
155 tcopt=-0
156 elif [ -x $tc_path ]; then
157 tcbin=tcmplex
158 tcopt=-p
159 else
160 cat <<EOF
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
165 exit 1
168 #pharsing parameters
170 if [ $# -le 0 ]; then
171 echo "Missing parameter!"
172 usage
173 exit 1
176 case $1 in
178 usage
179 exit 1
182 echo "Missing parameter!"
183 usage
184 exit 1
187 input=`echo $1 |sed 's/\\ / /'`
188 if [ "$input" = "`basename "$input"`" ]; then
189 input="`pwd`/$1"
191 nev=`basename "$input" .avi`
192 shift 1
194 esac
196 while [ "$1"x != "x" ]; do
197 case $1 in
198 -b|--bitrate)
199 bitrate=$2
200 shift 1
202 -s|--cdsize)
203 cdsize="$2"
204 shift 1
206 -d|--device)
207 dev4="$2"
208 shift 1
210 -w|--write)
211 burning=1
213 -c|--clean)
214 cleaning=1
216 -h|--help)
217 usage
218 exit 0
220 esac
221 shift 1
222 done
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
229 #linux 2.4.x
230 dev="dev=$dev4"
231 echo "$dev4"
232 elif [ `uname -r |cut -d '.' -f 2` = 6 ]; then
233 #linux 2.6.x
234 if [ -e /dev/cdrecorder ]; then
235 dev='dev=/dev/cdrecorder'
236 echo "/dev/cdrecorder"
237 else
238 cat <<EOF
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'
243 exit 1
245 else
246 cat <<EOF
247 ERROR: Linux 2.4 or 2.6 series not found. You can download it at
248 http://www.kernel.org/ ;-)
250 exit 1
253 #checking for cdrecord
254 which cdrecord >/dev/null 2>&1
255 cdrbin=`which cdrecord 2>/dev/null`
256 if [ $? != 0 ]; then
257 cat <<EOF
258 ERROR: Can't find cdrecord. You can download it at
259 ftp://ftp.berlios.de/pub/cdrecord/alpha/cdrtools-2.01a20.tar.gz
261 exit 1
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
266 cat <<EOF
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
270 else
271 echo "`$cdrbin -version |cut -d ' ' -f 2`"
276 #checking for sub avariable
278 if [ -f "$nev.sub" ]; then
279 subopts=$nev.sub
280 else
281 subopts=''
284 if [ "x$subopts" = "x" ]; then
285 subs=''
286 else
287 subs='-sub '
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
299 height=576
302 #find out the vf options
303 if [ "$height" = 576 ]; then
304 vfopts='-vf scale=480:576'
305 else
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
314 #asking for cd
315 cat <<EOF
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.
322 read -n 1 i
326 ###start working###
327 #encoding
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
334 else
335 #splitting
336 mplayer -dumpvideo -dumpfile "$nev.m2v" "${nev}2.avi"
337 mplayer -dumpaudio -dumpfile "$nev.mp2" "${nev}2.avi"
338 rm "${nev}2.avi"
339 echo "maxFileSize = $cdsize" > template
340 $tcbin -i "$nev.m2v" $tcopt "$nev.mp2" -o "$nev.mpg" -m s -F template
341 rm template
342 rm "$nev.m2v" "$nev.mp2"
345 for i in *mpg
347 nev2=`basename "$i" .mpg`
348 #creating images
349 vcdimager -t svcd -c "$nev2.cue" -b "$nev2.bin" "$i"
350 #burning if needs
351 if [ "$burning" = 1 ]; then
352 if [ "$firstcd" != 1 ]; then
353 cat <<EOF
355 Please insert an another blank cd in your cdwriter.
356 Press any key when your are ready.
358 read -n 1 i
359 else
360 firstcd=2
362 $cdrbin -v -dao $dev speed=12 gracetime=2 driveropts=burnfree -eject cuefile="$nev2.cue"
364 #cleaning if needs
365 if [ "$cleaning" = 1 ]; then
366 rm -f "$nev2.cue" "$nev2.bin"
368 done
369 rm -f "$nev"*mpg