4 # (c) 2002 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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; # and the writer speed
41 # end of default Settings
45 sub delete_tempfiles
{
46 if (open(FILE
, "< audio.stderr")) {
48 system ("rm audio.stderr")
50 if (open(FILE
, "< frameno.avi")) {
52 system ("rm frameno.avi");
54 if (open(FILE
, "< lavc_stats.txt")) {
56 system ("rm lavc_stats.txt");
60 GetOptions
( "help" => \
$help,
63 "cdsize=i" => \
$cdsize,
64 "dvd=i" => \
$dvd_track,
65 "keeptemp" => \
$keeptemp,
66 "shutdown" => \
$shutdown,
68 "writecd" => \
$writecd,
69 "writedev=s" => \
$writedev,
70 "speed=i" => \
$speed );
73 print "Welcome to the DVD to DIVX Helper Script\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";
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";
106 # testing user values && set defaults...
109 elsif ($abr == 128) {}
110 elsif ($abr == 192) {}
112 print "No AudioBitRate specified - Setting to Default Value\n";
116 print "AudioBitRate not valid. please choose [96|128|192]\n";
121 print "No Language specified - Setting to Default Value\n";
122 $lang = $lang_default;
126 if ($dvd_track == 0 ) {
127 print "No DVD Track selected - You must specify one with: --dvd trackno.\n";
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;
140 print "CD Size not valid. please choose [650|700|800]\n";
145 print "No MovieName given - You must specify one with: --out [movie_name]\n";
149 ($name, $extension) = split(/./, $out);
150 if ($extension eq "avi") {
151 $vob_tempfile = "$name.vob";
152 $avi_filename = "$output";
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";
166 print "System will be shut down after Movie encoding\n";
169 print "Cannot shutdown the system after Movie encoding - you are not 'root'\n";
175 if ($writedev == "") {
176 print "Setting CD Writer Device to Default Value\n";
177 $writedev = $writedev_default;
180 print "Setting CD Writer Speed to Default value\n";
181 $speed = $speed_default;
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";
197 print "CD Writer Dev.: $writedev\n";
198 print "Writer Speed: $speed\n";
201 # here comes the fun part...
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;
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;
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 ;-))
215 open(FILE
, "< audio.stderr") or die "Unable to open audio.stderr.";
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";
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;
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;
237 print "finished encoding\n";
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;
247 print "Finished - have a nice day ;-)\n";