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.
Structs§
- Color
Signal - What a stream says about the color it carries.
- 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.
- Wide
Frame Num - An x264 or NVENC stream with
frame_numwidened by a byte, in its sequence parameter sets and every slice header.
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_bufferingatmax_num_ref_frames; a declaredmax_num_reorder_framesabove zero rewritten to zero. Only a stream that cannot reorder takes it:in_orderwhere 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. - h264_
frame_ num_ range - How many values
frame_numtakes before it wraps, from the first SPS of an Annex-B H.264 stream. - read_
color - What the stream says about its color, or
Nonewhen it says nothing a decoder can use. - 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. - write_
color - The same SPS with
signaldeclared in its VUI, replacing whatever it declared before.