#!/usr/bin/perl # # dvd2xvid # Copyright (C) 2005 surfmasta # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # use Getopt::Long; ### ### Set an optional mencoder path (ie. for an own build) ### $MENCODER_PATH = ""; GetOptions("i=s" => \$ifile, "o=s" => \$ofile, "b=s" => \$bitrate, "t" => \$test, "m=s" => \$mencoder_cmd, "e=s" => \$encoder_cmd); if ($ifile && $ofile) { print "#########################################\n"; print "### dvd2xvid v1.0 ###\n"; print "#########################################\n\n"; if ($test) { print " !!! TEST-Modus aktiviert (Es wird eine 15 Sekunden Vorschau generiert) !!!\n\n"; } print " DVD-Image: $ifile\n"; print " Ausgabedatei: $ofile\n\n"; } else { print "Anwendung: dvd2xvid -i -o \n"; print " -i Eingabequelle angeben (z.B. /dev/dvd oder /home/user/dvdrip/MEIN_DVD_IMAGE)\n"; print " Im Beispiel ist MEIN_DVD_IMAGE ein DVD Abbild welches z.B. mit dvdbackup -M -i /dev/dvd -o ./\n"; print " erzeugt wurde\n"; print " -o Datei fuer die Ausgabe angeben (z.B. -o mein_film.dvdrip.xvid.avi)\n"; print " -b Optionale Bitrate angeben (z.B. -b 1200 / Standard: -b 900)\n"; print " -t Test Modus aktivieren. Dadurch wird eine 15 Sekunden Vorschau vom Ripvorgang erstellt\n"; print " die ab der 5ten Filmminute des Films beginnt\n"; print " -m Optionale mencoder Parameter angeben\n"; print " -e Optionale XVID-Encoder Parameter fuer den mencoder angeben (z.B. -e cartoon:gmc)\n"; exit; } if ($test) { $test = "-ss 300 -endpos 15"; } else { $test = ""; } ### ### Getting the main movie title ### open OUTPUT, "lsdvd $ifile 2>&1 |"; $mainmovielength = "00"; while ($output=) { $output =~ /Title\:\ \d/; $result = $&; if ($result) { @lsdvd = split(" ", $output); $lsdvd[3] =~ /\d\d/; $length = $&; if ($length > $mainmovielength) { $lsdvd[1] =~ /\d\d/; $title = $&; $mainmovielength = $length; } } } print " DVD-Titel: $title\n"; ### ### Getting german audio ### open OUTPUT, "lsdvd -a -t $title $ifile 2>&1 |"; $audiotrack = 127; while ($output=) { $output =~ /\,\ Language\:\ de/; $result = $`; if ($result) { $result =~ /\d/; if ($audiotrack == 127) { $audiotrack = $audiotrack + $&; } } } print " Audiospur: $audiotrack\n\n"; ### ### Getting crop parameters from mencoder and build mencoder command line ### open OUTPUT, $MENCODER_PATH . "mencoder dvd://$title -dvd-device $ifile -aid $audiotrack -oac copy -ovc lavc -vf cropdetect -o /dev/null -ss 300 -endpos 15 2>&1 |"; #for ($i = 25; $i < 255; $i++) { # print chr($i); #} #exit(); while ($output=) { $output =~ /\-vf\ crop\=\d{1,4}\:\d{1,4}:\d{1,4}:\d{1,4}/; $result = $&; if ($result) { $result =~ /\-vf\ crop\=/; $tmpresult = ($'); @tmp = split(":", $tmpresult); $width = $tmp[0]; $height = $tmp[1]; # But we want automatically calculate the scaling $height = "-2"; } } if (!$bitrate) { $bitrate="900"; } print " mencoder dvd://$title \\\n"; print " -dvd-device $ifile \\\n"; print " -aid $audiotrack \\\n"; print " -oac mp3lame -lameopts abr:br=128 -af volume=6:sc \\\n"; if ($mencoder_cmd) { print " $mencoder_cmd \\\n"; } print " -ovc xvid -xvidencopts $encoder_cmd:bitrate=$bitrate $result,scale=$width:$height \\\n"; print " -o $ofile \\\n"; print " $test\n\n"; system ($MENCODER_PATH . "mencoder dvd://$title -dvd-device $ifile -aid $audiotrack -oac mp3lame -lameopts abr:br=128 -af volume=6:sc $mencoder_cmd -ovc xvid -xvidencopts $encoder_cmd:bitrate=$bitrate $result,scale=$width:$height -o $ofile $test");