Skip to content

fix(hvcC, lhvC): read all three bits of numTemporalLayers - #587

Merged
rbouqueau merged 1 commit into
gpac:mainfrom
zzoraemon043:fix/num-temporal-layers
Nov 21, 2026
Merged

rbouqueau merged 1 commit into
gpac:mainfrom
zzoraemon043:fix/num-temporal-layers

Conversation

@zzoraemon043

Copy link
Copy Markdown
Contributor

Description

hvcC and lhvC read numTemporalLayers with the wrong mask:

this.numTemporalLayers = (tmp_byte & 0xd) >> 3;

The byte is bit(2) constantFrameRate (only in hvcC), bit(3) numTemporalLayers, bit(1) temporalIdNested, unsigned int(2) lengthSizeMinusOne (ISO/IEC 14496-15, HEVCDecoderConfigurationRecord and LHEVCDecoderConfigurationRecord). 0xd keeps only the lowest of the three bits, so 2, 4 and 6 layers are read as 0, and 3, 5 and 7 as 1. hvcC.write() then writes the wrong value back. The mask is now 0x38.

In the conformance files this affects 10 hvcC boxes in nalu/hevc: hevc_hev1_hev2_extractors.mp4, hevc_hev1_hev2_implicit.mp4, hevc_hvc1_hvc2_extractors.mp4 (2 layers, read as 0) and hvc2_extractors.mp4 (4 layers, read as 0). With the change, all 140 hvcC/lhvC boxes in the published conformance files match the raw bits.

Test: tests/temporal-layers.test.ts parses hand-built hvcC and lhvC boxes and writes an hvcC back. All 6 cases fail before the change. I kept it out of tests/hvcC.test.ts so it does not conflict with #585.

npx vitest run (Linux, Node 22): 521 passed. eslint, prettier and tsc -b pass (the existing sgpdBox export error in tests/sgpd.test.ts is unchanged). Changeset added.

@changeset-bot

changeset-bot Bot commented Nov 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e164731

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
mp4box Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@rbouqueau

Copy link
Copy Markdown
Member

That's right, thanks for your contribution !

@rbouqueau
rbouqueau added this pull request to the merge queue Nov 21, 2026
Merged via the queue into gpac:main with commit 9a8402a Nov 21, 2026
1 check passed
@github-actions github-actions Bot mentioned this pull request Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants