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:
- Send compressed packets with
send_packet - 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§
Sourcefn send_packet(&mut self, data: &[u8], pts: i64) -> CodecResult<()>
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.
Sourcefn receive_frame(&mut self) -> CodecResult<Option<VideoFrame>>
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.
Sourcefn flush(&mut self) -> CodecResult<()>
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.
Sourcefn output_format(&self) -> Option<PixelFormat>
fn output_format(&self) -> Option<PixelFormat>
Get decoder output format.
Sourcefn dimensions(&self) -> Option<(u32, u32)>
fn dimensions(&self) -> Option<(u32, u32)>
Get decoded frame dimensions.