<?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>numerodix blog &#187; undvd</title>
	<atom:link href="http://www.matusiak.eu/numerodix/blog/index.php/category/techno-babble/undvd/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.matusiak.eu/numerodix/blog</link>
	<description>A blog about nothing</description>
	<lastBuildDate>Sun, 12 Feb 2012 18:25:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>update on undvd packages</title>
		<link>http://www.matusiak.eu/numerodix/blog/index.php/2008/10/09/update-on-undvd-packages/</link>
		<comments>http://www.matusiak.eu/numerodix/blog/index.php/2008/10/09/update-on-undvd-packages/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 17:01:33 +0000</pubDate>
		<dc:creator>numerodix</dc:creator>
				<category><![CDATA[undvd]]></category>

		<guid isPermaLink="false">http://www.matusiak.eu/numerodix/blog/?p=1505</guid>
		<description><![CDATA[One of the benefits of coding in a scripting language is the ability to easily move the code around and it runs everywhere. undvd is easy to install, you just extract the source and it&#8217;s ready to go. Or, if you want to install it globally on the system, just run make install and you&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>One of the benefits of coding in a scripting language is the ability to easily move the code around and it runs everywhere. undvd is easy to install, you just extract the source and it&#8217;s ready to go. Or, if you want to install it globally on the system, just run <code>make install</code> and you&#8217;re set.</p>
<p>But undvd depends on a bunch of other tools, so what you really want is to let your package manager deal with satisfying the dependencies, and let you upgrade easily when a new version comes out.</p>
<h3>Where can I find undvd?</h3>
<p>I package undvd in three flavors myself: Gentoo, Fedora and Ubuntu. I run Gentoo and Ubuntu on my boxen, so those are the most well tested. In addition, <a href="https://sourceforge.net/projects/ripdvd/">ripdvd</a>&#8217;s author wedge does the honors for Slackware. <img src='http://www.matusiak.eu/numerodix/blog/wp-includes/images/smilies/cool.png' alt=':cool:' class='wp-smiley' /> </p>
<p>But there are some unofficial packages out there as well, so when you add it all up undvd is pretty well supported at this point.</p>
<ul>
<li>Arch :: <a href="http://aur.archlinux.org/packages.php?ID=12640">aur</a></li>
<li>Fedora :: <a href="https://sourceforge.net/project/showfiles.php?group_id=211949">sf.net</a></li>
<li>Gentoo :: <a href="http://packages.gentoo.org/package/media-video/undvd">portage</a> / <a href="https://sourceforge.net/project/showfiles.php?group_id=211949">sf.net</a></li>
<li>Slackware :: <a href="https://sourceforge.net/project/showfiles.php?group_id=211949">sf.net</a></li>
<li>Suse :: <a href="http://packman.links2linux.org/package/undvd">packman.links2linux.org</a></li>
<li>Ubuntu :: <a href="https://launchpad.net/~numerodix/+archive">ppa</a> / <a href="https://sourceforge.net/project/showfiles.php?group_id=211949">sf.net</a></li>
</ul>
<h3>Making friends with posix</h3>
<p>Recently, a user expressed an interest in running undvd on a Mac, which is a whole new angle. I guess it never occurred to me that someone would use undvd outside linux, but why not. The recent switch to perl has obsoleted the many external tools that undvd previously relied on, which is a big [if unplanned] step towards portability. I ran some tests that revealed there were still a couple linuxisms left, so I&#8217;ve gotten rid of them now.</p>
<p>undvd-0.7.1 should in principle run on a Posix system with perl-5.8.8. The big thing isn&#8217;t undvd, it&#8217;s getting mplayer and the other binaries, cause they have to be built specifically for that platform. And outside linux, there&#8217;s sometimes no standard package manager, which doesn&#8217;t help at all.</p>
<p>At the end of the day, there is no escaping the fact that undvd on Posix is a fish out of water (true not only of undvd but probably most free software) &#8211; the environment just isn&#8217;t as well supported as it is in a linux distribution that ships all the tools. There are no packages for any of these, but you can just extract the tarball and run undvd from whatever location.</p>
<p><strong>DesktopBSD 1.6 (FreeBSD Ubuntufied)</strong></p>
<p>It runs (except mencoder can&#8217;t find x264, so I used xvid). The dvd device is called <code>/dev/cdrom</code> or <code>/dev/acd0</code>. Cloning with dd fails, vobcopy works.</p>
<p><strong>OpenSolaris 2008.05</strong></p>
<p>It runs (except mencoder can&#8217;t find x264, so I used xvid). I have no idea how the device naming works, but when you put in a cd/dvd it should automount and you can look up the dvd device in the mount table. Packages for mplayer are available from <a href="http://www.blastwave.org/">Blastwave</a>. Playback with mplayer worked, encoding segfaulted mencoder.</p>
<p><strong>Mac OS X Leopard</strong></p>
<p>It runs. The dvd device is called something like <code>/dev/rdisk1</code>. Mac people seem to be obsessed with guis, so any builds I could find only had mplayer playback, no encoding. Your best bet is probably <a href="http://www.macports.org/">MacPorts</a>, modeled loosely on FreeBSD&#8217;s ports. You&#8217;ll want to build mplayer with the codecs you want selected as variants (think Gentoo USE flags). Disc cloning doesn&#8217;t seem to work at all.</p>
<p>To install globally you&#8217;ll want something like <code>DESTDIR=/opt/local sudo make install</code>.</p>
<p><strong>Cygwin</strong></p>
<p>It runs, and you can get builds of mplayer from the <a href="http://www.mplayerhq.hu/MPlayer/releases/win32/">official site</a>. The dvd device is called <code>d:</code> (or some other drive letter). Set <code>PATH=/cygdrive/c/mplayer:$PATH</code> and make sure <code>c:\mplayer</code> doesn&#8217;t contain both a directory <code>mplayer/</code> and a binary <code>mplayer.exe</code>, this makes cygwin very confused. On the whole it seems to work quite well, the process even successfully sets the cpu priority (nice).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matusiak.eu/numerodix/blog/index.php/2008/10/09/update-on-undvd-packages/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>undvd, now in perl!</title>
		<link>http://www.matusiak.eu/numerodix/blog/index.php/2008/10/05/undvd-now-in-perl/</link>
		<comments>http://www.matusiak.eu/numerodix/blog/index.php/2008/10/05/undvd-now-in-perl/#comments</comments>
		<pubDate>Sun, 05 Oct 2008 19:20:37 +0000</pubDate>
		<dc:creator>numerodix</dc:creator>
				<category><![CDATA[undvd]]></category>

		<guid isPermaLink="false">http://www.matusiak.eu/numerodix/blog/?p=1445</guid>
		<description><![CDATA[So it turns out you can do a whole lot with bash. More than I knew. But when you get to a point where you start hitting the limitations of your language*, it gets frustrating. The biggest problem with bash is that it doesn&#8217;t have functions. You can wrap a bunch of code and call [...]]]></description>
			<content:encoded><![CDATA[<p>So it turns out you can do a whole lot with bash. More than I knew. But when you get to a point where you start hitting the limitations of your language*, it gets frustrating. The biggest problem with bash is that it doesn&#8217;t have functions. You can wrap a bunch of code and call it with arguments, but it doesn&#8217;t return a value. I&#8217;ve tried to come up with a hack to emulate functions returning arguments, but in the end there just aren&#8217;t enough pieces in the box to build it from.</p>
<p>To date, undvd has been using various tricks to get around this. Let the function <code>echo</code> the value and capture this in the caller. But then what if you have a failing condition? Well, you can <code>echo</code> the <em>value</em> to <code>stdout</code> and echo the <em>error</em> to <code>stderr</code>, so it doesn&#8217;t get captured as the result of the function. And then <code>kill $$</code> to force an exit (you can&#8217;t just <code>exit</code> cause that is equivalent to a <em>return</em> from the function).</p>
<p>That kind of works, but eventually you break down when you have to return more than one string that may contain whitespace. Sure, you could quote them, let the caller find both strings based on where the quotes are, then chop off the quotes and voila. But all this just for a function call? It&#8217;s too much, and it&#8217;s unacceptable from a maintenance standpoint.</p>
<p>Bash&#8217;s overall weak support for other features of a typical programming language makes it a challenge to write structured programs. undvd-0.6 is therefore pretty much a dead end from a development standpoint. It works well enough, but it&#8217;s hard to get anything more out of bash. In order to keep evolving, undvd needs a new language.</p>
<p>Another substantial problem with bash is that you&#8217;re executing commands in the shell, in other words you build execution strings. There is a lot of potential for quoting bugs when you&#8217;re dealing with filenames that have spaces and quotes in them. And not just when feeding them as arguments to executables, but on every &#8220;function call&#8221; just the same. I&#8217;ve spent a lot of time trying to safeguard against this, but all it takes is one instance where the strings aren&#8217;t quoted correctly, and you have a fatal parsing error.</p>
<p>So it&#8217;s time to think about porting to another language. A language that is close to the shell. A language that lets you run a subprocess by passing in the arguments as a list, not a string. A language that has basic programming constructs, like functions. That has good string handling. That can do simple floating point arithmetic. That is as widely available as possible. A language like&#8230; perl.</p>
<p>It sounds absurd, doesn&#8217;t it? Porting to perl in the name of maintainability. But when you&#8217;re in bash and most of what you&#8217;re doing is string manipulation and calls to other executables, it&#8217;s the right choice. And I bet you have perl on your box.</p>
<p>Not that it hasn&#8217;t been fun. Bash was the right place to start, and I&#8217;ve learned a lot of things about bash on the way. I&#8217;ve also learned that you have to do obscene things like echo strings to <code>bc</code> to do simple floating point math.</p>
<h3>The port</h3>
<p>It&#8217;s a straight port. undvd 0.7 runs on perl, but the way it was written was to reproduce 0.6 exactly. The code is completely new, obviously, but the functionality is the same.</p>
<p>As a result of running in perl, all the string/numerical processing logic has been internalized, and all the calls to awk, sed, bc and so on are gone. This makes it run faster, <code>scandvd</code> is especially noticeable. This isn&#8217;t a big impact, since most of the work is done in mencoder, and that is still the same. Nevertheless, it&#8217;s a welcome side effect. It also makes me happier, since it&#8217;s less dependent on all these outside tools.</p>
<p>In terms of size the code is about the same. The perl code is actually 5% bigger.</p>
<h3>What this means for you</h3>
<ul>
<li>0.6 and 0.7 are functionally equivalent.</li>
<li>If you find a bug in 0.6, it&#8217;s probably also in 0.7.</li>
<li>If you find a bug in 0.7, try 0.6.</li>
<li>Please <a href="https://sourceforge.net/tracker2/?group_id=211949">report bugs</a>.</li>
</ul>
<p><em>* I&#8217;m using the term &#8220;language&#8221; loosely here. I&#8217;m talking about both the language, and the implementation, and the execution environment (ie. standard libraries, or in bash&#8217;s case the gnu userland). Often we just pile all of this under &#8220;language&#8221;, because it&#8217;s easier to talk about it that way.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.matusiak.eu/numerodix/blog/index.php/2008/10/05/undvd-now-in-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>general purpose video conversion has arrived!</title>
		<link>http://www.matusiak.eu/numerodix/blog/index.php/2008/09/18/general-purpose-video-conversion-has-arrived/</link>
		<comments>http://www.matusiak.eu/numerodix/blog/index.php/2008/09/18/general-purpose-video-conversion-has-arrived/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 10:11:31 +0000</pubDate>
		<dc:creator>numerodix</dc:creator>
				<category><![CDATA[undvd]]></category>

		<guid isPermaLink="false">http://www.matusiak.eu/numerodix/blog/?p=1312</guid>
		<description><![CDATA[When I started undvd I set out to solve one very specific, yet sizeable, problem: dvd ripping&#38;encoding. I did that not because I really felt like diving head first into the problem would be fun, but because there was nothing &#8220;out there&#8221; that I could use with my set of skills (none). Meanwhile, I needed [...]]]></description>
			<content:encoded><![CDATA[<p>When I <a href="http://www.matusiak.eu/numerodix/blog/index.php/2007/01/30/undvd-dvd-ripping-made-easy/">started</a> undvd I set out to solve one very specific, yet sizeable, problem: dvd ripping&amp;encoding. I did that not because I really felt like diving head first into the problem would be fun, but because there was nothing &#8220;out there&#8221; that I could use with my set of skills (none). Meanwhile, I needed a dvd ripper from time to time, and since I didn&#8217;t need it often I would completely forget everything I had researched the last time I had used one. This was a big hassle, I felt like I had no control over the process, and I could never assure myself that the result would be good. Somehow, somewhere, there was a reason why all my outputs seemed distinctly mediocre. Visibly downgraded from the source material.</p>
<p>Writing undvd was a decent challenge in itself, because of all the complexity involved in the process. I had to find out all the stuff about video encoding that I didn&#8217;t really care about, but I thought <em>if I put it into undvd, and make sure it works, then I can safely forget all about it and just use my encoder from that point on</em>. When you start a project you really have no idea of where it&#8217;s going to end up. undvd has evolved far beyond anything I originally set out to build. That&#8217;s just what happens when you add a little piece here and another piece there. It adds up.</p>
<p>It&#8217;s been about 20 months. undvd is quite well tested and has been &#8220;stable&#8221; (meaning I don&#8217;t find bugs in it myself anymore) for over a year. One of the by products is a tool called vidstat for checking properties of videos. I wrote that one just so I could easily check the video files undvd was producing. But it turns out to be useful and I use it all the time now (way more than undvd). In the beginning I was overwhelmed by the number of variables that go into video encoding, and I wanted to keep as many of them as I could under tight control. I have since backtracked on a number of features I initially thought would be a really bad idea for encoding stability. But that&#8217;s just the way code matures, you start with something simple and when you&#8217;ve given it enough thought and enough tests, you can afford to build a little more complexity into the code.</p>
<p>Codec selection landed just <a href="http://www.matusiak.eu/numerodix/blog/index.php/2008/09/08/of-codecs-and-containers/">recently</a>. And once I was done scratching my head and trying to decide which ones to allow and/or <a href="http://www.matusiak.eu/numerodix/blog/index.php/2008/09/11/how-to-pick-a-codec/">suggest</a>, I suddenly realized that with this last piece of the puzzle I was a stone&#8217;s throw away from opening up undvd to general video conversion. Urgently needed? Not really. But since it&#8217;s so easy to do at this point, why not empower?</p>
<p>The new tool is called <em>encvid</em>. It works just like undvd, stripped of everything dvd specific. It also doesn&#8217;t scale the video by default (generally in conversion you don&#8217;t want that). So if you&#8217;ve figured out how to use undvd, you already know how to use encvid, you dig? <img src='http://www.matusiak.eu/numerodix/blog/wp-includes/images/smilies/cap.png' alt=':cap:' class='wp-smiley' /> </p>
<h3>Demo time</h3>
<p>Suppose you want to watch a talk from this year&#8217;s <a href="http://archive.fosdem.org/2008/media/video">Fosdem</a> (which incidentally, you can fetch with <a href="http://www.matusiak.eu/numerodix/blog/index.php/2008/06/28/spiderfetch-now-in-python/">spiderfetch</a> if you&#8217;re so inclined). You get the video and play it. But what&#8217;s this? Seeking doesn&#8217;t work, mplayer seems to think the video stream is 21 hours long, that&#8217;s obviously not correct (incidentally, I heard a rumor that ffmpeg svn finally fixed this venerable bug). It seems a little heavy handed, but if you want to fix a problem like this, one obvious option is to transcode. If the source video is good quality, at least from my observations so far, the conversion won&#8217;t noticeably degrade it.</p>
<p><img class="alignnone size-full wp-image-1323" title="encvid" src="http://www.matusiak.eu/numerodix/blog/wp-content/uploads/encvid.png" alt="" width="479" height="81" /></p>
<p>So there you go, a conversion with the default options. You can also set the codecs and container to your heart&#8217;s content.</p>
<p>You can also use encvid (or undvd for that matter) to cut some segment of a video with the <code>--start</code> and <code>--end</code> options. <img src='http://www.matusiak.eu/numerodix/blog/wp-includes/images/smilies/smile.png' alt=':)' class='wp-smiley' /> </p>
<h3>I&#8217;m sold, where can I buy it?</h3>
<ul>
<li>Gentoo: undvd-0.6.0 is already <a href="http://packages.gentoo.org/package/media-video/undvd">in portage</a> <img src='http://www.matusiak.eu/numerodix/blog/wp-includes/images/smilies/cool.png' alt=':cool:' class='wp-smiley' /> </li>
<li>Ubuntu: use my <a href="https://launchpad.net/~numerodix/+archive">personal package archive</a> (small apt repository)</li>
<li>Rpm/others: grab it from <a href="http://sourceforge.net/projects/undvd/">sourceforge</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.matusiak.eu/numerodix/blog/index.php/2008/09/18/general-purpose-video-conversion-has-arrived/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>how to pick a codec</title>
		<link>http://www.matusiak.eu/numerodix/blog/index.php/2008/09/11/how-to-pick-a-codec/</link>
		<comments>http://www.matusiak.eu/numerodix/blog/index.php/2008/09/11/how-to-pick-a-codec/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 23:57:32 +0000</pubDate>
		<dc:creator>numerodix</dc:creator>
				<category><![CDATA[undvd]]></category>

		<guid isPermaLink="false">http://www.matusiak.eu/numerodix/blog/?p=1300</guid>
		<description><![CDATA[The great thing about standards is there are so many to choose from.
- Someone
undvd 0.5.0 introduced a new option to choose the codec and container for the rip. The only problem is that you have to know which ones to choose. mencoder supports a staggering number of codecs and containers, most of which are now [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>The great thing about standards is there are so many to choose from.<br />
- Someone</p></blockquote>
<p>undvd 0.5.0 <a href="http://www.matusiak.eu/numerodix/blog/index.php/2008/09/08/of-codecs-and-containers/">introduced</a> a new option to choose the codec and container for the rip. The only problem is that you have to know which ones to choose. mencoder supports a staggering number of codecs and containers, most of which are now exposed also in undvd. The resulting rip can also be remuxed to a couple of other popular containers with additional tools.</p>
<p>But I wasn&#8217;t content with solving a problem by introducing a new problem. Now, it&#8217;s not so easy to say exactly which combinations are good and bad, but if at least you knew which ones definitely do not work, that would be a start, wouldn&#8217;t it? Then at least you can rescue the user from phase one of the <a href="http://en.wikipedia.org/wiki/Monte_carlo_method">Monte Carlo method</a> in getting something that actually works.</p>
<p>The methodology is like this:</p>
<ol>
<li>Rip 5 seconds of the dvd using undvd with a given container/video codec/audio codec combination.</li>
<li>Attempt playback with mplayer.</li>
</ol>
<p>This is what <code>codectest</code> does. The result is either a text file showing line by line whether or not the given combination successfully produced a rip, or a pretty matrix picture. This gives you an idea of what you can expect to use. If you run this on your system, it&#8217;s also a tip off if you see something that should work but doesn&#8217;t.</p>
<p>I must stress that if the given combination of codecs does produce a file, this is no guarantee that the file is to be considered a good rip. It may not play on other media players, it may not even play on mplayer (incidentally, this is something akin to a <a href="http://en.wikipedia.org/wiki/Fuzzing">fuzzer</a>, I&#8217;ve discovered that some combinations really aren&#8217;t expected <img src='http://www.matusiak.eu/numerodix/blog/wp-includes/images/smilies/biggrin.png' alt=':D' class='wp-smiley' />  ). So if <code>codectest</code> says it works, verify that you get a working video file out of it!</p>
<p>The standard set looks something like this:</p>
<p><a href="http://www.matusiak.eu/numerodix/blog/wp-content/uploads/codectest_default.svg"><img class="alignnone size-full wp-image-1298" title="codectest_default" src="http://www.matusiak.eu/numerodix/blog/wp-content/uploads/codectest_default.png" alt="" width="500" height="257" /></a></p>
<p>It&#8217;s also possible to run it on the full combination of all codecs and containers that are now exposed in undvd. You&#8217;ll need a few hours to do it:</p>
<p><a href="http://www.matusiak.eu/numerodix/blog/wp-content/uploads/codectest_insane.svg"><img class="alignnone size-full wp-image-1305" title="codectest_insane" src="http://www.matusiak.eu/numerodix/blog/wp-content/uploads/codectest_insane.png" alt="" width="500" height="280" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.matusiak.eu/numerodix/blog/index.php/2008/09/11/how-to-pick-a-codec/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>of codecs and containers</title>
		<link>http://www.matusiak.eu/numerodix/blog/index.php/2008/09/08/of-codecs-and-containers/</link>
		<comments>http://www.matusiak.eu/numerodix/blog/index.php/2008/09/08/of-codecs-and-containers/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 21:52:55 +0000</pubDate>
		<dc:creator>numerodix</dc:creator>
				<category><![CDATA[undvd]]></category>

		<guid isPermaLink="false">http://www.matusiak.eu/numerodix/blog/?p=1278</guid>
		<description><![CDATA[I have been very skeptical about adding options for other codecs in undvd, purely because of the test burden. With a single combination of container and pair of audio/video codecs I can be reasonably confident that I&#8217;ve done enough manual testing (and judging video quality doesn&#8217;t trivially lend itself to automated testing, sadly) to account [...]]]></description>
			<content:encoded><![CDATA[<p>I have been very skeptical about adding options for other codecs in undvd, purely because of the test burden. With a single combination of container and pair of audio/video codecs I can be reasonably confident that I&#8217;ve done enough manual testing (and judging video quality doesn&#8217;t trivially lend itself to automated testing, sadly) to account for most potential problems.</p>
<p>But at the end of the day it&#8217;s a question of priorities, and having scratched all the important technical itches by now, if anything this is the right time for it. I got some user feedback recently that set me onto this path. The user was having trouble playing the files encoded in the classical <strong>avi+h264+mp3</strong> format on other platforms, and that&#8217;s when I asked myself how important is it really to have a single format? As long as the default still works well, what&#8217;s the harm in offering a little customization?</p>
<p>Testing <em>is</em> a huge problem, which is why this new feature is considered to be experimental. The most common seems to be bad a/v sync. There is just no way to account for all the possible combinations of codecs and containers, and to maintain an up-to-date document for this as things evolve. So the burden of testing is squarely on the user here (which is quite unfortunate).</p>
<p>The new functionality is available in undvd 0.5 and up. Here&#8217;s a shot of the new goodness. All these files were encoded from the same dvd title. A 22 minute title was ripped with different containers (represented with different filenames). The audio codec is mostly the same in all cases (mad = mp3), except for <code>1.mp4</code> (faad = aac). The video codec is also mostly the same (h264 = avc1), except for <code>1.flv</code>. The only variation here is the container being set to different values, all the other settings are defaults. You can also witness that some containers are more wasteful than others (given the same a/v streams), but not by a huge amount. (The audio bitrates shown are actually misleading, mplayer seems to give the lowest bitrate in a vbr setting.)</p>
<p><img class="size-full wp-image-1280 alignnone" title="vidstat_0.5.1" src="http://www.matusiak.eu/numerodix/blog/wp-content/uploads/vidstat_0.5.1.png" alt="" width="463" height="164" /></p>
<p>This demo is by no means exhaustive of the full collection of codecs that can be used, for that see the user guide. There is also an option to use the <em>copy</em> codec, which just copies the audio/video stream as is.</p>
<p style="text-align: center;">
]]></content:encoded>
			<wfw:commentRss>http://www.matusiak.eu/numerodix/blog/index.php/2008/09/08/of-codecs-and-containers/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>undvd gets smarter scaling</title>
		<link>http://www.matusiak.eu/numerodix/blog/index.php/2008/03/09/undvd-gets-smarter-scaling/</link>
		<comments>http://www.matusiak.eu/numerodix/blog/index.php/2008/03/09/undvd-gets-smarter-scaling/#comments</comments>
		<pubDate>Sat, 08 Mar 2008 22:51:28 +0000</pubDate>
		<dc:creator>numerodix</dc:creator>
				<category><![CDATA[undvd]]></category>

		<guid isPermaLink="false">http://www.matusiak.eu/numerodix/blog/index.php/2008/03/09/undvd-gets-smarter-scaling/</guid>
		<description><![CDATA[The big new change in undvd 0.4.0 was a dynamically set bitrate based on the bits-per-pixel (bpp) value. That addition not only completely changed the way undvd deals with bitrates, it also made possible further improvements.
The guiding principle of undvd remains be smart if possible, don&#8217;t bother the user. A brand new feature is a [...]]]></description>
			<content:encoded><![CDATA[<p>The big new change in undvd 0.4.0 was a <a href="http://www.matusiak.eu/numerodix/blog/index.php/2008/03/04/undvd-gets-dynamic-bitrate/">dynamically set bitrate</a> based on the bits-per-pixel (bpp) value. That addition not only completely changed the way undvd deals with bitrates, it also made possible further improvements.</p>
<p>The guiding principle of undvd remains <em>be smart if possible, don&#8217;t bother the user</em>. A brand new feature is a smarter way to determine how to scale the video. This is another under-the-hood improvement which improves the program without introducing any more bloat or changing the user interface.</p>
<p><strong>How do we scale?</strong></p>
<p>To motivate the issue, let&#8217;s consider an example. Until now, undvd scales to 2/3 of the original width.</p>
<p>For a 720&#215;576 (5:4) dvd movie this gives target dimensions 480&#215;384, for a total of <strong>184,320</strong> pixels. For a 2 hour movie (25 fps), this gives results in a video 771mb (plus the size of the audio, some 140mb).</p>
<blockquote><p>    480 * 384 * 25 * 0.195 * 7200 / 1024² / 8 = 771mb</p></blockquote>
<p>But for a movie of different dimensions, a constant scale factor would yield a smaller number of pixels per frame. Suppose another movie has dimensions 720&#215;480 (3:2). This would give target dimensions 480&#215;320, a total of <strong>153,600</strong> pixels. The video size would, of course, be proportionally smaller as well.</p>
<blockquote><p>    480 * 320 * 25 * 0.195 * 7200 / 1024² / 8 = 642mb</p></blockquote>
<p>This is probably not what you want. You give up the same proportion of pixels in both cases, but for a movie of smaller dimensions it would be nice to get the same frame size, ie. keep a greater portion of the frame. In the extreme case, for a movie with dimensions 720&#215;224 you would probably want to keep the frame intact (161,280 pixels) and you would still get a smaller file.</p>
<p><strong>Scaling by frame size, not width</strong></p>
<p>So the obvious solution is to consider the number of pixels in a frame, not just along the width. As with the bpp in the previous increment, what used to be the default  becomes the starting point for interpolation. So 720&#215;576 will still scale to 480&#215;384. But 720&#215;480 becomes 528&#215;352 (185,856 pixels) and 720&#215;224 would not be downscaled at all.</p>
<p>What complicates the issue somewhat is the need to pick dimensions such that it comes to an even number of 16&#215;16 pixel blocks (I&#8217;m not sure how crucial this actually is, but the absolute of majority of video files obey this rule). This reduces the number of possible dimensions for a movie of a given aspect ratio.</p>
<p>For instance, take dimensions 720&#215;272. This gives a frame size just over the desired <strong>184,320</strong> pixels<strong>.</strong> But the next possible option is 256&#215;96, which is tiny. Here undvd does the &#8220;smart&#8221; thing and picks the dimensions closest to the target size (in this case leaving it intact).</p>
<p><strong>The nitty gritty</strong></p>
<p>Deciding on a scaling factor is quite simple. Starting from the equations to scale the width and height separately,</p>
<blockquote><p>width * factor = scaled_width</p>
<p>height  * factor = scaled_height</p></blockquote>
<p>we obtain a formula to find the number of pixels in a frame.</p>
<blockquote><p>width * height * factor² = framesize</p></blockquote>
<p>Assuming we know how many pixels we want in a frame irrespective of the dimensions, we can derive a formula to find the scaling factor.</p>
<blockquote><p>factor = sqrt( framesize / (width * height)  )</p></blockquote>
<p>To reuse the example of the 720×480 movie, we find</p>
<blockquote><p>0.730 = sqrt( 184,320 / (720 * 480)  )</p></blockquote>
<p>Scaling by this factor we get the target dimensions of the video.</p>
<blockquote><p>720 * 0.730 = 525.813</p>
<blockquote></blockquote>
<p>480 * 0.730 = 350.542</p></blockquote>
<p>It may not surprise you to know that the new dimensions do not divide evenly by 16. The nearest dimensions satisfying the multiples-of-16 rule are 480&#215;320 and 528&#215;352, but the latter is closer to our starting point.</p>
<p><strong>Multiples of 16</strong></p>
<p>Finding the width and height is a bit more hairy because we have to find two values that correspond. I don&#8217;t think there is a formulaic solution to the problem because it amounts to solving this set of equations:</p>
<blockquote><p>width * height = framesize</p>
<p>width = ratio * height (where ratio is known)</p>
<p>width = a * 16</p>
<p>height = b * 16</p>
<p>framesize = c * 16</p></blockquote>
<p>The last three equations do not help, because they do not relate any two of the variables (width, height, framesize) to each other. And so we have the top two equations of three unknowns, which is not going to work. Intuitively, we know this is true, because we expect there are many sets of (width, height, framesize) that are possible solutions, so this set of equations will not give us a solution.</p>
<p>But it can be solved with an algorithm:</p>
<pre class="bash"><span style="color: #000066;">local</span> <span style="color: #0000ff;">ratio=</span><span style="color: #ff0000;">"$orig_height/$orig_width"</span>
&nbsp;
<span style="color: #0000ff;">step=</span><span style="color: #cc66cc;">-1</span>
<span style="color: #000066;">unset</span> completed
<span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#91;</span> ! <span style="color: #ff0000;">"$completed"</span> <span style="color: #66cc66;">&#93;</span>; <span style="color: #b1b100;">do</span>
	<span style="color: #0000ff;">step=</span>$<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$step</span> + <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
	<span style="color: #000066;">local</span> <span style="color: #0000ff;">up_step=</span>$<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$width</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$step</span> * <span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #000066;">local</span> <span style="color: #0000ff;">down_step=</span>$<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$width</span> - <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$step</span> * <span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #b1b100;">for</span> x_step <span style="color: #b1b100;">in</span> <span style="color: #0000ff;">$down_step</span> <span style="color: #0000ff;">$up_step</span>; <span style="color: #b1b100;">do</span>
		<span style="color: #000066;">local</span> <span style="color: #0000ff;">x_width=</span>$<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$x_step</span> - <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$x_step</span> % <span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #000066;">local</span> <span style="color: #0000ff;">x_height=</span>$<span style="color: #66cc66;">&#40;</span> <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"scale=0; $x_width*$ratio/1"</span> | bc <span style="color: #66cc66;">&#41;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$x_width</span> % <span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$x_height</span> % <span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #b1b100;">then</span>
			<span style="color: #0000ff;">completed=</span><span style="color: #ff0000;">"y"</span>
			<span style="color: #0000ff;">width=</span><span style="color: #0000ff;">$x_width</span>
			<span style="color: #0000ff;">height=</span><span style="color: #0000ff;">$x_height</span>
		<span style="color: #b1b100;">fi</span>
	<span style="color: #b1b100;">done</span>
<span style="color: #b1b100;">done</span></pre>
<p><i>Download this code: </i><a href="http://www.matusiak.eu/numerodix/blog/wp-content/uploads/undvd_scale16">undvd_scale16</a></p>
<p>Here <code>step</code> is the distance from our starting point, each time used to set the values <code>up_step</code> and <code>down_step</code> to successive upwards and downwards increments of 16 respectively <code>(525+16, 525-16)</code>. For each of these we run the inner loop, setting <code>x_width</code> to the value that divides 16 within the range <code>[x_step, x_step-16]</code>. We now have a valid value for the width. We now use the <code>ratio</code> to find the corresponding height while preserving the aspect ratio, stored in <code>x_height</code>. If both <code>x_width</code> and <code>x_height</code> are multiples of 16, we have found dimensions for the video.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matusiak.eu/numerodix/blog/index.php/2008/03/09/undvd-gets-smarter-scaling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>undvd gets dynamic bitrate</title>
		<link>http://www.matusiak.eu/numerodix/blog/index.php/2008/03/04/undvd-gets-dynamic-bitrate/</link>
		<comments>http://www.matusiak.eu/numerodix/blog/index.php/2008/03/04/undvd-gets-dynamic-bitrate/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 02:32:24 +0000</pubDate>
		<dc:creator>numerodix</dc:creator>
				<category><![CDATA[undvd]]></category>

		<guid isPermaLink="false">http://www.matusiak.eu/numerodix/blog/index.php/2008/03/04/undvd-gets-dynamic-bitrate/</guid>
		<description><![CDATA[If we were to apply the Pareto principle to fit the world of software development, I would suggest the following translation.
Building 80% of the product takes 20% of the effort.
It&#8217;s not surprising. A little code goes a long way. Typically problems we attack have a wide frontier we can cover with little effort. That is [...]]]></description>
			<content:encoded><![CDATA[<p>If we were to apply the <a href="http://en.wikipedia.org/wiki/Pareto_principle">Pareto principle</a> to fit the world of software development, I would suggest the following translation.</p>
<blockquote><p>Building 80% of the product takes 20% of the effort.</p></blockquote>
<p>It&#8217;s not surprising. A little code goes a long way. Typically problems we attack have a wide frontier we can cover with little effort. That is why we choose <em>them</em>. And while no software really can be said to be 100% complete in a mathematical sense, it certainly takes a great deal of effort to &#8220;finish it off&#8221; by handling all those special circumstances and corner cases.</p>
<p>What is wrong with 80% completion anyway? Isn&#8217;t that good enough? Often it is. But there is that little voice in your head that says since you&#8217;ve already done &#8220;almost all of it&#8221;, why not finish it? After all, there is a sense of accomplishment at stake, and since you&#8217;ve already attacked the problem, there is that urge to solve it completely.</p>
<p><a href="http://www.matusiak.eu/numerodix/blog/index.php/2007/01/30/undvd-dvd-ripping-made-easy/">undvd</a> was 80% complete by version 0.2.2, with packages for <a href="http://www.matusiak.eu/numerodix/blog/index.php/2007/12/18/undvd-now-in-portage/">Gentoo</a>, Ubuntu and Fedora. <a href="http://www.matusiak.eu/numerodix/blog/index.php/2007/12/11/undvd-looking-ahead-and-back/">Version 0.3.x</a> added things I didn&#8217;t plan to include at all when I started this project. The new features made it possible to set an output size (and thus indirectly set the bitrate), set 2 pass encoding, and set scaling. I was wary about compromising the key principle: <em>undvd should be obvious and easy to use</em>. But the new goodies were tucked into an &#8220;advanced&#8221; menu and so I don&#8217;t think they did a lot of damage.</p>
<p>Since 0.3.0 there has been a host of tweaks and small fixes for small problems. One such problem was that undvd worked well on terminals with a black/dark background, but was not tested on a white/light background. That is unfortunate, given how gnome-terminal and konsole both use a light background by default. These kinds of fixes are enjoyable in that they improve the overall user experience in subtle ways, but without changing anything in the way you have to use the software.</p>
<p><strong>Preparing to leap again</strong></p>
<p>Having said that, one technical aspect I wasn&#8217;t entirely pleased with was how undvd sets the bitrate. This is something of a black art, and I had done pretty intensive testing before deciding that 900kbps seemed ideal for h264 video. But debating <em>the ideal bitrate</em> is like debating the ideal size for a jpeg image. At the very least, it matters what the dimensions are. I had been scaling the image to 480 pixels wide in my tests, and so with greater dimensions the result wouldn&#8217;t be as good.</p>
<p>I came across a very helpful <a href="http://users.softlab.ece.ntua.gr/~ttsiod/x264.html">article</a> that deals with bitrates and also contrasts the h264 and xvid codecs. Discussing bitrate is pointless, because bitrate isn&#8217;t a constant, it&#8217;s a <em>function</em> of other quantities. What we need is a constant to standardize on.</p>
<p><img src="http://www.matusiak.eu/numerodix/blog/wp-content/uploads/undvd_bitrate_01.png" /></p>
<p>Going back to the jpeg example, let&#8217;s start with a frame of video.  480&#215;384 gives 184,320 pixels, if we use one bit to store each pixel we come up with a quantity that is <em>bits per pixel, </em>abbreviated to <strong>bpp</strong>. So we&#8217;re using 184,320 bits (180 kilobits, or 22 kilobytes) to store this one frame.</p>
<p><img src="http://www.matusiak.eu/numerodix/blog/wp-content/uploads/undvd_bitrate_02.png" /></p>
<p>Let&#8217;s take the single frame and another however many frames that fit into one second of video (25 is a common number). So now we have 25 of those 480&#215;384 frames. If we now use one bit to store one pixel we need 25 bits for the job.</p>
<p><img src="http://www.matusiak.eu/numerodix/blog/wp-content/uploads/undvd_bitrate_03.png" /></p>
<p>To complete the illustration, say we take our 480&#215;384 frame 25 times per second, for a total of 2 hours (7200 seconds). If we used one <em>bit per pixel</em>, we used 25 pixels for 7200 seconds, which gives 180,000 bits per pixel in the movie. Multiply that by the number of pixels in one frame and we find 33,177,600,000 bits (30 gigabits, or 3.8 gigabytes).</p>
<p>Where does the bitrate come in? The bitrate is bits per seconds, so now that we have the number of bits, we divide by the number of seconds and find 4,608,000 (4500 kbps). If it isn&#8217;t clear yet why the bitrate isn&#8217;t a useful measure, it soon will be.</p>
<p><strong>Getting it right </strong></p>
<p>To formalize our deductions we draw up some equations. First, as we said, bpp is bits per pixel:</p>
<blockquote><p>bpp = bits / pixel</p></blockquote>
<p>To calculate the size (in bits) of the movie we took the bpp, the framerate (frames per second), the length (in seconds) and the dimensions (in pixels).</p>
<blockquote><p>size = bpp * fps * length * width * height</p></blockquote>
<p>And the bitrate (bits per second) is now the size divided by the length of the movie:</p>
<blockquote><p>bitrate = size / length</p></blockquote>
<p>We can also solve this equation for size, and substitute the formula into the previous one, which gives a different equation for the bitrate:</p>
<blockquote><p> bitrate = bpp * fps * width * height</p></blockquote>
<p>It should now be clear what the problem is with the bitrate as a measure of quality. It not only encapsulates the bpp, it also subsumes the dimensions and the frame rate of the movie!</p>
<p>Still not clear? Let&#8217;s solve the equation for bpp.</p>
<blockquote><p>bpp = bitrate / (width * height * fps)</p></blockquote>
<p>Now let&#8217;s assume we use the bitrate as a measure of quality. As mentioned, undvd up to version 0.3.x sets a constant bitrate of 900kbps (921,600 bits). Let&#8217;s try that on a couple of examples.</p>
<blockquote><p>0.200 = 921600 / (480 * 384 * 25)</p></blockquote>
<p>When we plug the bitrate into the equation we find the bpp is <strong>0.2</strong>.</p>
<p>But now suppose the user does not want any video scaling and the dimensions of the output video are 720&#215;576.</p>
<blockquote><p>0.088 = 921600 / (720 * 576 * 25)</p></blockquote>
<p>Now we have less than half the space to store one pixel than we did in the first case, because we have more than twice the number of pixels in every frame. Clearly, the same number of bits to store this movie, spread across more pixels, will allow less for each pixel, and thus lower the quality.</p>
<p>Therefore, the bitrate needs to vary depending on the dimensions and the length of the movie. It is thus a function, not a constant! On the other hand, bpp <em>is</em> a constant, and so if we want a measure of quality we should use that instead.</p>
<p><strong>Getting practical</strong></p>
<p>The equations are easy. The question at hand is what value to set for the bpp. As shown in the example, 900kbps at the dimensions frequently used gives about 0.2 bpp, which is known to work well.    <a href="http://users.softlab.ece.ntua.gr/~ttsiod/x264.html">Thanassis Tsiodras</a> suggests that 0.2 bpp is enough for xvid, while h264 can be encoded at just 0.125 bpp. But considering that undvd is a one-size-fits-all solution, and therefore should encode any video well (even at the cost of filesize in cases where it&#8217;s unnecessary), I would rather overshoot the target size a bit and play it safe. Therefore, based on my results, the default bpp is set to <strong>0.195</strong>. In case of two pass encoding, we trade processing time for filesize, and the value is set to 0.150. For xvid the corresponding values are 0.250 and 0.200.</p>
<p>As before,  these defaults can be overridden by setting the output filesize.</p>
<p>The best thing about this new functionality is that it doesn&#8217;t invalidate any existing assumptions. For a default rip the result will be the same as always, which is supposed to be very good. But now it scales to custom video dimensions as well.</p>
<p><strong>Something missing?</strong></p>
<p>Pleased as I was that undvd now has a mathematical underpinning for deciding the bitrate, I was still not quite satisfied. It&#8217;s nice and all that we now use a constant to determine the quality, but what is bpp anyway? How do we relate to it? And how do we know what a good value of bpp is?</p>
<p>To make this more tangible, I decided it can&#8217;t just be a value in a calculation, it has to be made visible. undvd now has a &#8220;dry run&#8221; option -D, which shows all the parameters of the video to be encoded. The bpp value is highlighted, because that is our measure of quality. This image shows title 01 is chosen for ripping. The dimensions will be scaled to 480&#215;384, the frame rate is 25 fps, the length is 148 minutes, the bpp is .195, the bitrate is thus calculated to 877kbps, we are using one pass encoding, and the h264 codec. The output size is estimated at 1122mb.</p>
<p><img src="http://www.matusiak.eu/numerodix/blog/wp-content/uploads/undvd_dynamicbitrate_dryrun.png" /></p>
<p>Short of showing the bpp for a title we are about to encode, it would also be useful to inspect videos we have encoded in the past, wouldn&#8217;t it? That would give us an idea of what to expect.</p>
<p>For this there is a new tool <strong>vidstat</strong>, which displays the same information about any file or dvd title (much like <code>stat</code> displays information about a file on the filesystem) .</p>
<p>Here we see the first 60 seconds of title 01 (from above) being ripped. Then we run vidstat on the output file to examine it. Here we see that mencoder decided to use 809kbps instead of  877 as it was instructed to.</p>
<p><img src="http://www.matusiak.eu/numerodix/blog/wp-content/uploads/undvd_dynamicbitrate_vidstat.png" /></p>
<p>The bpp value is highlighted in yellow, red or green depending on whether undvd thinks it&#8217;s unnecessarily high (above the single pass bpp default) or low (below the two pass bpp default), or just right (within the two).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matusiak.eu/numerodix/blog/index.php/2008/03/04/undvd-gets-dynamic-bitrate/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>undvd now in portage</title>
		<link>http://www.matusiak.eu/numerodix/blog/index.php/2007/12/18/undvd-now-in-portage/</link>
		<comments>http://www.matusiak.eu/numerodix/blog/index.php/2007/12/18/undvd-now-in-portage/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 23:39:29 +0000</pubDate>
		<dc:creator>numerodix</dc:creator>
				<category><![CDATA[undvd]]></category>

		<guid isPermaLink="false">http://www.matusiak.eu/numerodix/blog/index.php/2007/12/18/undvd-now-in-portage/</guid>
		<description><![CDATA[I was pleasantly surprised today to discover that undvd has made its way into portage.   It does now have three releases on sourceforge with packages for gentoo (ebuild), ubuntu and fedora. But I haven&#8217;t made any requests for it to be included, so apparently the powers that be decided it&#8217;s not completely useless. [...]]]></description>
			<content:encoded><![CDATA[<p>I was pleasantly surprised today to discover that undvd has made its way <a href="http://packages.gentoo.org/package/media-video/undvd">into portage</a>. <img src='http://www.matusiak.eu/numerodix/blog/wp-includes/images/smilies/cool.png' alt=':cool:' class='wp-smiley' />  It does now have three releases <a href="http://sourceforge.net/project/showfiles.php?group_id=211949">on sourceforge</a> with packages for gentoo (ebuild), ubuntu and fedora. But I haven&#8217;t made any requests for it to be included, so apparently the powers that be decided it&#8217;s not completely useless. <img src='http://www.matusiak.eu/numerodix/blog/wp-includes/images/smilies/party.png' alt=':party:' class='wp-smiley' /> </p>
<p>It&#8217;s actually a bit of a dilemma what to do with these small projects. A big project just looks neglected without a website, complete documentation, packages for several distributions, up-to-date entries on various directory sites etc. I did the full scale follow-up with <a href="http://galleryforge.berlios.de/">galleryforge</a>, and that now speaks for itself, it presents itself as a proper project. But for one thing it was my first time hosting with one of these open source providers, so I wanted to explore the options quite deeply. And secondly, you don&#8217;t really know what kind of a future a project will have when you&#8217;re starting it, but galleryforge isn&#8217;t used much, not even by me. So it was fine to do then, but it&#8217;s some effort to put in for every small piece of code like this. (Not so much doing it then, but the burden of maintenance is the key issue.)</p>
<p>undvd is even smaller, and isn&#8217;t expected to grow much (beyond feature complete by now). It started out as <a href="http://www.matusiak.eu/numerodix/blog/index.php/2007/01/30/undvd-dvd-ripping-made-easy/">a blog entry</a> and a link on my <a href="http://www.matusiak.eu/numerodix/code.php">code</a> page. Then I posted it on <a href="http://www.opendesktop.org/content/show.php/undvd?content=64833">opendesktop</a>, and it got seen by a handful of people who happened to be looking at the frontpage when it was added. There was also a regression bug posted there, which spurred me to start tracking it <a href="http://repo.or.cz/w/undvd.git">with git</a> to avoid these things in the future. Then I decided I wanted to package it up, because that makes it organized and easy to use. But then I couldn&#8217;t figure out how to write the url (in the ebuild) for the tarball hosted on opendesktop, because their file hosting is a little sucky. So I registered <a href="http://sourceforge.net/projects/undvd/">on sourceforge</a>. The only thing I&#8217;m using there right now is the file release function. There&#8217;s no website, and I don&#8217;t really see the call for one. Meanwhile, I&#8217;ve been trying to maintain the user guide (which is shipped with the code) clear and up-to-date, to make that the one source of information. I think that&#8217;s enough for now.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matusiak.eu/numerodix/blog/index.php/2007/12/18/undvd-now-in-portage/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>undvd: looking ahead. and back.</title>
		<link>http://www.matusiak.eu/numerodix/blog/index.php/2007/12/11/undvd-looking-ahead-and-back/</link>
		<comments>http://www.matusiak.eu/numerodix/blog/index.php/2007/12/11/undvd-looking-ahead-and-back/#comments</comments>
		<pubDate>Tue, 11 Dec 2007 21:55:44 +0000</pubDate>
		<dc:creator>numerodix</dc:creator>
				<category><![CDATA[undvd]]></category>

		<guid isPermaLink="false">http://www.matusiak.eu/numerodix/blog/index.php/2007/12/11/undvd-looking-ahead-and-back/</guid>
		<description><![CDATA[When you decide to code an application in a problem space that already has a rich bouquet of solutions the typical questions come to mind immediately. What is this going to accomplish? Why not just use an existing application? Why reinvent the wheel? Perfectly valid concerns, and yet every application has some reason to be, [...]]]></description>
			<content:encoded><![CDATA[<p>When you decide to code an application in a problem space that already has a rich bouquet of solutions the typical questions come to mind immediately. <em>What is this going to accomplish? Why not just use an existing application? Why reinvent the wheel?</em> Perfectly valid concerns, and yet every application has some reason to be, or it wouldn&#8217;t exist in the first place. Sometimes it&#8217;s a question of timing &#8211; better solutions did not exist at inception. Sometimes it&#8217;s about quality: <em>that one over there works but doesn&#8217;t do it well enough</em>. And sometimes it&#8217;s something different altogether. <em>That one does too much and I don&#8217;t understand it.</em></p>
<p>There are people out there who are proper movie buffs. People who can quote lines out of a movie and identify passages to extreme detail. I&#8217;ve known a bunch of people like that, but I&#8217;ve never been like that myself. To me watching movies was never a really important thing, it was kind of a second tier interest. But knowing people like this has its advantages, you can borrow their movies. <img src='http://www.matusiak.eu/numerodix/blog/wp-includes/images/smilies/cool.png' alt=':cool:' class='wp-smiley' />  I remember how we used to lug around VHS tapes at school.</p>
<p>So my lack of outright passion about movies is really the reason why I never took after the dvd ripping crowd. When DVDs were fairly new, people were so excited about divx. My friends at school used to discuss bitrates and filesizes. I didn&#8217;t follow any of that, I wasn&#8217;t really interested. I didn&#8217;t have a DVD drive, nor did I think paying <font size="-1">€</font>38 for a movie was such a good deal.</p>
<p>But admittedly, ripping the occasional movie is useful. DVDs in general are just a hassle and I don&#8217;t like to put up with them. Back in those days (a few years later, when I had bought my first dvd drive for my first custom built computer) I would try it a few times. I didn&#8217;t mirror the excitement of my friends. It took a really long time to rip a movie, and the result wasn&#8217;t that good. I don&#8217;t know what I was doing wrong. We used the <a href="http://sourceforge.net/projects/gordianknot">Gordian Knot</a> suite and followed the guides on <a href="http://www.doom9.org/">Doom9</a>. But while the program gave me every possibility to tweak the settings, I didn&#8217;t know what they mean, I didn&#8217;t *want* to know what they mean, I just wanted to rip it and move on.</p>
<p>And that is precisely the point where <a href="http://www.matusiak.eu/numerodix/blog/index.php/2007/01/30/undvd-dvd-ripping-made-easy/">undvd</a> comes in. I&#8217;ve tried a bunch of tools for ripping DVDs. <a href="http://www.exit1.org/dvdrip/">dvd::rip</a> might be the most merited linux tool. There&#8217;s also <a href="http://untrepid.com/acidrip/">acidrip</a> and a bunch of others I don&#8217;t even remember anymore. All these tools had the same two flaws:</p>
<ul>
<li>They present a lot of options that I don&#8217;t know anything about, and I don&#8217;t care about. And presumably, since my results were never very good, these are crucial for good results.</li>
<li>It takes anything from 15 to 45 minutes to actually set up all the options, inputs, outputs, filters, cropping, the whole shebang. When something fails, like the disc can&#8217;t be read from, the tool sometimes crashes. If it does, all your set-up work is lost. But even if you have a working setup from before and you want to rip another movie you still have to double check all these settings, because ripping takes a long time and if you mis set something by accident you may only discover it far along the way.</li>
</ul>
<p>Therefore, I think it&#8217;s fair to say that we have the <a href="http://en.wikipedia.org/wiki/Photoshop">Photoshop</a> of DVD ripping in place. Personally I want to use <a href="http://en.wikipedia.org/wiki/Paint_(software)">Paint</a> for this activity, because I have no deep interest in all the details.</p>
<p><strong>Making it work</strong></p>
<p>So if there is something complicated you have to do again and again, and every time you worry that you&#8217;ll get it wrong and even if you get it right next time you probably don&#8217;t remember what you did again. Faced with that, what do you do? In the middle ages monks would copy books by hand, at extraordinary effort. Not only would they transcribe the text, they would also copy and enhance the illustrations so that the copy, while not being the original, would be no less worthy. This was their calling, transcribing was an art form. Then came Gutenberg. Now granted, building a printing press took a lot more effort than transcribing a book. But once you had done that, copying books was a no brainer.</p>
<p>To me ripping a DVD is not an art form, it&#8217;s a chore. And if I can figure out how to do it once and never have to worry about it again, then it&#8217;s well worth the effort. So I set out to figure it out, I looked up the details and read the fine print. Eventually I had a fairly good idea of how to do it, and the results were coming along.</p>
<p>undvd became the wrapper around that nastiness I didn&#8217;t want to look at or remember. And for my money it worked well. It also encompasses certain design decisions that were important to me.</p>
<p><em>Why no gui?</em></p>
<p>The <em>Photoshop</em> rippers all come with a gui interface. That&#8217;s hardly a surprise, the plethora of settings they allow you to fiddle with would look like <a href="http://www.mplayerhq.hu/">mplayer</a>&#8217;s list of options if they weren&#8217;t gui apps. It&#8217;s practically impossible *not* to have a gui for those guys.</p>
<p>But DVD ripping is not inherently a gui centric activity. You need the gui to write your missile launch plan, but once you start ripping the gui doesn&#8217;t serve any purpose anymore. It just sits there in memory, and you could just as well remove it while ripping and then bring it back once it&#8217;s over. So 95% of the time the gui isn&#8217;t being used.</p>
<p>Apart from the simple fact that coding a gui is a lot more work, I consider a gui a hindrance in this case. There is nothing a gui would do for undvd that would improve how the program is being used.</p>
<p><em>Why not interactive?</em></p>
<p>There are some non-gui rippers/encoders out there, like <a href="http://h264enc.sourceforge.net/">h264enc</a> and <a href="http://sourceforge.net/projects/ripdvd/">ripdvd</a> (and probably a bunch of others). Common to them is that they run interactively. They ask you a series of questions to determine everything they need to know about ripping the DVD before they can start doing the work.</p>
<p>Unfortunately, interactive mode suffers from the same problems that a gui interface does. You have to answer all the questions whether you know what to answer or you don&#8217;t. And more importantly, it&#8217;s hard to reproduce the result, because you don&#8217;t remember what you answered the last time.</p>
<p>And crucially, an interactive program won&#8217;t let you just run it and go do something else, you have to stick around to do your part before the app will do its part. With a ripper this isn&#8217;t such a big deal, because all the interaction happens at the beginning, but it&#8217;s still something I like to do without.</p>
<p><em>Why bash?</em></p>
<p>The standard way of building a ripper is to wrap an interface around the scary mencoder command line interface. Whether this is a gui or not has no impact on how the ripper interacts with mencoder. There is no programmatic interface to mencoder, so you&#8217;re stuck running it from a shell one way or the other.</p>
<p>Taking this into account, a bash script is pretty much the easiest way to handle shell commands. (If you&#8217;re a perl nut, perhaps that would suit you better, but I&#8217;m not.) I&#8217;ve tried running commands from python (and using it to capture the exit code, stdout, stderr etc), and it&#8217;s far easier just to use plain bash.</p>
<p>As a self imposed restriction, it will also keep the program from becoming too big. Bash is not exactly the greatest abstraction language and takes quite a bit of discipline to keep it from getting totally convoluted, which is why I would not use it for anything bigger than a simple application.</p>
<p><strong>Feature creep</strong></p>
<p>Unfortunately, every program that evolves will face the issue of new features. Personally I think undvd does what it does well enough, I&#8217;m satisfied. But any one-size-fits-all strategy is bound to be somewhat constrained. The question is where to stop?</p>
<p>Two things <a href="http://www.opendesktop.org/content/show.php/undvd?content=64833">came up</a> that weren&#8217;t intended for undvd:</p>
<p><em>Scaling</em></p>
<p>To start off with the first issue, undvd makes the assumption that the output video will be smaller than the original. This is fairly sensible, given that most rips are done this way, and considering that 6x compression does demand a lot from your encoder unless you compromise a bit on dimensions. Crucially, even if you watch a movie full screen the software/hardware scaling does a good enough job of stretching the image without clobbering it. Having said that, undvd&#8217;s decision to scale to 2/3 of the original size is arbitrary and I accept that it&#8217;s not a well justified constraint.</p>
<p>So scaling will be added.</p>
<p><em>Bitrate and 2-pass encoding<br />
</em></p>
<p>The bitrate issue, on the other hand, is hairy. Very hairy. I kept thinking about a meaningful way to set the bitrate. The obvious thing is to make it an integer parameter, like say 1000kbps. But what is that? It&#8217;s just a number, a meaningless number. The &#8220;right&#8221; bitrate differs from movie to movie, from codec to codec, perhaps even from encoder to encoder. We are back in Photoshop land.</p>
<p>So I follow the convention of setting a file output size instead. If you say you want this title ripped to a file of 700mb, the bitrate is calculated automatically. This method is flawed, however, because the size we can accommodate for the video depends on how much space the audio requires, and there&#8217;s no way to know this exactly. (Currently the mean audio bitrate is presumed 160kbps.) So the output size tends to come within 10% of the user-specified size.</p>
<p>The thing is, if you start messing with the bitrate you should also consider 2-pass encoding, because you can mess up your video quite badly that way. undvd tries to do &#8220;the right thing&#8221; by picking 2-pass encoding if the calculated bitrate is below the default. But you can always override to 1-pass or 2-pass whatever the case is.</p>
<p>In any event, if you don&#8217;t use these new options then undvd does exactly what it always has.</p>
<p><em>And now for some screenshots</em></p>
<p style="text-align: center"><img src="http://www.matusiak.eu/numerodix/blog/wp-content/uploads/undvd-030-1.png" /></p>
<p style="text-align: center"><img src="http://www.matusiak.eu/numerodix/blog/wp-content/uploads/undvd-030-2.png" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.matusiak.eu/numerodix/blog/index.php/2007/12/11/undvd-looking-ahead-and-back/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>undvd: dvd ripping made easy</title>
		<link>http://www.matusiak.eu/numerodix/blog/index.php/2007/01/30/undvd-dvd-ripping-made-easy/</link>
		<comments>http://www.matusiak.eu/numerodix/blog/index.php/2007/01/30/undvd-dvd-ripping-made-easy/#comments</comments>
		<pubDate>Mon, 29 Jan 2007 22:47:35 +0000</pubDate>
		<dc:creator>numerodix</dc:creator>
				<category><![CDATA[undvd]]></category>

		<guid isPermaLink="false">http://www.matusiak.eu/numerodix/blog/index.php/2007/01/30/undvd-dvd-ripping-made-easy/</guid>
		<description><![CDATA[I always found ripping dvds to be a huge pain, because of how complex the process is. There is a million ways to convert a dvd into avi format, a myriad of settings to play with, options to tune for performance, for size etc. That&#8217;s great if you want to tinker. But it&#8217;s much more [...]]]></description>
			<content:encoded><![CDATA[<p>I always found ripping dvds to be a <a href="http://www.matusiak.eu/numerodix/blog/index.php/2007/01/27/is-2-pass-encoding-really-worth-it/">huge pain</a>, because of how complex the process is. There is a million ways to convert a dvd into avi format, a myriad of settings to play with, options to tune for performance, for size etc. That&#8217;s great if you want to tinker. But it&#8217;s much more difficult to give a straight answer to the question &#8220;how do I rip a dvd?&#8221; without going into all these details. I for one would like a simple way that would work on any dvd everytime.</p>
<p>So that&#8217;s what I set out to do. It took me *a lot* of testing and playing with the settings to find a recipe that both gives great quality and doesn&#8217;t take too long. And still there may be, and probably will be, cases where the results aren&#8217;t great. But for my own use, it works very well. My main goal was to hide as many details as possible from the user, turning the complicated maze that is <code>mencoder</code> into a single button to push. As it turns out, however, it&#8217;s really hard to abstract away everything completely, so even with <code>undvd</code> there is a (hopefully modest) learning curve.</p>
<p><code>undvd</code> is a collection of a couple bash scripts, which I decided to base on <code>lsdvd</code> and <code>mencoder</code>, part of <code>mplayer</code>. In doing so, I wanted to use the disc as little as possible, considering all the problems I&#8217;ve had with reading dvds in the past. I also found out that by extracting the vob, some of the information about audio/subtitles is lost, so I first clone the disc with <code>dd</code>, and then go to work on it. The script starts off by making an image of the disc, whereupon the disc is no longer needed.</p>
<p>First, to see what&#8217;s on the disc, run <code>scandvd.sh</code>.</p>
<p style="text-align: center"><img src="http://www.matusiak.eu/numerodix/blog/wp-content/uploads/scandvd.png" alt="scandvd.png" /></p>
<p>At this point, you have to decide on which title(s) to rip. If you don&#8217;t know what they are, <code>scandvd.sh</code> suggests using mplayer to find out. Once you know what to rip, you run <code>undvd.sh</code> with the chosen options. Just keep in mind that the files will be created in the directory you run <code>undvd.sh</code> from, so make sure you have enough disk space.</p>
<p style="text-align: center"><img src="http://www.matusiak.eu/numerodix/blog/wp-content/uploads/undvd.png" alt="undvd.png" /></p>
<p>What is worth noting here is everything that you <em>don&#8217;t</em> see. <code>mencoder</code> is run in the background, with a host of complicated settings, but you don&#8217;t see the horrifying output. You only see the status of what is happening, the settings you chose, and <code>mencoder</code>&#8217;s estimated time to completion. Sure, the full log is there if you want it, just say the word. But unless something goes wrong, you don&#8217;t need to see it, this will do just fine.</p>
<p style="text-align: center"><img src="http://www.matusiak.eu/numerodix/blog/wp-content/uploads/undvd_result.png" alt="undvd_result.png" /></p>
<p>After ripping is finished, what you&#8217;ll have is the files shown. <code>01.avi</code> and <code>02.avi</code> are the titles. <code>disc.iso</code> is the image of the dvd, which you can use to rip more titles still, or just delete. And then there&#8217;s <code>logs</code> that you won&#8217;t bother even looking at unless something went haywire.</p>
<p>And that is dvd ripping reduced to one line of output for every title. Simple, isn&#8217;t it? <img src='http://www.matusiak.eu/numerodix/blog/wp-includes/images/smilies/smile.png' alt=':)' class='wp-smiley' /> </p>
<p>Get undvd from <a href="http://www.opendesktop.org/content/show.php?content=64833">opendesktop.org</a>.</p>
<p><strong>A technical note</strong></p>
<p>Make sure you have <code>lsdvd</code> and <code>mplayer</code> installed (with support for <code>encoding</code>, <code>x264</code>, <code>xvid</code>, and <code>mp3</code>/<code>mad</code>).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matusiak.eu/numerodix/blog/index.php/2007/01/30/undvd-dvd-ripping-made-easy/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
	</channel>
</rss>

