wav1c - Wondrous AV1 Encoder
An AV1 video encoder written from scratch in safe Rust with zero dependencies. Produces IVF files decodable by dav1d.
Features
- YUV 4:2:0 encoding (8-bit)
- Intra prediction (DC, V, H, Smooth, Paeth) with RD-cost mode selection
- Inter prediction (GLOBALMV with LAST_FRAME reference)
- Forward DCT/ADST transforms with RD-cost type selection (4x4 chroma, 8x8/16x16 luma)
- MSAC arithmetic coding with full coefficient encoding
- GoP structure (keyframe + inter frames)
- Arbitrary frame dimensions up to 4096x2304
- Y4M input, IVF output
- Streaming encoder API (frame-by-frame encoding)
- C FFI shared library for embedding in non-Rust applications
Workspace Structure
wav1c/ Core library with batch and streaming APIs
wav1c-cli/ Command-line encoder
wav1c-ffi/ C FFI shared library (cdylib + staticlib)
wav1c-wasm/ WebAssembly bindings (wasm-bindgen)
Build
CLI Usage
Encode a Y4M video:
Encode a solid color frame:
With options:
Decode with dav1d:
Generate test input with ffmpeg:
Rust Streaming API
use ;
use FramePixels;
let config = EncoderConfig ;
let mut encoder = new.unwrap;
let frame = solid;
encoder.send_frame.unwrap;
let packet = encoder.receive_packet.unwrap;
assert_eq!;
// packet.data contains raw AV1 OBUs (TD + SequenceHeader + Frame)
C FFI
The wav1c-ffi crate produces libwav1c_ffi.dylib (macOS) / libwav1c_ffi.so (Linux) and libwav1c_ffi.a.
Wav1cConfig cfg = ;
Wav1cEncoder *enc = ;
;
Wav1cPacket *pkt = ;
// pkt->data, pkt->size contain raw AV1 OBUs
;
;
Build the C example:
FFmpeg Integration
A patch is included to add wav1c as an FFmpeg external encoder (-c:v libwav1c).
# Build the wav1c static library
# Clone and patch FFmpeg
# Configure with libwav1c (adjust library path as needed)
# Encode
Test
Integration tests decode output with dav1d and verify pixel accuracy. Install dav1d and ensure it is available in your PATH, or set the DAV1D environment variable to point to the binary. Tests will skip gracefully if dav1d is not found.
License
This project is licensed under the Mozilla Public License 2.0. See LICENSE for details.