pub struct Decoder { /* private fields */ }Expand description
The main VP8/VP9 video decoder.
§Example
use std::num::NonZero;
use vpx_rs::{Decoder, DecoderConfig, Error, DecodedImageData};
// Initialize a new decoder
fn new_vp8_decoder(width: u32, height: u32,) -> Result<Decoder, Error> {
// Prepare the configuration
let config = DecoderConfig::new(
vpx_rs::dec::CodecId::VP8,
width,
height,
);
// Instantiate the decoder
Decoder::new(config)
}
// Passes a buffer to the decoder and extracts any completed frames
fn decode_vp8_buf(
decoder: &mut Decoder,
stream_data: &[u8],
) -> Result<(), Error> {
for decoded_image in decoder.decode(stream_data)?.into_iter() {
let (format, bit_depth) = match decoded_image.data() {
DecodedImageData::Data8b(data) =>
(format!("{:?}", data.format()), 8),
DecodedImageData::Data16b(data) =>
(format!("{:?}", data.format()), 16),
};
println!(
"Decoded a {}x{} pixel image in {} format with bit depth {}",
decoded_image.width(),
decoded_image.height(),
format,
bit_depth,
);
}
Ok(())
}Implementations§
Source§impl Decoder
impl Decoder
Sourcepub fn new(config: DecoderConfig) -> Result<Self>
pub fn new(config: DecoderConfig) -> Result<Self>
Constructs a new decoder for the given configuration. After
successful construction, you can start sending bitstream buffers
to the decoder by calling Decoder::decode().
Sourcepub fn decode(&mut self, data: &[u8]) -> Result<DecodedImageIterator<'_>>
pub fn decode(&mut self, data: &[u8]) -> Result<DecodedImageIterator<'_>>
Submits data to be decoded by the decoder, yielding a number of
decoded images as a result. Please note that even if you only send
data for a single frame at a time, due to internal bitstream frame
rendering, the decoder might produce any number of frames per
decode call. You should retrieve all decoded images from the
returned iterator before trying to push more data to the decoder.
The images will always be returned to you in presentation order,
so there’s no need to perform image reordering on your end.
Sourcepub fn stream_info(&mut self) -> Option<StreamInfo>
pub fn stream_info(&mut self) -> Option<StreamInfo>
Returns stream information for the decoder. This might not return stream information initially, especially before sending any data to the decoder.