AkarinVS / L-SMASH-Works

Works based on L-SMASH project; This repo focuses on the common portion and the VapourSynth plugin. AviSynth users please use https://github.com/HomeOfAviSynthPlusEvolution/L-SMASH-Works. ffmpeg 5.0+ please use ffmpeg-4.5 branch.
47 stars 11 forks source link

DolbyE audio decoding doesn't work and DolbyE tracks are decoded as noise instead #17

Open FranceBB opened 2 years ago

FranceBB commented 2 years ago

DolbyE audio decoding doesn't work and DolbyE tracks are decoded as noise instead.

Expected behavior

Once Indexing an mxf file with DolbyE 5.1 tracks is concluded, LWLibavAudioSource() should be able to recognize them and index them correctly providing a nice decode. The decoding is already supported in FFMpeg.

Actual behavior of LWLibavAudioSource

Audio is indexed and decoded as noise which might damage hardware.

How to reproduce

Step 1: Download the sample file from here: https://we.tl/t-R8dRX8gIzT Step 2: Index it with LWLibavAudioSource() Step 3: Hear the noise on the first track and on the second track via VirtualDub or whatever

Avisynth Script

video=LWLibavVideoSource("\\mibctvan000\Ingest\MEDIA\temp\DolbyE.mxf")
audio=LWLibavAudioSource("\\mibctvan000\Ingest\MEDIA\temp\DolbyE.mxf")
AudioDub(video, audio)

Audio Layout of the Sample:

The sample has the following audio layout: Track 1: DolbyE 5.1 + 2.0 Stereo Downmix Italian Track 2: DolbyE 5.1 + 2.0 Stereo Downmix English Track 3: PCM S24LE 2.0 Stereo Downmix Italian (you can index and listen to this one just fine) Track 4: PCM S24LE 2.0 Stereo Downmix English (you can index and listen to this one just fine)

Behavior with other indexers:

The very same happens with FFAudioSource() and BestAudioSource()

Mediainfo

General
Complete name                            : \\mibctvan000\Ingest\MEDIA\temp\DolbyE.mxf
Format                                   : MXF
Commercial name                          : XDCAM HD422
Format version                           : 1.3
Format profile                           : OP-1a
Format settings                          : Open / Incomplete
File size                                : 872 MiB
Duration                                 : 1 min 2 s
Overall bit rate                         : 116 Mb/s
Encoded date                             : 2021-10-25 12:27:15.452
Writing application                      : Omneon Inc. Omneon Media Subsystem 8.2.0.0.1
Writing library                          : Omneon Media Api (windows)

Video
ID                                       : 2
Format                                   : MPEG Video
Commercial name                          : XDCAM HD422
Format version                           : Version 2
Format profile                           : 4:2:2@High
Format settings                          : CustomMatrix / BVOP
Format settings, BVOP                    : Yes
Format settings, Matrix                  : Custom
Format settings, GOP                     : M=3, N=12
Format settings, picture structure       : Frame
Format settings, wrapping mode           : Frame
Codec ID                                 : 0D01030102046101-0401020201040300
Duration                                 : 1 min 2 s
Bit rate mode                            : Constant
Bit rate                                 : 50.0 Mb/s
Width                                    : 1 920 pixels
Clean aperture width                     : 1 571 pixels / 1 571 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate                               : 25.000 FPS
Standard                                 : Component
Color space                              : YUV
Chroma subsampling                       : 4:2:2
Bit depth                                : 8 bits
Scan type                                : Interlaced
Scan order                               : Top Field First
Compression mode                         : Lossy
Bits/(Pixel*Frame)                       : 0.965
Time code of first frame                 : 00:00:00:00
Time code source                         : Group of pictures header
GOP, Open/Closed                         : Closed
Stream size                              : 375 MiB (43%)
Color range                              : Limited
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709

