Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
|
6th August 2019, 15:52 | #1 | Link | |
Broadcast Encoder
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,904
|
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:
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. |
|
10th August 2019, 08:55 | #2 | Link |
Big Bit Savings Now !
Join Date: Feb 2007
Location: close to the wall
Posts: 1,545
|
Many thanks !
__________________
"To bypass shortcuts and find suffering...is called QUALity" (Die toten Augen von Friedrichshain) "Data reduction ? Yep, Sir. We're that issue working on. Synce invntoin uf lingöage..." |
12th August 2019, 10:42 | #3 | Link |
Registered User
Join Date: Nov 2004
Location: Poland
Posts: 2,843
|
Try adding this before -i:
-guess_layout_max 0 which will cause ffmpeg to stop guessing channel order. I think it simply treats your source as 7.1, which is typical for ffmpeg and 8 channels input (which in case of DolbyE is of course causing massive issues). You may want after mapping tell it how many ac it actually has, eg -ac 2. No idea if this is needed for DolbyE or not. If you have not seen it already: https://trac.ffmpeg.org/wiki/AudioChannelManipulation very useful. If DolbyE track is detected properly it should work. If not you may want to map it to be stereo and then decode. All can be done in 1 command I think. Last edited by kolak; 12th August 2019 at 11:10. |
10th March 2023, 11:06 | #4 | Link | |||
Broadcast Encoder
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,904
|
Hi everyone,
I'm bringing this topic back to attention 'cause we've been working on a patch to fix a decoding issue for normal DolbyE streams and one to introduce DolbyED2 Atmos decoding over the last 7 months, however the FFMpeg community has been ignoring us: https://trac.ffmpeg.org/ticket/9864 This patch by Nicolas Gaullier https://patchwork.ffmpeg.org/project...ier@cji.paris/ should really be merged upstream 'cause it's really really important. That bug affects the 20 bits section of standard DolbyE 5.1 + 2.0 files which raises an error “Read past end of channel XX” while decoding them with FFMpeg. That is a bug 'cause it's not just a "simple warning" but rather a real error as it really truncates the audio, hence throwing away few ms. When I decode the very same file with the official Dolby DP600, however, there are no warnings and the decoding completes correctly. By applying Nicolas' patch, there's gonna be a simple warning, but data will be preserved and we're gonna avoid the few ms of mute audio. This is really important as we use DolbyE 5.1 + 2.0 in production on a daily basis, therefore it should really be merged sooner rather than later. The last updated version is here: https://patchwork.ffmpeg.org/project...ier@cji.paris/ in which the required documentation about the decoder and the demuxer has been added. In particular, the Dolby E audio decoder is a raw decoder without any further processing, which means the output sample rate is different from the 48KHz input sample rate. A dolby E stream is always carried in a s337m muxer, as a raw file or muxed in any format that is able to transport an AES3 or an equivalent uncompressed audio stream (stereo, 48KHz, 16/20/24 bits). Currently, only wav and raw file formats are supported. Other formats require two passes of processing: a first one to extract the s337m stream and another to decode it. In case of AES3, or if the format itself supports it, the non-PCM mode may be signaled, but in a more general manner, a stream has to be probed to be handled as dolby E rather than pcm. By default, stream probing is enabled which forbids pass-through as no s337m muxer is implemented yet. In order to pass-through a dolby E stream, @code{--non_pcm_mode copy} must be specified (see input muxer options). The other patch we're trying to get merged upstream is the following: https://trac.ffmpeg.org/attachment/t...-support.patch Such a patch allows DolbyED2 5.1.4 Atmos to be decoded. Unlike DolbyE which is carried as 1 AES (i.e 1 fake stereo pair - so 1 .wav - or 2 fake mono pairs - so 2 .wav), DolbyED2 is carried as 2 AES (i.e 2 fake stereo pairs) so either 2 separate fake stereo .wav files that need to be merged together to be decoded or 1 fake quad .wav file. If we use the same logic as DolbyE, however, without the patch the decoder doesn't recognize the file as a valid file and therefore doesn't decode it. We contacted the FFMpeg community 7 months ago at ffmpeg-devel@ffmpeg.org and heard nothing back from them. We also tried to contact the current maintainer, foobaz86@gmail.com, via email on 29/09/2022 and heard nothing back from him. We tried to contact the FFMpeg community again at ffmpeg-devel@ffmpeg.org on 14/10/2022 with the following email: Quote:
and I've been ignored again. I tried again to contact the ffmpeg-devel@ffmpeg.org on 16/02/2023: Quote:
Needless to say, I've been ignored once again. Days passed and today, 10/03/2023 I wrote again to the FFMpeg community: Quote:
Let's see if they'll keep ignoring us... Needless to say such a thing would never happen in the Avisynth community where everyone is always available and kind and actually bothers to reply. I wish there were people like Ferenc, DTL, qyot, jpsdr etc in the ffmpeg community too... |
|||
11th March 2023, 00:18 | #5 | Link |
Registered Developer
Join Date: Mar 2010
Location: Hamburg/Germany
Posts: 10,346
|
Are you aware that none of your mails ever even arrived on the mailing list? Should've probably checked that, its easy to ignore mails that noone sees.
Additionally, the patchset you are referring to in your latest "mail" (dolby e in s337m in wav, or something) was just re-submitted yesterday. Before that, it was on the mailing list three weeks ago and was actually being reviewed by Tomas Härdin. Nothing about that indicates in any way that the patches are being "ignored". They got reviewed, and only a day ago, a revised version was posted, presumably with fixes from said review. So... everything is working as designed so far?
__________________
LAV Filters - open source ffmpeg based media splitter and decoders Last edited by nevcairiel; 11th March 2023 at 00:30. |
11th March 2023, 10:28 | #6 | Link | ||||
Broadcast Encoder
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,904
|
Quote:
Quote:
Last time around, the argument was that it was the responsibility of the "current" maintainer so we contacted the current maintainer directly to his email, namely foobaz86@gmail.com but heard nothing back. Quote:
I even tried to ask for an explanation on LinkedIn in the official ffmpeg page and got ignored, while on the bug tracker the only one who is still replying is Balling who unfortunately is not a maintainer and cannot merge it anyway. I still find this whole email thing much harder to follow and work with than the simple GitHub pull requests we have here on Doom9 for Avisynth. I'm gonna add one last thing which I didn't post before but for the sake of transparency I will. In one of my attempts while sending an email, this was what one of the Devs commented in their own chat: Quote:
The reason is that back in the days those people were kids, I was young myself when I started watching anime in 2006. Then I eventually joined crunchyroll and then viewster and then Sky in 2016. The same happened for other people who were enthusiast first and then got a professional position across different broadcasting companies and streaming platforms. They should be proud that open source software is currently being used by companies across the world and certainly from the support I constantly get from the Avisynth community I feel like they are, but apparently it's not quite the same for ffmpeg... |
||||
11th March 2023, 18:43 | #7 | Link | |
Registered Developer
Join Date: Mar 2010
Location: Hamburg/Germany
Posts: 10,346
|
Quote:
Refer to the ML archive from February (which you can also use to see that I could not find any mails from you): http://ffmpeg.org/pipermail/ffmpeg-d...ry/thread.html There is numerous back and forth on the patchset between Nicolas and Tomas Härdin, reviewing the patchset. I'm not sure what you are stating here? "No feedback whatsoever"?
__________________
LAV Filters - open source ffmpeg based media splitter and decoders Last edited by nevcairiel; 11th March 2023 at 18:46. |
|
11th March 2023, 19:33 | #8 | Link | ||
Broadcast Encoder
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,904
|
Quote:
Uhmmm something is broken, it looks like something is filtering our mails in and out when we use our office 365 emails... I think I got the culprit and they should be ok now, I'll try once again to ping on Monday and see whether this time it goes through. Thanks for helping me out, by the way. No one else ever bothered before. If I knew I would have asked you 7 months ago instead of wasting all this time. Fingers crossed. p.s this is why I said that we didn't get a reply: http://ffmpeg.org/pipermail/ffmpeg-d...ch/307293.html To quote Nicolas: Quote:
Last edited by FranceBB; 11th March 2023 at 21:26. |
||
11th March 2023, 10:40 | #9 | Link | |
Broadcast Encoder
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,904
|
Quote:
Why? I mean how? I'm subscribed to the mailing list so I should be allowed to send. Does it mean that everyone I put in cc has to be registered too for the email to go through? |
|
4th April 2023, 23:31 | #12 | Link |
Big Bit Savings Now !
Join Date: Feb 2007
Location: close to the wall
Posts: 1,545
|
Now how original is that?
That moeboid came before: https://en.wikipedia.org/wiki/File:L...12-2014%29.svg
__________________
"To bypass shortcuts and find suffering...is called QUALity" (Die toten Augen von Friedrichshain) "Data reduction ? Yep, Sir. We're that issue working on. Synce invntoin uf lingöage..." |
22nd June 2023, 18:20 | #13 | Link | |
Registered User
Join Date: Jun 2023
Posts: 12
|
I have a feed recording from BT sport 4K, please guide me how to convert Dolby E
Quote:
Last edited by bbc; 22nd June 2023 at 18:26. Reason: add link |
|
23rd June 2023, 12:44 | #14 | Link | |||||||||||||
Broadcast Encoder
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,904
|
I saw that game. Inter tried its best to contain City but they just couldn't and in the end they went 1 down and never managed to recover.
Anyway, in Italy we aired that game in BT2020 HLG at 1000 nits 50p, I didn't know that the BT Sport master was actually PQ BT2020 1200 nits. Well, moving on to the DolbyE part, looks like we're dealing with: CH.1-2 MP2 Stereo English Full Mix CH.3-4 MP2 Stereo International Full Mix CH.5-6 DolbyE 5.1 + 2.0 English CH.7-8 DolbyE 5.1 + 2.0 International however, DolbyE was NOT muxed as a standard SMPTE ST 337 but rather as SMPTE ST 302. This makes things a bit more difficult 'cause we need to first remux as SMPTE ST337 and then work with the stream. Step 1: Decode the first MP2 stereo audio track and save it as PCM lossless stereo 48000Hz .wav with Avisynth + Virtualdub and save it as "stream1.wav": Quote:
Decode the second MP2 stereo audio track and save it as PCM lossless stereo 48000Hz .wav with Avisynth + Virtualdub and save it as "stream2.wav": Quote:
Index the first DolbyE 5.1 + 2.0 SMPTE ST 302 track and remux it as DolbyE 5.1 + 2.0 SMPTE ST 337.wav (it's carried as a fake PCM 48000Hz 32bit stereo track) and save it as "stream3.wav": Quote:
Index the second DolbyE 5.1 + 2.0 SMPTE ST 302 track and remux it as DolbyE 5.1 + 2.0 SMPTE ST 337.wav (it's carried as a fake PCM 48000Hz 32bit stereo track) and save it as "stream4.wav": Quote:
This will therefore give us the following files: CH.1-2 Stereo PCM 48'000Hz 16bit Stream1.wav Quote:
CH.3-4 Stereo PCM 48'000Hz 16bit Stream2.wav Quote:
CH.5-6 DolbyE 5.1 + 2.0 48000Hz 20bit Stream3.wav Quote:
CH.7-8 DolbyE 5.1 + 2.0 48000Hz 20bit Stream4.wav Quote:
Step 2: Get rid of the zero padding in stream3.wav and stream4.wav. Given that the DolbyE decoder inside FFMpeg is very picky about the input, it will NOT like zero filled streams and, when we remuxed from SMPTE ST 302 to SMPTE ST 337 with VirtualDub after going through LWLibavAudioSource() as indexer, we zero filled a 24bit stream into 32bit, so we gotta get rid of those zeroes. To do that, we remux from 32bit wav to 24bit wav like so: Quote:
Step 3: create the u8 that will be used to feed the decoder from the newly created 24bit stream3_v2.wav and stream4_v2.wav Quote:
Step 4: Decode DolbyE to get the relative 16 channels (5.1 + 2.0 downmix of stream 3 and 5.1 + 2.0 downmix of stream 4): Quote:
Step 5: Put the 16 PCM decoded discrete separate channels together to create two 5.1 tracks and two stereo tracks Quote:
Step 6: Remux everything to .mkv with MKVToolnix so that we're gonna have the following file: Video: UHD H.265 50 Mbit/s High Profile Level 5.1 4:2:2 10bit BT2020 HDR PQ 1200 nit Audio Track 1: PCM Stereo 48000Hz 16bit English Audio Track 2: PCM Stereo 48000Hz 16bit International Audio Track 3: PCM 5.1 48000Hz 24bit English Audio Track 4: PCM Stereo downmix 48000Hz 24bit English Audio Track 5: PCM 5.1 48000Hz 24bit International Audio Track 6: PCM Stereo downmix 48000Hz 24bit International Quote:
Here are the individual PCM.wav decoded audio tracks, namely stream1.wav stream2.wav stream3_51.wav stream3_20.wav stream4_51.wav stream4_20.wav: https://we.tl/t-9LFKrwYIlo (link valid for 7 days) Here's is out1, out2.wav, out3.wav, out4.wav, out5.wav, out6.wav, out7.wav, out8.wav, out9.wav, out10.wav, out11.wav, out12.wav, out13.wav, out14.wav, out15.wav, out16.wav in case you wanted them as mono channels straight from the DolbyE decoding: https://we.tl/t-FTJoy8iI1q (link valid for 7 days) Here's the remuxed mkv with video and all the PCM audio: https://www.transfernow.net/dl/2023062347isW8vn (link valid for 7 days) Open source rocks Last edited by FranceBB; 23rd June 2023 at 12:49. |
|||||||||||||
23rd June 2023, 18:21 | #15 | Link | |
Registered User
Join Date: Jun 2023
Posts: 12
|
thanks for the guide , i will try it tomorrow . I have a 4K feed version from UEFA . it also has multiple Dolby E audio tracks. Can you write a tutorial, if possible. In addition, I want to convert to EAC3 (DD+) because PCM audio can't be decoded on some TV devices.
Quote:
|
|
24th June 2023, 18:35 | #17 | Link |
Moderator
Join Date: Feb 2005
Location: Spain
Posts: 6,915
|
Use VirtualDub2:
https://www.videohelp.com/software/VirtualDub2
__________________
BeHappy, AviSynth audio transcoder. |
24th June 2023, 18:48 | #18 | Link |
Moderator
Join Date: Feb 2005
Location: Spain
Posts: 6,915
|
Steps 1 to 3 are a workaround to obtain a DolbyE stream than can be decoded by ffmpeg, until a better support of DolbyE muxed in containers.
If you want recode the DolbyE stream to eac3 the steps 4 and 5 can be replaced by: ffmpeg.exe -hide_banner -i "A:\MEDIA\temp\stream3_v2.u8" -filter_complex "asplit [s][d]; [s] pan=5.1|c0=c0|c1=c1|c2=c2|c3=c3|c4=c4|c5=c5 [ss]; [d] pan=stereo|c0=c6|c1=c7 [dd]" -map "[ss]" -ar 48000 -acodec eac3 -ab 640k 1_51.eac3 -map "[dd]" -ar 48000 -acodec eac3 -ab 256k 1_20.eac3 The same for stream4_v2.u8, of course you can change the bitrates.
__________________
BeHappy, AviSynth audio transcoder. |
25th June 2023, 06:35 | #19 | Link | |
Registered User
Join Date: Jun 2023
Posts: 12
|
Quote:
I get this error : Filesize 5191465062 invalid for wav, output file will be broken |
|
25th June 2023, 10:12 | #20 | Link | ||
Moderator
Join Date: Feb 2005
Location: Spain
Posts: 6,915
|
Quote:
ffmpeg.exe -hide_banner -i "A:\MEDIA\temp\stream3.wav" -acodec pcm_s24le -y "A:\MEDIA\temp\stream3_v2.wav" Of course wav files greater 4 GB can be broken. I haven't big files to test it, and I don't know if output can be used in step 3, but continue with it ignoring the warning. If the output .u8 is recognized by ffmpeg like DolbyE can work fine. Something like: Quote:
__________________
BeHappy, AviSynth audio transcoder. Last edited by tebasuna51; 25th June 2023 at 10:43. Reason: add info |
||
Thread Tools | Search this Thread |
Display Modes | |
|
|