DVDAGuide

From Avisynth wiki
Jump to: navigation, search

Contents

Introduction

DVD-Audio is a standard for storing high quality stereo or multi-channel audio content on a standard DVD disk. Supported sample rates range from 44.1KHz up to 192KHz, with bit depths of 16, 20 or 24 bits. A DVD-Audio contains both DVD-Audio content (in the AUDIO_TS folder) and DVD-Video content (in the VIDEO_TS folder) and has the DVD-Audio logo. The audio in the AUDIO_TS folder can be either Linear Pulse Code Modulation (abbreviated LPCM, which is uncompressed) or Meridian Lossless Packing (abbreviated MLP, which is losslessly compressed). Usually, a DVD-Audio contains 5.1ch MLP / 2.0ch MLP or 5.1ch MLP / 2.0ch LPCM. There is also audio present in the VIDEO_TS folder, but of lower quality (that is with a lower sample rate and a lower bit depth). More information can be found here.

DVD-Audio streams can be encrypted. The encryption is called Content Protection for Prerecorded Media (CPPM), which uses a media key block (MKB) to authenticate DVD-Audio players. In order to decrypt the audio, players must obtain a media key from the MKB, which also is encrypted. The player must use its own unique key to decrypt the MKB. If a DVD-Audio player's decryption key is compromised, that key can be rendered useless for decrypting future DVD-Audio discs. DVD-Audio discs can also contain digital watermarking technology, typically embedded into the audio once every thirty seconds. If a DVD-Audio player encounters a watermark on a disc without a valid MKB, it will halt playback. quoted from wikipedia.

As of today (3 July 2011), the encryption is broken, but it is not possible to remove the watermarks. In July 2005, CPPM encryption was cracked (source). Then in July 2007, the first open source tool for decryption, dvdcpxm, was released. One year after that, MLP decoding support was implemented in mlpdec.c into libavcodec (source). That original open source implementation has been utilized in several other projects, both open sourced and closed. The following are the most common tools to decrypt and decode MLP streams:

The purpose of this guide is the following:

  • Explain how to decrypt and re-encode the audio of your DVD-Audio to FLAC (which is an open source, lossless audio codec). This enables you to play your files on your PC without any hassle (i.e. using open source tools).
  • The above will be done retaining higher quality than the audio counterpart that is located on the video section of the disc.

The next section of this guide will discuss going from an encrypted DVD-A to FLAC files using only two programs: DVD-Audio Explorer and the FLAC encoder. The sections that follow the section below are outdated and are much more complicated and require much more effort, but will result in the same files.

Modern method