Audio #1
ID                                       : 3-1
Format                                   : Dolby E
Format settings                          : Little
Format settings, wrapping mode           : Frame (BWF)
Muxing mode                              : SMPTE ST 337
Codec ID                                 : 0D01030102060100-0402020203021C00
Duration                                 : 1 min 2 s
Bit rate mode                            : Constant
Bit rate                                 : 1 291 kb/s
Channel(s)                               : 6 channels
Channel layout                           : L C Ls X R LFE Rs X
Sampling rate                            : 48.0 kHz
Frame rate                               : 25.000 FPS (1920 SPF)
Bit depth                                : 20 bits
Delay relative to video                  : -9 h 59 min
Stream size                              : 9.67 MiB (1%)
Title                                    : Program_1
Locked                                   : Yes

Audio #2
ID                                       : 3-2
Format                                   : Dolby E
Format settings                          : Little
Format settings, wrapping mode           : Frame (BWF)
Muxing mode                              : SMPTE ST 337
Codec ID                                 : 0D01030102060100-0402020203021C00
Duration                                 : 1 min 2 s
Bit rate mode                            : Constant
Bit rate                                 : 505 kb/s
Channel(s)                               : 2 channels
Channel layout                           : X X X L X X X R
Sampling rate                            : 48.0 kHz
Frame rate                               : 25.000 FPS (1920 SPF)
Bit depth                                : 20 bits
Delay relative to video                  : -9 h 59 min
Stream size                              : 3.78 MiB (0%)
Title                                    : Program_2
Locked                                   : Yes

Audio #3
ID                                       : 5-1
Format                                   : Dolby E
Format settings                          : Little
Format settings, wrapping mode           : Frame (BWF)
Muxing mode                              : SMPTE ST 337
Codec ID                                 : 0D01030102060100-0402020203021C00
Duration                                 : 1 min 2 s
Bit rate mode                            : Constant
Bit rate                                 : 1 291 kb/s
Channel(s)                               : 6 channels
Channel layout                           : L C Ls X R LFE Rs X
Sampling rate                            : 48.0 kHz
Frame rate                               : 25.000 FPS (1920 SPF)
Bit depth                                : 20 bits
Delay relative to video                  : -9 h 59 min
Stream size                              : 9.67 MiB (1%)
Title                                    : Program_1
Locked                                   : Yes

Audio #4
ID                                       : 5-2
Format                                   : Dolby E
Format settings                          : Little
Format settings, wrapping mode           : Frame (BWF)
Muxing mode                              : SMPTE ST 337
Codec ID                                 : 0D01030102060100-0402020203021C00
Duration                                 : 1 min 2 s
Bit rate mode                            : Constant
Bit rate                                 : 505 kb/s
Channel(s)                               : 2 channels
Channel layout                           : X X X L X X X R
Sampling rate                            : 48.0 kHz
Frame rate                               : 25.000 FPS (1920 SPF)
Bit depth                                : 20 bits
Delay relative to video                  : -9 h 59 min
Stream size                              : 3.78 MiB (0%)
Title                                    : Program_2
Locked                                   : Yes

Audio #5
ID                                       : 6
Format                                   : PCM
Format settings                          : Little
Format settings, wrapping mode           : Frame (BWF)
Codec ID                                 : 0D01030102060100
Duration                                 : 1 min 2 s
Bit rate mode                            : Constant
Bit rate                                 : 2 304 kb/s
Channel(s)                               : 2 channels
Sampling rate                            : 48.0 kHz
Frame rate                               : 25.000 FPS (1920 SPF)
Bit depth                                : 24 bits
Stream size                              : 17.3 MiB (2%)
Locked                                   : Yes

Audio #6
ID                                       : 7
Format                                   : PCM
Format settings                          : Little
Format settings, wrapping mode           : Frame (BWF)
Codec ID                                 : 0D01030102060100
Duration                                 : 1 min 2 s
Bit rate mode                            : Constant
Bit rate                                 : 2 304 kb/s
Channel(s)                               : 2 channels
Sampling rate                            : 48.0 kHz
Frame rate                               : 25.000 FPS (1920 SPF)
Bit depth                                : 24 bits
Stream size                              : 17.3 MiB (2%)
Locked                                   : Yes

Text
ID                                       : 8-777
Format                                   : Teletext Subtitle
Muxing mode                              : Ancillary data / OP-47 / SDP
Duration                                 : 1 min 2 s

