comparison TOOLS/divx2svcd @ 11839:cbde5342c574

add divx2svcd script. uses mencoder instead of mpegtools by VMiklos <mamajom@axelero.hu>
author attila
date Sat, 24 Jan 2004 13:03:38 +0000
parents
children 38fd3979872b
comparison
equal deleted inserted replaced
11838:b4f1df0c1e3a 11839:cbde5342c574
1 #!/bin/bash
2
3 # (c) 2003 Vajna Miklos <mainroot@freemail.hu>
4 # divx2svcd for MPlayer 1.0pre3+dumpvideo patch
5 # distributed under GPL License
6
7 # A simple utility that creates SvcD from a video which uses avi container
8
9 # The newest version of this utility can be found at
10 # http://vmiklos.uw.hu/divx2svcd/divx2svcd
11
12 # MPlayer avariable at
13 # http://www1.mplayerhq.hu/MPlayer/releases/MPlayer-1.0pre3.tar.bz2
14 # dumpvideo patch at
15 # http://vmiklos.uw.hu/divx2svcd/mplayer-1.0pre3-dumpvideo.diff
16
17 ###changelog###
18 #nobody cares about it :-)
19 cat >/dev/null <<EOF
20 0.4.8
21 - small fixes
22
23 0.4.7
24 - fixed bug, when there is no sub available
25
26 0.4.6
27 - support for burning the svcd with cdrecord
28 - lots of paranoid options for better quality from Denes Balatoni
29
30 0.4.5
31 - support for filenames including spaces
32
33 0.4.4
34 - support for checking all applications this script uses
35 - this changelog
36
37 0.4.3
38 - advanced detectation of movie aspect (mpeg4 codec, mpeg container)
39
40 0.4.2
41 - advanced vf options for movies with non-standard aspect
42
43 0.4.1
44 - checking for available sub
45
46 0.4.0
47 - support for tcmplex-panteltje
48 - support for libavcodec audio encoder
49
50 0.3.1-0.3.2
51 - small fixes
52
53 0.3
54 - almost totally rewritten from scratch
55 based on the idea of Denes Balatoni <pnis@coder.hu>
56 - support for toolame instead of mp2enc
57 - suppert for libavcodec mpeg2video codec instead of mpeg2enc
58
59 0.2
60 - support for tcmplex instead of mplex
61
62 0.1rc2-rc4
63 - small bugfixes
64
65 0.1rc1
66 - initial release
67
68 EOF
69
70
71 ###preparing###
72 #help
73
74 function usage()
75 {
76 cat <<EOF
77 Usage: `basename $0` input_avi [options]
78
79 Options:
80 -b|--bitrate=xx bitrate of mp2 video stream [1600]
81 -s|--cdsize=xx size of the cd we split the video to [795]
82 -w|--writecd enables burning [disable]
83 -d|--device=xx scsi cd-recording device if you are using linux 2.4.x [0,0,0]
84 -c|--clean clean up svcd images you just created
85 -h|--help this help screen
86 EOF
87
88 }
89
90 #initializating constants
91 version='0.4.8'
92 bitrate=1200
93 cdsize=795
94 burning=0
95 cleaning=0
96 dev4='0,0,0'
97 firstcd=1
98
99 #paranoid options
100 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'
101
102 #header
103 echo "DivX2SvcD $version (C) 2003-2004 Vajna Miklos"
104 echo
105
106 #checking for bc
107 which bc >/dev/null 2>&1
108 bcbin=`which bc 2>/dev/null`
109 if [ $? != 0 ]; then
110 cat <<EOF
111 ERROR: Can't find bc. You can download it at
112 ftp://ftp.ibiblio.org/pub/gnu/bc/bc-1.06.tar.gz
113 EOF
114 exit 1
115 fi
116
117 #checking for vcdimager
118 which vcdimager >/dev/null 2>&1
119 bcbin=`which vcdimager 2>/dev/null`
120 if [ $? != 0 ]; then
121 cat <<EOF
122 ERROR: Can't find vcdimager. You can download it at http://www.vcdimager.org
123 /pub/vcdimager/vcdimager-0.7_UNSTABLE/vcdimager-0.7.14.tar.gz
124 EOF
125 exit 1
126 fi
127
128 #checking which mplex utility we have to use
129 which tcmplex-panteltje >/dev/null 2>&1
130 if [ $? = 0 ]; then
131 tcp_path=`which tcmplex-panteltje 2>&1`
132 else
133 tcp_path="x"
134 fi
135 which tcmplex >/dev/null 2>&1
136 if [ $? = 0 ]; then
137 tc_path=`which tcmplex 2>&1`
138 else
139 tc_path="x"
140 fi
141
142 if [ -x $tcp_path ]; then
143 tcbin=tcmplex-panteltje
144 tcopt=-0
145 elif [ -x $tc_path ]; then
146 tcbin=tcmplex
147 tcopt=-p
148 else
149 cat <<EOF
150 ERROR: Can't find any sutable mplex utility. You can download
151 tcmplex-panteltje at http://sunsite.rediris.es/
152 sites2/ibiblio.org/linux/apps/video/tcmplex-panteltje-0.3.tgz
153 EOF
154 exit 1
155 fi
156
157 #pharsing parameters
158
159 if [ $# -le 0 ]; then
160 echo "Missing parameter!"
161 usage
162 exit 1
163 fi
164
165 case $1 in
166 -h)
167 usage
168 exit 1
169 ;;
170 -*)
171 echo "Missing parameter!"
172 usage
173 exit 1
174 ;;
175 *)
176 input=`echo $1 |sed 's/\\ / /'`
177 if [ "$input" == "`basename "$input"`" ]; then
178 input="`pwd`/$1"
179 fi
180 nev=`basename "$input" .avi`
181 shift 1
182 ;;
183 esac
184
185 while [ "$1"x != "x" ]; do
186 case $1 in
187 -b|--bitrate)
188 bitrate=$2
189 shift 1
190 ;;
191 -s|--cdsize)
192 cdsize="$2"
193 shift 1
194 ;;
195 -d|--device)
196 dev4="$2"
197 shift 1
198 ;;
199 -w|--write)
200 burning=1
201 ;;
202 -c|--clean)
203 cleaning=1
204 ;;
205 -h|--help)
206 usage
207 exit 0
208 ;;
209 esac
210 shift 1
211 done
212
213 #checking for cd-recording device
214 if [ "$burning" == 1 ]; then
215 echo -n "Searching for cdrecorder device... "
216
217 if [ `uname -r |cut -d '.' -f 2` == 4 ]; then
218 #linux 2.4.x
219 dev="dev=$dev4"
220 echo "$dev4"
221 elif [ `uname -r |cut -d '.' -f 2` == 6 ]; then
222 #linux 2.6.x
223 if [ -e /dev/cdrecorder ]; then
224 dev='dev=/dev/cdrecorder'
225 echo "/dev/cdrecorder"
226 else
227 cat <<EOF
228 ERROR: Device file /dev/cdrecorder not found. Please link your
229 cd-recording device to /dev/cdrecorder!
230 Example: 'cd /dev; ln -s hdc cdrecorder'
231 EOF
232 exit 1
233 fi
234 else
235 cat <<EOF
236 ERROR: Linux 2.4 or 2.6 series not found. You can download it at
237 http://www.kernel.org/ ;-)
238 EOF
239 exit 1
240 fi
241
242 #checking for cdrecord
243 which cdrecord >/dev/null 2>&1
244 cdrbin=`which cdrecord 2>/dev/null`
245 if [ $? != 0 ]; then
246 cat <<EOF
247 ERROR: Can't find cdrecord. You can download it at
248 ftp://ftp.berlios.de/pub/cdrecord/alpha/cdrtools-2.01a20.tar.gz
249 EOF
250 exit 1
251 else #checking for version >= 2.01a14
252 echo -n "Checking for cdrecord version >= 2.01a14... "
253 $cdrbin cuefile=a 2>&1 |grep 'Bad Option' >/dev/null 2>&1
254 if [ "$?" == 0 ]; then
255 cat <<EOF
256 ERROR: Can't find cdrecord version >= 2.01a14. You can download it at
257 ftp://ftp.berlios.de/pub/cdrecord/alpha/cdrtools-2.01a20.tar.gz
258 EOF
259 else
260 echo "`$cdrbin -version |cut -d ' ' -f 2`"
261 fi
262 fi
263 fi
264
265 #checking for sub avariable
266
267 if [ -f "$nev.sub" ]; then
268 subopts=$nev.sub
269 else
270 subopts=''
271 fi
272
273 if [ "x$subopts" == "x" ]; then
274 subs=''
275 else
276 subs='-sub '
277 fi
278
279 #checking for what height needed
280 inputwidth=`mplayer -vo null -ao null "$input" -frames 1 2>/dev/null |grep '=>'|cut -d ' ' -f 5|cut -d x -f 1`
281 inputheight=`mplayer -vo null -ao null "$input" -frames 1 2>/dev/null |grep '=>'|cut -d ' ' -f 5|cut -d x -f 2`
282 svcdaspect=`echo -e "scale=10\n1.596/($inputwidth/$inputheight)"|bc /dev/stdin`
283 height=`echo -e "scale=10\n$svcdaspect*480"|bc /dev/stdin|cut -d . -f 1`
284
285 #checking for ratios less than 1.33
286 istoohigh=`expr $height \> 577`
287 if [ "$istoohigh" = 1 ]; then
288 height=576
289 fi
290
291 #find out the vf options
292 if [ "$height" = 576 ]; then
293 vfopts='-vf scale=480:576'
294 else
295 #-vf processes filters in reverse order
296 exy=`echo -e "scale=10\n(576-$height)/2"|bc /dev/stdin|cut -d . -f 1`
297 vfopts="-vf scale=480:$height,expand=480:576:0:$exy:1"
298 echo "Using filter options: '$vfopts'"
299 fi
300
301 #finish displaying informations
302 if [ "$burning" == 1 ]; then
303 #asking for cd
304 cat <<EOF
305
306 Please insert a blank cd in your cdwriter.
307 (If you are using a rewritable media,
308 don't forgot to blank it before using divx2svcd.)
309 Press any key when your are ready.
310 EOF
311 read -n 1 i
312 fi
313
314
315 ###start working###
316 #encoding
317 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 -channels 2 $vfopts $subs "$subopts"
318
319 #splitting
320 mplayer -dumpvideo -dumpfile "$nev.m2v" "${nev}2.avi"
321 mplayer -dumpaudio -dumpfile "$nev.mp2" "${nev}2.avi"
322 rm "${nev}2.avi"
323 echo "maxFileSize = $cdsize" > template
324 $tcbin -i "$nev.m2v" $tcopt "$nev.mp2" -o "$nev.mpg" -m s -F template
325 rm template
326 rm "$nev.m2v" "$nev.mp2"
327
328 `which ls` -N "$nev"*mpg | while read i
329 do
330 nev2=`basename "$i" .mpg`
331 #creating images
332 vcdimager -t svcd -c "$nev2.cue" -b "$nev2.bin" "$i"
333 #burning if needs
334 if [ "$burning" == 1 ]; then
335 if ["$firstcd" != 1 ]; then
336 cat <<EOF
337
338 Please insert an another blank cd in your cdwriter.
339 Press any key when your are ready.
340 EOF
341 read -n 1 i
342 fi
343 $cdrbin -v -dao $dev speed=12 gracetime=2 driveropts=burnfree -eject cuefile="$nev2.cue"
344 fi
345 #cleaning if needs
346 if [ "$cleaning" == 1 ]; then
347 rm -f "$nev2.cue" "$nev2.bin"
348 fi
349 done
350 rm -f "$nev"*mpg