Mercurial > mplayer.hg
comparison TOOLS/dvd2divxscript.pl @ 7116:e751a2b0991d
written by Florian Schilhabel <florian.schilhabel@gmx.net>
author | alex |
---|---|
date | Wed, 28 Aug 2002 17:14:02 +0000 |
parents | |
children | a5785a0b9ee1 |
comparison
equal
deleted
inserted
replaced
7115:55716603988c | 7116:e751a2b0991d |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # | |
4 # (c) 2002 by Florian Schilhabel <florian.schilhabel@web.de> | |
5 # | |
6 # | |
7 # version 0.1 initial release 22/08/2002 | |
8 # | |
9 # | |
10 # If you have any comments, suggestions, etc., feel free to send me a mail ;-)) | |
11 # flames and other things like that should go to /dev/null | |
12 # thankx to all the mplayer developers for this really *great* piece of software | |
13 # | |
14 # | |
15 # This script is free software; you can redistribute it and/or | |
16 # modify it under the terms of the GNU Lesser General Public | |
17 # License as published by the Free Software Foundation; either | |
18 # version 2 of the License, or (at your option) any later version. | |
19 # | |
20 # This script is distributed in the hope that it will be useful, | |
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
23 # Lesser General Public License for more details. | |
24 # | |
25 # You should have received a copy of the GNU Lesser General Public | |
26 # License along with this library; if not, write to the Free Software | |
27 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
28 # | |
29 # | |
30 # | |
31 use Getopt::Long; | |
32 | |
33 # specify your default Settings here... | |
34 | |
35 $abr_default = 128; # The default AudioBitRate | |
36 $lang_default = "de"; # ... the language | |
37 $cdsize_default = 700; # ... the CD-Rom Size | |
38 $writedev_default = "0,1,0"; # ... the CD Writer Device | |
39 $speed_default = 4; # and the writer speed | |
40 | |
41 # end of default Settings | |
42 | |
43 | |
44 | |
45 sub delete_tempfiles { | |
46 if (open(FILE, "< audio.stderr")) { | |
47 close (FILE); | |
48 system ("rm audio.stderr") | |
49 } | |
50 if (open(FILE, "< frameno.avi")) { | |
51 close (FILE); | |
52 system ("rm frameno.avi"); | |
53 } | |
54 if (open(FILE, "< lavc_stats.txt")) { | |
55 close (FILE); | |
56 system ("rm lavc_stats.txt"); | |
57 } | |
58 } | |
59 | |
60 GetOptions( "help" => \$help, | |
61 "abr=i" => \$abr, | |
62 "lang=s" =>\$lang, | |
63 "cdsize=i" => \$cdsize, | |
64 "dvd=i" => \$dvd_track, | |
65 "keeptemp" => \$keeptemp, | |
66 "shutdown" => \$shutdown, | |
67 "out=s" => \$output, | |
68 "writecd" => \$writecd, | |
69 "writedev=s" => \$writedev, | |
70 "speed=i" => \$speed ); | |
71 | |
72 if ($help) { | |
73 print "Welcome to the DVD to DIVX Helper Script\n"; | |
74 print "\n"; | |
75 print "this script encodes a DVD track in 3-pass mode to libavcodec's mpeg4\n"; | |
76 print "Optionally it writes the resulting MovieFile to a CD-Rom\n"; | |
77 print "as well as the corresponding audio track to mp3\n"; | |
78 print "Optionally it writes the resulting MovieFile to a CD-Rom\n"; | |
79 print "and shuts down the Computer.\n"; | |
80 print "If you like, you can watch the mencoder output on /dev/tty8\n"; | |
81 print "Usage:\n"; | |
82 print "--help show this text\n"; | |
83 print "--abr (AudioBitRate) Please enter the desired bitrate\n"; | |
84 print " this can be either [96|128|192] kbit/sec.\n"; | |
85 print " Default: 128 kbit/sec.\n"; | |
86 print "--lang specify the Language of the audio track\n"; | |
87 print " this can be for example <en> or <de>\n"; | |
88 print " Default: <de>\n"; | |
89 print "--dvd specify the DVD Track, you want to encode\n"; | |
90 print "--cdsize specify the Size of your CD-ROM\n"; | |
91 print " Default: 700MB\n"; | |
92 print "--shutdown Shutdown the System, when the encoding process has finished\n"; | |
93 print " this will only be possible if you are root\n"; | |
94 print "--out Specify the Name of your encoded Movie\n"; | |
95 print " The File Extension will be appended automatically\n"; | |
96 print "--writecd takes the newly created Movie and writes it to a CD-Rom\n"; | |
97 print "--writedev is the usual cdrecord device identifier\n"; | |
98 print " for example 0,1,0\n"; | |
99 print "--speed the writing speed\n"; | |
100 print " Default: 4\n"; | |
101 exit; | |
102 } | |
103 | |
104 delete_tempfiles(); | |
105 | |
106 # testing user values && set defaults... | |
107 | |
108 if ($abr == 96){} | |
109 elsif ($abr == 128) {} | |
110 elsif ($abr == 192) {} | |
111 elsif ($abr == 0 ) { | |
112 print "No AudioBitRate specified - Setting to Default Value\n"; | |
113 $abr = $abr_default; | |
114 } | |
115 else { | |
116 print "AudioBitRate not valid. please choose [96|128|192]\n"; | |
117 exit; | |
118 } | |
119 | |
120 if ($lang eq "") { | |
121 print "No Language specified - Setting to Default Value\n"; | |
122 $lang = $lang_default; | |
123 } | |
124 else {} | |
125 | |
126 if ($dvd_track == 0 ) { | |
127 print "No DVD Track selected - You must specify one with: --dvd trackno.\n"; | |
128 exit; | |
129 } | |
130 | |
131 if ($cdsize == 650) {} | |
132 elsif ($cdsize == 700) {} | |
133 elsif ($cdsize == 800) {} | |
134 elsif ($cdsize == 0 ) { | |
135 print "No CD Size Specified - Setting to Default Value\n"; | |
136 $cdsize = $cdsize_default; | |
137 } | |
138 | |
139 else { | |
140 print "CD Size not valid. please choose [650|700|800]\n"; | |
141 exit; | |
142 } | |
143 | |
144 if ($output eq "") { | |
145 print "No MovieName given - You must specify one with: --out [movie_name]\n"; | |
146 exit; | |
147 } | |
148 else { | |
149 ($name, $extension) = split(/./, $out); | |
150 if ($extension eq "avi") { | |
151 $vob_tempfile = "$name.vob"; | |
152 $avi_filename = "$output"; | |
153 } | |
154 else { | |
155 $vob_tempfile = "$output.vob"; | |
156 print "VOB CacheFile set to $vob_tempfile\n"; | |
157 $avi_filename = "$output.avi"; | |
158 print "Movie Filename set to $avi_filename\n"; | |
159 } | |
160 } | |
161 | |
162 if ($shutdown) { | |
163 # test who i am | |
164 $user = `id -u`; | |
165 if ($user == 0) { | |
166 print "System will be shut down after Movie encoding\n"; | |
167 } | |
168 else { | |
169 print "Cannot shutdown the system after Movie encoding - you are not 'root'\n"; | |
170 exit; | |
171 } | |
172 } | |
173 | |
174 if ($writecd) { | |
175 if ($writedev == "") { | |
176 print "Setting CD Writer Device to Default Value\n"; | |
177 $writedev = $writedev_default; | |
178 } | |
179 if ($speed == 0) { | |
180 print "Setting CD Writer Speed to Default value\n"; | |
181 $speed = $speed_default; | |
182 } | |
183 | |
184 } | |
185 | |
186 | |
187 | |
188 ### | |
189 | |
190 print "Your Settings for this run are:\n"; | |
191 print "AudioBitRate: $abr\n"; | |
192 print "Language: $lang\n"; | |
193 print "DVD-Track: $dvd_track\n"; | |
194 print "CD-Rom Size: $cdsize\n"; | |
195 print "Movie FIlename: $avi_filename\n"; | |
196 if ($writecd) { | |
197 print "CD Writer Dev.: $writedev\n"; | |
198 print "Writer Speed: $speed\n"; | |
199 } | |
200 | |
201 # here comes the fun part... | |
202 | |
203 print "precacheing...\n"; | |
204 $status = system ("mencoder -dvd $dvd_track -ovc copy -oac copy -alang $lang -o $vob_tempfile 1>/dev/tty8 2>/dev/tty8"); | |
205 die "Prechacheing failed. mencoder exited with Status Code $?" unless $status == 0; | |
206 | |
207 print "Encoding Audio...\n"; | |
208 $status = system ("mencoder $vob_tempfile -ovc frameno -oac mp3lame -lameopts br=$abr:cbr:vol=3 -o frameno.avi 1>./audio.stderr 2>/dev/tty8"); | |
209 die "Encoding Audio failed. mencoder exited with Status Code $?" unless $status == 0; | |
210 | |
211 # now we have to find out the recommended bitrate for the Video encoding process... | |
212 # my current method to find this out is, hmm, well, *strange* | |
213 # but anyway, it works ;-)) | |
214 | |
215 open(FILE, "< audio.stderr") or die "Unable to open audio.stderr."; | |
216 @lines = <FILE>; | |
217 foreach $line (@lines) { | |
218 ($index, $zz) = split(" ", $line); | |
219 if ($index eq "Recommended") { | |
220 ($a, $b, $c, $d, $size, $f, $bitrate) = split(" ", $line); | |
221 if ($cdsize == $size) { | |
222 $video_bitrate = $bitrate; | |
223 print "Setting Videobitrate to $video_bitrate\n"; | |
224 } | |
225 } | |
226 } | |
227 close (FILE); | |
228 | |
229 print "Encoding Video Stream, 1st pass...\n"; | |
230 $status = system ("mencoder $vob_tempfile -ovc lavc -lavcopts vpass=1:vcodec=mpeg4:vbitrate=$video_bitrate:vhq -oac copy -o $avi_filename 1>/dev/tty8 2>/dev/tty8"); | |
231 die "Encoding Video Stream failed. mencoder exited with Status Code $?" unless $status == 0; | |
232 | |
233 print "Encoding Video Stream, 2nd pass...\n"; | |
234 $status = system ("mencoder $vob_tempfile -ovc lavc -lavcopts vpass=2:vcodec=mpeg4:vbitrate=$video_bitrate:vhq -oac copy -o $avi_filename 1>/dev/tty8 2>/dev/tty8"); | |
235 die "Encoding Video Stream failed. mencoder exited with Status Code $?" unless $status == 0; | |
236 | |
237 print "finished encoding\n"; | |
238 | |
239 | |
240 if ($writecd) { | |
241 print "Now writing CD-Rom\n"; | |
242 $status = system("mkisofs -r -J $avi_filename | cdrecord speed=$speed dev=$writedev -data - 2>/dev/tty8 1>/dev/tty8"); | |
243 die "Writing CD failed. cdrecord exited with Status Code $?" unless $status == 0; | |
244 } | |
245 delete_tempfiles(); | |
246 | |
247 print "Finished - have a nice day ;-)\n"; | |
248 if ($shutdown) { | |
249 system("halt"); | |
250 exit; | |
251 } | |
252 exit; | |
253 | |
254 | |
255 | |
256 | |
257 | |
258 | |
259 | |
260 |