As touched on in the introduction, the once daunting task of decrypting AOB files, demuxing streams from them, decoding the resulting .mlp or .pcm files, and compressing the resulting .wav files has been made very simple with just a couple tools. In this method the open source program DVD-Audio Explorer will be used (I'm using version 2008.07.21). FLAC will be used to compress the resulting .wav files. In a nutshell:

  1. Insert DVD-A into disc drive
  2. Select tracks to extract in DVD-Audio Explorer
  3. Set extraction options how you would like
  4. (optional) Compress .wav files into a different format, such as FLAC
    1. Add metadata to FLACs
  5. Enjoy your high resolution audio!

Required tools

  • DVD-Audio Explorer -- displays detailed info about MLP and LPCM streams on a DVD-A; allows decryption, demuxing, and decoding to .wav.
  • FLAC -- losslessly compresses .wav files into .flac files, usually 60-70% of their uncompressed size, and is a common file format

Setup

DVD-Audio Explorer is a standalone application that requires no install; FLAC, on the other hand, will usually install to "C:\Program Files\FLAC\" and the encoder flac.exe is inside that "FLAC" folder. Take note where you install it to -- we'll use it later.

Using DVD-Audio Explorer

Extraction options
  1. Open DVD-Audio Explorer
  2. Click the Open button, and browse to your disc drive
  3. Select any of the .IFO files in the \AUDIO_TS\ folder of the disc

Now try clicking on some tracks and read some of the technical info about those tracks. It should become apparent, for example, which set of tracks is the 5.1 surround set (you'll see more than just "L-R" under the "channel assignment" parameter(s)). Also present in the info pane is bit depth and sample rate, which are important attributes to audiophiles. You can select a range of tracks to extract by selecting the start of the range, hold the shift key, and select the end of the range. Click the Extract button and continue onto extraction options:

  1. Click the Extract button.
  2. Choose the desired destination of the files.
  3. Choose if you want to Store simple .mlp or .pcm files (not sure why you would want to do that), or Convert to wave (much more manipulable).
  4. Select Merge groups if you want to create a single file for each track on the DVD-A, or Split groups to create a file for each channel group (sometimes surround tracks have a Group 1 [Lf-Rf-Ls-Rs] and Group 2 [C-LFE]) for each track. I'm not sure why anyone would choose to Split rather than Merge.
  5. Get stereo downmix extraction only applies if the structure of the files on the DVD-A is such that the "Substreams" parameter on the tracks is 2.
  6. Enable Recover from stream errors if you experience inconvertible tracks.
  7. As far as I can tell (the README doesn't mention it), Use old format is for if for some reason the .wav's that are output don't play well with other software. I've never had to enable it.

Here's the best part! The Run program field allows us to send the decoded tracks straight to flac.exe to be compressed as soon as they're ready. Below is my suggestion on what to put in this field:

"C:\Program Files\FLAC\flac.exe" -8 -V -T COMMENT="Ripped with DVD-Audio Explorer 2008.07.21, compressed with FLAC 1.2.1 level 8" --delete-input-file -w "%filepath%"
  • Change the location of flac.exe appropriately for your system.
  • -8 specifies compression level 8 (highest compression / longest time required to compress).
  • -V verifies that the .flac file contains exactly the same audio data as the input file. If errors occur, they will appear in DVDAExplorerEnc.log in the same folder as the DVD-A Explorer binary.
  • -T COMMENT="..." adds the string in quotes to the Comment tag in the .flac file; change DVD-Audio Explorer and FLAC versions as necessary. I don't imagine the former will be receiving an update any time soon, though.
  • --delete-input-file -w will delete the .wav file once everything is done, provided no errors occured. The -w flag tells the encoder to treat warnings as errors, too.
  • %filepath% is the path of the input file, thus necessary to include.

Moving on,

  1. Wait threshold shouldn't need to be modified from it's default 1,000 MB. README has this to say: "Extraction process will wait until difference in sizes between extracted and processed files drops below threshold. Use smaller values when short of free space."
  2. Delete files need not be enabled as that is taken care of by flac.exe.
  3. Ignore stream encryption -- I suppose this disables the libdvdcpxm function. I've never had to use it.
  4. Log messages should be enabled to make sure no errors occurred. DVD-A Explorer log is DVDAExplorer.log in the same folder as the program itself, as is FLAC's log, DVDAExplorerEnc.log.
  5. Click the large, unlabeled button at the bottom to Extract!

Post-extraction

DVD-Audio Explorer will tell you if everything went OK or not. You can check the aforementioned two log files if you suspect anything went wrong. All that's left now is,

  • tag the files. I use Mp3tag to add album art (look on Google Images for the best image; something around 500 x 500 is ideal), and foobar2000 to add the text tags.
  • (optional) I'm also a fan of ReplayGain. flac.exe's ReplayGain scanner does not allow scanning files with more than two channels, however. foobar2000 is there for you, though. Like it always is, and always will be. ;)
  • Drop the .flac's into a folder with a meaningful name like "Steven Wilson - Insurgentes [2009] [MLP surround 24-48]" or "King Crimson - In the Court of the Crimson King [1969] [MLP stereo 24-96]".

And that should be just about it! I hope you had a successful DVD-A high resolution audio extraction journey! Special thanks to paradynamic (author of dvdcpxm), Ian Caulfield (author of the MLP decoding component of libavcodec), the anonymous developer of DVD-Audio Explorer for putting the two together with a nice GUI, and Josh Coalson (author of FLAC). Happy extracting!

-- mcpancakes

Old method

Required tools

If you want to use AviSynth (without creating intermediate WAV files) then you need to get the Sonic filters somewhere. As of today, 192kHz 24bit MLP tracks are not supported by the Sonic filters, so you are forced to use Surcode MLP in that case. The Sonic filters which support MLP decoding are the following:

  1. CinemasterAudio.dll v4.2.0.840, SonicHDDemuxer.dll v4.2.0.59
  2. CinemasterAudio.dll v4.3.0.151, SonicHDDemuxer.dll v4.3.0.73
  3. CinemasterAudio.dll v4.3.0.169, SonicHDDemuxer.dll v4.3.0.89
  • cpxm/dvdcpxm: this tool can decrypt CPRM/CPPM protected video and audio, that is both CPRM/CPPM protected AOBs and VOBs. Here the decrypter is called dvdcpxm.exe, but i compiled it as cpxm.exe, so that's why that name is used in this guide. Alternatively, you can also use the closed source but free "DVDFab HD Decrypter 3.1.6.2" to decrypt the AOBs.
  • DVDAExplorer_a7.exe: a tool for browsing the contents of AUDIO_TS. As of now, it's the only tool which can demux the audio streams correctly.
  • The Sonic filters "Sonic HD Demuxer" and "Sonic Cinemaster@Audio Decoder 4.3.0" for decoding MLP streams (the needed directshow filters are contained in the package "Sonic.CinePlayer.HD.DVD.Decoder.v4.3.rar").
  • NicAudio.dll v1.82 (or more recent) for decoding the LPCM streams.
  • FLAC 1.2.0: for encoding to FLAC (when you want to use AviSynth with the AviSynth input plugin for Foobar 0.9.4.3). Get the Windows version with installer.
  • The SoundOut AviSynth plugin: for encoding to FLAC within AviSynth. In this case, there is no need to install a FLAC encoder in addition. The plugin will be also be included in the installation of AviSynth v2.6.
  • GraphEdit. Needed when using the Sonic filters to decode the MLP streams. These filters don't work with 192kHz streams.
  • Foobar 0.9.4.3 for playing your FLAC files.

EVODemux doesn't demux MLP streams properly. Last time I checked, there was no sound beyond the first audio track.

Decrypting (.AOBs)

Check whether the AOBs are encrypted. When there is a file DVDAUDIO.MKB in the AUDIO_TS you will know the contents is encrypted, and you need to decrypt it first. If it is not encrypted you can continue with the next section.

Get dvdcpxm. It's a commandline utility. So open a dos-prompt, go to the location of cpxm.exe/dvdcpxm.exe and type for example (use the appropriate folders and paths of the folders/files):

cpxm.exe G:\AUDIO_TS\ATS_01_1.AOB D:\Install\dvd-audio\TheCorrs

Decrypt1.jpg

You need to decrypt the AOBs one by one. As you can see, this DVD-A is protected by CPPM.

Demuxing (audio streams, MLP or LPCM, from .AOBs)

Open DVDAExplorer_a7.exe and open AUDIO_TS.IFO:

Decrypt2.jpg

Each ATS_01_XX.IFO contains one titleset. So, in the example, there is only one titleset (ATS_01_O.IFO) which contains three titles. The first title contains Packed PCM (abbreviated PPCM), which is also called Meridian Lossless Packing (abbreviated MLP). It is 5.1ch 96kHz 24bit MLP. You can see that the channels are divided into two groups: group 1 (Lf Rf Ls Rs) and group 2 (C LFE) with "Channel assignment id" 20. The assignment tells you how the channels are ordered in the stream, which in this case is "Lf Rf Ls Rs C LFE". When using the MLP decoders which are mentioned in the guide, you don't need this information. As can be seen, the length of for example the first audio track in Title 01 is 00:03:28. Or more accurately:

18,762,600 PTS (Presentation TimeStamp) ticks = 18,762,600/90,000 seconds = 208,473 seconds = 00:03:28.473 (3 min 28.473 seconds)

A last comment about the group assignments. The sample rate and the bit depth of the channels in the second group can be lower than those in the first group. For example this is the Case on the "Invaders Must Die" DVD-Audio by The Prodigy. There the First group has a sample rate of 96 kHz and the second one of 48 kHz. Here they are the same for both groups.

Each of the sixteen tracks needs to be extracted. So select the first one, select the File-tab and select "Extract". Select the output directory (by clicking on the icon next to the output directory name) and click on the disc-icon. It will overwrite the name you specified, so give it a different name before proceeding with the next track. Continue until all of the tracks are demuxed. The LPCM track will be saved as track-xx-[L R].pcm. Don't forget to rename the extension to lpcm.

Note the second title contains 2.0ch 88.2kHz 24bit MLP. So it is just a downmixed version of it. I have no idea what the third title is though.

For completeness, here is a screenshot of the contents of a DVD-A which contains both 5.1ch 96kHz 24bit MLP (in Title 01) and 2.0ch 96kHz LPCM (in Title 03):

Decrypt3.jpg

Converting (the raw .mlp or .pcm audio streams to FLAC)

There are basically two ways of converting MLP or LPCM to FLAC. The first one is to decode the MLP/LPCM stream to WAV and convert the latter to FLAC. The second one is to use AviSynth without creating intermediate WAV files. As an example of the conversion using intermediate WAVs, a DVD-A with 192kHz 24bit stereo MLP tracks will be used. As explained in the introduction, this is not possible with the Sonic filters, and the only alternative to use is Surcode MLP.

using Surcode MLP

"Mahler Symphony No. 8" is an example which contains 192kHz 24bit stereo MLP tracks. Demux the MLP tracks with DVDAExplorer_a7.exe as explained above. Decoding MLP with Surcode MLP is possible, but it is a bit of hassle. First we have to create fake WAVs in order to be able to use Surcode MLP. In our case, we need to create two 192kHz 24bit fake mono WAVs. This can be easily created with AviSynth and VirtualDub. Just create the following script:

v = BlankClip()
a = Tone(channels=1)
a = a.AssumeSampleRate(192000)
a = a.ConvertAudioTo24Bit()
AudioDub(v,a)

Open the script in VirtualDub and save it as a WAV file. Duplicate and name them as mono_Lf.wav and mono_Rf.wav. (For 5.1ch MLP you need to have six of them. The length doesn't matter.) Open Surcode MLP. Go to "Options", and select "Encoder Options":

Surcode4.jpg

Make sure that "Downmix" is unchecked and "ReBit" is checked (read the MLP manual if you want to know more about bit-depth reduction). Make also sure that "Verify after encoding is complete" and "Write decoded wave files while verifying" are checked. Click "OK":

Surcode1.jpg

Change the "Channel Assignment" to "(Group 1) L, R" for stereo clips or "(Group 1) Lf, Rf, Ls, Rs / (Group 2) C, LFE" for 5.1ch clips. Open your WAVs by clicking the boxes on the left "Left Front" and "Right Front". Depending on the Channel Assignment you have chosen, more boxes will be visible. Press the "Destination" box and give the fake MLP a name (it is called fake.mlp here).

Now comes the tricky part. The fake MLP needs to be replaced by the real MLP before the verification process, because the MLP will be decoded during the verification process. So move your real MLP that you want to decode to a separate folder (doesn't matter which one, but it shouldn't be in the same folder as your fake MLP). Rename your real MLP to fake.MLP (the name your fake MLP has). After doing this, press "Encode". After the encoding it will ask to save a log-file. BEFORE pressing save or cancel, copy the real MLP (also called fake.MLP) over your fake MLP (fake.MLP). Press cancel, and it will start the verifying process. After verifying you will see the following warning:

Surcode2.jpg

So it writes two channels to one WAV file. Since our MLP is stereo, only the surcode_lfrf.wav is filled. Press Cancel again, and you will end up with the decoded WAV file (for 5.1ch MLP streams you will end up with three WAV files). Open your WAV files in AviSynth and create the following script:

rate = 25 # arbitrary
frames = 2300 # = (PTS ticks / 90,000) * rate = 8,280,000/90,000 * 25
a = WavSource("D:\Install\dvd-audio\Mahler\surcode_lfrf.wav")
v = BlankClip(length=frames, fps=rate)
AudioDub(v,a)

Since 192kHz 24bit streams are not supported by most audio cards, you can down-sample it in the following way:

rate = 25 # arbitrary
frames = 2300 # = (PTS ticks / 90,000) * rate = 8,280,000/90,000 * 25
a = WavSource("D:\Install\dvd-audio\Mahler\surcode_lfrf.wav")
v = BlankClip(length=frames, fps=rate)
AudioDub(v,a)
SSRC(96000) # downsample to 96kHz
# if you want to lower the bit depth you can use ConvertAudioTo16Bit()

Here we will use the "SoundOut AviSynth plugin" to convert the script to FLAC. When opening the final script:

rate = 25 # arbitrary
frames = 2300 # = (PTS ticks / 90,000) * rate = 8,280,000/90,000 * 25
a = WavSource("D:\Install\dvd-audio\Mahler\surcode_lfrf.wav")
v = BlankClip(length=frames, fps=rate)
AudioDub(v,a)
SSRC(96000)
SoundOut()

in VirtualDub, the SoundOut GUI will pop up:

Surcode3.jpg

Check the Sound Info (the number of audio channels, the bit depth, the sample rate and the audio length). Note that

8,280,000 PTS ticks = 8,280,000/90,000 seconds = 92 seconds = 00:01:32.000 (1 min 32.000 seconds)

Press "Save FLAC". The "FLAC Compression Settings" will pop up where you can set the compression level:

Soundout2.jpg

Just leave it at the default setting (6), press "Save As" and give it a name. Finally, do the same for all the other tracks.

For 5.1ch MLP tracks you can use the following script:

rate = 25 # arbitrary
frames = 2300 # = (PTS ticks / 90,000) * rate = 8,280,000/90,000 * 25
a1 = WavSource("D:\Install\dvd-audio\Mahler\surcode_lfrf.wav")
a2 = WavSource("D:\Install\dvd-audio\Mahler\surcode_lsrs.wav")
a3 = WavSource("D:\Install\dvd-audio\Mahler\surcode_clfe.wav")
# channel ordering of FLAC: Lf, Rf, C, LFE, Ls, Rs:
multich = MergeChannels(a1, a3, a2)
v = BlankClip(length=frames, fps=rate)
AudioDub(v,multich)
SSRC(96000) # if necessary
SoundOut()

It's possible to do this without using AviSynth at all, but it's a bit of a hassle. You need WaveWizard/Foobar2000 or WaveWizard/the FLAC Frontend (which is automatically installed when installing FLAC 1.2.0). [discussion].

using AviSynth

using FLAC 1.2.0 and the SoundOut AviSynth plugin (MLP)

Open GraphEdit. Go to the Graph-tab and select 'Insert Filters'. Under the category "DirectShow Filters" you can find all the filters we need. Select the "File Source (Async)" filter to open your MLP stream. After that, select the "Sonic HD Demuxer" and "Sonic Cinemaster@Audio Decoder 4.3.0" filters and connect them in the following way:

When you right-click on the "Sonic HD Demuxer", select "Filter properties", you will get the Configuration tab as shown above. If you select the audio stream, you will see that its properties are listed as "Dolby TrueHD 6 chans 88200 hz 24 bps". This is a bug in the demuxer and it appears on 96kHz and 192kHz streams. The problem can be fixed in AviSynth for 96kHz streams (by forcing the sample rate as 96kHz as we will see below), but for 192kHz you are out of luck (1). Hopefully this will be fixed in a newer version. Save the graph as sonic_avs.grf (or whatever you want to call it).

Create the following AviSynth script:

rate = 25 # arbitrary
frames = 5212#  = (PTS ticks / 90,000) * rate = 18,762,600/90,000 * 25
a = DirectShowSource("D:\Install\dvd-audio\TheCorrs\DVDAExplorer\sonic_avs.grf", video=false, fps=rate, framecount=frames)
# as stated this comes out as 88.2 kHz (which can be checked with Info), and the sample rate should be forced as 96 kHz:
a = a.AssumeSampleRate(96000)
v = BlankClip(length=frames, fps=rate)
AudioDub(v,a)
# although the channels in a 5.1ch MLP (id20) are stored in a different as in FLAC,
# the Sonic filters output them in the standard WAV order. Since this is the same order
# as in FLAC, the channels need not be reordered.
SoundOut()

When opening the script above in VirtualDub, the SoundOut gui will pop up:

Soundout.jpg

Check the Sound Info (the number of audio channels, the bit depth, the sample rate and the audio length). Press "Save FLAC". The "FLAC Compression Settings" will pop up where you can set the compression level:

Soundout2.jpg

Just leave it at the default setting (6), press "Save As" and give it a name. Finally, do the same for all the other tracks.

using AviSynth (LPCM)

All the examples I have seen contain stereo LPCM (and not 5.1ch LPCM). The AviSynth plugin NicAudio is able to decode those.

Create the following AviSynth script:

rate = 25 # arbitrary
frames = 6466 # = (PTS ticks / 90,000) * rate = 23,274,450/90,000 * 25
v = BlankClip(length=frames, fps=rate)
# insert the samplerate, bit-depth and the number of channels as input in NicLPCMSource:
a = NicLPCMSource("D:\Install\dvd-audio\RodStewart\track-01-[L R].lpcm", 96000, 24, 2)
AudioDub(v,a)
SoundOut()

When opening the script above in VirtualDub, the SoundOut gui will pop up:

Soundout3.jpg

Check the Sound Info (the number of audio channels, the bit depth, the sample rate and the audio length). Note that:

23,274,450 PTS ticks = 23,274,450/90,000 seconds = 258.605 seconds = 00:04:18.605 (4 min 18.605 seconds)

Press "Save FLAC". The "FLAC Compression Settings" will pop up where you can set the compression level:

Just leave it at the default setting (6), press "Save As" and give it a name.

Finally, do the same for all the other tracks.

using AviSynth input plugin for Foobar2000 v0.9 (MLP and LPCM)

Get Foobar2000 v0.9 and the AviSynth input plugin "foo_input_avs.dll". Put the input plugin in the foobar2000\components folder. After installing FLAC 1.2.0, create your AviSynth script. How to do that is explained in the previous sections, and won't be repeated here. Open your script in Foobar2000 using the File tab. Right-click on the script, select "Convert" and select "Convert to":

Foobar1.jpg

Change the encoding preset to "FLAC, level 5" (level is the compression level):

Foobar2.jpg

For 2.0ch MLP/LPCM, click "OK" and save it somewhere. For 5.1ch MLP/LPCM, we need to change the standard settings (due to an incompatibility between recent FLAC versions and Foobar2000 (2)). Click on the dots in the 'Encoding Preset' box (next to the triangular) to change the 'Commandline Encoder Settings':

Foobar3.jpg

The Parameters (standard value: -s -8 - -o %) should be changed to:

-s -8 - -o %d --channel-map=none

Click "OK", and click "OK" to start the encoding.

using eac3to

eac3to track.mlp track.flac

Playback of FLAC

There are many great audio players with FLAC support nowadays; see the "Players and plugins" list on the FLAC site.

References

Footnotes

  1. As stated in the introduction, you can't use Sonic filters for 192kHz streams. Patching the streams to a lower samplerate doesn't help. Apperently they are keying on the pack size to find out the samplerate. Until they fixed it, you will need to get Surcode MLP somewhere and use this to decode the streams to WAV.
  2. The new flac 1.1.3 requires multichannel wav files to be in WAVE_FORMAT_EXTENSIBLE, but currently fb2k generates it in WAVE_FORMAT_EX for 'compatibility' reason. source discussion
Personal tools