roboto.experimental.video.h264#
Minimal H.264 Annex B bitstream inspection.
Implements only the byte-level parsing needed to drive a GOP-aware decoder: splitting a frame’s data into NAL units and detecting keyframes (IDR slices). It neither decodes video nor parses variable-length (Exp-Golomb) fields — the decoder reads everything else (dimensions, reference frame count, …) from the in-band parameter sets.
Module Contents#
- class roboto.experimental.video.h264.NalUnit#
One NAL unit split out of an Annex B-framed H.264 frame.
- data: bytes#
header byte included, start code excluded.
- Type:
The unit’s bytes
- type: int#
nal_unit_typefrom the unit’s header byte.
- class roboto.experimental.video.h264.NalUnitType#
Bases:
enum.IntEnumH.264 NAL unit types (ITU-T H.264 table 7-1) relevant to this module.
NAL headers can carry any 5-bit type value, so
NalUnit.typeis a plainint; compare against these members for the types that matter here.- IDR_SLICE = 5#
- NON_IDR_SLICE = 1#
- PICTURE_PARAMETER_SET = 8#
- SEI = 6#
- SEQUENCE_PARAMETER_SET = 7#
- roboto.experimental.video.h264.find_nal_units(data)#
Split Annex B-framed H.264 data into its NAL units.
- Parameters:
data (bytes) – One frame’s Annex B-framed bytes, using 3-byte or 4-byte start codes.
- Returns:
The frame’s NAL units in bitstream order. Each unit’s
datais a copy of the unit’s bytes (header included, start code excluded).- Return type:
list[NalUnit]
Examples
>>> from roboto.experimental.video import NalUnitType, find_nal_units >>> units = find_nal_units(annex_b_frame_bytes) >>> [unit.type for unit in units] [7, 8, 5]
- roboto.experimental.video.h264.is_keyframe(data)#
Whether the Annex B-framed H.264 frame contains an IDR slice.
An IDR slice is a clean decoder entry point: decoding may start at this frame without any earlier GOP state. Frames without one are delta frames, decodable only after the preceding keyframe has been fed to the decoder.
- Parameters:
data (bytes) – One frame’s Annex B-framed bytes.
- Returns:
True when the frame contains an IDR slice.
- Return type:
bool