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
impl AsyncVideoDecoder
Sourcepub fn builder(path: impl AsRef<Path>) -> AsyncVideoDecoderBuilder
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?;Sourcepub async fn open(
path: impl AsRef<Path> + Send + 'static,
) -> Result<Self, DecodeError>
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.
Sourcepub async fn decode_frame(&mut self) -> Result<Option<VideoFrame>, DecodeError>
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.
Sourcepub fn into_stream(
self,
) -> impl Stream<Item = Result<VideoFrame, DecodeError>> + Send
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.