Skip to main content

Module sps

Module sps 

Source
Expand description

The color an H.264 stream declares: read from a sequence parameter set, and written into one for a device that converts without saying what it converted with. The color a stream declares, read from an H.264 sequence parameter set and written into one.

An encoder that converts RGB itself decides the matrix and the range, and the stream is the only place a decoder learns which it was: with no video_signal_type in the VUI a browser guesses from the frame size, so one session is colored one way at 1080p and another at 800x600. Devices differ in whether they say: a Raspberry Pi with firmware from August 2024 or later converts and declares it, and the same board on an older firmware converts to full range BT.601 and declares nothing at all.

So this reads first. A stream that declares its color is left alone, whatever it declares, because the device knows what it did and we do not. Only a stream that declares nothing is written into, and then only with a value the caller can justify.

The VUI sits at the end of the SPS, ahead of the trailing bits, and the fields after the insertion point are copied as opaque bits rather than re-encoded: a writer that re-emits what it does not understand is a writer that corrupts streams on devices it was never run against.

The same VUI bounds reordering. Without a bitstream_restriction a decoder has to assume the stream may reorder as deep as its level’s decoded picture buffer, and Chromium’s hardware H.264 decoder (VA-API, D3D11, VideoToolbox) holds that many pictures back before it outputs one, up to sixteen at a small size. A stream whose pictures leave in the order they are shown is written a bound of zero. That write reads through the timing and HRD parameters to reach the restriction, still copying them as they came, and the read has to land on the stop bit, so a field it stepped over wrongly refuses the write instead of corrupting the set.

x264’s and NVENC’s frame_num are widened here too (WideFrameNum), the one write that reaches past the set into every slice header.

Modules§

dpb 🔒
The sequence parameter set read an H.264 session makes of its own key frames, and the reference checks of every backend share.

Structs§

ColorSignal
What a stream says about the color it carries.
Located 🔒
Where the video signal type sits in a VUI, and what it says today.
NoReorder
A device’s H.264 stream held to a reorder bound of zero: each sequence parameter set it sends is rewritten once and matched by its bytes after that, since a device repeats the same set with every key frame.
Reader 🔒
Restriction 🔒
Where a VUI’s bitstream restriction sits, and the reordering it declares.
WideFrameNum
An x264 or NVENC stream with frame_num widened by a byte, in its sequence parameter sets and every slice header.
Writer 🔒

Constants§

WIDER_FRAME_NUM 🔒
The bits WideFrameNum adds to frame_num: a whole byte, so everything after the field in a slice moves by one byte and keeps the alignment its entropy coding and trailing bits rest on.

Functions§

bound_reorder
The same SPS bounding reordering at zero, or None where it already does: a restriction written where the VUI carries none (a VUI created where there is none), with every other restriction field at the value a decoder infers in its absence and max_dec_frame_buffering at max_num_ref_frames; a declared max_num_reorder_frames above zero rewritten to zero. Only a stream that cannot reorder takes it: in_order where the session proves its pictures leave in the order they are shown, else a stream at picture order count type 2, whose output order is its decoding order.
escape 🔒
h264_frame_num_range
How many values frame_num takes before it wraps, from the first SPS of an Annex-B H.264 stream.
hrd 🔒
Step over one hrd_parameters structure.
locate 🔒
read_color
What the stream says about its color, or None when it says nothing a decoder can use.
restriction 🔒
The restriction of the VUI at located, read through what follows its video signal type. The read has to end on the stop bit, the check that no field was stepped over wrongly.
sequence_parameter_sets
Where each H.264 sequence parameter set sits in an Annex B access unit, as (start, end) of the NAL unit itself, the start code excluded. A set repeats with every key frame when the encoder is asked for headers on each one, and a stream whose first set alone is written says one thing to the client that connected first and another to the one that joined later.
stop_bit 🔒
The last bit that carries meaning: the RBSP stop bit, with alignment zeros after it.
unescape 🔒
widen_slice 🔒
A slice under a widened set, and its widened frame_num: the encoder’s narrow bits numbered on from last, the widened value of the slice before it, with the byte above them inserted ahead.
widen_sps 🔒
The set with frame_num WIDER_FRAME_NUM bits wider, and the log2_max_frame_num it had; None where the wider field would pass sixteen bits or the set cannot be read.
write_color
The same SPS with signal declared in its VUI, replacing whatever it declared before.
write_signal 🔒

Type Aliases§

Coded 🔒
A field’s value, with the first bit its code spans and the bit after it.