hvcC write clears the reserved bits before min_spatial_segmentation_idc

Open
#584 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@bardrop is already working on this.

Since Nov 20, 2026.

  • #585 by @bardrop — open

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
backend

Research direction

Read src/boxes/hvcC.ts at the hvcCBox.write() call identified in the issue and check how the 16-bit field is written. The issue author says they have a fix and plan to open a pull request, so check for that work before starting. Done means the four reserved bits are written as 1111 and the round-trip test preserves the hvcC bytes.

Written by the indexing model from the issue text.

Description

hvcCBox.write() drops the 4 reserved bits in front of min_spatial_segmentation_idc:

https://github.com/gpac/mp4box.js/blob/main/src/boxes/hvcC.ts#L89

stream.writeUint16(this.min_spatial_segmentation_idc + (15 << 24));

15 << 24 is outside the 16-bit field, so setUint16 cuts it off and the bits are written as 0000. ISO/IEC 14496-15 says bit(4) reserved = '1111'b there (the other reserved bits in the same record are written right). It should be 15 << 12.

How I hit it: I made an HEVC file with ffmpeg -f lavfi -i testsrc=d=2 -c:v libx265 -tag:v hvc1 out.mp4, parsed it with mp4box.js and wrote every box back. All boxes in stbl came back byte for byte except hvcC, where the byte after general_level_idc changed from f0 to 00. So any file mp4box.js writes with an HEVC track (e.g. segments from initializeSegmentation()) has a non-conformant hvcC.

I have a fix with a round-trip test and will open a PR.

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.