Comment out the correct #endif directive.
[mplayer/greg.git] / TOOLS / dvd2divxscript.pl
blobd2cd9c8b74d77dd95335ae8a51fc1c74d18c581c
1 #!/usr/bin/perl
4 # (c) 2002-2004 by Florian Schilhabel <florian.schilhabel@web.de>
7 # version 0.1 initial release 22/08/2002
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
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 use Getopt::Long;
33 # specify your default Settings here...
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; # ... the writer speed
40 $dvd_device = "/dev/dvd"; # and the DVD Rom Device
42 # end of default Settings
46 sub delete_tempfiles {
47 if (open(FILE, "< audio.stderr")) {
48 close (FILE);
49 system ("rm audio.stderr")
51 if (open(FILE, "< frameno.avi")) {
52 close (FILE);
53 system ("rm frameno.avi");
55 if (open(FILE, "< lavc_stats.txt")) {
56 close (FILE);
57 system ("rm lavc_stats.txt");
61 GetOptions( "help" => \$help,
62 "abr=i" => \$abr,
63 "lang=s" =>\$lang,
64 "cdsize=i" => \$cdsize,
65 "dvd=i" => \$dvd_track,
66 "keeptemp" => \$keeptemp,
67 "shutdown" => \$shutdown,
68 "out=s" => \$output,
69 "writecd" => \$writecd,
70 "writedev=s" => \$writedev,
71 "speed=i" => \$speed,
72 "dvd-device=s" => \$dvd_device );
74 if ($help) {
75 print "Welcome to the DVD to DIVX Helper Script\n";
76 print "\n";
77 print "this script encodes a DVD track in 3-pass mode to libavcodec's mpeg4\n";
78 print "Optionally it writes the resulting MovieFile to a CD-Rom\n";
79 print "as well as the corresponding audio track to mp3\n";
80 print "Optionally it writes the resulting MovieFile to a CD-Rom\n";
81 print "and shuts down the Computer.\n";
82 print "If you like, you can watch the mencoder output on /dev/tty8\n";
83 print "Usage:\n";
84 print "--help show this text\n";
85 print "--abr (AudioBitRate) Please enter the desired bitrate\n";
86 print " this can be either [96|128|192] kbit/sec.\n";
87 print " Default: 128 kbit/sec.\n";
88 print "--lang specify the Language of the audio track\n";
89 print " this can be for example <en> or <de>\n";
90 print " Default: <de>\n";
91 print "--dvd specify the DVD Track, you want to encode\n";
92 print "--cdsize specify the Size of your CD-ROM\n";
93 print " Default: 700MB\n";
94 print "--shutdown Shutdown the System, when the encoding process has finished\n";
95 print " this will only be possible if you are root\n";
96 print "--out Specify the Name of your encoded Movie\n";
97 print " The File Extension will be appended automatically\n";
98 print "--writecd takes the newly created Movie and writes it to a CD-Rom\n";
99 print "--writedev is the usual cdrecord device identifier\n";
100 print " for example 0,1,0\n";
101 print "--speed the writing speed\n";
102 print " Default: 4\n";
103 print "--dvd-device device to pull the video off\n";
104 print " Default: /dev/dvd\n";
105 exit;
108 delete_tempfiles();
110 # testing user values && set defaults...
112 if ($abr == 96){}
113 elsif ($abr == 128) {}
114 elsif ($abr == 192) {}
115 elsif ($abr == 0 ) {
116 print "No AudioBitRate specified - Setting to Default Value\n";
117 $abr = $abr_default;
119 else {
120 print "AudioBitRate not valid. please choose [96|128|192]\n";
121 exit;
124 if ($lang eq "") {
125 print "No Language specified - Setting to Default Value\n";
126 $lang = $lang_default;
128 else {}
130 if ($dvd_track == 0 ) {
131 print "No DVD Track selected - You must specify one with: --dvd trackno.\n";
132 exit;
135 if ($cdsize == 650) {}
136 elsif ($cdsize == 700) {}
137 elsif ($cdsize == 800) {}
138 elsif ($cdsize == 0 ) {
139 print "No CD Size Specified - Setting to Default Value\n";
140 $cdsize = $cdsize_default;
143 else {
144 print "CD Size not valid. please choose [650|700|800]\n";
145 exit;
148 if ($output eq "") {
149 print "No MovieName given - You must specify one with: --out [movie_name]\n";
150 exit;
152 else {
153 ($name, $extension) = split(/./, $out);
154 if ($extension eq "avi") {
155 $vob_tempfile = "$name.vob";
156 $avi_filename = "$output";
158 else {
159 $vob_tempfile = "$output.vob";
160 print "VOB CacheFile set to $vob_tempfile\n";
161 $avi_filename = "$output.avi";
162 print "Movie Filename set to $avi_filename\n";
166 if ($shutdown) {
167 # test who i am
168 $user = `id -u`;
169 if ($user == 0) {
170 print "System will be shut down after Movie encoding\n";
172 else {
173 print "Cannot shutdown the system after Movie encoding - you are not 'root'\n";
174 exit;
178 if ($writecd) {
179 if ($writedev == "") {
180 print "Setting CD Writer Device to Default Value\n";
181 $writedev = $writedev_default;
183 if ($speed == 0) {
184 print "Setting CD Writer Speed to Default value\n";
185 $speed = $speed_default;
194 print "Your Settings for this run are:\n";
195 print "AudioBitRate: $abr\n";
196 print "Language: $lang\n";
197 print "DVD-Track: $dvd_track\n";
198 print "CD-Rom Size: $cdsize\n";
199 print "Movie FIlename: $avi_filename\n";
200 if ($writecd) {
201 print "CD Writer Dev.: $writedev\n";
202 print "Writer Speed: $speed\n";
205 # here comes the fun part...
207 print "precacheing...\n";
208 $status = system ("mencoder dvd://$dvd_track -ovc copy -oac copy -dvd-device $dvd_device -alang $lang -o $vob_tempfile 1>/dev/tty8 2>/dev/tty8");
209 die "Prechacheing failed. mencoder exited with Status Code $?" unless $status == 0;
211 print "Encoding Audio...\n";
212 $status = system ("mencoder $vob_tempfile -ovc frameno -oac mp3lame -lameopts br=$abr:cbr:vol=3 -o frameno.avi 1>./audio.stderr 2>/dev/tty8");
213 die "Encoding Audio failed. mencoder exited with Status Code $?" unless $status == 0;
215 # now we have to find out the recommended bitrate for the Video encoding process...
216 # my current method to find this out is, hmm, well, *strange*
217 # but anyway, it works ;-))
219 open(FILE, "< audio.stderr") or die "Unable to open audio.stderr.";
220 @lines = <FILE>;
221 foreach $line (@lines) {
222 ($index, $zz) = split(" ", $line);
223 if ($index eq "Recommended") {
224 ($a, $b, $c, $d, $size, $f, $bitrate) = split(" ", $line);
225 if ($cdsize == $size) {
226 $video_bitrate = $bitrate;
227 print "Setting Videobitrate to $video_bitrate\n";
231 close (FILE);
233 print "Encoding Video Stream, 1st pass...\n";
234 $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");
235 die "Encoding Video Stream failed. mencoder exited with Status Code $?" unless $status == 0;
237 print "Encoding Video Stream, 2nd pass...\n";
238 $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");
239 die "Encoding Video Stream failed. mencoder exited with Status Code $?" unless $status == 0;
241 print "finished encoding\n";
244 if ($writecd) {
245 print "Now writing CD-Rom\n";
246 $status = system("mkisofs -r -J $avi_filename | cdrecord speed=$speed dev=$writedev -data - 2>/dev/tty8 1>/dev/tty8");
247 die "Writing CD failed. cdrecord exited with Status Code $?" unless $status == 0;
249 delete_tempfiles();
251 print "Finished - have a nice day ;-)\n";
252 if ($shutdown) {
253 system("halt");
254 exit;
256 exit;