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 set_color_range(&mut self, _range: ColorRange) -> bool { ... }
fn flush(&mut self) { ... }
}Required Methods§
Sourcefn send_frame(&mut self, frame: &Frame) -> Result<()>
fn send_frame(&mut self, frame: &Frame) -> Result<()>
Submit one raw frame for encoding.
Sourcefn receive_packet(&mut self) -> Result<Packet>
fn receive_packet(&mut self) -> Result<Packet>
Retrieve the next encoded packet, if one is ready.
Provided Methods§
Sourcefn configure(&mut self, _options: &Dictionary) -> Result<()>
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.
Sourcefn accepted_sample_rates(&self) -> Option<Vec<u32>>
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).
Sourcefn accepted_pixel_formats(&self) -> Option<Vec<PixelFormat>>
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.
Sourcefn set_color_range(&mut self, _range: ColorRange) -> bool
fn set_color_range(&mut self, _range: ColorRange) -> bool
Tell a video encoder the colour range of the frames it will receive.
Called once, before the first frame, with ColorRange::Limited or
ColorRange::Full.
Return true when the encoder takes frames in that range: it either
signals the range in its bitstream (the AV1 sequence header’s
color_range, the VP9 frame header’s color_range, the H.264 VUI’s
video_full_range_flag) or has a fixed range of its own that the
pipeline already reconciles (JPEG, PNG, raw video). Return false when
it cannot signal range: the pipeline then converts the frames to
limited range, what a bitstream without a range flag is read as, and
calls this again with Limited. FFmpeg’s encoders do the same through
AVCodecContext::color_range.
Default: true, with nothing signalled.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".