av-decoders
A unified Rust library for video decoding that provides a consistent interface across multiple decoding backends. Part of the rust-av ecosystem, outputting frames in the standard v_frame format.
Features
- Multiple Decoding Backends: Supports Y4M, FFmpeg, and VapourSynth decoders
- Automatic Format Detection: Automatically selects the best decoder for your input
- Consistent API: Same interface regardless of the underlying decoder
- Zero-Copy Operations: Efficient frame handling with minimal memory overhead
- Comprehensive Error Handling: Detailed error messages for debugging
Supported Formats
| Backend | Formats | Notes |
|---|---|---|
| Y4M (default) | .y4m, .yuv |
Fastest, lowest overhead |
| FFmpeg (optional) | Most video formats | Broad format support |
| VapourSynth (optional) | Enhanced processing | Best metadata accuracy and seeking |
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Feature Flags
Enable additional decoders with feature flags:
[]
= { = "0.1.0", = ["ffmpeg", "vapoursynth"] }
Available features:
ffmpeg- Enable FFmpeg-based decoding for broad format supportvapoursynth- Enable VapourSynth-based decoding for advanced processingffmpeg_static- Link FFmpeg staticallyffmpeg_build- Build FFmpeg from source
Quick Start
Basic Usage
use Decoder;
// Decode from a file
let mut decoder = from_file?;
let details = decoder.get_video_details;
println!;
// Read frames
while let Ok = decoder.
Reading from stdin
use Decoder;
let mut decoder = from_stdin?;
let frame = decoder.?;
Working with Different Bit Depths
// For 8-bit video
let frame_8bit = decoder.?;
// For 10-bit video
let frame_10bit = decoder.?;
Accessing Video Metadata
let details = decoder.get_video_details;
println!;
println!;
println!;
println!;
API Reference
Main Functions
Decoder::from_file(path)- Create a decoder from a file pathDecoder::from_stdin()- Create a decoder reading from stdin
Decoder Methods
get_video_details()- Get video metadata and configurationread_video_frame::<T>()- Read the next frame as type T (u8 or u16)
Video Details
The VideoDetails struct provides essential video information:
Backend Selection
The library automatically selects the best decoder based on:
- File Extension: Y4M files (
.y4m,.yuv) use the Y4M parser - Feature Availability: FFmpeg preferred over VapourSynth when both available
Error Handling
use ;
match from_file
Examples
Frame Processing Pipeline
use Decoder;
use ChromaSampling;
Building from Source
# Clone the repository
# Build with default features (Y4M only)
# Build with all features
# Run tests
System Dependencies
For FFmpeg support:
- FFmpeg development libraries
- Or use
ffmpeg_buildfeature to compile from source
For VapourSynth support:
- VapourSynth installation
- Python development headers
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.