#[non_exhaustive]pub struct Config {
pub width: u32,
pub height: u32,
pub framerate: u32,
pub bitrate: Option<u64>,
pub gop: u32,
pub codec: Codec,
pub kind: Kind,
pub color: Option<Color>,
}Expand description
Encoder configuration. width / height / framerate are the encoded
output; input frames must already be at this resolution.
#[non_exhaustive]: build via Config::new and set the optional fields,
so future knobs don’t break callers.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.width: u32§height: u32§framerate: u32§bitrate: Option<u64>Target bitrate in bits per second. None derives a sane default
from resolution and framerate (~0.07 bits per pixel per second).
gop: u32Keyframe interval in frames. Subscribers joining mid-stream wait at most this many frames before they can start decoding.
codec: CodecOutput codec. Defaults to Codec::H264.
kind: Kind§color: Option<Color>The color space of the input frames, written into the bitstream’s VUI so a
decoder doesn’t have to guess. None uses Color::infer, which is both
what the crate’s own RGB conversions produce and what a player falls back
to, so leaving it unset keeps the pixels and the label in agreement.
Set it only when feeding frames the crate did not convert and whose space you know from elsewhere.
Implementations§
Source§impl Config
impl Config
Sourcepub fn new(width: u32, height: u32, framerate: u32) -> Self
pub fn new(width: u32, height: u32, framerate: u32) -> Self
A config encoding width x height at framerate, with the default
codec, GOP, and bitrate.
Sourcepub async fn probe(&self) -> Result<VideoConfig, Error>
pub async fn probe(&self) -> Result<VideoConfig, Error>
The catalog rendition an encoder for this config produces.
Resolved by opening a throwaway encoder and encoding one frame, so the profile, level, and constraints are the ones this machine writes into the bitstream rather than a guess. The backend picks all three itself (VideoToolbox asks for High, openh264 leaves it at Baseline, VAAPI writes Main) and its choice depends on the config it opened with, so reading them back is the only way to know.
This is what lets a track be advertised before it carries anything: a subscriber can only discover a track the catalog names, and an on-demand encoder only encodes once a subscriber arrives. Publishing the probed rendition breaks that cycle without publishing a claim that has to be corrected later, since it already says what the first keyframe will say.
Costs an encoder open and a single frame, so call it once per track. Call it before opening the encoder you will actually use, so the two never hold a codec session at once.
§Errors
Fails when this machine cannot encode the config at all, which makes it a fail-fast check: better here than on the first frame of a track that is already advertised.