Skip to main content

AsyncVideoDecoder

Struct AsyncVideoDecoder 

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

Async wrapper around VideoDecoder.

open and decode_frame both execute on a spawn_blocking thread so the Tokio executor is never blocked by FFmpeg I/O or decoding work. Multiple concurrent callers share the inner decoder through Arc<Mutex<...>>.

§Examples

use ff_decode::AsyncVideoDecoder;
use futures::StreamExt;

let mut decoder = AsyncVideoDecoder::open("video.mp4").await?;
while let Some(frame) = decoder.decode_frame().await? {
    println!("frame at {:?}", frame.timestamp().as_duration());
}

Implementations§

Source§

impl AsyncVideoDecoder

Source

pub fn builder(path: impl AsRef<Path>) -> AsyncVideoDecoderBuilder

Returns a builder for configuring the async video decoder.

Use this when you need to control the output pixel format or frame scaling. For zero-configuration decoding, prefer AsyncVideoDecoder::open.

§Examples
use ff_decode::AsyncVideoDecoder;
use ff_format::PixelFormat;

let decoder = AsyncVideoDecoder::builder("video.mp4")
    .output_format(PixelFormat::Rgb24)
    .output_size(640, 360)
    .build()
    .await?;
Source

pub async fn open( path: impl AsRef<Path> + Send + 'static, ) -> Result<Self, DecodeError>

Opens the video file asynchronously.

File I/O and codec initialisation are performed on a spawn_blocking thread so the async executor is not blocked.

§Errors

Returns DecodeError if the file is missing, contains no video stream, or uses an unsupported codec.

Source

pub async fn decode_frame(&mut self) -> Result<Option<VideoFrame>, DecodeError>

Decodes the next video frame.

The blocking FFmpeg call is offloaded to a spawn_blocking thread so the Tokio executor is never blocked.

Returns Ok(None) at end of stream.

§Errors

Returns DecodeError on codec or I/O errors.

Source

pub fn into_stream( self, ) -> impl Stream<Item = Result<VideoFrame, DecodeError>> + Send

Converts this decoder into a Stream of video frames.

Decoding is offloaded to a spawn_blocking thread on each poll via Self::decode_frame. The stream is Send and can be used with tokio::spawn.

The stream ends when the file is exhausted (Ok(None) from decode_frame). Errors are yielded as Err items; the stream terminates after the first error.

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, 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.