Get AV1 payload and alpha channel metadata out of AVIF image files. The parser is a fork of Mozilla's MP4 parser used in Firefox, so it's designed to be robust and safely handle untrusted data.
The parser is compatible with files supported by libavif, Chrome 85 and Firefox 81a.
This crate doesn't include an AV1 decoder. To display the pixels you will additionally need dav1d or libaom.
It takes io::Read
, so you can use any readable input, such as a byte slice (vec.as_slice()
), or a File
wrapped in BufReader
, etc.
rust
let data = read_avif(&mut slice)?;
av1_decode(&data.primary_item)?;
if let Some(alpha) = &data.alpha_item {
av1_decode(alpha)?;
}
if data.premultiplied_alpha {
// after decoding, remember to divide R,G,B values by A
}
Install Rust 1.45 or later, preferably via rustup, and run:
bash
cargo build --release
It will build ./target/release/libavif_parse.a
(or avif_parse.lib
on Windows). Link it with your project.
Cargo supports cross-compilation, so you can easily build it for other platforms (e.g. iOS).
```c
avifdatat data = avifparse(filedata, file_length);
if (data) { av1decode(data.primarydata, data.primarysize); if (data.alphadata) { av1decode(data.alphadata, data.alphasize); } if (data.premultipliedalpha) { // after decoding, remember to divide R,G,B values by A } }
avifdatafree(data); ```