Other #1
ID                                       : 1-Material
Type                                     : Time code
Format                                   : MXF TC
Frame rate                               : 25.000 FPS
Time code of first frame                 : 10:00:00:00
Time code settings                       : Material Package
Time code, striped                       : Yes

Other #2
ID                                       : 1-Source
Type                                     : Time code
Format                                   : MXF TC
Frame rate                               : 25.000 FPS
Time code of first frame                 : 10:00:00:00
Time code settings                       : Source Package
Time code, striped                       : Yes

Other #3
ID                                       : System scheme 1-1-0
Muxing mode                              : System scheme 1

How to decode DolbyE 5.1 with FFMpeg

@echo off 
setlocal EnableDelayedExpansion

cd /d %~dp0

for %%a in (%*) do  (
   call :inizia %%a
   shift
)
exit

:inizia

ffmpeg.exe  -i %1  -map 0:1 -acodec copy  -f u8 -y stream1.u8
ffmpeg.exe  -i %1  -map 0:2 -acodec copy  -f u8 -y stream2.u8
ffmpeg.exe  -i stream1.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.0:0.0.0 -y out1.wav
ffmpeg.exe  -i stream1.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.1:0.0.0 -y out2.wav
ffmpeg.exe  -i stream1.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.2:0.0.0 -y out3.wav
ffmpeg.exe  -i stream1.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.3:0.0.0 -y out4.wav
ffmpeg.exe  -i stream1.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.4:0.0.0 -y out5.wav
ffmpeg.exe  -i stream1.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.5:0.0.0 -y out6.wav
ffmpeg.exe  -i stream1.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.6:0.0.0 -y out7.wav
ffmpeg.exe  -i stream1.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.7:0.0.8 -y out8.wav
ffmpeg.exe  -i stream2.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.0:0.0.0 -y out9.wav
ffmpeg.exe  -i stream2.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.1:0.0.0 -y out10.wav
ffmpeg.exe  -i stream2.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.2:0.0.0 -y out11.wav
ffmpeg.exe  -i stream2.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.3:0.0.0 -y out12.wav
ffmpeg.exe  -i stream2.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.4:0.0.0 -y out13.wav
ffmpeg.exe  -i stream2.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.5:0.0.0 -y out14.wav
ffmpeg.exe  -i stream2.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.6:0.0.0 -y out15.wav
ffmpeg.exe  -i stream2.u8 -acodec pcm_s24le -ar 48000 -ac 1 -map_channel 0.0.7:0.0.8 -y out16.wav

pause

:eof
AkarinVS commented 2 years ago

Thanks for the report.

I haven't yet taken a closer look, but is it possible that "Delay relative to video: -9 h 59 min" affected the indexing? (the delay moved the audio tracks so far ahead that when the video starts, they are already over.)

Though in this case, the audio output shouldn't be noise....

FranceBB commented 2 years ago

Not really. That's the timecode set at 10.00.00.00 which is common for broadcasters. No, I think that LWLibavAudioSource() is trying to decode it incorrectly and that the channel map has to be specified. This is actually common for DolbyE files (see FFMpeg), but it has to be done in the code

p.s please download the sample (or reupload it somewhere) 'cause WeTransfer deletes it after 7 days

AkarinVS commented 2 years ago

Thanks very much for the explanation. I will see what I can do.

FranceBB commented 2 years ago

By the way we're also discussing this here: https://forum.doom9.org/showthread.php?p=1955905 but still, there must be something we can do from an indexer point of view.

FranceBB commented 2 years ago

Here's another sample:

https://user-images.githubusercontent.com/18946343/140714877-ca9ab507-b8a1-4738-af1d-0bcc61bc99df.mov

(unfortunately it's just 1 second 'cause GitHub is picky about 10 MB max file size)

FranceBB commented 2 years ago

And another one

https://user-images.githubusercontent.com/18946343/140722392-a623950a-8248-4863-9ef8-0d70b6c86236.mov

FranceBB commented 1 year ago

Here's another sample, this time without video, just a normal DolbyE 5.1 + 2.0 track muxed as .wav (SMPTE ST 337) and zipped (.zip) for GitHub upload. DolbyE_51_20.zip