Skip to content

Parse colr box CICP data for video tracks#447

Merged
kinetiknz merged 3 commits intomozilla:masterfrom
alastor0325:master
Apr 18, 2026
Merged

Parse colr box CICP data for video tracks#447
kinetiknz merged 3 commits intomozilla:masterfrom
alastor0325:master

Conversation

@alastor0325
Copy link
Copy Markdown
Member

Summary

The read_colr function and ColourInformationBox parsing already existed in this codebase, but were only wired up
to the AVIF/image item path (read_iprp). The video track path (read_video_sample_entry) silently discarded the
colr box via the default skip_box_content arm.

This PR connects the existing read_colr to video tracks and exposes the CICP values through the C API.

Changes

mp4parse (Layer 1 — parser)

  • Add colour_info: Option<ColourInformation> field to VideoSampleEntry
  • Add BoxType::ColourInformationBox arm in read_video_sample_entry to call the existing read_colr
  • Add strictness parameter to read_video_sample_entry (needed to pass to read_colr, consistent with
    read_audio_sample_entry)
  • Make NclxColourInformation fields pub so mp4parse_capi can read them
  • Duplicate colr boxes violate ISO 14496-12:2020 §12.1.5 — we warn and keep the first rather than failing, to
    avoid breaking playback of malformed content

mp4parse_capi (Layer 2 — C API)

  • Add four fields to Mp4parseTrackVideoSampleInfo:
    • has_colour_info: bool — canonical presence flag; needed because MC=0 is a valid CICP value (Identity/GBR), not
      an absence indicator
    • colour_primaries: u8
    • transfer_characteristics: u8
    • matrix_coefficients: u8
    • full_range_flag: bool
  • Populate these fields from video.colour_info in mp4parse_get_track_video_info_safe

Tests

Six integration tests with ffmpeg-generated MP4 files (-movflags +write_colr, -x264-params colorprim/transfer/colormatrix):

Test cp tc mc full_range
HDR10 9 16 9 false
HDR10 full-range 9 16 9 true
HLG 9 18 9 false
HLG full-range 9 18 9 true
RGB/Identity (MC=0) 1 1 0 false
No colr box

Add parsing of the ISO BMFF `colr` box (ISO 14496-12:2020 §12.1.5) in
`read_video_sample_entry`, storing the result in a new `colour_info` field
on `VideoSampleEntry`. Expose the nclx CICP values through the C API via
four new fields on `Mp4parseTrackVideoSampleInfo`: `has_colour_info`,
`colour_primaries`, `transfer_characteristics`, `matrix_coefficients`, and
`full_range_flag`.

This enables Firefox's MP4 demuxer to set `mVideoInfo.mTransferFunction`
for fMP4 content (Netflix, Prime Video, DRM), fixing HDR10/HLG video
appearing near-black on Windows HDR displays.

- `read_video_sample_entry` now takes `strictness` (consistent with
  `read_audio_sample_entry`) and passes it to `read_colr`.
- Duplicate `colr` boxes in a sample entry violate ISO 14496-12:2020
  §12.1.5; we warn and keep the first rather than failing playback.
- `has_colour_info: bool` is the canonical "present" flag; avoids
  misinterpreting MC=0 (Identity/GBR) as "absent".
- `NclxColourInformation` fields made public for Rust callers.
- Seven integration tests added. Test MP4 files were generated with ffmpeg
  using `-movflags +write_colr` and `-x264-params colorprim/transfer/colormatrix`:
  HDR10 (cp=9,tc=16,mc=9), HLG (tc=18), HDR10 full-range, HLG full-range,
  RGB/Identity (mc=0, exercises has_colour_info), and no-colr variants.
@alastor0325
Copy link
Copy Markdown
Member Author

@kinetiknz could you help review this? This is a fix for bug 2030296 where we miss parse colr for mp4 playback. Thanks!

Copy link
Copy Markdown
Collaborator

@kinetiknz kinetiknz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good, just a couple of things to address.

Comment thread mp4parse/src/lib.rs
Comment thread mp4parse/src/lib.rs Outdated
- Add ColrBadQuantityBMFF status (distinct from the HEIF-specific
  ColrBadQuantity) and enforce it via fail_with_status_if when
  strictness != Permissive for duplicate colr boxes in video tracks.
- Introduce ParsedColourInformation enum so read_colr returns
  Supported/Unsupported instead of always erroring on unknown
  colour_type values; the AVIF call site converts Unsupported to
  ColrBadType, while the video call site warns and continues.
- Document that VideoSampleEntry::colour_info only surfaces Nclx
  through the C API.
@alastor0325 alastor0325 requested a review from kinetiknz April 17, 2026 18:52
Copy link
Copy Markdown
Collaborator

@kinetiknz kinetiknz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@kinetiknz kinetiknz merged commit 952f517 into mozilla:master Apr 18, 2026
15 checks passed
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