Getting Lossless Audio off the PC


While video quality is important, I find that it’s the audio that
really transforms a good movie into an immersive experience.  As
challenging as it can be to get flawless video playback working on the
HTPC, enabling proper lossless multi-channel audio playback adds
another layer of difficultly into the mix.  In this guide we will
discuss the different options available for getting full fidelity HD
audio off your PC and into the Audio/Video receiver (AVR).

you’ve probably guessed the crux of this guide is about converting
compressed lossless audio formats into LPCM (Linear Pulse Code
Modulation) for output over the HDMI or analog connections to an AVR. 
So if your PC isn’t setup to support one of these connections stop
reading and fix it; take your time, we’ll be here when you’re done. 
Also if you’re using an application like Power DVD or Total Media
Theater for all your media needs, while you probably need to reexamine
that choice (unless the player is being launched per media item from
another application like Media Center or Sage), you’ve already
covered.  Both applications support lossless multi-channel LPCM output
without much effort, just configure the audio settings to 6 or 8
channel (depending on your setup) and it’s done. 

With that out of the way let’s talk codecs and containers.

of the retail lossless audio content is encoded as Dolby TrueHD or
DTS-MA but some (mostly older files) contain LPCM audio tracks.  LPCM
is the easiest codec to deal with because there’s nothing to do, it’s
already raw lossless audio just waiting for transport.  You can leave
it in the M2TS or remux to MKV, either will work fine with the ffdshow
or MPC-HC audio decoder.  The only real problem is that because it’s
raw audio, the file uses a lot more space than a compressed format
would.  Now if you have unlimited storage that inefficiency isn’t an
issue, but personally I don’t like to waste even when there’s plenty. 

TrueHD is the most popular audio codec that I’ve seen, but
unfortunately the options are more limited compared to LPCM.  As far as
I know ffdshow is the only free/open source software (OSS) DirectShow
decoder for TrueHD, but even it requires using newer a version than the "stable" build we installed last week
I’ve done some testing and ffdshow seems to work great provided you can
find a splitter that actually presents the full TrueHD stream. 

Going through the different M2TS and MKV splitter/demux filters on my HTPC with GraphStudio we can see that support is limited.

ArcSoft Mpeg Demux (M2TS):
TrueHD is presented and will connect to ffdshow, but audio type isn’t
created correctly (note only two channels are available) so no audio

Haali Splitter (MKV):
Even though we can clearly see that the TrueHD track is contained in
the file, no audio track presented.  Haali clearly doesn’t support
TrueHD at all.

Haali Splitter (M2TS): Same result as when using Haali to split a MKV.

MPC-HC Mpeg Splitter (M2TS):
Audio track is presented as AC-3, it’s unclear if ffdshow is decoding
HD or extracting core AC-3 for playback.  I tried to build ffdshow
locally so I could attach the debugger and see how the audio is
handled, but wasn’t able to get it to compile. 

