Skip to content

Lowercase '6b' in 'mp4a.6b' fails Chromium's canPlayType() check #586

Open

Description

@ptim0626

I encountered this when parsing an MP4 containing MP3 audio with codec 'mp4a.6B'. (Thanks for the package! first time reporter here).

mp4box.js reports mp4a.6b, while MP4Box reports mp4a.6B (note the capital). Passing the lowercase one to Chromium's canPlayType() returns an empty string (i.e. not supported) and uppercase returns "probably".

This is because of the mapping in Chromium's source code here (line 64), it doesn't recognise the lowercase version in this particular audio codec. The justification of using the uppercase version is here in RFC 6381. So I think it makes sense for mp4box.js to also report mp4a.6B instead so applications can pass the reported codec from mp4box.js directly to browser capability checks (which is what I was trying to do).

Happy to contribute a PR to fix this if this is the direction maintainers think it should be taken (with some guidance ideally as I am not familiar with the codebase). Thank you.

To Reproduce

Using an MP4 containing MP3 audio with codec 'mp4a.6B' (audio_mp4a.6b.mp4 here):

mp4box.js (@2.5.0)

import { readFileSync } from 'node:fs';
import { createFile } from 'mp4box';

const buf = readFileSync(process.argv[2]);
const data = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
data.fileStart = 0;

const file = createFile();
file.onReady = info => console.log(info.audioTracks[0].codec);
file.appendBuffer(data);
file.flush();
node script.js audio_mp4a.6b.mp4
# mp4a.6b

MP4Box (GPAC version 26.07-revrelease)

MP4Box -info audio_mp4a.6b.mp4
# ...
# RFC6381 Codec Parameters: mp4a.6B
# ...

Chrome (157.0.0):

const audio = document.createElement('audio');
audio.canPlayType('audio/mp4; codecs="mp4a.6b"'); // ""
audio.canPlayType('audio/mp4; codecs="mp4a.6B"'); // "probably"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions