Skip to main content

VideoDecoder

Trait VideoDecoder 

Source
pub trait VideoDecoder: Send {
    // Required methods
    fn codec(&self) -> CodecId;
    fn send_packet(&mut self, data: &[u8], pts: i64) -> CodecResult<()>;
    fn receive_frame(&mut self) -> CodecResult<Option<VideoFrame>>;
    fn flush(&mut self) -> CodecResult<()>;
    fn reset(&mut self);
    fn output_format(&self) -> Option<PixelFormat>;
    fn dimensions(&self) -> Option<(u32, u32)>;
}
Expand description

Video decoder trait.

Implements a push-pull decoding model:

  1. Send compressed packets with send_packet
  2. Receive decoded frames with receive_frame

§Example

while let Some(packet) = demuxer.read_packet()? {
    decoder.send_packet(&packet)?;
    while let Some(frame) = decoder.receive_frame()? {
        process_frame(frame);
    }
}
decoder.flush()?;
while let Some(frame) = decoder.receive_frame()? {
    process_frame(frame);
}

Required Methods§

Source

fn codec(&self) -> CodecId

Get codec identifier.

Source

fn send_packet(&mut self, data: &[u8], pts: i64) -> CodecResult<()>

Send a compressed packet to the decoder.

§Errors

Returns error if the packet is invalid or decoder is in error state.

Source

fn receive_frame(&mut self) -> CodecResult<Option<VideoFrame>>

Receive a decoded frame.

Returns Ok(None) if more data is needed.

§Errors

Returns error if decoding fails.

Source

fn flush(&mut self) -> CodecResult<()>

Flush the decoder.

Call this after all packets have been sent to retrieve remaining frames.

§Errors

Returns error if flush fails.

Source

fn reset(&mut self)

Reset the decoder state.

Source

fn output_format(&self) -> Option<PixelFormat>

Get decoder output format.

Source

fn dimensions(&self) -> Option<(u32, u32)>

Get decoded frame dimensions.

Implementors§