Skip to main content

Decoder

Struct Decoder 

Source
pub struct Decoder { /* private fields */ }
Expand description

Decode video files and streams.

§Example

let decoder = Decoder::new(Path::new("video.mp4")).unwrap();
decoder
    .decode_iter()
    .take_while(Result::is_ok)
    .for_each(|frame| println!("Got frame!"),
);

Implementations§

Source§

impl Decoder

Source

pub fn new(source: impl Into<Location>) -> Result<Self, Error>

Create a decoder to decode the specified source.

§Arguments
  • source - Source to decode.
Source

pub fn time_base(&self) -> AvRational

Get decoder time base.

Source

pub fn duration(&self) -> Result<Time, Error>

Duration of the decoder stream.

Source

pub fn frames(&self) -> Result<u64, Error>

Number of frames in the decoder stream.

Source

pub fn decode_iter( &mut self, ) -> impl Iterator<Item = Result<(Time, Frame), Error>> + '_

Decode frames through iterator interface. This is similar to decode but it returns frames through an infinite iterator.

§Example
decoder
    .decode_iter()
    .take_while(Result::is_ok)
    .map(Result::unwrap)
    .for_each(|(ts, frame)| {
        // Do something with frame...
    });
Source

pub fn decode(&mut self) -> Result<(Time, Frame), Error>

Decode a single frame.

§Return value

A tuple of the frame timestamp (relative to the stream) and the frame itself.

§Example
loop {
    let (ts, frame) = decoder.decode()?;
    // Do something with frame...
}
Source

pub fn decode_raw_iter( &mut self, ) -> impl Iterator<Item = Result<RawFrame, Error>> + '_

Decode frames through iterator interface. This is similar to decode_raw but it returns frames through an infinite iterator.

Source

pub fn decode_raw(&mut self) -> Result<RawFrame, Error>

Decode a single frame and return the raw ffmpeg AvFrame.

§Return value

The decoded raw frame as RawFrame.

Source

pub fn seek(&mut self, timestamp_milliseconds: i64) -> Result<(), Error>

Seek in reader.

See Reader::seek for more information.

Source

pub fn seek_to_frame(&mut self, frame_number: i64) -> Result<(), Error>

Seek to specific frame in reader.

See Reader::seek_to_frame for more information.

Source

pub fn seek_to_start(&mut self) -> Result<(), Error>

Seek to start of reader.

See Reader::seek_to_start for more information.

Source

pub fn into_parts(self) -> (DecoderSplit, Reader, usize)

Split the decoder into a decoder (of type DecoderSplit) and a Reader.

This allows the caller to detach stream reading from decoding, which is useful for advanced use cases.

§Return value

Tuple of the DecoderSplit, Reader and the reader stream index.

Source

pub fn size(&self) -> (u32, u32)

Get the decoders input size (resolution dimensions): width and height.

Source

pub fn size_out(&self) -> (u32, u32)

Get the decoders output size after resizing is applied (resolution dimensions): width and height.

Source

pub fn frame_rate(&self) -> f32

Get the decoders input frame rate as floating-point value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more