Skip to main content

Module codec

Module codec 

Source
Expand description

Codec identities, wire framing, quantizer domains, level ladders, bitstream reads. What every encoder backend shares about a codec: its name and wire identity, the quantizer domain the session-wide quality index maps onto, the level a stream of a given geometry advertises, and the bitstream reads that label a frame on the wire.

Enums§

Codec
The picture codec of a capture session, and of a virtual-camera uplink. Jpeg is the striped still-image mode; the rest are video codecs, which stream as whole frames. The discriminants are the codec ids the Python API speaks (VirtualCamera.CODEC_*) and the video wire ids.
Hardware
The hardware encoder family a session’s quantizer curve is read for (Codec::hardware_quantizer).

Constants§

AV1_NVENC_QINDEX 🔒
Session quality index → NVENC AV1 base_q_idx breakpoints.
AV1_QINDEX 🔒
Session quality index → AV1 base_q_idx (0..=255) breakpoints.
AV1_VAAPI_QINDEX 🔒
Session quality index → VA-API AV1 base_q_idx breakpoints.
FRAME_ANCHOR
A bit ORed into a delta frame’s kind: the session keeps the frame as a long-term reference and it predicts from one every client holds (ReferenceWindow::settle), so every client can decode it.
FRAME_DELTA
FRAME_INTRA
FRAME_KEY
Frame kinds in the low nibble of the video type byte: a decode entry point, an intra-coded picture that is not one, and a predicted picture.
H26X_HARDWARE_QP 🔒
Session quality index → hardware H.264 QP breakpoints, and VA-API H.265’s.
H265_INTEL_QP 🔒
Session quality index → Intel VA-API H.265 QP breakpoints.
JPEG_HEADER_LEN
Bytes of the JPEG stripe header and the video frame header.
VIDEO_HEADER_LEN
VP8_FINEST_MATCHED 🔒
The finest session quality index VP8_QINDEX matches against x264, under which a step of the index moves VP8’s quantizer by one or none.
VP8_LEVEL_QINDEX
VP8 quantizer index of each libvpx VP8 quantizer level 0..=63.
VP8_QINDEX 🔒
Session quality index → VP8 quantizer index (0..=127) breakpoints.
VP8_REFRESH_QUANTIZER 🔒
The VP8 quantizer a capped CRF’s refresh codes a block at, at the coarsest, where the session’s quality index is at or under VP8_FINEST_MATCHED (Codec::refresh_index), where three index steps move VP8’s quantizer by one or two. Refreshed three steps finer, a 320x240 page of text a capped session coded bound came out 0.5 dB under the uncapped session at indices 22 to 24, and a 1280x720 page of text and UI 0.11 under at 22 and 23; at quantizer 2 they came within 0.06 dB at 22 and 23 and level or past at 24 and 25, at 4% fewer to 8% more bytes. Quantizer 3 came out under 4 (43.95 dB against 44.40 at 25), and 1 under 2 (44.68 against 44.79, at 4% more bytes); nine index steps at every index took those past 26 to quantizers 1 to 9, 4 to 17 dB past the session’s quality at up to twice the bytes.
VP9_QINDEX 🔒
Session quality index → VP9 base_q_idx (0..=255) breakpoints.
VP9_VAAPI_QINDEX 🔒
Session quality index → VA-API VP9 base_q_idx breakpoints.
VPX_QINDEX
base_q_idx of each libvpx / libaom quantizer level 0..=63, as those libraries map their --min-q / --max-q / --cq-level arguments.
WIRE_JPEG
Wire tag of a JPEG stripe: u8 reserved, u16 frame id, u16 stripe Y, JPEG data.
WIRE_VIDEO
Wire tag of an encoded video frame: a type byte whose low nibble is the frame kind and whose high nibble is the codec’s Codec::wire_id, then u16 frame id, u16 y (the frame’s top row, 0), u16 width, u16 height, u16 reference (the frame it predicts from, its own id where it names none), and the codec’s own bitstream.

Functions§

