Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
avif-rs
A Rust library to encode AVIF images using SVT-AV1 and decode using dav1d.
⬇️ Installation
This library can be installed using Cargo. To do that, run the following command in your project's root directory:
The crate links as avif, so you import it with use avif; regardless of the package name.
[!NOTE] The first build downloads the prebuilt static binaries for your platform, so an internet connection is required (see Troubleshooting for offline builds).
🤖 Usage
Here are some examples of how to encode and decode AVIF images using this library. These snippets don't have any error handling for the sake of simplicity, but you should always check for errors in production code.
Encoding
let img = open.unwrap; // an image to be encoded
let bytes = encode.unwrap; // encode the image with default settings
write.unwrap; // save the AVIF to a file
Encoding with custom settings
use AvifEncoder;
use ImageEncoder;
let img = open.unwrap;
let mut bytes = Vecnew;
img.write_with_encoder.unwrap;
Decoding
let bytes = read.unwrap; // read the AVIF file
let img = decode.unwrap; // decode it into a DynamicImage
img.save.unwrap; // save it in another format
Probing (header only)
Read the image dimensions and bit depth without decoding the pixels — useful for validation or thumbnailing pipelines:
let bytes = read.unwrap;
let info = probe.unwrap;
println!;
The public API also exposes [encode_buffer] (encode a typed ImageBuffer directly), [AvifEncoder] / [AvifDecoder] for image-trait integration, [EncoderConfig] / [DecoderConfig] for full control, and [libavif_version].
Runnable examples
The examples/ directory has standalone programs covering each part of the API, runnable out of the box against the bundled assets:
💣 Troubleshooting
Encoding in parallel with different configurations crashes
The bundled SVT-AV1 encoder keeps global state that is set per-encode (preset/speed, quality, threading). When two or more encodes run concurrently in the same process with different configurations, that shared state is corrupted and the process segfaults.
- Safe: parallel encoding where every concurrent encode uses the same configuration (e.g. all defaults). This was verified stable under heavy load — dozens of concurrent encodes, including RGBA.
- Unsafe: parallel encoding where threads use different settings at the same time (e.g. one thread at
speed 9 / quality 20while another runs at the defaults).
If you need to encode with different settings across threads, serialize the encode calls behind a lock:
use Mutex;
static ENCODE_LOCK: = new;
let bytes = ;
This is a limitation of the underlying SVT-AV1 C library, not of the wrapper. Decoding is unaffected.
My build fails because it can't download the binaries
The first build fetches the prebuilt static libraries for your platform over the network. For offline or air-gapped builds, download the archive for your target from binaries-avif, extract it, and point the build at it with the AVIF_BINARIES_DIR environment variable:
$ AVIF_BINARIES_DIR=/path/to/extracted/libs cargo build
📝 License
avif-rs is released under the Apache 2.0 License. See LICENSE for details.
👨🏾💻 Author
Vinicius Egidio (vinicius.io)