Pure Rust AVIF image decoder powered by rav1d.
- 100% Safe Rust - Default
managedfeature uses zero unsafe code - Fast - Optional
asmfeature uses hand-written assembly for maximum performance - Comprehensive - Supports 8/10/12-bit, all chroma subsampling modes, alpha channel
- Ergonomic API - Simple decode functions with detailed error types
- Cancellable - Built-in cooperative cancellation support
use zenavif::decode;
let avif_data = std::fs::read("image.avif")?;
let image = decode(&avif_data)?;
match image {
DecodedImage::Rgb8(img) => {
println!("RGB8 image: {}x{}", img.width(), img.height());
}
DecodedImage::Rgba8(img) => {
println!("RGBA8 image: {}x{}", img.width(), img.height());
}
_ => {}
}100% safe Rust implementation using rav1d-safe's managed API. No unsafe code in the entire decode path. Enforced by #![deny(unsafe_code)] at module level.
High-performance implementation using hand-written assembly. Uses C FFI for maximum speed. Best for production workloads where performance is critical.
use zenavif::{decode_with, DecoderConfig};
use enough::Unstoppable;
let config = DecoderConfig::new()
.threads(4) // Use 4 threads (0 = auto-detect)
.apply_grain(true) // Apply film grain
.frame_size_limit(8192 * 8192); // Max 8K resolution
let image = decode_with(&avif_data, &config, &Unstoppable)?;- ✅ 8-bit, 10-bit, 12-bit color depth
- ✅ 4:2:0, 4:2:2, 4:4:4 chroma subsampling
- ✅ Monochrome (grayscale)
- ✅ Alpha channel (straight and premultiplied)
- ✅ Full and limited color range
- ✅ HDR color spaces (BT.2020, P3, etc.)
- ❌ Animated AVIF (use real AV1 video instead)
- ❌ Grid-based collages
# Safe managed API (default)
cargo build --release
# Fast assembly version
cargo build --release --no-default-features --features asm
# Run tests
cargo test
# Run with test vectors
just download-vectors
just test-integrationThis project builds on excellent work by others:
-
rav1d (BSD-2-Clause) — Pure Rust AV1 decoder (Rust port of dav1d). Provides the AV1 decoding backend via its managed safe API.
-
avif-parse (MIT/Apache-2.0) — AVIF container parser for extracting image items and metadata from the ISOBMFF container.
-
yuv (MIT) — YUV to RGB color conversion.
-
libavif (BSD-2-Clause) — Reference AVIF implementation used for pixel-level verification and behavioral reference.
-
Claude (Anthropic) — AI-assisted development. Not all code manually reviewed — review critical paths before production use.
Sustainable, large-scale open source work requires a funding model, and I have been doing this full-time for 15 years. If you are using this for closed-source development AND make over $1 million per year, you'll need to buy a commercial license at https://www.imazen.io/pricing
Commercial licenses are similar to the Apache 2 license but company-specific, and on a sliding scale. You can also use this under the AGPL v3.