Expand description
Pixel-format detection from codec sequence headers.
Given raw bitstream samples (the same Vec<Vec
Why not use the full decoder: our CPU decoders (H.264 openh264, HEVC Rust, VP9 Rust, rav1d AV1) each have their own parser entry points, but none of them expose a “just probe the format” API. NVDEC’s sequence_callback tells us, but only after decode starts. This module gives the pipeline a fast, codec-agnostic probe path that runs before decoder construction.
Structs§
- Av1Frame
Header - Parsed AV1 frame header — full §5.9.1 uncompressed_header parse.
Provides everything needed to populate
StdVideoDecodeAV1PictureInfo - Av1Sequence
Header - Parsed AV1 sequence header fields (from OBU type 1, §5.5.2).
Minimum subset needed to build
StdVideoAV1SequenceHeaderfor Vulkan AV1 decode session parameters. - H264
PpsInfo - Parsed H.264 PPS fields. Consumers: Vulkan Video decoder (fills
StdVideoH264PictureParameterSet), slice-header parser (needsbottom_field_pic_order_in_frame_present_flag+redundant_pic_cnt_present_flagas branching predicates). - H264
Slice Header - Parsed H.264 slice header — just the fields the Vulkan Video
decoder + our DPB manager need. See ITU-T H.264 §7.3.3. Full slice
header has ref_pic_list_modification, weighted_prediction tables,
dec_ref_pic_marking, etc., which we don’t consume (the driver
re-derives them from the PPS +
StdVideoDecodeH264PictureInfoflags). - H264
SpsInfo - Parsed H.264 SPS fields relevant to the pipeline.
- H265
PpsInfo - Parsed HEVC PPS.
- H265
Slice Header - HEVC slice header — subset needed for StdVideoDecodeH265PictureInfo.
- H265
VpsInfo - Parsed HEVC VPS — minimum fields needed for StdVideoH265VideoParameterSet.
- Hevc
SpsInfo - Parsed HEVC SPS fields relevant to the pipeline.
- Mpeg2
SeqInfo - Parsed MPEG-2 sequence header + (optional) sequence extension.
Enums§
- Av1Frame
Type - H264
Slice Type - Slice type name (decoded from
slice_typeue(v) value). Per H.264 §7.4.3 Table 7-6, values 0..=4 are one iteration of the slice types; values 5..=9 are the same types but mark “all slices in the current picture have this type” (akaslice_type_all_same). Both halves collapse to the same enum. - H265
Slice Type
Functions§
- av1_
frame_ header_ offset - Locate the byte offset, within
sample, of the uncompressed_header payload of the first Frame OBU (obu_type 3 or 6). Returns None if no such OBU is found. - av1_
tile_ group_ offset - Locate the byte offset of the first tile_group_obu payload within
the sample buffer, used for
VkVideoDecodeAV1PictureInfoKHR::pTileOffsets. Two shapes: - av1_
tile_ group_ offset_ fallback - Backwards-compatible shim — uses an empty-ish sequence header
default that only works for the fallback path (standalone type-4
OBU). Callers with access to the parsed sequence header should
use
av1_tile_group_offset(the seq-aware form) instead. - detect
- Detect pixel format from the first sequence header in
samples. Falls back to Yuv420p on any parse failure — that matches the previous hard-coded behavior so a bad probe doesn’t block the transcode, just the probe payload accuracy. - detect_
dims - Public entry point — dispatch by codec and return
Some((width, height))if the sequence header insamples[0]is parseable,Noneotherwise. - find_
av1_ obu_ with_ offset_ pub - Public re-export so the Vulkan Video decoder can extract the byte range of an OBU from a demuxed sample.
- h264_
first_ slice_ nal_ offset - Scan an Annex-B H.264 sample for the first coded-slice NAL
(types 1 / 5 / 19) and return its byte offset within
data. Parallel tohevc_first_slice_nal_offset. - hevc_
first_ slice_ nal_ offset - Scan an Annex-B HEVC sample and return the offset, in bytes from
the start of
data, where the first coded-slice NAL begins (the byte AFTER the start code). Vulkanslice_segment_offsetswants offsets to NAL-unit first bytes, not to start codes. - parse_
av1_ frame_ header - Parse an AV1 frame_header_obu (or the frame_header part of a frame_obu) from the given sample. Requires the sequence header for branch predicates (order_hint_bits, enable flags).
- parse_
av1_ sequence_ header - Parse the AV1 sequence header OBU (obu_type=1). Returns the subset of §5.5.2 fields needed for Vulkan decode-session-params. Partial parse: we stop after color_config + film_grain_params_present (everything Vulkan’s StdVideoAV1SequenceHeader cares about).
- parse_
h264_ pps - Walk an Annex-B sample looking for the first NAL of type 8 (PPS)
and decode its syntax elements. Returns
Nonewhen no PPS is in the sample or the syntax is truncated beforeredundant_pic_cnt_present_flag(the last required field). - parse_
h264_ slice_ header - Parse the first slice-NAL in
sample, using the SPS + PPS for branch predicates. The NAL header’snal_unit_typegates which slice types we accept: 1 (non-IDR), 5 (IDR), 19 (auxiliary coded slice) all share the same syntax. ReturnsNonewhen the sample contains no slice NAL or the SPS/PPS didn’t provide the required context (e.g., SPSpic_order_cnt_typewasNoneso we can’t branch into the POC reads). - parse_
h264_ sps - Full H.264 SPS walker — see §7.3.2.1.1 + §7.4.2.1.1. The parse is greedy: profile_idc + chroma fields are populated first, then we walk the variable-length sections (scaling lists, pic_order_cnt_type branch) to reach pic_width_in_mbs_minus1 etc. If any of those sections hit end-of-buffer the dims come back as None but the early fields are returned.
- parse_
h265_ pps - Parse the HEVC PPS (NAL type 34). Subset needed for Std PPS.
- parse_
h265_ slice_ header - Parse the HEVC slice header — subset needed for StdVideoDecodeH265PictureInfo.
sps/ppsprovide context for bit-width of POC lsb and branch predicates. - parse_
h265_ vps - Parse the HEVC VPS (NAL type 32). Minimum fields for Std VPS.
- parse_
hevc_ sps - Full HEVC SPS walker — see H.265 §7.3.2.2.1 + §7.4.3.2.1. Consumes
profile_tier_levelvia the existingskip_hevc_profile_tier_levelhelper, then reads pic_width_in_luma_samples + pic_height_in_luma_samples and applies the conformance window crop if present. - parse_
mpeg2_ sequence_ header - MPEG-2 sequence header scan — ISO/IEC 13818-2 §6.2.2.1 (sequence
header, start code
00 00 01 B3) + §6.2.2.3 (sequence extension, start code00 00 01 B5withextension_start_code_identifier==1).