Skip to main content

Module stream

Module stream 

Source
Expand description

Async streaming for video and audio extraction.

This module provides FrameStream for asynchronously iterating over decoded video frames, and AudioFuture for extracting audio data in the background without blocking the async runtime.

Both types use tokio::task::spawn_blocking internally — decoding happens on a dedicated blocking thread while results are streamed back through a bounded channel. This avoids tying up the Tokio runtime’s cooperative task budget with CPU-heavy FFmpeg work.

§Example

use tokio_stream::StreamExt;

use unbundle::{ExtractOptions, FrameRange, MediaFile, UnbundleError};

let mut unbundler = MediaFile::open("input.mp4")?;
let config = ExtractOptions::new();
let mut stream = unbundler
    .video()
    .frame_stream(FrameRange::Range(0, 9), config)?;

while let Some(result) = stream.next().await {
    let (frame_number, image) = result?;
    image.save(format!("frame_{frame_number}.png"))?;
}

Structs§

AudioFuture
A future that resolves to extracted audio data.
FrameStream
A stream of decoded video frames produced by a background decode thread.
MetadataFuture
A future that resolves to media metadata.