SageTV Beta Demuxer (M2TS):
TrueHD is presented, connects to ffdshow and plays perfectly. (Note
that the subtype GUID displayed matches the TrueHD media type from
wmcodec.h in the Windows Platform SDK, which is exactly what should be

you can see, TrueHD can work under the right conditions with the right
container.  Taking a longer term look, the MKV ecosystem is half way
there; MKVToolnix will mux TrueHD into mkv, and it’s detected properly
in MediaInfo, so it will just take some effort from Haali to get it
working properly for DirectShow players.

Where TrueHD is a little
complex, DTS-MA is blocking.  There are no free/OSS decoders available
that can decode with full fidelity. Even in the professional space only
the ArcSoft decoder supports 7.1 DTS-MA, but as it doesn’t remember
channel settings you will only get two channels of lossless audio. 
There is some good news for the lazy/patient, because ffdshow can
connect to the DTS-MA and decode the core so you’ll at least get
multi-channel audio with that option.

Now that we’ve covered the
problems, let’s discuss one solution.  Before we get to that it is
important to remember that lossless audio is lossless audio; as long as
we can guarantee that each step in our process is bit perfect it
doesn’t matter what codec is used while the audio sits on the hard
disc.  I know it seems pretty obvious when you think about it, but for
those who’ve been around for a while it can be a difficult to get past
the "all transcoding is lossy" mindset; at least it was for me.

put, for everything but TrueHD, I think the best solution is to convert
the lossless audio track to FLAC.  For those who don’t know, FLAC or
"Free Lossless Audio Codec" is (as you can probably guess from the
name) a lossless open source audio codec.  The main benefit to FLAC is
that because the specification and tools are open source, and it’s been
around for a while, there is a mature environment where several excellent options for converting, decoding (madFLAC, MPC-HC
audio decoder, ffdshow, etc) are available, and it all works perfectly in MKV so we
can leverage a single splitter and not have to worry about potential
issues with merit and the different m2ts splitters.  The approach for
TrueHD is a bit more nuanced, if you’re a SageTV user and don’t mind
running beta bits either keeping the original M2TS or remuxing (w/ TSMuxer)
a streamlined version with just the A/V tracks you want is a viable
option.  On the other hand if you’re a Media Center user, M2TS can work
on Vista with the right splitter but 7MC uses Media Foundation instead
of DirectShow for M2TS playback, and at least in my [limited] testing
the experience was pretty bad (i.e. VC-1 files don’t play video), and
there is no lossless audio support. 

Before we get started you’ll need a copy of eac3to and MKVToolnix
We’re only going to use eac3to to handle audio conversion and video
extraction right now, but it has several other features that should be
noted.  The most useful is the ability to work on Blue-ray and HD-DVD
folder structures directly, instead of the M2TS approach we’re going to
use in the walk through.  Usage is the same, but when run on a disc
structure eac3to can also extract the chapter information which can
also be muxed into the MKV later.  The other feature we’re not going to
use now but worth pointing out, is subtitle extraction; unfortunately
eac3to doesn’t do all the work here and only a .sup is produced, but
five/ten minutes with SupRip
(not to be confused with the myriad of other subtitle OCR software with
similar names) will turn the images into a very useful SRT file which
can also be muxed into the MKV or left on the file system if your
player supports external subtitles.

For the command line challenged, there are GUIs for eac3to available, the more popular ones are linked from the eac3to page on Doom9.  For the rest of us go ahead and open up a command window (type "cmd" into the start search box) and hit enter.

"CD" (type "cd \process" at the prompt and hit enter) to your process
directory, input the path to eac3to (the easiest way on Vista to get
the full path is to hold down the shift key and right-click the exe and
select "Copy as Path", then right-click the command window to paste it
in; 7 users can just drag the exe from explorer into the command
window), the path to the M2TS file that will be processed, and press

you can see, when eac3to is run directly on the file (or disc
structure) without any arguments it just enumerates the streams that
are contained.  The reason we do this is to tell it next which streams
to extract and what to do with them.

In this case we’re just
going to extract the video and HD audio streams, so we want to run the
same command as before (press the up key to reload it at the prompt)
but this time we want to add the stream number and the target format
(i.e. 1: dtshdvideo.mkv 2: dtshdaudio.flac) before hitting the "enter"
key.  It doesn’t matter where you put the files (in this case they will
end up in the folder we’re running the tool from) but it’s very
important to get the extension right as that’s how eac3to knows what
format/container to use when extracting the stream.

TrueHD and LPCM can be handled using OSS, bit-perfect decoders included
with eac3to for our test a file with DTS-MA was purposely selected
because it’s the most complex.  Referring back to the screen shot,
you’ll notice that the "ArcSoft DTS Decoder" was used to decode the
audio.  While eac3to will work with different decoders, the ArcSoft one
is the only filter that supports 7.1 bit-perfect decoding. 

you have an HD PVR you’re covered, the version of ArcSoft TMT that’s
included works great after updating to the (or later) rev.  For
everyone else I also tested with the trial rev of TMT3, and that works
too.  So just include this a step to checking out the software;
personally after years of using PowerDVD I think TMT provides a better
BD playback experience so it’s worth checking out anyway.  For those
using Window 7, note that TMT2 (the version included with the HD PVR)
is not compatible; so you’ll want to install it on a virtual machine
(or another box with XP or Vista) and copy the ArcSoft folder
("%ProgramFiles%\ArcSoft") over if you want to run eac3to natively. 

final step is to mux the A/V files into an MKV using mkvmerge, a tool
included in MKVToolnix.  If you chose the installer an option for
MKVMerge will be available from the programs menu, otherwise double
click "mmg.exe" to run the tool. 

After it opens either
drag/drop the two files onto mkvmerge, or click "Add" to browse and
select them.  I like to order the video stream first, and add a "Track
Name" that describes the stream.  For audio tracks, it’s also a good
idea to set the correct language.  For those who use an HD200 extender,
now is a good time to jump back to the eac3to window and extract or
encode a 5.1 AC-3 stream that you should mux in as a secondary audio
stream (the HD200 will only decode to stereo); order is important
because while the HD200 supports stream switching, the PC doesn’t
without dragging out a mouse.  Make sure to change the "Output
filename" before you "Start muxing".

you ran eac3to on a disc structure to extract chapters, or dumped the
.sup and did the OCR already both can be added as tracks prior to
muxing as well.