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