pub struct Encoder { /* private fields */ }Expand description
A Constrained Baseline H.264 encoder.
Implementations§
Source§impl Encoder
impl Encoder
Sourcepub fn new(cfg: EncoderConfig) -> Result<Self, EncodeError>
pub fn new(cfg: EncoderConfig) -> Result<Self, EncodeError>
Creates an encoder, validating that the configuration is within the implemented subset.
Sourcepub fn config(&self) -> &EncoderConfig
pub fn config(&self) -> &EncoderConfig
The active configuration.
Sourcepub fn encode(&mut self, frame: &YuvFrame) -> Vec<u8> ⓘ
pub fn encode(&mut self, frame: &YuvFrame) -> Vec<u8> ⓘ
Encodes one frame, returning the Annex-B access unit. Every gop_size
frames (and always the first) is coded as an IDR, prefixed with SPS/PPS.
Generation 1 codes every picture as an IDR (all-intra); inter frames arrive with motion compensation later.
Sourcepub fn try_encode(&mut self, frame: &YuvFrame) -> Result<Vec<u8>, EncodeError>
pub fn try_encode(&mut self, frame: &YuvFrame) -> Result<Vec<u8>, EncodeError>
Fallible encode: validates the frame against the config.
Sourcepub fn encode_all(
&self,
frames: &[YuvFrame],
) -> Result<Vec<Vec<u8>>, EncodeError>
pub fn encode_all( &self, frames: &[YuvFrame], ) -> Result<Vec<Vec<u8>>, EncodeError>
Batch-encodes every frame, returning one Annex-B access unit per frame.
At constant QP the GOPs are independent — each begins with an IDR that
resets the DPB, frame_num and POC, and SPS/PPS precede every IDR — so they
are encoded in parallel across CPU cores and the result is
byte-identical to calling encode frame-by-frame. With
rate control enabled the per-frame QP depends on history, so this falls back
to sequential encoding. Within a GOP, P-frames are inherently sequential
(each predicts from the previous reconstruction); the parallelism is across
GOPs, so it scales with the number of GOPs in the clip.