One thing that I really enjoy is to be able to watch my DVDs from any computer in the house, or from (almost) any of the TVs, without having to deal with physical media. The way I do this is to “rip” the movies to my media server, and then transcode them to a smaller format. This guide will discuss part one of this — ripping a DVD. I know there are several utilities which will do this for me, but since I have very specific needs, and like things to be as automated as possible, I wrote a script to do this (naturally).
In order to use this script, you will need to install a few things:
- lsdvd
- vobcopy
- libdvdcss2
The first two are easy – simply:
% sudo apt-get install lsdvd vobcopy
For the CSS library, you’ll need to first add medibuntu sources:
% sudo wget http://www.medibuntu.org/sources.list.d/jaunty.list --output-document=/etc/apt/sources.list.d/medibuntu.list % sudo apt-get update % sudo apt-get install medibuntu-keyring % sudo apt-get update
Then install libdvdcss2:
% sudo apt-get install libdvdcss2
The next thing will be to download this script, and change $VOBDIR and $QUEUE according to where you want to put the VOB files and which text file to write the list of titles to transcode.
Here’s some examples on how to use it:
To rip a movie, choosing the longest title:
% ripper -n "My Movie"
To rip a movie, specifying the title number:
% ripper -n "My Movie" -t 5
To rip a TV Show disc – choosing only titles that are 20 minutes or longer:
% ripper -n "My TV Show" -m 20
Note: This script doesn’t convert from VOB files to anything else, it just copies the contents of the DVD, and writes to a queue file. Transcoding to other formats will come soon.
#!/usr/bin/perl
# DVD Ripper
# Uses vobcopy to rip DVDs
# by Ed Salisbury (ed@edsalisbury.net)
# http://www.edsalisbury.net
# (c)2009 Ed Salisbury, Some Rights Reserved
#
# External Utilities Required:
# * lsdvd
# * vobcopy
# * libdvdcss2 library
#
#
# Usage:
# ripper -n <name> -t <title num> -l -m <minlength>
# -t: Title Number
# -l: Longest title (default)
# -m: Minimum title length (in minutes)
#
#
# Examples:
# Rip a movie, choosing the longest title
# % ripper -n "My Movie"
#
# Rip a movie, specifying the title number
# % ripper -n "My Movie" -t 5
#
# Rip a TV Show disc - choosing only titles that are 20 minutes or longer
# % ripper -n "My TV Show" -m 20
#
#
# Limitations:
# * Will not rip some DVDs (limitation of vobcopy)
# * Will not transcode the VOB files
#
#
# License:
# Except where otherwise noted, this work is licensed under Creative Commons
# Attribution ShareAlike 3.0.
#
# You are free:
# * to Share — to copy, distribute and transmit the work
# * to Remix — to adapt the work
#
# Under the following conditions:
# * Attribution. You must attribute the work in the manner specified by the
# author or licensor (but not in any way that suggests that they endorse
# you or your use of the work).
# * Share Alike. If you alter, transform, or build upon this work, you may
# distribute the resulting work only under the same, similar or a
# compatible license.
# * For any reuse or distribution, you must make clear to others the license
# terms of this work. The best way to do this is with a link to the
# license's web page (http://creativecommons.org/licenses/by-sa/3.0/)
# * Any of the above conditions can be waived if you get permission from the
# copyright holder.
# * Nothing in this license impairs or restricts the author's moral rights.
use warnings;
use strict;
use Getopt::Std;
use File::Copy;
$|++;
sub usage();
# Where to store the VOB files
my $VOBDIR = "/data/Video/Rip";
# Queue for transcoding (not done by this script)
my $QUEUE = "/data/Video/queue.txt";
my $VERSION = "1.1";
my $LONGEST;
my $title_num = 0;
my $title_name;
my $min_time;
my $name;
my $mounted = '';
my $count = 0;
my $cmd;
my %opt = ();
# External Utilities
my $VOBCOPY = '/usr/bin/vobcopy';
my $LSDVD = '/usr/bin/lsdvd';
my $MOUNT = '/bin/mount';
my $GREP = '/bin/grep';
my $EJECT = '/usr/bin/eject';
getopts("v?n:t:lm:", \%opt);
if ($opt{'?'})
{
usage();
}
if ($opt{'v'})
{
print "DVD Ripper ver. $VERSION by Ed Salisbury <ed\@edsalisbury.net>\n";
exit();
}
# Check for installed external utilities
unless (-f $VOBCOPY)
{
print "ERROR: vobcopy not installed\n";
exit(1);
}
unless (-f $LSDVD)
{
print "ERROR: lsdvd not installed\n";
exit(1);
}
# Get Name
if ($opt{'n'})
{
$name = $opt{'n'};
}
else
{
print "Error: No name specified\n";
usage();
}
if ($opt{'l'})
{
$LONGEST++;
}
if ($opt{'m'})
{
$min_time = $opt{'m'};
}
if ($opt{'t'})
{
$title_num = $opt{'t'};
}
if (!$min_time && !$title_num)
{
$LONGEST++;
}
if ($LONGEST)
{
print "Using longest title.\n";
}
# Check for mounted DVD
print "Checking for DVD-ROM...";
while (!$mounted)
{
$mounted = `$MOUNT | $GREP cdrom`;
if (!$mounted)
{
if ($count < 20)
{
print ".";
sleep(1);
$count++;
}
else
{
print " not found.\n";
exit();
}
}
else
{
print " found.\n";
}
}
my @titles_to_xcode;
if ($title_num)
{
push (@titles_to_xcode, $title_num);
}
else
{
print "Getting DVD title info... ";
$cmd = "$LSDVD 2>/dev/null";
my @lsdvd = `$cmd`;
foreach my $line (@lsdvd)
{
if ($line =~ /^Disc Title: (.*?)$/)
{
$title_name = $1;
}
if ($min_time && $line =~ /^Title: (\d+), Length: (\d+):(\d+):/)
{
my $length = ($1 * 60) + $2;
if ($length > $min_time)
{
push (@titles_to_xcode, $1);
}
}
if ($LONGEST && $line =~ /^Longest track: (\d+)$/)
{
push (@titles_to_xcode, $1);
}
}
print "done.\n";
}
print "Ripping...\n";
$cmd = "$VOBCOPY -m -o $VOBDIR -F64";
system($cmd);
print "done.\n";
print "Moving to proper location... ";
move("$VOBDIR/$title_name/VIDEO_TS", "$VOBDIR/$name");
rmdir("$VOBDIR/$title_name");
print "done.\n";
print "Updating queue... ";
open (QUEUE, ">>$QUEUE");
foreach my $title (@titles_to_xcode)
{
print QUEUE "$VOBDIR/$name|$title\n";
}
close (QUEUE);
print "done.\n";
print "Ejecting DVD-ROM... ";
system("$EJECT");
print "done.\n";
sub usage()
{
print "ripper -n <name> -t <title num> -l -m <minlength>\n";
print "\t-t: Title Number\n";
print "\t-l: Longest title (default)\n";
print "\t-m: Minimum title length (in minutes)\n";
exit();
}
Soon I’ll post my scripts for transcoding DVDs to H.264. Please let me know if you find this useful or have any comments/suggestions.
Update: I have posted a new guide and script for processing the DVD rips here.


