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

Open Beginner friendly
#586 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
73/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active

Research direction

Start by tracing how mp4box.js derives and formats the RFC 6381 codec string for MP3 audio, then compare that path with the reported mp4a.6B output. Check for existing codec formatting tests and add a case using the provided MP4 sample or an equivalent fixture. Done when the reported codec preserves the uppercase B and the test verifies it.

Written by the indexing model from the issue text.

Description

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"
Dominant language
TypeScript
Stars
2.5k
Forks
390
Avg merge
3d 20h
Merged PRs (30d)
10

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from gpac/mp4box.js

All issues in gpac/mp4box.js

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.