DVDAGuide
From Avisynth
[edit] Decrypting and re-encoding DVD-Audio
[edit] 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.
A DVD-Audio 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, the encryption is broken, but it is not possible to remove the watermarks yet.
The purpose of this guide is the following:
- It explains 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 re-encodings on your PC without any hassle (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.
As of today, it is not possible to decode the MLP tracks of your DVD-Audio using open source (or even free) tools. So you need to get one of the following two tools:
- The Sonic filters "Sonic HD Demuxer" and "Sonic Cinemaster@Audio Decoder 4.3.0". They are directshow filters contained in the package "Sonic.CinePlayer.HD.DVD.Decoder.v4.3.rar".
- Surcode MLP.
We can't tell you where to find them, so don't bother asking.
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:
- CinemasterAudio.dll v4.2.0.840, SonicHDDemuxer.dll v4.2.0.59
- CinemasterAudio.dll v4.3.0.151, SonicHDDemuxer.dll v4.3.0.73
- CinemasterAudio.dll v4.3.0.169, SonicHDDemuxer.dll v4.3.0.89
[edit] Needed tools in this guide
- 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.
[edit] Decrypting DVD-Audio
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
You need to decrypt the AOBs one by one. As you can see, this DVD-A is protected by CPPM.
[edit] Demuxing audio streams (MLP or LPCM) from AOBs
Open DVDAExplorer_a7.exe and open AUDIO_TS.IFO:
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):
[edit] Converting the 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.
[edit] Converting MLP to FLAC 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":
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":
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:
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:
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:
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].
[edit] Converting MLP/LPCM to FLAC using AviSynth
[edit] Using FLAC 1.2.0 and the SoundOut AviSynth plugin
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:
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:
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.
[edit] Converting LPCM to FLAC using AviSynth
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:
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.
[edit] Converting MLP/LPCM to FLAC using the AviSynth input plugin for Foobar2000 v0.9
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":
Change the encoding preset to "FLAC, level 5" (level is the compression level):
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':
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.
[edit] Converting MLP to FLAC with eac3to
eac3to track.mlp track.flac
[edit] Playback of FLAC
There are two ways to play FLAC using open source tools:
- Get Foobar 0.9.4.3 (or a newer version). It supports FLAC natively.
- Get Illiminable's directshow filters.
The closed source, but free directshow filter CoreFLAC should be able to play them too, but I didn't have any success playing my 94kHz 24bit 5.1ch FLAC tracks with it.
[edit] References
- http://www.minnetonkaaudio.com/PDFs/MLP_Manual.pdf
- DVD-A specification and authoring tools: http://dvd-audio.sourceforge.net/
[edit] Footnotes
- 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.
- 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














