gpac / mp4box.js

JavaScript version of GPAC's MP4Box tool
https://gpac.github.io/mp4box.js/
BSD 3-Clause "New" or "Revised" License
1.94k stars 326 forks source link

Wrong Audio Channel Count #261

Closed fyuvb closed 2 years ago

fyuvb commented 2 years ago

Thank for this great project.

I was trying to use mp4box.js to do some metadata collection. However, I found that there might be something wrong with the audio channel count metadata retrieval. It seemed to me that it tend to return that there are 2 channels even it is a mono channel audio.

Here is an example:

https://user-images.githubusercontent.com/35753211/148497627-f4cf1ba8-3373-4299-8222-bdd66afb7b35.mp4

I have used local mp4box binary to check the meta and here is the output:

  • Movie Info * Timescale 1000 - 2 tracks Computed Duration 00:00:05.015 - Indicated Duration 00:00:05.039 Fragmented File: no File Brand isom - version 512 Compatible brands: isom iso2 avc1 mp41 Created: UNKNOWN DATE Modified: UNKNOWN DATE File has no MPEG4 IOD/OD

iTunes Info: Encoder Software: Lavf58.45.100 1 UDTA types: meta (1)

Track # 1 Info - TrackID 1 - TimeScale 12288 Media Duration 00:00:05.000 - Indicated Duration 00:00:05.000 Track has 1 edit lists: track duration is 00:00:05.000 Media Info: Language "Undetermined (und)" - Type "vide:avc1" - 120 samples Visual Sample Entry Info: width=1920 height=1080 (depth=24 bits) Visual Track layout: x=0 y=0 width=1920 height=1080 MPEG-4 Config: Visual Stream - ObjectTypeIndication 0x21 AVC/H264 Video - Visual Size 1920 x 1080 AVC Info: 1 SPS - 1 PPS - Profile High @ Level 4 NAL Unit length bits: 32 Pixel Aspect Ratio 1:1 - Indicated track size 1920 x 1080 Chroma format YUV 4:2:0 - Luma bit depth 8 - chroma bit depth 8 SPS#1 hash: 6960433C4AA4D8A48045D5DD969C650A90A7AE0C PPS#1 hash: 6648DAA985D842149E548D6CDE2C2151B02BF03F Self-synchronized RFC6381 Codec Parameters: avc1.640028 Only one sync sample Max sample duration: 512 / 12288

Track # 2 Info - TrackID 2 - TimeScale 44100 Media Duration 00:00:05.038 - Indicated Duration 00:00:05.038 Track has 1 edit lists: track duration is 00:00:05.015 Media Info: Language "Undetermined (und)" - Type "soun:mp4a" - 217 samples MPEG-4 Config: Audio Stream - ObjectTypeIndication 0x40 MPEG-4 Audio AAC LC (AOT=2 implicit) - 1 Channel(s) - SampleRate 44100 Synchronized on stream 1 RFC6381 Codec Parameters: mp4a.40.2 Alternate Group ID 1 All samples are sync Max sample duration: 1024 / 44100

However, mp4box.js would give meta saying that there are two channels in audio. Screen Shot 2022-01-07 at 1 44 33 PM

Is there something I missed? Thank you so much!

cconcolato commented 2 years ago

I think there is an inconsistency in your file. At the container level, the value of channelcount in the Sample Entry is 2. Running MP4Box(.exe) with -diso gives the following

<MPEGAudioSampleDescriptionBox Size="90" Type="mp4a" Specification="p14" Container="stsd"  DataReferenceIndex="1" SampleRate="44100" Channels="2" BitsPerSample="16">

The codecs parameter as reported in your logs says:

RFC6381 Codec Parameters: mp4a.40.2

What is reported in:

MPEG-4 Audio AAC LC (AOT=2 implicit) - 1 Channel(s) - SampleRate 44100

is obtained by parsing the DecoderSpecificInfo which has a channelconfiguration field set to 1, setting the channel count to 1.

mp4box.js does not go as deep as mp4box(.exe) and does not show the inconsistency.

I'm closing this issue as it does not seem to be a bug in mp4box.js.

nonitasharmaMSFT commented 8 months ago

@cconcolato @fyuvb We are also facing the similar issue and we can see this incorrect identification of channel counts in multiple videos, sharing some here for reference:

  1. Channel count for this 5.1 but is coming as 2 https://github.com/gpac/mp4box.js/assets/148072691/fcee59e4-b76d-43f2-95af-665ac68573fb

  2. Similary for this it should be 1 (mono) but is coming as 2 https://github.com/gpac/mp4box.js/assets/148072691/69882081-2032-4f00-974f-1d2290f2f9e4

In ffprobe it's coming correct though.

hughfenghen commented 3 months ago

Prefer using the channel count obtained from DecoderSpecificInfo in the ESDS box.

https://github.com/bilibili/WebAV/blob/7694db198905e9302de33017361212a90400ef1d/packages/av-cliper/src/mp4-utils/mp4box-utils.ts#L113