Skip to main content

Module hevc_sei

Module hevc_sei 

Source
Expand description

HEVC SEI extractor for HDR static metadata.

libde265 does not expose SEI messages through its public C API (the sei_message type lives in libde265/libde265/sei.h as internal C++; only the processing side that hashes pictures is visible), so we vendor a minimal pure-Rust NAL/SEI parser here that reads just the two payload types HDR10 pass-through needs:

  • Mastering display colour volumepayload_type=137, per HEVC spec D.2.28.
  • Content light level informationpayload_type=144, per HEVC spec D.2.35.

Inputs are raw Annex-B samples (start-code delimited NAL units) — the same bytes we push into libde265. Output merges into ColorMetadata.mastering_display / content_light_level. The parser does not touch the decode path at all; it just scans the bitstream once at demux / decoder-construction time and caches the two structs.

Referenced normative text:

  • ITU-T H.265 (2021) §7.3.5 “SEI payload syntax”
  • ITU-T H.265 (2021) D.2.28 mastering_display_colour_volume()
  • ITU-T H.265 (2021) D.2.35 content_light_level_info()
  • ITU-T H.265 (2021) §7.3.2.4 “SEI RBSP syntax” — NAL units 39/40

Anti-emulation: the SEI RBSP uses emulation-prevention byte stuffing (any 0x00 0x00 0x00, 0x00 0x00 0x01, 0x00 0x00 0x02, or 0x00 0x00 0x03 in the decoded payload is written as the original first two bytes followed by a 0x03 in the coded bitstream). For the two payload types we parse, all fields are single bytes or 16/32-bit BE words whose payload lengths are fixed; we strip emulation-prevention bytes out on a per-NAL basis before parsing.

Structs§

HevcHdrSei

Functions§

parse_annexb
Scan an Annex-B byte buffer for HEVC SEI NAL units (nal_unit_type 39 prefix, 40 suffix) and extract HDR static metadata payloads. Returns a potentially-empty HevcHdrSei; callers should fold it into ColorMetadata only when non-empty.