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.1 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
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")) {
49 system ("rm audio.stderr")
51 if (open(FILE
, "< frameno.avi")) {
53 system ("rm frameno.avi");
55 if (open(FILE
, "< lavc_stats.txt")) {
57 system ("rm lavc_stats.txt");
61 GetOptions
( "help" => \
$help,
64 "cdsize=i" => \
$cdsize,
65 "dvd=i" => \
$dvd_track,
66 "keeptemp" => \
$keeptemp,
67 "shutdown" => \
$shutdown,
69 "writecd" => \
$writecd,
70 "writedev=s" => \
$writedev,
72 "dvd-device=s" => \
$dvd_device );
75 print "Welcome to the DVD to DIVX Helper Script\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";
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";
110 # testing user values && set defaults...
113 elsif ($abr == 128) {}
114 elsif ($abr == 192) {}
116 print "No AudioBitRate specified - Setting to Default Value\n";
120 print "AudioBitRate not valid. please choose [96|128|192]\n";
125 print "No Language specified - Setting to Default Value\n";
126 $lang = $lang_default;
130 if ($dvd_track == 0 ) {
131 print "No DVD Track selected - You must specify one with: --dvd trackno.\n";
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;
144 print "CD Size not valid. please choose [650|700|800]\n";
149 print "No MovieName given - You must specify one with: --out [movie_name]\n";
153 ($name, $extension) = split(/./, $out);
154 if ($extension eq "avi") {
155 $vob_tempfile = "$name.vob";
156 $avi_filename = "$output";
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";
170 print "System will be shut down after Movie encoding\n";
173 print "Cannot shutdown the system after Movie encoding - you are not 'root'\n";
179 if ($writedev == "") {
180 print "Setting CD Writer Device to Default Value\n";
181 $writedev = $writedev_default;
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";
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.";
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";
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";
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;
251 print "Finished - have a nice day ;-)\n";