<?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; FFMpeg</title>
	<atom:link href="http://savvyadmin.com/tag/ffmpeg/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.2</generator>
		<item>
		<title>Extract AC3 Dolby Digital with FFMpeg</title>
		<link>http://savvyadmin.com/extract-ac3-dolby-digital-with-ffmpeg/</link>
		<comments>http://savvyadmin.com/extract-ac3-dolby-digital-with-ffmpeg/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 19:02:01 +0000</pubDate>
		<dc:creator>gmendoza</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[AC3]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[FFMpeg]]></category>
		<category><![CDATA[Multimedia]]></category>

		<guid isPermaLink="false">http://www.savvyadmin.com/?p=401</guid>
		<description><![CDATA[If you have a source video file encoded with an AC3 Dolby Digital audio stream, you can extract the audio in it&#8217;s native format using FFMpeg. The following example shows how to identify the available audio streams of the file video.avi. Just use ffmpeg without any output options, and you can see there are two [...]
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/convert-3gp-videos-to-xvid-avi/' rel='bookmark' title='Convert 3gp Videos to XviD AVI'>Convert 3gp Videos to XviD AVI</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>
</ol>]]></description>
			<content:encoded><![CDATA[<p>If you have a source video file encoded with an AC3 Dolby Digital audio stream, you can extract the audio in it&#8217;s native format using FFMpeg.</p>
<p>The following example shows how to identify the available audio streams of the file <code>video.avi</code>.  Just use ffmpeg without any output options, and you can see there are two streams (0.0 and 0.1), the second is AC3 audio.</p>
<blockquote><p><code><strong>ffmpeg -i video.avi</strong><br />
Input #0, avi, from 'video.avi':<br />
  Duration: 01:17:57.64, start: 0.000000, bitrate: 1587 kb/s<br />
    Stream #0.0: Video: mpeg4, yuv420p, 672x576 (snipped for brevity)<br />
    Stream #0.1: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s<br />
At least one output file must be specified</code></p></blockquote>
<p>The following command will extract the AC3 audio stream to a file called <code>audio.ac3</code>.</p>
<blockquote><p><code><strong>ffmpeg -i video.avi -acodec copy audio.ac3</strong><br />
Input #0, avi, from 'video.avi':<br />
  Duration: 01:17:57.64, start: 0.000000, bitrate: 1587 kb/s<br />
    Stream #0.0: Video: mpeg4, yuv420p, 672x576 (snipped for brevity)<br />
    Stream #0.1: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s<br />
Output #0, ac3, to 'audio.ac3':<br />
    Stream #0.0: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s<br />
Stream mapping:<br />
  Stream #0.1 -> #0.0<br />
Press [q] to stop encoding<br />
size=  255799kB time=4677.51 bitrate= 448.0kbits/s<br />
video:0kB audio:255799kB global headers:0kB muxing overhead 0.000000%</code></p></blockquote>
<p>Verify the file was created.  The output below shows that this stream is about 250Mb.</p>
<blockquote><p><code><strong>ls -lh audio.ac3 </strong><br />
-rw-r--r-- 1 username gmendoza 250M 2010-02-21 09:47 audio.ac3</code></p></blockquote>
<p>You can now use ffmpeg again to show that <code>audio.ac3</code> only contains the ac3 audio stream.</p>
<blockquote><p><code><strong>ffmpeg -i audio.ac3</strong><br />
Input #0, ac3, from 'audio.ac3':<br />
  Duration: 01:17:57.46, bitrate: 448 kb/s<br />
    Stream #0.0: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s<br />
At least one output file must be specified</code></p></blockquote>
<p>Now that you have extracted the audio stream, you can do anything you wish with it.  Enjoy.</p>
<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/convert-3gp-videos-to-xvid-avi/' rel='bookmark' title='Convert 3gp Videos to XviD AVI'>Convert 3gp Videos to XviD AVI</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>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://savvyadmin.com/extract-ac3-dolby-digital-with-ffmpeg/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert 3gp Videos to XviD AVI</title>
		<link>http://savvyadmin.com/convert-3gp-videos-to-xvid-avi/</link>
		<comments>http://savvyadmin.com/convert-3gp-videos-to-xvid-avi/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 18:30:33 +0000</pubDate>
		<dc:creator>gmendoza</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[3gp]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[FFMpeg]]></category>
		<category><![CDATA[Multimedia]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://savvyadmin.com/?p=581</guid>
		<description><![CDATA[3gp is the container format used when recording video with many mobile phones, which can be a pain when trying to view them using a number of multimedia players. Fortunately, converting videos from 3gp to XviD AVI is easy with FFmpeg. Usually, there&#8217;s not much to the quality of these types of source video files, [...]
Related posts:<ol>
<li><a href='http://savvyadmin.com/convert-video-files-to-dvd/' rel='bookmark' title='Convert Video Files to DVD'>Convert Video Files to DVD</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/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><a href="http://en.wikipedia.org/wiki/3GP" target="_blank">3gp</a> is the container format used when recording video with many mobile phones, which can be a pain when trying to view them using a number of multimedia players.  Fortunately, converting videos from <a href="http://en.wikipedia.org/wiki/3GP" target="_blank">3gp</a> to XviD AVI is easy with <a href="http://ffmpeg.org/" target="_blank">FFmpeg</a>.</p>
<p>Usually, there&#8217;s not much to the quality of these types of source video files, so many of the more complex video and audio options aren&#8217;t needed.  A simple FFmpeg command that retains as much quality as possible would look like the following.</p>
<blockquote><p><code><strong>ffmpeg -i video.3gp -acodec libmp3lame -vcodec libxvid -qscale 2 -f avi video.avi</strong></code></p></blockquote>
<p>Related posts:<ol>
<li><a href='http://savvyadmin.com/convert-video-files-to-dvd/' rel='bookmark' title='Convert Video Files to DVD'>Convert Video Files to DVD</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/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-3gp-videos-to-xvid-avi/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extract Audio from Video Files to WAV using FFmpeg</title>
		<link>http://savvyadmin.com/extract-audio-from-video-files-to-wav-using-ffmpeg/</link>
		<comments>http://savvyadmin.com/extract-audio-from-video-files-to-wav-using-ffmpeg/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 04:49:47 +0000</pubDate>
		<dc:creator>gmendoza</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[Audio]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[FFMpeg]]></category>
		<category><![CDATA[MKV]]></category>
		<category><![CDATA[Multimedia]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://www.savvyadmin.com/?p=537</guid>
		<description><![CDATA[Previously, I described how to Extract Audio from Video Files to WAV using Mplayer. Another method using FFmpeg instead of Mplayer was also pointed out in the post titled Add Stereo Audio Tracks to MKV Files, and I figured it would be useful to outline the quick one-step process in a post all by itself. [...]
Related posts:<ol>
<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/extract-audio-from-video-files-to-wav-using-mplayer/' rel='bookmark' title='Extract Audio from Video Files to WAV using Mplayer'>Extract Audio from Video Files to WAV using Mplayer</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>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Previously, I described how to <a href="http://www.savvyadmin.com/extract-audio-from-video-files-to-wav-using-mplayer/" target="_blank">Extract Audio from Video Files to WAV using Mplayer</a>.  Another method using FFmpeg instead of Mplayer was also pointed out in the post titled <a href="http://www.savvyadmin.com/add-stereo-audio-tracks-to-mkv-files/" target="_blank">Add Stereo Audio Tracks to MKV Files</a>, and I figured it would be useful to outline the quick one-step process in a post all by itself.</p>
<p>Here&#8217;s an example of extracting the audio from a video file called <code>video.mkv</code> and saving it to a file called <code>audio.wav</code>.  This very well could have been an AVI, MPEG, or any other video format that FFmpeg can decode.</p>
<blockquote><p><code><strong>ffmpeg -i video.mkv -acodec pcm_s16le -ac 2 audio.wav</strong></code></p></blockquote>
<p>It should also be mentioned that your source video file may have multiple audio channels or streams.  For example, you may have both English AC3 and DTS channels, but you may also have other audio streams for other languages, directors comments, etc.  If you want more control over which stream you are using, first identify them all with ffmpeg.</p>
<blockquote><p><code><strong>ffmpeg -i video.mkv</strong><br />
[snipped for brevity]<br />
Input #0, matroska, from 'video.mkv':<br />
  Duration: 01:30:38.78, start: 0.000000, bitrate: N/A<br />
    Stream #0.0(eng): Video: h264, yuv420p, 1280x720, PAR 1:1 DAR 16:9, 23.98 tbr, 1k tbn, 47.95 tbc<br />
    Stream <strong><em>#0.1(eng)</em></strong>: Audio: <strong><em>ac3</em></strong>, 48000 Hz, 5.1, s16<br />
    Stream #0.2(eng): Subtitle: 0x0000<br />
    Stream <strong><em>#0.3(heb)</em></strong>: Audio: <strong><em>mp3</em></strong>, 48000 Hz, stereo, s16<br />
    Stream #0.4(heb): Subtitle: 0x0000<br />
    Stream #0.5: Attachment: 0x0000<br />
    Stream #0.6: Attachment: 0x0000<br />
At least one output file must be specified</code></p></blockquote>
<p>From the example above, you see that Stream #0.0 is labeled as being an English video stream with h264 encoding.  Stream #0.1 and #0.3 are both audio streams, but #0.1 is English AC3 5.1 and #0.3 is Hebrew MP3 stereo.  Simply reference the stream id with the -map option in the following format.</p>
<blockquote><p><code><strong>ffmpeg -i video.mkv -map 0:1 -acodec pcm_s16le -ac 2 audio.wav</strong><br />
[snipped for brevity]<br />
Output #0, wav, to 'audio.wav':<br />
    Stream #0.0(eng): Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s<br />
Stream mapping:<br />
  Stream #0.1 -> #0.0<br />
[snipped for brevity]</code></p></blockquote>
<p>Now that you have a PCM WAV file, you can manipulated it however you like, e.g. encode to MP3, OGG, FLAC, etc.</p>
<blockquote><p><code><strong>lame -V0 -q0 --vbr-new audio.wav audio.mp3<br />
oggenc -q6 audio.wav<br />
flac audio.wav</strong></code></p></blockquote>
<p>Related posts:<ol>
<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/extract-audio-from-video-files-to-wav-using-mplayer/' rel='bookmark' title='Extract Audio from Video Files to WAV using Mplayer'>Extract Audio from Video Files to WAV using Mplayer</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>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://savvyadmin.com/extract-audio-from-video-files-to-wav-using-ffmpeg/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Convert Video Files to DVD</title>
		<link>http://savvyadmin.com/convert-video-files-to-dvd/</link>
		<comments>http://savvyadmin.com/convert-video-files-to-dvd/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 03:40:36 +0000</pubDate>
		<dc:creator>gmendoza</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[DVD]]></category>
		<category><![CDATA[dvdauthor]]></category>
		<category><![CDATA[FFMpeg]]></category>
		<category><![CDATA[genisoimage]]></category>
		<category><![CDATA[growisofs]]></category>
		<category><![CDATA[Multimedia]]></category>

		<guid isPermaLink="false">http://www.savvyadmin.com/?p=452</guid>
		<description><![CDATA[If you have a video vile that you wish to convert and burn to DVD, you can do so from a Linux command line very easily. We will use FFmpeg for the video conversion, DVDAuthor to create the DVD file system structure, and Growisofs to burn the DVD. Using FFmpeg, simply specify your input file, [...]
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/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 have a video vile that you wish to convert and burn to DVD, you can do so from a Linux command line very easily.  We will use FFmpeg for the video conversion, DVDAuthor to create the DVD file system structure, and Growisofs to burn the DVD.</p>
<p>Using FFmpeg, simply specify your input file, the target format, resolution and an output file name.  While the following is an over simplified example, it will more than likely work very nicely in most scenarios.  The source video file is movie.avi, the target will be formatted for NTSC, and a standard DVD resolution of 720&#215;480 will be used to create a new video file called movie.mpg.  There are many additional options that FFMpeg can use to increase quality, so be sure to check out the documentation.</p>
<blockquote><p><code><strong>ffmpeg -i movie.avi -target ntsc-video -s 720x480 movie.mpg</strong></code></p></blockquote>
<p>Next, you will need to take your new movie.mpg file, and create a DVD file structure that you will burn to disc.  Just create a folder that will serve as the parent directory of your DVD.  I Like to name it after the title of the movie.  Then you will use dvdauthor to create a title set and table of contents and no DVD menus.  The movie will just play.  :-)</p>
<blockquote><p><code><strong>mkdir MOVIE_TITLE<br />
dvdauthor -o MOVIE_TITLE/ -t movie.mpg<br />
dvdauthor -o MOVIE_TITLE/ -T</strong></code></p></blockquote>
<p>The <code>dvdauthor -t</code> option creates a title track in the VIDEO_TS directory.  If you list the contents after running the first command, you&#8217;ll see the corresponding <code>VTS_01_0.BUP</code>, <code>VTS_01_0.IFO</code>, and <code>VTS_01_X.VOB</code> files.  The <code>-T</code> option creates a table of contents for all title sets in the file system, which are listed as <code>VIDEO_TS.BUP</code> and <code>VIDEO_TS.IFO</code>.</p>
<p>You are now ready to burn the DVD.  In the following command, we will use the <code>-Z</code> option to burn an initial session to the disc, the <code>-dvd-video</code> option to generate a DVD-Video compliant UDF file system, and the <code>-V</code> option to give the disc a Volume ID.  This Volume ID is read by your computer to and displays as a nice human readable title typically underneath the icon representing the disc.  The <code>-dvd-video</code> and <code>-V</code> options are actually part of the mkisofs (genisoimage) command sets, so they do not show up in the growisofs man pages.</p>
<blockquote><p><code><strong>growisofs -Z /dev/dvdrw -dvd-video -V MOVIE_TITLE MOVIE_TITLE/</strong></code></p></blockquote>
<p>Notice, you do not need to generate an ISO file to burn the DVD.  This would only waste space if your intention is not to distribute or store the video as a disc image.  To create the image however, that&#8217;s as easy as the following.</p>
<blockquote><p><code><strong>genisoimage -o MOVIE_TITLE.iso -dvd-video MOVIE_TITLE/</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/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/convert-video-files-to-dvd/feed/</wfw:commentRss>
		<slash:comments>0</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>13</slash:comments>
		</item>
	</channel>
</rss>

