ff-decode
Decode video and audio frames without managing codec contexts, packet queues, or timestamp conversions. Open a file, call decode_frame in a loop, and receive VideoFrame objects with their position already expressed as a Duration.
Installation
[]
= "0.3"
= "0.3"
Video Decoding
use VideoDecoder;
use PixelFormat;
let mut decoder = open?
.output_format
.build?;
while let Some = decoder.decode_frame?
Audio Decoding
use AudioDecoder;
use ;
let mut decoder = open?
.output_format
.output_sample_rate
.output_channel_layout
.build?;
while let Some = decoder.decode_frame?
Seeking
use ;
use Duration;
let mut decoder = open?.build?;
// Jump to the nearest keyframe at or before 30 seconds.
decoder.seek?;
// Jump to the exact position (may decode additional frames internally).
decoder.seek?;
Seeking does not re-open the file. The existing codec context is flushed and reused.
Hardware Acceleration
use ;
let mut decoder = open?
.hardware_accel
.build?;
HardwareAccel::Auto probes for NVDEC, DXVA2, VideoToolbox, and VAAPI in that order, and falls back to software decoding if none is available.
Error Handling
| Variant | When it occurs |
|---|---|
DecodeError::FileNotFound |
The input path does not exist |
DecodeError::CannotOpen |
FFmpeg could not open the container or codec |
DecodeError::UnsupportedCodec |
No decoder available for the stream's codec |
DecodeError::InvalidConfig |
Builder options are inconsistent or unsupported |
DecodeError::Io |
Read error on the underlying file |
What the Crate Handles for You
- Codec context allocation and lifetime
- PTS-to-
Durationconversion using the stream's time base - Packet queue management and buffering
- EOF signalled as
Ok(None)rather than a special error variant - Pixel format and sample format negotiation via
swscale/swresample
Feature Flags
| Flag | Description | Default |
|---|---|---|
tokio |
Enables AsyncVideoDecoder and AsyncAudioDecoder. Wraps each blocking FFmpeg call in tokio::task::spawn_blocking and exposes a futures::Stream interface via into_stream(). Requires a tokio 1.x runtime. |
disabled |
[]
= { = "0.5", = ["tokio"] }
When the tokio feature is disabled, only the synchronous VideoDecoder and AudioDecoder APIs are compiled. No tokio dependency is pulled in.
MSRV
Rust 1.93.0 (edition 2024).
License
MIT OR Apache-2.0