#!/usr/bin/perl -w use strict; print "****************************************\n"; print "* Quick DVD Ripper *\n"; print "* *\n"; print "* Author: Michael A. Smith *\n"; print "* Modified: April 26, 2006 *\n"; print "* Description: *\n"; print "* *\n"; print "* Rips DVD to AVI. Does not alter *\n"; print "* format or compression. *\n"; print "* *\n"; print "****************************************\n"; print "\n\n\n"; # first step, get the number of titles # and resolution from mplayer sub getNumTitles { my $result = `mplayer dvd:// -identify -vo null -ao null -frames 0 -novideo`; foreach(split(/\n/, $result)) { if ($_ =~ /^ID_DVD_TITLES=([0-9]+).*$/) { return $1; } } } sub main { foreach(1..&getNumTitles) { my $avi = "Title $_.avi"; my $mp4 = "Title $_.mp4"; my $res = getResolution($_); my $mencode = "mencoder dvd://$_ &getDvdDevice -ovc copy -oac copy -alang en -o '$avi'"; system "$mencode"; my $log = "ffmpeg2pass-0.log"; if (-e "$log") {unlink "$log";} foreach(1..2) { my $ffmpeg = "ffmpeg -y -pass $_ -vcodec xvid -b 750 -acodec aac -ab 96 -i '$avi' -s $res '$mp4'"; system "$ffmpeg"; } if (-e "$log") {unlink "$log";} if (-e "$avi") {unlink "$avi";} } } main; sub getResolution { my $width=480; my $height; my $command = "mplayer dvd://$_[0] -vo null -ao null -frames 0"; foreach(split(/\n/, `$command`)) { # Line: "Movie-Aspect is 1.78:1 - prescaling to correct movie aspect." if ($_ =~ /^Movie-Aspect is ([0-9.]*):([0-9.]*) -.*$/) { $height = sprintf("%.0f", 480 * $2 / $1); return "480x$height"; } } } sub getDvdDevice { if (@ARGV) { if (($ARGV[0] == "-D") or ($ARGV[0] == "--dvd-device")) { return "-dvd-device $ARGV[1]"; } } return ""; # no argument, no foul :-) }