pub struct AsyncVideoEncoder { /* private fields */ }Expand description
Async wrapper around VideoEncoder.
Frames are queued into a bounded channel (capacity 8) and encoded by a
dedicated worker thread. When the channel is full, push suspends the
caller, providing natural back-pressure.
§Construction
Use VideoEncoder::create to configure the encoder, then call
AsyncVideoEncoder::from_builder:
use ff_encode::{AsyncVideoEncoder, VideoEncoder, VideoCodec};
let mut encoder = AsyncVideoEncoder::from_builder(
VideoEncoder::create("output.mp4")
.video(1920, 1080, 30.0)
.video_codec(VideoCodec::H264),
)?;
encoder.push(frame).await?;
encoder.finish().await?;§Back-pressure
The internal channel holds at most 8 frames. Once that buffer is full,
push yields until the worker drains a slot. This prevents unbounded
memory growth when the encoder cannot keep up with the frame rate.
Implementations§
Source§impl AsyncVideoEncoder
impl AsyncVideoEncoder
Sourcepub fn from_builder(builder: VideoEncoderBuilder) -> Result<Self, EncodeError>
pub fn from_builder(builder: VideoEncoderBuilder) -> Result<Self, EncodeError>
Builds an async encoder from a configured builder.
Consumes the builder, validates the configuration, opens the output file, and starts the worker thread. The worker runs the synchronous FFmpeg encode loop in the background.
§Errors
Returns EncodeError if the builder configuration is invalid or
the output file cannot be created.
Sourcepub async fn push(&mut self, frame: VideoFrame) -> Result<(), EncodeError>
pub async fn push(&mut self, frame: VideoFrame) -> Result<(), EncodeError>
Queues a video frame for encoding.
If the internal channel (capacity 8) is full, this method suspends the caller until the worker drains a slot.
§Errors
Returns EncodeError::WorkerPanicked if the worker thread has
exited unexpectedly.
Sourcepub async fn finish(self) -> Result<(), EncodeError>
pub async fn finish(self) -> Result<(), EncodeError>
Signals end-of-stream, flushes remaining frames, and writes the file trailer.
Drops the channel sender (signalling EOF to the worker), then waits for the worker thread to finish without blocking the async executor. Any error from the worker is propagated back to the caller.
§Errors
Returns EncodeError if encoding fails during flush or if the
worker thread panicked.