Skip to content
Roboto
Esc
↑↓navigate↵open⌘Jpreview
On this page

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.

The start-code scan shared with H.265 lives in annexb; this module adds the H.264 specifics: a 1-byte NAL header carrying a 5-bit type.

Module Contents

NalUnit

class roboto.experimental.video.h264.NalUnit#View Source

One NAL unit split out of Annex B-framed data.

Attributes

NalUnit.data

data bytes #

The unit’s bytes: header included, start code excluded.

NalUnit.type

type int #

nal_unit_type from the unit’s header (codec-specific layout).

NalUnitType

class roboto.experimental.video.h264.NalUnitType#View Source

Bases: enum.IntEnum

H.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.type is a plain int; compare against these members for the types that matter here.

Attributes

NalUnitType.IDR_SLICE

IDR_SLICE = 5 #

NalUnitType.NON_IDR_SLICE

NON_IDR_SLICE = 1 #

NalUnitType.PICTURE_PARAMETER_SET

PICTURE_PARAMETER_SET = 8 #

NalUnitType.SEI

SEI = 6 #

NalUnitType.SEQUENCE_PARAMETER_SET

SEQUENCE_PARAMETER_SET = 7 #

find_nal_units()

roboto.experimental.video.h264.find_nal_units(data)#View Source

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 data is a copy of the unit’s bytes (header included, start code excluded).

Usage

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]

is_keyframe()

roboto.experimental.video.h264.is_keyframe(data)#View Source

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

bool

True when the frame contains an IDR slice.

Was this page helpful?