<?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>SavvyAdmin.com &#187; mplayer</title>
	<atom:link href="http://savvyadmin.com/tag/mplayer/feed/" rel="self" type="application/rss+xml" />
	<link>http://savvyadmin.com</link>
	<description>For savvy admins everywhere...</description>
	<lastBuildDate>Fri, 21 Jan 2011 17:53:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>DVD to XviD Encoding with Mencoder</title>
		<link>http://savvyadmin.com/dvd-to-xvid-encoding-with-mencoder/</link>
		<comments>http://savvyadmin.com/dvd-to-xvid-encoding-with-mencoder/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 01:44:55 +0000</pubDate>
		<dc:creator>gmendoza</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[DVD]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[lsdvd]]></category>
		<category><![CDATA[mencoder]]></category>
		<category><![CDATA[mplayer]]></category>
		<category><![CDATA[Multimedia]]></category>
		<category><![CDATA[Xvid]]></category>

		<guid isPermaLink="false">http://savvyadmin.com/?p=568</guid>
		<description><![CDATA[If you would like to copy a DVD to an XviD video file using Linux, doing so from the command line offers a number of flexibility benefits over many graphical tools. Two fantastic tools for the job are lsdvd and mencoder. I like lsdvd because it provides a great deal of information in an easy [...]
Related posts:<ol>
<li><a href='http://savvyadmin.com/using-mencoder-profiles/' rel='bookmark' title='Using Mencoder Profiles'>Using Mencoder Profiles</a></li>
<li><a href='http://savvyadmin.com/convert-mkv-to-xvid-with-mencoder/' rel='bookmark' title='Convert MKV to Xvid with Mencoder'>Convert MKV to Xvid with Mencoder</a></li>
<li><a href='http://savvyadmin.com/convert-3gp-videos-to-xvid-avi/' rel='bookmark' title='Convert 3gp Videos to XviD AVI'>Convert 3gp Videos to XviD AVI</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>If you would like to copy a DVD to an XviD video file using Linux, doing so from the command line offers a number of flexibility benefits over many graphical tools.  Two fantastic tools for the job are <code>lsdvd</code> and <code>mencoder</code>.  I like <code>lsdvd</code> because it provides a great deal of information in an easy to read format, and <code>mencoder</code> is just a phenomenal tool for multimedia encoding.</p>
<p>There are some pre-requisite applications you need in order to follow along.  Be sure to install <code>mplayer</code>, <code>mencoder</code>, <code>lsdvd</code>, <code>lame</code>, and if your DVD&#8217;s are encrypted, the <code>libdvdcss2</code> libraries.  If using Ubuntu, Debian, etc, then all are available in the repositories, except <code>libdvdcss2</code> which is available in the <a href="http://www.medibuntu.org/" target="_blank">Medibuntu repositories</a>.</p>
<p><strong>Quick XviD Encoding Examples (For the Impatient)</strong></p>
<p>In the following examples, we&#8217;ll use <code>mencoder</code> with the most basic of options, allowing <code>mencoder</code> to decide which video and audio streams to use.  Mencoder&#8217;s choice may not be what you want, and the audio will also be converted to a high quality VBR stereo MP3.  Adjust any settings as you see fit.</p>
<p><strong>Single-Pass Encoding</strong></p>
<p>Fixed Quantizer Value of 4 (Good quality, decent file size)</p>
<blockquote><p><code><strong>mencoder dvd:// -oac mp3lame -lameopts q=0:aq=0 \<br />
-ovc xvid -xvidencopts fixed_quant=4:autoaspect -o video.avi</strong></code></p></blockquote>
<p>Fixed Quantizer Value of 2 (High quality, larger file size)</p>
<blockquote><p><code><strong>mencoder dvd:// -oac mp3lame -lameopts q=0:aq=0 \<br />
-ovc xvid -xvidencopts fixed_quant=2:autoaspect -o video.avi</strong></code></p></blockquote>
<p><strong>Two Pass Encoding </strong></p>
<p>Pass 1: (no need for audio or quality settings such as bitrate)</p>
<blockquote><p><code><strong>mencoder dvd:// -nosound -passlogfile pass1.log \<br />
-ovc xvid -xvidencopts pass=1:turbo:autoaspect -o /dev/null</strong></code></p></blockquote>
<p>Pass 2 Option 1: (VBR ~ 1500 kbps)</p>
<blockquote><p><code><strong>mencoder dvd:// -oac mp3lame -lameopts q=0:aq=0 -passlogfile pass1.log \<br />
-ovc xvid -xvidencopts pass=2:autoaspect:bitrate=1500 -o video.avi</strong></code></p></blockquote>
<p>Pass 2 Option 2: (VBR ~ Restrict final video size to 1.5 Gb)</p>
<blockquote><p><code><strong>mencoder dvd:// -oac mp3lame -lameopts q=0:aq=0 -passlogfile pass1.log \<br />
-ovc xvid -xvidencopts pass=2:autoaspect:bitrate=-1500000 -o video.avi</strong></code></p></blockquote>
<p><strong>Basic Source Selection Examples</strong></p>
<p>If you are copying a DVD directly from a physical disc as the examples throughout this post will assume, the following two examples will work.  The first automatically selects title 1, and the second specifies title 2.</p>
<blockquote><p><code><strong>mencoder dvd:// (other options)<br />
mencoder dvd://2 (other options)</strong></code></p></blockquote>
<p>If you&#8217;re encoding a DVD from an ISO or similar image file, or have the contents of a DVD extracted to directory, use the <code>-dvd-device</code> option as shown below.</p>
<blockquote><p><code><strong>mencoder dvd:// -dvd-device video.iso (other options)<br />
mencoder dvd:// -dvd-device /path/to/dvd_directory/ (other options)</strong></code></p></blockquote>
<p><strong>Basic Audio Examples</strong></p>
<p>To encode the selected audio stream to a high quality VBR stereo MP3 format.</p>
<blockquote><p><code><strong>mencoder dvd:// -oac mp3lame -lameopts q=0:aq=0 (other options)</strong></code></p></blockquote>
<p>If the source audio stream is encoded as AC3 or DTS 5.1 (6 Channels), you can simply copy the stream, but remember to specify 6 channels.  The default is 2.</p>
<blockquote><p><code><strong>mencoder dvd:// -oac copy -channels 6 (other options)</strong></code></p></blockquote>
<p>To exclude all sound, which is useful for the first pass of a two-pass job, or if you prefer to multiplex the audio later, use the <code>-nosound</code> option.</p>
<blockquote><p><code><strong>mencoder dvd:// -nosound (other options)</strong></code></p></blockquote>
<p><strong>Gathering Source Video Information for Informed Encoding Decisions</strong></p>
<p>First you should identify which DVD title tracks are available, so you can determine which one you want to copy.  Most DVDs will place the movie as the first track, but you may not always be that lucky.  You can use lsdvd to list the number of titles, chapters, and audio tracks on your DVD.</p>
<blockquote><p><code><strong>lsdvd /dev/dvd</strong><br />
Disc Title: DVD_TITLE<br />
Title: 01, Length: 01:26:08.200 Chapters: 13, Cells: 13, Audio streams: 02, Subpictures: 01<br />
Title: 02, Length: 00:02:01.120 Chapters: 01, Cells: 01, Audio streams: 02, Subpictures: 01<br />
Title: 03, Length: 00:02:26.120 Chapters: 01, Cells: 01, Audio streams: 02, Subpictures: 01<br />
Longest track: 01</code></p></blockquote>
<p>In the example above, we found that Title 01 is the longest at 1 hour 26 minutes, has 13 chapters and 2 audio streams.</p>
<p>Use <code>lsdvd</code> again to gather additional information about video properties of this specific title.</p>
<blockquote><p><code><strong>lsdvd -v -t 1 /dev/dvd</strong><br />
Disc Title: DVD_TITLE<br />
Title: 01, Length: 01:26:08.200 Chapters: 13, Cells: 13, Audio streams: 02, Subpictures: 01<br />
	VTS: 01, TTN: 01, FPS: 25.00, Format: PAL, Aspect ratio: 4/3, Width: 720, Height: 576, DF: ?</code></p></blockquote>
<p>From the output above, we see that this video is in the PAL format at 25.00 frames per second and an aspect ratio of 4/3.  Use mplayer to play this title and verify it&#8217;s the one you want.</p>
<blockquote><p><code><strong>mplayer dvd://1</strong></code></p></blockquote>
<p><strong>Gathering Source Audio Information</strong></p>
<p>Use lsdvd to give you more detail on the available audio streams for the title you&#8217;re working on.</p>
<blockquote><p><code><strong>lsdvd -a -t 1 /dev/dvd</strong><br />
Disc Title: DVD_TITLE<br />
Title: 01, Length: 01:26:08.200 Chapters: 13, Cells: 13, Audio streams: 02, Subpictures: 01<br />
	Audio: 1, Language: nl - Nederlands, Format: ac3, Frequency: 48000, Quantization: drc, Channels: 2, AP: 0, Content: Undefined, Stream id: 0x80<br />
	Audio: 2, Language: en - English, Format: ac3, Frequency: 48000, Quantization: drc, Channels: 2, AP: 0, Content: Undefined, Stream id: 0x81</code></p></blockquote>
<p>The output above shows that there are two audio streams, both AC3 Dolby Digital, however only the second one is in English.  Mencoder and mplayer allow you to specify your desired audio stream by language as shown in the following example.</p>
<blockquote><p><code><strong>mencoder dvd://1 -alang eng <em>(other options)</em></strong></code></p></blockquote>
<p>If your source has multiple English streams, you can specify which particular audio ID (aid) you want.  Mplayer can be used to display all available audio identifiers of a DVD.  The following command is a little long but it should serve you well.</p>
<blockquote><p><code><strong>mplayer dvd://1  -identify -frames 0 -vo null 2>&#038;1 | grep aid</strong><br />
audio stream: 0 format: ac3 (stereo) language: nl aid: 128.<br />
audio stream: 1 format: ac3 (stereo) language: en aid: 129.</code></p></blockquote>
<p>From the output above, the English AC3 audio stream we want is identified by aid 129.  It can be specified when using mplayer and mencoder as shown below.</p>
<blockquote><p><code><strong>mencoder dvd://1 -aid 129 <em>(other options)</em></strong></code></p></blockquote>
<p><strong>Advanced Single-Pass XviD Encoding</strong></p>
<p>As mentioned before, you can encode your video using a single-pass fixed quantizer mode.  It may not be as efficient in size and quality as opposed to a two-pass method, but it can save some time and complexity.  Here&#8217;s the more advanced encoding options I tend to use for virtually all of my XviD encoding jobs, coupled with the information we gathered from above.  A <code>fixed_quant</code> value between 2 and 4 work very well.  The lower the number the higher the quality and larger the resulting file size.</p>
<blockquote><p><code><strong>mencoder dvd://1 -alang eng -oac mp3lame -lameopts q=0:aq=0 \<br />
-ovc xvid -xvidencopts fixed_quant=4:autoaspect:max_key_interval=25:\<br />
vhq=2:bvhq=1:trellis:hq_ac:chroma_me:chroma_opt:quant_type=mpeg \<br />
 -o video.avi</strong></code></p></blockquote>
<p>I added a number of quality settings as discussed both in the <code>mencoder</code> man page and this <a href="http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-xvid.html" target="_blank">useful link here</a>.  </p>
<p>One option that seems to lack a lot of documentation is the <code>max_key_interval</code> setting.  It influences the seekability of the encoded video.  By default, the <code>max_key_interval</code> is set to a value of 250, which adds an I-frame at a maximum interval of 250 frames.  This equates to approximately every 10 seconds depending on the frame rate of your source video.  I like to set the value to 25 which is pretty low and results in a slightly larger file, but provides a seek accuracy of about 1 second.  That&#8217;s just my preference, so feel free to change it as you wish.</p>
<p><strong>Advanced Two-Pass XviD Encoding</strong></p>
<p>Using the same advanced XviD encoding options as above, here&#8217;s what a two pass encoding job would look like.</p>
<blockquote><p><code><strong>mencoder dvd:// -nosound -passlogfile pass1.log \<br />
-ovc xvid -xvidencopts pass=1:turbo:autoaspect:vhq=0:max_key_interval=25 \<br />
-o /dev/null<br />
</strong></code></p>
<p><code><strong>mencoder dvd:// -oac mp3lame -lameopts q=0:aq=0 -passlogfile pass1.log \<br />
-ovc xvid -xvidencopts pass=2:autoaspect:max_key_interval=25:bitrate=1500:\<br />
vhq=2:bvhq=1:trellis:hq_ac:chroma_me:chroma_opt:quant_type=mpeg -o video.avi</strong></code></p></blockquote>
<p><strong>Cropping Black Borders</strong></p>
<p>If your video source has black borders, you can crop them out to reduce the overall size of your video.  For example, you video may resemble the following diagram.</p>
<div id="attachment_633" class="wp-caption aligncenter" style="width: 552px"><a href="http://savvyadmin.com/wp-content/uploads/2010/02/movie-uncropped.png"><img src="http://savvyadmin.com/wp-content/uploads/2010/02/movie-uncropped.png" alt="" title="movie-uncropped" width="542" height="361" class="size-full wp-image-633" /></a><p class="wp-caption-text">Video with black borders</p></div>
<p>These borders can be cropped with a video filter <code>-vf crop=w:h:x:y</code> where w, h, x and y are the width, height, x and y coordinates.  To help determine which crop values are appropriate, first play your video with <code>mplayer</code> using the <code>-vf cropdetect</code> option, and seek through the movie to bright points of the movie where the black borders are clearly visible.  Dark opening scenes may give you inaccurate edge readings.</p>
<blockquote><p><code><strong>mencoder dvd:// -vf cropdetect</strong><br />
(snipped for brevity)<br />
[CROP] Crop area: X: 6..711  Y: 0..575  (-vf crop=704:576:8:0).0 0<br />
[CROP] Crop area: X: 6..711  Y: 0..575  (-vf crop=704:576:8:0).0 0<br />
[CROP] Crop area: X: 6..711  Y: 0..575  (-vf crop=704:576:8:0).0 0<br />
[CROP] Crop area: X: 6..711  Y: 0..575  (-vf crop=704:576:8:0).0 0<br />
[CROP] Crop area: X: 6..711  Y: 0..575  (-vf crop=704:576:8:0).0 0<br />
</code></p></blockquote>
<p>Copy the values that <code>mplayer</code> displays in the background terminal as the example above shows and use them like the following.</p>
<blockquote><p><code><strong>mencoder dvd:// -vf crop=704:576:8:0 (other options)</strong></code></p></blockquote>
<p><strong>Conclusion</strong></p>
<p>I hope this post provides you with detail that helps you with your DVD encoding endeavors.  Please feel free to post your comments, questions and tips.  If needed, I&#8217;ll adjust the post to include your valuable input!</p>
<p>Related posts:<ol>
<li><a href='http://savvyadmin.com/using-mencoder-profiles/' rel='bookmark' title='Using Mencoder Profiles'>Using Mencoder Profiles</a></li>
<li><a href='http://savvyadmin.com/convert-mkv-to-xvid-with-mencoder/' rel='bookmark' title='Convert MKV to Xvid with Mencoder'>Convert MKV to Xvid with Mencoder</a></li>
<li><a href='http://savvyadmin.com/convert-3gp-videos-to-xvid-avi/' rel='bookmark' title='Convert 3gp Videos to XviD AVI'>Convert 3gp Videos to XviD AVI</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://savvyadmin.com/dvd-to-xvid-encoding-with-mencoder/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extract Audio from Video Files to WAV using Mplayer</title>
		<link>http://savvyadmin.com/extract-audio-from-video-files-to-wav-using-mplayer/</link>
		<comments>http://savvyadmin.com/extract-audio-from-video-files-to-wav-using-mplayer/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 20:24:09 +0000</pubDate>
		<dc:creator>gmendoza</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[Audio]]></category>
		<category><![CDATA[mplayer]]></category>
		<category><![CDATA[Multimedia]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://www.savvyadmin.com/?p=424</guid>
		<description><![CDATA[You can extract the audio from a video file using mplayer and save the result to a WAV file, which you can then manipulate to your hearts content. For example, you may want to compress the audio to a stereo MP3 or OGG. The following command instruct that the audio output (-ao) should be redirected [...]
Related posts:<ol>
<li><a href='http://savvyadmin.com/extract-audio-from-video-files-to-wav-using-ffmpeg/' rel='bookmark' title='Extract Audio from Video Files to WAV using FFmpeg'>Extract Audio from Video Files to WAV using FFmpeg</a></li>
<li><a href='http://savvyadmin.com/add-stereo-audio-tracks-to-mkv-files/' rel='bookmark' title='Add Stereo Audio Tracks to MKV Files'>Add Stereo Audio Tracks to MKV Files</a></li>
<li><a href='http://savvyadmin.com/quickly-identify-video-file-attributes/' rel='bookmark' title='Quickly Identify Video File Attributes'>Quickly Identify Video File Attributes</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>You can extract the audio from a video file using mplayer and save the result to a WAV file, which you can then manipulate to your hearts content.  For example, you may want to compress the audio to a stereo MP3 or OGG.</p>
<p>The following command instruct that the audio output (-ao) should be redirected out to a PCM WAV file as fast as possible, while suppressing all video output.</p>
<blockquote><p><code><strong>mplayer -ao pcm:fast:file=audio.wav -vo null -vc null video.avi</strong></code></p></blockquote>
<p>Convert the resulting WAV to MP3.  The following is a great way to convert your WAV files to a high quality Variable Bitrate MP3.  See the man page for a decent tutorial on the available options.</p>
<blockquote><p><code><strong>lame -V0 -q0 --vbr-new audio.wav audio.mp3</strong></code></p></blockquote>
<p>Related posts:<ol>
<li><a href='http://savvyadmin.com/extract-audio-from-video-files-to-wav-using-ffmpeg/' rel='bookmark' title='Extract Audio from Video Files to WAV using FFmpeg'>Extract Audio from Video Files to WAV using FFmpeg</a></li>
<li><a href='http://savvyadmin.com/add-stereo-audio-tracks-to-mkv-files/' rel='bookmark' title='Add Stereo Audio Tracks to MKV Files'>Add Stereo Audio Tracks to MKV Files</a></li>
<li><a href='http://savvyadmin.com/quickly-identify-video-file-attributes/' rel='bookmark' title='Quickly Identify Video File Attributes'>Quickly Identify Video File Attributes</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://savvyadmin.com/extract-audio-from-video-files-to-wav-using-mplayer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Add Stereo Audio Tracks to MKV Files</title>
		<link>http://savvyadmin.com/add-stereo-audio-tracks-to-mkv-files/</link>
		<comments>http://savvyadmin.com/add-stereo-audio-tracks-to-mkv-files/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 22:33:50 +0000</pubDate>
		<dc:creator>gmendoza</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[AC3]]></category>
		<category><![CDATA[Audio]]></category>
		<category><![CDATA[Dolby Digital]]></category>
		<category><![CDATA[FFMpeg]]></category>
		<category><![CDATA[LAME]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Matroska]]></category>
		<category><![CDATA[MKV]]></category>
		<category><![CDATA[mplayer]]></category>
		<category><![CDATA[Multimedia]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://www.savvyadmin.com/?p=403</guid>
		<description><![CDATA[If you have Matroska Video (MKV) files encoded with AC3 Dolby Digital 5.1 or DTS audio tracks, you may want to simply extract the audio, convert it to a 2-channel stereo format like WAV, MP3 OGG, etc, and then add it back into the MKV as a separate audio track. This is useful when your [...]
Related posts:<ol>
<li><a href='http://savvyadmin.com/extract-audio-from-video-files-to-wav-using-ffmpeg/' rel='bookmark' title='Extract Audio from Video Files to WAV using FFmpeg'>Extract Audio from Video Files to WAV using FFmpeg</a></li>
<li><a href='http://savvyadmin.com/extract-ac3-dolby-digital-with-ffmpeg/' rel='bookmark' title='Extract AC3 Dolby Digital with FFMpeg'>Extract AC3 Dolby Digital with FFMpeg</a></li>
<li><a href='http://savvyadmin.com/adding-chapters-to-videos-using-mkv-containers/' rel='bookmark' title='Adding Chapters to Videos Using MKV Containers'>Adding Chapters to Videos Using MKV Containers</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>If you have <a href="http://www.matroska.org" target="_blank">Matroska Video (MKV) files</a> encoded with AC3 Dolby Digital 5.1 or DTS audio tracks, you may want to simply extract the audio, convert it to a 2-channel stereo format like WAV, MP3 OGG, etc, and then add it back into the MKV as a separate audio track.  This is useful when your media player (e.g. <a href="http://www.westerndigital.com/en/products/products.asp?driveid=572">Western Digital Media Player WDAVN00</a>) will not downscale the audio from a digital format like AC3 or DTS to stereo when you don&#8217;t have a receiver or TV with a built in Dolby Digital decoder.  Now you&#8217;ll have the choice of either audio format depending on your technical requirements.</p>
<p>The great thing about the <a href="http://www.matroska.org/">Matroska multimedia container</a> is that you can easily manipulate these files without having to re-encode, saving lots of time.  I&#8217;ll be using <strong><em>mkvextract</em></strong> to extract the AC3 audio, <strong><em>ffmpeg</em></strong> to convert ac3 to mp3, and finally <strong><em>mkvmerge</em></strong> to add and remux the new audio track to the MKV container.  All of these are available to a number of platforms, but in my examples, I&#8217;m using Linux.  Check out the <a href="http://www.bunkus.org/videotools/mkvtoolnix/" target="_blank">MKVToolnix</a> and <a href="http://ffmpeg.org/" target="_blank">FFMpeg</a> websites for more info on the software.</p>
<p>If using Ubuntu Linux, install the relevant <strong><em>mkvtoolnix</em></strong>,  <em><strong>mkvtoolnix-gui</strong> </em>and <strong><em>ffmpeg</em></strong> packages.</p>
<blockquote><p><code><strong>sudo apt-get install mkvtoolnix mkvtoolnix-gui ffmpeg libavcodec-unstripped-52</strong></code></p></blockquote>
<p>To view the existing tracks of the MKV, use the <em>mkvmerge -i</em> option.  In the following example, you see my &#8220;<strong>Cool.Video.mkv</strong>&#8221; file has an MPEG4 video in track 1, an AC3 Dolby Digital audio file in track 2, and subtitles in track 3.</p>
<blockquote><p><code><strong>mkvmerge -i Cool.Movie.mkv </strong><br />
File 'Cool.Movie.mkv': container: Matroska<br />
Track ID 1: video (V_MPEG4/ISO/AVC)<br />
Track ID 2: audio (A_AC3)<br />
Track ID 3: subtitles (S_TEXT/UTF8)</code></p></blockquote>
<p>Using <em>mkvextract</em>, extract the AC3 Dolby Digital audio from track 2, saving it to a file called audio.ac3.</p>
<blockquote><p><code><strong>mkvextract tracks Cool.Movie.mkv 2:audio.ac3</strong><br />
Extracting track 2 with the CodecID 'A_AC3' to the file 'audio.ac3'. Container format: Dolby Digital (AC3)<br />
Progress: 100%</code></p>
<p><code><strong>ls -lh audio.ac3</strong><br />
-rw-r--r-- 1 gmendoza gmendoza 432M 2009-09-26 11:58 audio.ac3</code></p></blockquote>
<p>Convert the 6-channel ac3 file to a 2-channel stereo MP3 using <em>ffmpeg</em>.  If you prefer a higher audio bitrate, adjust the -ab value as desired.  e.g. 256, 384, etc, and adjust the audio rate to your liking as well.</p>
<blockquote><p><code><strong>ffmpeg -i audio.ac3 -acodec libmp3lame -ab 160k -ac 2 audio.mp3</strong><br />
[output omitted for brevity]</code></p>
<p><code><strong>ls -lh audio.*</strong><br />
-rw-r--r-- 1 gmendoza gmendoza 432M 2009-09-26 11:58 audio.ac3<br />
-rw-r--r-- 1 gmendoza gmendoza  87M 2009-09-26 12:08 audio.mp3</code></p></blockquote>
<p>To simplify things, you could actually skip the digital format extraction process by running ffmpeg against the MKV file directly.</p>
<blockquote><p><code><strong>ffmpeg -i Cool.Movie.mkv -acodec libmp3lame -ab 160k -ac 2 audio.mp3</strong></code></p></blockquote>
<p>If you prefer encoding with more advanced options, you could extract the audio as a 2-channel WAV file instead, and then process it with LAME, Oggenc, or some other encoder of your choosing.  The following shows the extraction to WAV, and then conversion to various formats for fun, e.g. MP3, OGG, and FLAC.</p>
<blockquote><p><code><strong>ffmpeg -i Cool.Movie.mkv -acodec pcm_s16le -ac 2 audio.wav<br />
lame -V0 -q0 --vbr-new audio.wav audio.mp3<br />
oggenc -q6 audio.wav<br />
flac audio.wav</strong></code></p></blockquote>
<p>Use <em>mkvmerge</em> to combine the original MKV with the MP3 audio track to create a new file called Cool.Movie.New.mkv.  Make sure you have enough disk space for both the original and new MKV file.</p>
<blockquote><p><code><strong>mkvmerge -o Cool.Movie.New.mkv Cool.Movie.mkv audio.mp3</strong><br />
mkvmerge v2.4.1 ('Use Me') built on Dec 13 2008 21:03:46<br />
'Cool.Movie.mkv': Using the Matroska demultiplexer.<br />
'audio.mp3': Using the MP2/MP3 demultiplexer.<br />
Warning: 'audio.mp3': Skipping 32 bytes at the beginning (no valid MP3 header found).<br />
'Cool.Movie.mkv' track 1: Using the MPEG-4 part 10 (AVC) video output module.<br />
'Cool.Movie.mkv' track 2: Using the AC3 output module.<br />
'Cool.Movie.mkv' track 3: Using the text subtitle output module.<br />
'audio.mp3' track 0: Using the MPEG audio output module.<br />
The file 'Cool.Movie.New.mkv' has been opened for writing.<br />
Progress: 100%<br />
The cue entries (the index) are being written...<br />
Muxing took 270 seconds.</code></p></blockquote>
<p>Verify that the audio track has been added.  You can see Track ID 4 has been successfully added.</p>
<blockquote><p><code><strong>mkvmerge -i New.Cool.Movie.mkv </strong><br />
File 'New.Cool.Movie.mkv': container: Matroska<br />
Track ID 1: video (V_MPEG4/ISO/AVC)<br />
Track ID 2: audio (A_AC3)<br />
Track ID 3: subtitles (S_TEXT/UTF8)<br />
Track ID 4: audio (A_MPEG/L3)</code></p></blockquote>
<p>That&#8217;s really all there is to it.  There are quite a few options available when editing MKV container files.  For example, I wanted nice descriptions for my tracks since various media players will read and display them for you during menu navigation.  I recommend using the mkvmerge gui application as shown in this screenshot.</p>
<p style="text-align: center;"><a href="http://www.savvyadmin.com/wp-content/uploads/2009/09/mkvmerge-gui.png" target="_blank"><img class="aligncenter size-medium wp-image-410" title="mkvmerge-gui" src="http://www.savvyadmin.com/wp-content/uploads/2009/09/mkvmerge-gui-300x175.png" alt="mkvmerge-gui" width="300" height="175" /></a></p>
<p>It&#8217;s really just a front-end application to mkvmerge, and the following text shows the commands that were used to specify the language for each tag, re-order the audio tracks, disable subtitles by default, and give useful descriptions to each Track ID.</p>
<blockquote><p><code><strong>mkvmerge -o "Cool.Movie.New.mkv"  \<br />
--language 1:eng \<br />
--track-name "1:Cool Movie (MPEG4)" \<br />
--default-track 1:yes \<br />
--display-dimensions 1:40x17 \<br />
--language 2:eng \<br />
--track-name "2:Dolby Digital 5.1 (AC3)" \<br />
--default-track 2:yes \<br />
--language 3:eng \<br />
--track-name "3:English Subtitles" \<br />
--default-track 3:no \<br />
-a 2 -d 1 -s 3 Cool.Movie.mkv \<br />
--language 0:eng \<br />
--track-name "0:2-Channel Stereo (MP3)" \<br />
--default-track 0:no \<br />
-a 0 -D -S audio.mp3 \<br />
--track-order 0:1,0:2,1:0,0:3</strong></code></p>
<p><code><strong>mkvmerge -i Cool.Movie.New.mkv</strong><br />
File 'Cool.Movie.New.mkv': container: Matroska<br />
Track ID 1: video (V_MPEG4/ISO/AVC)<br />
Track ID 2: audio (A_AC3)<br />
Track ID 3: audio (A_MPEG/L3)<br />
Track ID 4: subtitles (S_TEXT/UTF8)</code></p></blockquote>
<p>Related posts:<ol>
<li><a href='http://savvyadmin.com/extract-audio-from-video-files-to-wav-using-ffmpeg/' rel='bookmark' title='Extract Audio from Video Files to WAV using FFmpeg'>Extract Audio from Video Files to WAV using FFmpeg</a></li>
<li><a href='http://savvyadmin.com/extract-ac3-dolby-digital-with-ffmpeg/' rel='bookmark' title='Extract AC3 Dolby Digital with FFMpeg'>Extract AC3 Dolby Digital with FFMpeg</a></li>
<li><a href='http://savvyadmin.com/adding-chapters-to-videos-using-mkv-containers/' rel='bookmark' title='Adding Chapters to Videos Using MKV Containers'>Adding Chapters to Videos Using MKV Containers</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://savvyadmin.com/add-stereo-audio-tracks-to-mkv-files/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Convert MKV to Xvid with Mencoder</title>
		<link>http://savvyadmin.com/convert-mkv-to-xvid-with-mencoder/</link>
		<comments>http://savvyadmin.com/convert-mkv-to-xvid-with-mencoder/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 01:57:54 +0000</pubDate>
		<dc:creator>gmendoza</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[AC3]]></category>
		<category><![CDATA[Dolby Digital]]></category>
		<category><![CDATA[mencoder]]></category>
		<category><![CDATA[MKV]]></category>
		<category><![CDATA[mplayer]]></category>
		<category><![CDATA[Multimedia]]></category>
		<category><![CDATA[Xvid]]></category>

		<guid isPermaLink="false">http://www.savvyadmin.com/?p=329</guid>
		<description><![CDATA[I recently wanted to convert some of my 720p and 1080p Matroska Video (MKV) files to the Xvid format so that I can play them on my Xbox 360 (check out ushare). I really wanted to make sure that the video quality and Dolby Digital 5.1 audio would remain intact, and was pleased to get [...]
Related posts:<ol>
<li><a href='http://savvyadmin.com/dvd-to-xvid-encoding-with-mencoder/' rel='bookmark' title='DVD to XviD Encoding with Mencoder'>DVD to XviD Encoding with Mencoder</a></li>
<li><a href='http://savvyadmin.com/using-mencoder-profiles/' rel='bookmark' title='Using Mencoder Profiles'>Using Mencoder Profiles</a></li>
<li><a href='http://savvyadmin.com/extract-audio-from-video-files-to-wav-using-ffmpeg/' rel='bookmark' title='Extract Audio from Video Files to WAV using FFmpeg'>Extract Audio from Video Files to WAV using FFmpeg</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I recently wanted to convert some of my 720p and 1080p Matroska Video (MKV) files to the Xvid format so that I can play them on my Xbox 360 (check out <a target="_blank" href="http://ushare.geexbox.org/">ushare</a>).  I really wanted to make sure that the video quality and Dolby Digital 5.1 audio would remain intact, and was pleased to get the job done with mencoder.</p>
<p>In the following example, I decided to use a single pass, fixed quantizer value of 4.  The audio will simply be copied.</p>
<blockquote><p><code><strong>mencoder movie.mkv -channels 6 -ovc xvid -xvidencopts fixed_quant=4 \<br />
-vf harddup -oac copy -o movie.avi</strong></code></p></blockquote>
<p>The Dolby Digital 5.1 (AC3) output was a major pain to figure out because by default, mencoder (and mplayer) only will select 2 audio channels.  So increasing the value to 6 ensures you receive them all.  Otherwise, you end up getting standard stereo out all channels.</p>
<p>There&#8217;s a ton of options that you can use, so just be sure to read the man pages for mencoder.</p>
<p><strong>NOTE 1:</strong>  This is not an exhaustive or definitive post on quality retention.  This is just an easy way to re-encode a source video file to Xvid.</p>
<p><strong>NOTE 2:</strong> MKV is only a container file format, meaning that you store audio and video tracks within an MKV file, as well as a number of other data types.  e.g. Subtitles, Pictures, Fonts, etc.  Many times, these video and audio tracks may already have been encoded with a codec supported by your media player.  You could potentially extract the appropriate audio and video tracks with mkvextract (a component of the mkvtoolnix package), and recombine them into a container format supported by your platform.  This is a great option because you would not have to re-encode, saving time and quality loss.  I&#8217;ll update with more examples later.</p>
<p>Related posts:<ol>
<li><a href='http://savvyadmin.com/dvd-to-xvid-encoding-with-mencoder/' rel='bookmark' title='DVD to XviD Encoding with Mencoder'>DVD to XviD Encoding with Mencoder</a></li>
<li><a href='http://savvyadmin.com/using-mencoder-profiles/' rel='bookmark' title='Using Mencoder Profiles'>Using Mencoder Profiles</a></li>
<li><a href='http://savvyadmin.com/extract-audio-from-video-files-to-wav-using-ffmpeg/' rel='bookmark' title='Extract Audio from Video Files to WAV using FFmpeg'>Extract Audio from Video Files to WAV using FFmpeg</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://savvyadmin.com/convert-mkv-to-xvid-with-mencoder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

