<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>edsalisbury.net &#187; dvd</title>
	<atom:link href="http://edsalisbury.net/tag/dvd/feed/" rel="self" type="application/rss+xml" />
	<link>http://edsalisbury.net</link>
	<description>your guide to user-friendly entertainment</description>
	<lastBuildDate>Wed, 28 Mar 2012 02:07:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>How to Convert DVDs and TiVo MPEG2 Videos to H.264</title>
		<link>http://edsalisbury.net/how-to-convert-dvds-and-tivo-mpeg2-videos-to-h-264/</link>
		<comments>http://edsalisbury.net/how-to-convert-dvds-and-tivo-mpeg2-videos-to-h-264/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 02:31:52 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[dvd]]></category>
		<category><![CDATA[h.264]]></category>
		<category><![CDATA[mpeg2]]></category>
		<category><![CDATA[TiVo]]></category>

		<guid isPermaLink="false">http://www.edsalisbury.net/?p=353</guid>
		<description><![CDATA[<a href="http://edsalisbury.net/how-to-convert-dvds-and-tivo-mpeg2-videos-to-h-264/" title="How to Convert DVDs and TiVo MPEG2 Videos to H.264"></a>Previously, I have showed you how to set up software to be able to rip DVDs to your hard drive, and I&#8217;ve also shown you how to copy your TiVo videos nightly. I&#8217;ve described the method I use to transcode &#8230;<p class="read-more"><a href="http://edsalisbury.net/how-to-convert-dvds-and-tivo-mpeg2-videos-to-h-264/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://edsalisbury.net/how-to-convert-dvds-and-tivo-mpeg2-videos-to-h-264/" title="How to Convert DVDs and TiVo MPEG2 Videos to H.264"></a><p><img src="http://www.edsalisbury.net/wp-content/uploads/2009/07/Sony-H_264-compress-250-150x150.jpg" alt="H.264" title="H.264" width="150" height="150" class="alignright size-thumbnail wp-image-357" /><br />
Previously, I have showed you how to set up software to be able to <a href="http://www.edsalisbury.net/linux/how-to-rip-dvds-on-ubuntu-linux-9-04-jaunty/">rip DVDs</a> to your hard drive, and I&#8217;ve also shown you how to <a href="http://www.edsalisbury.net/linux/how-to-copy-videos-from-a-series-3-tivo-to-ubuntu-linux/">copy your TiVo videos</a> nightly.  I&#8217;ve described the method I use to <a href="http://www.edsalisbury.net/linux/how-to-convert-tivo-mpeg2-videos-to-h264/">transcode</a> the videos, but haven&#8217;t provided the script&#8230; Until now.  After months of using and tweaking, here&#8217;s what I use.  I call it VidProc.</p>
<p><span id="more-353"></span></p>
<pre class="brush:perl; gutter: false; wrap-lines: true; ruler: false">
#!/usr/bin/perl
# VidProc
# Transcode videos that have been either ripped by ripper or copied from a TiVo
#    to H.264 format
# by Ed Salisbury (ed@edsalisbury.net)
# http://www.edsalisbury.net
# (c)2009 Ed Salisbury, Some Rights Reserved
#
# External Utilities Required:
# * HandBrakeCLI
# * MPlayer/Mencoder
#
# Notes:
# * Settings for HandBrake and mencoder are what I have come up with after
#   doing a fair bit of research, and seem to work pretty well - if you have
#   any concrete suggestions on *better* general-purpose settings, let me know.
#
# 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 File::Copy;
use File::Basename;

sub system_int($);

# Locations
my $DEST = &quot;/path/to/destdir&quot;;
my $QUEUE = &quot;/path/to/queue.txt&quot;;

# Encoding Options
my $DEINT = &quot;pp=md&quot;;    # Deinterlacer
my $VBITRATE = 1000;    # Video Bitrate
my $SAMPLE_RATE = 44.1; # Audio Sample Rate
my $ABITRATE = 192;     # Audio Bitrate
my $OVERSCAN = 6;       # Overscan size (# of lines)

# File Extensions
my $SRC_EXT = &quot;mpg&quot;;
my $DEST_EXT = &quot;mp4&quot;;

# External Utilities
my $HANDBRAKE = &quot;/usr/local/bin/HandBrakeCLI&quot;;
my $MENCODER = &quot;/usr/bin/mencoder&quot;;
my $MPLAYER = &quot;/usr/bin/mplayer&quot;;

# Add backslashes to spaces
$DEST =~ s/ /\ /g;

while (1)
{
    # Read in the queue
    open(QUEUE, $QUEUE);
    my $line = &lt;QUEUE&gt;;
    my @fields;
    if ($line)
    {
        chomp ($line);
        @fields = split(/|/, $line);
    }
    else
    {
        print &quot;Waiting for new stuff to show up in the queue...n&quot;;
        close(QUEUE);
        sleep(60);
        next;
    }
    close (QUEUE);

    my $input = $fields[0];

    print &quot;Processing $inputn&quot;;

    # Fix spaces
    $input =~ s/ /\ /g;
    $input =~ s/'/\'/g;
    $input =~ s/&amp;/\&amp;/g;
    $input =~ s/;/\;/g;
    my @extlist = (&quot;.$SRC_EXT&quot;);

    my $base = basename($input, @extlist);

    if ($fields[1])
    {
        # DVD, since it has a title number
        my $title = $fields[1];
        my $output = &quot;$DEST/${base}_&quot; . $fields[1] . &quot;.$DEST_EXT&quot;;

        system_int(&quot;$HANDBRAKE --input $input --output $output --title $title --turbo --encoder x264 --vb $VBITRATE --audio 1 --aencoder faac --mixdown 6ch --arate $SAMPLE_RATE --ab $ABITRATE --detelecine --decomb --loosePixelratio --markers --two-pass --x264opts ref=3:mixed-refs:bframes=6:weightb:direct=auto:b-pyramid:me=umh:subme=9:analyse=all:8x8dct:trellis=1:nr=150:no-fast-pskip=1:psy-rd=1,1&quot;);
    }
    else
    {
        # TiVo file, since it has no title number
        my $output = &quot;$DEST/${base}.$DEST_EXT&quot;;
        my $line;
        my $width;
        my $height;

        # Get video dimensions
        print &quot;Getting video information... &quot;;
        my @id = `$MPLAYER -nojoystick -nolirc -vo null -ao null -identify -frames 0 $input 2&gt;&amp;1`;
        foreach (@id)
        {
            if (/ID_VIDEO_WIDTH=(d+)/)
            {
                $width = $1;
            }
            if (/ID_VIDEO_HEIGHT=(d+)/)
            {
                $height = $1;
            }
        }
        if (!$width || !$height)
        {
            print &quot;FAILED!&quot;;
        }
        else
        {
            print &quot;(${width}x$height)n&quot;;
        }

        # Crop overscan
        $height-=$OVERSCAN;

        my %croptest;

        # Detect crop region
        print &quot;Detecting crop region... &quot;;
        my @cropdetect = `$MPLAYER -nojoystick -nolirc -vo null -ao null -vf crop=$width:$height:0:$OVERSCAN,cropdetect -ss 600 -endpos 180 $input 2&gt;&amp;1`;
        foreach $line (@cropdetect)
        {
            if ($line =~ /-vf crop=([d:]+)/)
            {
                $croptest{$1}++;
            }
        }

        # Get the crop value with the most hits
        my @croplist = sort { $croptest{$b} &lt;=&gt; $croptest{$a} } keys (%croptest);
        my $crop = $croplist[0];

        if (!$crop)
        {
            print &quot;FAILEDn&quot;;
            exit();
        }
        print &quot;($crop)n&quot;;
        print '-' x 80 . &quot;n&quot;;

        print &quot;Encoding first passn&quot;;
        print '-' x 80 . &quot;n&quot;;
        system_int(&quot;$MENCODER -ovc x264 -x264encopts pass=1:turbo:bitrate=$VBITRATE:bframes=1:me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 -vf $DEINT,crop=$crop,scale=-1:-10,harddup -oac copy -ofps 30000/1001 $input -o /dev/null&quot;);

        print &quot;nn&quot;;
        print '-' x 80 . &quot;n&quot;;
        print &quot;Encoding second passn&quot;;
        print '-' x 80 . &quot;n&quot;;
        system_int(&quot;$MENCODER -ovc x264 -x264encopts pass=2:turbo:bitrate=$VBITRATE:bframes=1:me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 -vf $DEINT,crop=$crop,scale=-1:-10:,harddup -oac copy -ofps 30000/1001 $input -o $output&quot;);
    }
    print &quot;Done. Removing from queuen&quot;;
    print &quot;nn&quot;;
    open(IN, $QUEUE);
    open(OUT, &quot;&gt;$QUEUE.tmp&quot;);
    while (my $qline = &lt;IN&gt;)
    {
        chomp ($qline);
        unless ($line eq $qline)
        {
            print OUT &quot;$qlinen&quot;;
        }
    }
    close (IN);
    close (OUT);
    unlink($QUEUE);
    move(&quot;$QUEUE.tmp&quot;, $QUEUE);
}

# Interruptible System Command
sub system_int($)
{
    my ($cmd) = @_;
    my $pid = fork();
    my $rc;
    if ($pid == 0)
    {
        exec($cmd);
    }
    else
    {
        waitpid($pid,0);
        $rc = $?;
    }
    return $rc;
}
</pre>
<p>It uses the same queue file that the other scripts will write to, so think of this as a continuation of the previous articles.  To use it, stick it somewhere like /usr/local/bin, and then change the locations to be wherever your queue is, and where you want your videos to end up.  The transcoding settings can get a little hairy, so I would say don&#8217;t mess with the actual command lines unless you know what you&#8217;re doing (but, if you did, you probably wouldn&#8217;t need this script!)</p>
<h4>External Utilities Needed:</h4>
<p>HandBrakeCLI &#8211; this can be downloaded from <a href="http://handbrake.fr/?article=download">here</a><br />
mplayer/mencoder &#8211; This can be installed via apt-get</p>
<h4>A couple of Notes/FAQs:</h4>
<p><b>Overscan removal:</b><br />
If you deal with letterboxed videos copied from TV, you&#8217;ll know what a pain overscan can be &#8211; Overscan is the generic term for the fuzzy line above the video that gets really annoying when watching on your monitor, but not on your TV.  This can wreak havoc with detecting where to crop the video, so I remove it.</p>
<p><b>HandBrake *AND* mencoder??  Why?</b><br />
I found that for some reason, Handbrake didn&#8217;t like working with the files that were copied from the TiVo &#8211; I dealt with lots of weird sync issues.  I posted it on the Handbrake forum, but never got a solution.  I ended up just using mencoder for the TiVo files, and Handbrake for the DVD rips, and left it at that.</p>
<p><b>Your setting XXX sucks &#8211; you should use YYY!</b><br />
If you can state that for any type of program (animation, TV, letterboxed, HD, etc.) that this is correct (and that it doesn&#8217;t make the process take much longer), I&#8217;ll happily thank you and update the script (as well as give you a mention here.)  I spent a bit of time trying to find settings that would work well for what I wanted, and ended up choosing these.  They&#8217;re not going to have the <b>best</b> quality, but the size and the time to transcode were good, so that&#8217;s what I stuck with.</p>
]]></content:encoded>
			<wfw:commentRss>http://edsalisbury.net/how-to-convert-dvds-and-tivo-mpeg2-videos-to-h-264/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>How to Rip DVDs on Ubuntu Linux 9.04 (Jaunty)</title>
		<link>http://edsalisbury.net/how-to-rip-dvds-on-ubuntu-linux-9-04-jaunty/</link>
		<comments>http://edsalisbury.net/how-to-rip-dvds-on-ubuntu-linux-9-04-jaunty/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 06:41:37 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[dvd]]></category>
		<category><![CDATA[jaunty]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.edsalisbury.net/?p=25</guid>
		<description><![CDATA[<a href="http://edsalisbury.net/how-to-rip-dvds-on-ubuntu-linux-9-04-jaunty/" title="How to Rip DVDs on Ubuntu Linux 9.04 (Jaunty)"></a>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 &#8230;<p class="read-more"><a href="http://edsalisbury.net/how-to-rip-dvds-on-ubuntu-linux-9-04-jaunty/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://edsalisbury.net/how-to-rip-dvds-on-ubuntu-linux-9-04-jaunty/" title="How to Rip DVDs on Ubuntu Linux 9.04 (Jaunty)"></a><p><img src="http://www.edsalisbury.net/wp-content/uploads/2009/06/dvd_discs-150x150.png" alt="DVDs" title="DVDs" width="150" height="150" class="alignleft size-thumbnail wp-image-185" />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 &#8220;rip&#8221; the movies to my media server, and then transcode them to a smaller format.  This guide will discuss part one of this &#8212; 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).<br/><br />
<span id="more-25"></span><br />
In order to use this script, you will need to install a few things:<br/></p>
<ul>
<li>lsdvd</li>
<li>vobcopy</li>
<li>libdvdcss2</li>
</ul>
<p>The first two are easy &#8211; simply:<br/></p>
<pre>% sudo apt-get install lsdvd vobcopy</pre>
<p>For the CSS library, you&#8217;ll need to first add medibuntu sources:<br/></p>
<pre>% 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</pre>
<p>Then install libdvdcss2:<br/></p>
<pre>% sudo apt-get install libdvdcss2</pre>
<p>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.<br/></p>
<p>Here&#8217;s some examples on how to use it:<br/></p>
<p>To rip a movie, choosing the longest title:</p>
<pre>% ripper -n "My Movie"</pre>
<p>To rip a movie, specifying the title number:</p>
<pre>% ripper -n "My Movie" -t 5</pre>
<p>To rip a TV Show disc &#8211; choosing only titles that are 20 minutes or longer:</p>
<pre>% ripper -n "My TV Show" -m 20</pre>
<p>Note: This script doesn&#8217;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.<br/></p>
<pre class="brush:perl; gutter: false; wrap-lines: true; ruler: false">
#!/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 &lt;name&gt; -t &lt;title num&gt; -l -m &lt;minlength&gt;
#        -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 &lt;ed@edsalisbury.net&gt;n";
    exit();
}

# Check for installed external utilities
unless (-f $VOBCOPY)
{
    print "ERROR: vobcopy not installedn";
    exit(1);
}

unless (-f $LSDVD)
{
    print "ERROR: lsdvd not installedn";
    exit(1);
}

# Get Name
if ($opt{'n'})
{
    $name = $opt{'n'};
}
else
{
    print "Error: No name specifiedn";
    usage();
}

if ($opt{'l'})
{
    $LONGEST++;
}

if ($opt{'m'})
{
    $min_time = $opt{'m'};
}

if ($opt{'t'})
{
    $title_num = $opt{'t'};
}

if (!$min_time &#038;&#038; !$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 &#038;&#038; $line =~ /^Title: (d+), Length: (d+):(d+):/)
        {
            my $length = ($1 * 60) + $2;
            if ($length > $min_time)
            {
                push (@titles_to_xcode, $1);
            }
        }

        if ($LONGEST &#038;&#038; $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|$titlen";
}
close (QUEUE);
print "done.n";

print "Ejecting DVD-ROM... ";
system("$EJECT");
print "done.n";

sub usage()
{
    print "ripper -n &lt;name&gt; -t &lt;title num&gt; -l -m &lt;minlength&gt;n";
    print "t-t: Title Numbern";
    print "t-l: Longest title (default)n";
    print "t-m: Minimum title length (in minutes)n";
    exit();
}
</pre>
<p>Soon I&#8217;ll post my scripts for transcoding DVDs to H.264.  Please let me know if you find this useful or have any comments/suggestions.</p>
<p><b>Update:</b> I have posted a new guide and script for processing the DVD rips <a href="http://www.edsalisbury.net/linux/how-to-convert-dvds-and-tivo-mpeg2-videos-to-h-264/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://edsalisbury.net/how-to-rip-dvds-on-ubuntu-linux-9-04-jaunty/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

