View Single Post
Old 6th August 2019, 15:52   #1  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,905
DolbyE Decoding Guide

One of the reason why I'm opening up this topic is that I wanna describe how to decode one of the most common audio format used in mezzanine files by TV Stations: DolbyE.
Although there are still no free open source DolbyE encoders yet Link, there are DolbyE decoders, however they are not very documented.

In my first attempt to index an .MXF masterfile that had a DolbyE stream, I tried to use FFAudioSource, LWLibavAudioSource and DGIndex but they all failed.
The reason why they failed is the non-standard configuration of having a DolbyE with 5.1+2.0 within the same track.
Let me explain this.
In general, whenever you have an XDCAM Masterfile, you could have the following configuration:

CH.1-2 DolbyE Dubbed Language 5.1
CH.3-4 DolbyE Original Language 5.1
CH.5-6 Stereo Downmix Dubbed Language 2.0
CH.7-8 Stereo Downmix Original Language 2.0

In this scenario, indexing the DolbyE streams (CH.1-2 and CH.3-4) works perfectly fine along with indexing the normal stereo tracks in CH.5-6 and CH.7-8, however, this configuration is hardly used.
Why? Well, that's because the playout ports generally only look for CH.1-2 and CH.3-4 as they are gonna be the ones that are gonna be re-encoded on the fly and then aired... So... what about the downmix information in the other channels? Well, by DolbyE specifications is actually possible to include 8 channels within a single stream, namely a 5.1 + 2.0 configuration which is gonna be:

- Front Left
- Front Right
- Center
- LFE
- Surround Left
- Surround Right
- Stereo Downmix Left
- Stereo Downmix Right

By doing so, broadcast engineers are generally happy as they can have the following audio configuration:

- CH.1-2 DolbyE Dubbed 5.1+2.0
- CH.3-4 DolbyE Original 5.1+2.0
- CH.5-6 PCM Stereo Downmix Dubbed 2.0
- CH.7-8 PCM Stereo Downmix Original 2.0

So, the streams in CH.1-2 and CH.3-4 are gonna be encoded on the fly and aired correctly, while CH.5-6 and CH.7-8 are just gonna be discarded and they are only gonna be kept for archival purposes in the mezzanine file.

Everything works, so we're good, right? No!
Here comes the first problem: although this way of having a 5.1+2.0 stream works for professional broadcast decoders along with the proprietary Dolby decoders, it really confuses open source indexers like FFAudioSource and LWLibavAudioSource as they think that it's a 7.1 stream and they try to decode it that way, thus getting a horrible, just horrible track full of undetermined noise. Using ffmpeg itself without Avisynth has the same result 'cause ffmpeg thinks that it's a 7.1 pcm_s24 stream and fails to decode it properly, however MediaInfo can detect that it's a DolbyE 5.1 + 2.0 stream, so... what's going on here? Something "fishy" is happening.
Well, in order to properly decode a DolbyE 5.1 + 2.0 stream, you need to first remux in a .u8 file with ffmpeg and then decode and encode it with ffmpeg, 'cause this way it's gonna be identified correctly by ffmpeg:

Code:
ffmpeg.exe  -i %1  -acodec copy  -f u8 -y out.u8
ffmpeg.exe  -i out.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.0:0.0.0 -y out1.wav
ffmpeg.exe  -i out.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.1:0.0.0 -y out2.wav
ffmpeg.exe  -i out.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.2:0.0.0 -y out3.wav
ffmpeg.exe  -i out.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.3:0.0.0 -y out4.wav
ffmpeg.exe  -i out.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.4:0.0.0 -y out5.wav
ffmpeg.exe  -i out.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.5:0.0.0 -y out6.wav
ffmpeg.exe  -i out.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.6:0.0.0 -y out7.wav
ffmpeg.exe  -i out.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.7:0.0.8 -y out8.wav

pause

That's pretty much it.
I hope it helps you folks trying to decode and re-encode DolbyE 5.1 + 2.0 streams.


As a side note, DolbyE can also be carried as 2 fake mono pairs instead of 1 fake stereo pair as above, therefore you would need to merge the two tracks before using the .u8 trick, like so:


Quote:
ffmpeg.exe -i "Input1.wav" -i "Input2.wav" -filter_complex "[0:a][1:a]join=inputs=2:channel_layout=stereo[a]" -map "[a]" -c:a pcm_s24le -ar 48000 -f wav "DolbyE.wav"

ffmpeg.exe -i "DolbyE.wav" -map 0:0 -acodec copy -f u8 -y "out.u8"
and then it's business as usual and you can use the code above to decode the u8.


And of course, if you also want to re-encode to PCM 5.1 and PCM 2.0 you can easily do that like this:

Code:
 #Extract DolbyE track 1
    ffmpeg  -i "DolbyE.mov"  -map 0:1 -acodec copy -f u8 -y "stream1.u8"
    #Extract each channel of DolbyE 5.1
    ffmpeg  -i "stream1.u8" -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.0:0.0.0 -y "FL.wav"
    ffmpeg  -i "stream1.u8" -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.1:0.0.0 -y "FR.wav"
    ffmpeg  -i "stream1.u8" -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.2:0.0.0 -y "CC.wav"
    ffmpeg  -i "stream1.u8" -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.3:0.0.0 -y "LFE.wav"
    ffmpeg  -i "stream1.u8" -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.4:0.0.0 -y "SL.wav"
    ffmpeg  -i "stream1.u8" -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.5:0.0.0 -y "SR.wav"
    #Extract each channel of DolbyE 2.0
    ffmpeg  -i "stream1.u8" -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.6:0.0.0 -y $jobOutputFolder:Left.wav
    ffmpeg  -i "stream1.u8" -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.7:0.0.0 -y $jobOutputFolder:Right.wav
    #Audio 5.1
    ffmpeg -i "FL.wav" -i "FR.wav" -i "CC.wav" -i "LFE.wav" -i "SL.wav" -i "SR.wav" -filter_complex "[0:a][1:a][2:a][3:a][4:a][5:a]join=inputs=6:channel_layout=5.1:map=0.0-FL|1.0-FR|2.0-FC|3.0-LFE|4.0-BL|5.0-BR[a]" -map "[a]" -c:a pcm_s24le -ar 48000 -f wav -y "Track1_51.wav"
    #Audio 2.0
    ffmpeg -i "Left.wav" -i "Right.wav" -filter_complex "[0:a][1:a]join=inputs=2:channel_layout=stereo[a]" -map "[a]" -c:a pcm_s24le -ar 48000 -f wav -y "Track2_20.wav"

If you want to try it yourself, you can try it with those sample files:

Sample 1: DolbyE.mov

Sample 2: DolbyE.mxf

Cheers,
Frank.

Last edited by FranceBB; 20th July 2023 at 12:13.
FranceBB is offline   Reply With Quote