<?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>JpegServ Weblog&#187; dvd</title>
	<atom:link href="http://jpegserv.com/?feed=rss2&#038;cat=72" rel="self" type="application/rss+xml" />
	<link>http://jpegserv.com</link>
	<description>GPL Images and Code</description>
	<lastBuildDate>Sat, 18 Jul 2009 21:19:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>DVD to streamable mp4 on Ubuntu 9.04</title>
		<link>http://jpegserv.com/?p=215</link>
		<comments>http://jpegserv.com/?p=215#comments</comments>
		<pubDate>Mon, 25 May 2009 15:49:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[GPL]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[dvd]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mp4]]></category>
		<category><![CDATA[stream]]></category>
		<category><![CDATA[ubuntu 9.04]]></category>

		<guid isPermaLink="false">http://jpegserv.com/?p=215</guid>
		<description><![CDATA[j++; if(j == 1 &#124;&#124; j == 2 &#124;&#124; j ==3) document.write(' '); This guide is intended to explain how to encode a DVD to a streamable mp4 codec under Ubuntu with ffmpeg. Get Deps The first thing you need to do is get the dependencies, you can do this with the following command; sudo [...]]]></description>
			<content:encoded><![CDATA[<p>
<!-- Begin Google Adsense code -->
<div style="float: right; width:300px; height:250px; margin:5px 5px 5px 5px; ">
<script type="text/javascript"><!--
	google_ad_client = "pub-4362190332215502";
	/* 300x250, created 11/29/08 */
	google_ad_slot = "2817087570";
	google_ad_width = 300;
	google_ad_height = 250;
	//-->
</script>
<script language="JavaScript">
	j++;
	if(j == 1 || j == 2 || j ==3)
 document.write('<div class="advert"><scr' + 'ipt type="text/javascript" ' + 
 'src="http://pagead2.googlesyndication.com/pagead/show_ads.js"' +'>  </scr' +'ipt></div>');
</script>
</div>
<!-- End Google Adsense code -->
</p>
<p>This guide is intended to explain how to encode a DVD to a streamable mp4 codec under Ubuntu with ffmpeg.</p>
<p><strong>Get Deps</strong></p>
<p>The first thing you need to do is get the dependencies, you can do this with the following command;</p>
<p><code>sudo apt-get install build-essential dvdrip subversion avidemux libfaac-dev libspeex-dev libgsm-dev libgsm1-dev libmp3lame-dev libtheora-dev libvorbis-dev libx264-dev libxvidcore4-dev<br />
</code></p>
<p>Or you can click on this apt link, which will install these dependencies for you;</p>
<p><a href="apt://build-essential,dvdrip,subversion,avidemux,libfaac-dev,libspeex-dev,libgsm1-dev,libmp3lame-dev,libtheora-dev,libvorbis-dev,libx264-dev,libxvidcore4-dev">Install Dependencies</a></p>
<p><strong>Set up Programs</strong></p>
<p><strong><em>ffmpeg</em></strong></p>
<p>This part will require the terminal, to get to the terminal;</p>
<p><code>Applications > Accessories > Terminal<br />
</code></p>
<p>Then issue the following commands;</p>
<p><code>cd Documents ; mkdir src ; cd src<br />
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg<br />
cd ffmpeg<br />
</code></p>
<p>This will download a snapshot of ffmpeg, in the same terminal do the following to configure and install ffmpeg;</p>
<p><code>./configure --extra-cflags=-fno-common --enable-memalign-hack --enable-pthreads --enable-libmp3lame --enable-libxvid --enable-libvorbis --enable-libtheora --enable-libspeex --enable-libfaac --enable-libgsm --enable-libx264 --enable-gpl --enable-nonfree<br />
make<br />
make install<br />
cd tools<br />
gcc qt-faststart.c -o qt-faststart<br />
sudo cp qt-faststart /usr/local/bin/<br />
</code></p>
<p><strong><em>libdvdcss</em></strong></p>
<p>We need to set up protected DVD decryption Ubuntu makes this pretty easy, do the following commands to set it up;</p>
<p><code>cd /usr/share/doc/libdvdread4/<br />
sudo sh install-css.sh<br />
</code></p>
<p><strong>Ripping the DVD</strong></p>
<p>Start dvdrip;</p>
<p><code>Applications > Sound  &#038; Video > dvd::rip<br />
</code><br />
or &#8220;dvdrip&#8221; from cli.</p>
<p>When You first start dvdrip it will ask you what Directories to use for the projects, It&#8217;s up to you which directory to use. Once you have done that you will need to put a DVD into your DVD drive and start a new project. To start a new project go to &#8220;File > New Project&#8221; in dvdrip. You will need to enter a name for the project;</p>
<p><center><br />
<div id="attachment_231" class="wp-caption aligncenter" style="width: 310px"><a href="http://jpegserv.com/wp-content/uploads/2009/05/dvdrip-project-name.png"><img src="http://jpegserv.com/wp-content/uploads/2009/05/dvdrip-project-name-300x211.png" alt="DVD Rip select project name" title="dvdrip-project-name" width="300" height="211" class="size-medium wp-image-231" /></a><p class="wp-caption-text">DVD Rip select project name</p></div><br />
</center></p>
<p>When you have selected a name for the project hit the &#8220;Create Project&#8221; button and select ok to save the .rip file, then select &#8220;Rip Title&#8221; and &#8220;Read DVD table of contents&#8221;;</p>
<p><center><br />
<div id="attachment_234" class="wp-caption aligncenter" style="width: 310px"><a href="http://jpegserv.com/wp-content/uploads/2009/05/dvdrip-read-dvd.png"><img src="http://jpegserv.com/wp-content/uploads/2009/05/dvdrip-read-dvd-300x211.png" alt="DVD Rip Read table of contents" title="dvdrip-read-dvd" width="300" height="211" class="size-medium wp-image-234" /></a><p class="wp-caption-text">DVD Rip Read table of contents</p></div><br />
</center></p>
<p>When you have done that you have to select the title that the film is on, which is almost always the one with the most frames;</p>
<p><center><br />
<div id="attachment_236" class="wp-caption aligncenter" style="width: 310px"><a href="http://jpegserv.com/wp-content/uploads/2009/05/dvdrip-rip-selected.png"><img src="http://jpegserv.com/wp-content/uploads/2009/05/dvdrip-rip-selected-300x211.png" alt="DVD Rip selected tracks" title="dvdrip-rip-selected" width="300" height="211" class="size-medium wp-image-236" /></a><p class="wp-caption-text">DVD Rip selected tracks</p></div><br />
</center></p>
<p>To rip the dvd select &#8220;Rip selected title(s)/Chapter(s)&#8221; button, highlighted in blue on the above picture. dvd::rip will begin to rip the dvd, on my computer it takes about 10 minutes to rip a title.</p>
<p><strong>Merge Vob files</strong></p>
<p>At this point merge the vob files with the cat command;</p>
<p><code>cat title-001.vob title-002.vob title-003.vob title-004.vob >> output.vob<br />
</code></p>
<p><center><br />
<div id="attachment_239" class="wp-caption aligncenter" style="width: 310px"><a href="http://jpegserv.com/wp-content/uploads/2009/05/vob-merge.png"><img src="http://jpegserv.com/wp-content/uploads/2009/05/vob-merge-300x294.png" alt="Linux: merge vob files into a single file" title="vob-merge" width="300" height="294" class="size-medium wp-image-239" /></a><p class="wp-caption-text">Linux: merge vob files into a single file</p></div><br />
(filenames covered up because despite having paid for the DVDs and the act that I&#8217;m only doing this for personal use, I don&#8217;t want to take any chances)<br />
</center></p>
<p><strong>Cut and Crop Film</strong></p>
<p>The next step is to use avidemux to cut, crop and transcode the video to a format ready for conversion to mp4. Start avidemux with the following command;</p>
<p><code>avidemux<br />
</code></p>
<p>open the merged vob file that you created in the previous step and when asked &#8220;This looks like mpeg<br />
 Do you want to index it?&#8221; select yes;</p>
<p><center><br />
<div id="attachment_244" class="wp-caption aligncenter" style="width: 310px"><a href="http://jpegserv.com/wp-content/uploads/2009/05/avidemux-open-vob.png"><img src="http://jpegserv.com/wp-content/uploads/2009/05/avidemux-open-vob-300x199.png" alt="avidemux: index vob file" title="avidemux-open-vob" width="300" height="199" class="size-medium wp-image-244" /></a><p class="wp-caption-text">avidemux: index vob file</p></div><br />
</center></p>
<p>I takes a little while for avidemux to generate the index;</p>
<p><center><br />
<div id="attachment_245" class="wp-caption aligncenter" style="width: 310px"><a href="http://jpegserv.com/wp-content/uploads/2009/05/avidemux-generating-index.png"><img src="http://jpegserv.com/wp-content/uploads/2009/05/avidemux-generating-index-300x199.png" alt="Avidemux: Generaing a vob file index" title="avidemux-generating-index" width="300" height="199" class="size-medium wp-image-245" /></a><p class="wp-caption-text">Avidemux: Generaing a vob file index</p></div><br />
</center></p>
<p><strong><em>Select Output Formats</em></strong></p>
<p>The first thing you need do in avidemux is select the output formats that you will use, for this I choose;</p>
<p>VIdeo: MPEG-4 ASP (lavc)<br />
Audio: MP3 (LAME)<br />
Container: AVI</p>
<p><center><br />
<div id="attachment_247" class="wp-caption aligncenter" style="width: 310px"><a href="http://jpegserv.com/wp-content/uploads/2009/05/avidemux-main.png"><img src="http://jpegserv.com/wp-content/uploads/2009/05/avidemux-main-300x250.png" alt="Video Format selection" title="avidemux-main" width="300" height="250" class="size-medium wp-image-247" /></a><p class="wp-caption-text">Video Format selection</p></div><br />
</center></p>
<p><strong><em>Select filters</em></strong></p>
<p>There are a couple of filters that you might want to take advantage of, for the video I use the crop filter, to do this select filter under the video section of the left hand side of avidemux and double click on crop;</p>
<p><center><br />
<div id="attachment_250" class="wp-caption aligncenter" style="width: 310px"><a href="http://jpegserv.com/wp-content/uploads/2009/05/avidemux-transform.png"><img src="http://jpegserv.com/wp-content/uploads/2009/05/avidemux-transform-300x200.png" alt="Double click crop" title="avidemux-transform" width="300" height="200" class="size-medium wp-image-250" /></a><p class="wp-caption-text">Double click crop</p></div><br />
</center></p>
<p>This will bring up a window where you can set the crop dimensions, move the frame selector (highlighted in red) to a point in the movie where the border is well defined and press the Auto crop button (highlighted in green);</p>
<p><center><br />
<div id="attachment_251" class="wp-caption alignnone" style="width: 281px"><a href="http://jpegserv.com/wp-content/uploads/2009/05/avidemux-crop-window.png"><img src="http://jpegserv.com/wp-content/uploads/2009/05/avidemux-crop-window-271x300.png" alt="Avidemux crop settings " title="avidemux-crop-window" width="271" height="300" class="size-medium wp-image-251" /></a><p class="wp-caption-text">Avidemux crop settings </p></div><br />
</center></p>
<p>You might need to adjust the settings slightly, you should end up with something like this;</p>
<p><center><br />
<div id="attachment_253" class="wp-caption aligncenter" style="width: 281px"><a href="http://jpegserv.com/wp-content/uploads/2009/05/avidemux-crop-apply.png"><img src="http://jpegserv.com/wp-content/uploads/2009/05/avidemux-crop-apply-271x300.png" alt="Avidemux crop example" title="avidemux-crop-apply" width="271" height="300" class="size-medium wp-image-253" /></a><p class="wp-caption-text">Avidemux crop example</p></div><br />
</center></p>
<p>Click apply and then ok to accept these settings, then close the video filter window. The only filter that needs to be applied to the audio is the mixer setting, it needs to be set to stereo;</p>
<p><code>Audio > filters > mixer > stereo<br />
</code></p>
<p><center><br />
<div id="attachment_255" class="wp-caption aligncenter" style="width: 295px"><a href="http://jpegserv.com/wp-content/uploads/2009/05/mixer-stereo.png"><img src="http://jpegserv.com/wp-content/uploads/2009/05/mixer-stereo-285x300.png" alt="Avidemux Stereo" title="mixer-stereo" width="285" height="300" class="size-medium wp-image-255" /></a><p class="wp-caption-text">Avidemux Stereo</p></div><br />
</center></p>
<p>Click ok and you will done with filters.</p>
<p><strong><em>Cut video</em></strong></p>
<p>You can set the start and the end point of the video using the a and b buttons you can use this to cut out the titles at the start of the film and the credits at the end;</p>
<p><center><br />
<div id="attachment_259" class="wp-caption aligncenter" style="width: 310px"><a href="http://jpegserv.com/wp-content/uploads/2009/05/avidemux-a.png"><img src="http://jpegserv.com/wp-content/uploads/2009/05/avidemux-a-300x250.png" alt="Set where you want he video to start" title="avidemux-a" width="300" height="250" class="size-medium wp-image-259" /></a><p class="wp-caption-text">Set where you want he video to start</p></div><br />
</center></p>
<p>Move the frame selector (Red) to where you want the video to start (you can fine tune with the arrows to the left of the &#8220;a&#8221; button) and press the &#8220;a&#8221; button (Green), the frame number will be shown in the bottom right of the window (Blue). Do the same for where you want the movie to end, substituting the &#8220;a&#8221;  button for the &#8220;b&#8221; button.</p>
<p><strong><em>Start encoding</em></strong></p>
<p>Now that everything is set up, press the save button, give the file a name (you need to include the extension as avidemux doesn&#8217;t do this automatically) and press ok. Avidemux should begin encoding;</p>
<p><center><br />
<div id="attachment_261" class="wp-caption aligncenter" style="width: 310px"><a href="http://jpegserv.com/wp-content/uploads/2009/05/encoding.png"><img src="http://jpegserv.com/wp-content/uploads/2009/05/encoding-300x220.png" alt="Avidemux Encoding" title="encoding" width="300" height="220" class="size-medium wp-image-261" /></a><p class="wp-caption-text">Avidemux Encoding</p></div><br />
</center></p>
<p><strong>Encode to mp4</strong></p>
<p>The final step is to issue two commands that will convert the  file that avidemux created, into a stream-able mp4 file, the first command does the actual conversion;</p>
<p><code>/usr/local/bin/ffmpeg -i "input.avi" -vcodec libx264 -flags +loop -cmp +chroma -deblockalpha 0 -deblockbeta 0 -b 1250k -maxrate 1500k -bufsize 4M -bt 600k -refs 1 -bf 3 -coder 1 -me_method umh -me_range 16 -subq 7 -partitions +parti4x4+parti8x8+partp8x8+partb8x8 -g 250 -keyint_min 25 -level 30 -qmin 10 -qmax 51 -qcomp 0.6 -trellis 2 -sc_threshold 40 -i_qfactor 0.71 -acodec libfaac -ab 128k -ar 48000 -ac 2 "output.mp4"<br />
</code>Where input.avi is the video created by Avidemux.</p>
<p>If you have a dual or quad core processor, it&#8217;s worth adding the &#8220;-threads&#8221; switch to that, so that you can get the most from your processor;<br />
<code>/usr/local/bin/ffmpeg -i "input.avi" -threads 4 -vcodec libx264 -flags +loop -cmp +chroma -deblockalpha 0 -deblockbeta 0 -b 1250k -maxrate 1500k -bufsize 4M -bt 600k -refs 1 -bf 3 -coder 1 -me_method umh -me_range 16 -subq 7 -partitions +parti4x4+parti8x8+partp8x8+partb8x8 -g 250 -keyint_min 25 -level 30 -qmin 10 -qmax 51 -qcomp 0.6 -trellis 2 -sc_threshold 40 -i_qfactor 0.71 -acodec libfaac -ab 128k -ar 48000 -ac 2 "output.mp4"<br />
</code>Example for a quad core processor.</p>
<p>and this command makes the file stream-able;</p>
<p><code>qt-faststart "output.mp4" "faststart-output.mp4"<br />
</code>Where &#8220;faststart-output.mp4&#8243; is the streamable mp4 file.</p>
<p><strong>comments</strong></p>
<p>If you have any suggestions,questions or comments about how I could improve is article please feel free to leave a comment. Thanks</p>
]]></content:encoded>
			<wfw:commentRss>http://jpegserv.com/?feed=rss2&amp;p=215</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