av1_is_key
Whether an AV1 temporal unit opens with a key frame: the first frame header or frame OBU’s frame_type, read past any temporal delimiter and sequence header. A show existing frame, or a unit without a frame, is a delta.
av1_level
Lowest AV1 level whose Annex A limits admit a width x height stream at fps carrying up to bitrate_bps (0 where no rate is declared), as seq_level_idx (8 = 4.0, 13 = 5.1, 19 = 6.3).
frame_type_from_key
The frame kind of a key/delta answer an encoder reports without a bitstream parse.
h264_dpb_frames
The decoded picture buffer, in frames, an H.264 stream at level may declare for a width x height picture: the level’s MaxDpbMbs over the picture’s macroblocks, at most REFERENCE_FRAMES.
h264_frame_type
Wire frame kind of one encoded H.264 access unit, read from the bitstream itself: IDR = key, intra-only non-IDR = intra, predicted = delta. The video header labels real decode entry points, so the NAL and slice types the encoder actually produced decide, never what was requested of it. An access unit whose slices cannot be parsed is labeled delta: a false delta costs one skipped entry point, a false key breaks the decoder.
h264_level
Lowest H.264 level whose Annex-A Table A-1 limits admit a width x height stream at fps carrying up to bitrate_bps (0 where no rate is declared), as level_idc (41 = 4.1, 52 = 5.2, 62 = 6.2).
h264_reference_level
The level an x264 session declares so its decoded picture buffer holds REFERENCE_FRAMES: the lowest from level up to 5.2 whose buffer admits them at width x height, else 5.2, or level itself above 5.2.
h264_slice_is_intra 🔒
Whether a non-IDR H.264 slice header opens an I/SI slice. Reads first_mb_in_slice and slice_type (both ue(v)) from the start of the slice RBSP, undoing emulation prevention bytes; None when the header is truncated or malformed.
h265_dpb_frames
The reference frames an H.265 stream at level may hold for a width x height picture: the decoded picture buffer A.4.2 sizes (six pictures at the level’s full MaxLumaPs, more for a smaller picture) less the picture being decoded, at most REFERENCE_FRAMES.
h265_frame_type
Wire frame kind of one encoded H.265 access unit: an IRAP picture (BLA, IDR, or CRA, which every backend here emits as an IDR with its parameter sets) is a key, anything else a delta.
h265_level
Lowest H.265 level whose Annex-A Tables A.8 and A.9 limits admit a width x height stream at fps carrying up to bitrate_bps (0 where no rate is declared) at the High tier or the Main one, as general_level_idc (123 = 4.1, 156 = 5.2, 186 = 6.2).
h265_tier
The tier an H.265 session declares at level (general_level_idc): High (1) from level 4.0 up, where Annex A defines one and every decoder of those levels takes it, so a CBR target above the level’s Main-tier MaxBR is not refused by an encoder that validates the two together; Main (0) below, where no High tier exists.
interpolate 🔒
Piecewise-linear lookup of x in ascending (x, y) breakpoints, clamped at both ends.
nearest_index 🔒
The quality index in 0..=51 whose quantizer is nearest q, the lowest on a tie.
parse_video_type
The codec and frame kind a video type byte carries.
push_jpeg_header
Append the header of one JPEG stripe.
push_video_header
Append the header of one encoded video frame: the tag, the codec and frame kind, then the frame id, its top row, its width and height, and the id of the frame it predicts from, all big-endian u16. A frame that predicts from none, or whose encoder does not say, names itself there.
vp8_is_key
Whether a VP8 frame is a key frame: the frame tag’s lowest bit is clear.
vp9_base_q_idx
The base_q_idx of a VP9 frame, read from its uncompressed header past the color configuration, the frame size, the references, and the loop filter; None for a shown existing frame or a header cut short.
vp9_is_key
Whether a VP9 frame is a key frame, read from its uncompressed header: not a shown existing frame, and frame_type KEY_FRAME. Profile 3 carries one reserved bit ahead of those two.
vpx_level
The libvpx / SVT-AV1 quantizer level (0..=63) closest to a quantizer index of codec’s domain: the software encoders take the level, the hardware ones the index.