Skip to main content

Encoder

Trait Encoder 

Source
pub trait Encoder: Send {
    // Required methods
    fn send_frame(&mut self, frame: &Frame) -> Result<()>;
    fn receive_packet(&mut self) -> Result<Packet>;

    // Provided methods
    fn configure(&mut self, _options: &Dictionary) -> Result<()> { ... }
    fn accepted_sample_rates(&self) -> Option<Vec<u32>> { ... }
    fn accepted_pixel_formats(&self) -> Option<Vec<PixelFormat>> { ... }
    fn flush(&mut self) { ... }
}
Expand description

Encodes raw Frames into compressed Packets. Mirror of Decoder.

Required Methods§

Source

fn send_frame(&mut self, frame: &Frame) -> Result<()>

Submit one raw frame for encoding.

Source

fn receive_packet(&mut self) -> Result<Packet>

Retrieve the next encoded packet, if one is ready.

Provided Methods§

Source

fn configure(&mut self, _options: &Dictionary) -> Result<()>

Receive output options before encoding begins — rate control and tuning: crf/qp (quality), preset (speed/quality trade-off), b (bitrate), pass (1 or 2). Default: ignore them. Called once, after construction.

Source

fn accepted_sample_rates(&self) -> Option<Vec<u32>>

The input sample rates this encoder accepts, or None for “any rate”. The transcode pipeline resamples audio to the nearest accepted rate before feeding frames (mirrors FFmpeg’s automatic aresample).

Source

fn accepted_pixel_formats(&self) -> Option<Vec<PixelFormat>>

The pixel formats this encoder accepts, most-preferred first, or None for “any format”. The transcode pipeline converts video to the first accepted format before feeding frames (FFmpeg’s automatic scale).

Declaring this lets decoders emit whatever layout is cheapest for them — a JPEG decoder can hand out planar Y’CbCr instead of converting to RGB — without breaking encoders that need something else. An encoder that leaves this None must genuinely handle every format it is given.

Source

fn flush(&mut self)

Signal end-of-input to drain buffered packets.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§