rusty_aac
A pure-Rust AAC decoder (LC, Main, LTP, HE-AAC v1/v2, ER LC/LTP/LD/ELD) and AAC-LC encoder. Zero dependencies, no C, no FFI, Apache-2.0.
- Decoder — the whole MPEG-4 AAC family short of USAC: AAC-LC, Main (prediction), LTP, HE-AAC v1 (SBR) and v2 (Parametric Stereo), ER AAC-LC/ LTP, AAC-LD and AAC-ELD, 1024- and 960-sample frames, every sampling rate, mono to 7.1 plus PCE layouts and coupling channels. Every non-USAC ISO/IEC 14496-26 conformance stream decodes sample-exact (≤1 LSB) against FFmpeg — 81 of 83 outright, the other two exact except where FFmpeg itself deviates — see Conformance.
- Encoder — to our knowledge the first pure-Rust AAC encoder on
crates.io (the alternatives,
fdk-aacand libxaac bindings, are C FFI). Psychoacoustic Bark-scale masking model, level-invariant transient detection, block switching, per-band M/S stereo with a joint pair rate loop routed by inter-channel correlation, frame-parallel encoding, an N/4-FFT MDCT and AVX2 (opt-in AVX-512) quantize kernels. - Transport — ADTS, MP4
esds, and LATM/LOAS (the MPEG-TS / broadcast carriage format). - Full configuration support — the complete
AudioSpecificConfig(GASpecificConfig, PCE, ELD, error-resilience flags, all three SBR/PS signalling forms) in theconfigmodule. --no-default-featuresturns off the runtime-detected SIMD kernels and gives a 100%-safe scalar build (everyunsafeblock in the crate is feature-gated SIMD).
What's new in 1.0.0
1.0.0 is the decoder release, and the stable API.
- The whole MPEG-4 AAC family short of USAC decodes: Main (prediction), LTP,
HE-AAC v1 (SBR) and v2 (Parametric Stereo), ER AAC-LC/LTP, AAC-LD,
AAC-ELD, 960-sample frames, 7.1 and PCE layouts (with the CRC-checked height
extension), coupling channels, LATM v0/v1 with mid-stream configuration
changes (
latm::LatmDecoder), and the completeAudioSpecificConfig(config::StreamConfig). - Conformance: every non-USAC stream of the ISO/IEC 14496-26 suite matches FFmpeg 8.1.2 to ≤1 LSB — see Conformance.
- Decode speed: SIMD twins for the FFT under the IMDCT and both SBR filterbanks (AVX / NEON) and for the IMDCT overlap window (SSE / NEON), plus a tabulated dequantiser — each bit-identical with the scalar path it replaces. Measured end to end: LC decode 1.43×, HE-AAC v1 ≈1.4× over the pre-SIMD decoder.
- API changes from 0.5:
SbrSupportgainsFulland is#[non_exhaustive];LoasFramecarries the fullStreamConfig; new modulesconfig,latm'sLatmDecoder, and theprofilefeature (stage profiler + SIMD census, for measurement only).
Measured against FFmpeg's AAC encoder
Everything below is measured, reproducible, and generated by the harness in this repo. 0.5.0 is a large quality step over 0.4.0 — a mean +0.33 ODG across the whole corpus, with gains up to +2.6 ODG on the weakest content — while staying ~5x faster than FFmpeg.
- Encoders: this crate via its CLI vs
ffmpeg -c:a aac(FFmpeg's native AAC encoder), FFmpeg 8.1.2. - Quality metric: PEAQ ODG (ITU-R BS.1387), an external oracle, range
[-4, 0]where 0 is imperceptible. Our own NMR metric is not used for ranking — a self-metric provably flatters the encoder it came from. - Fairness: both candidates are decoded with the same neutral decoder (system FFmpeg) before scoring, so the comparison isolates the encoders.
- Null arm: reference-vs-itself through the same path scores +0.14 ODG. That is the harness ceiling — any score at or above it means transparent.
- Speed: both encoders run as subprocesses with identical invocation shape, best-of-5, ABBA-interleaved, on 24 s clips.
- Corpus: real CC0/Public-Domain music (piano, guitar, vocal; mono and stereo) plus a synthetic suite covering content classes the real corpus lacks. Real and synthetic are reported separately and never averaged together.
Reproduce: python tools/quality/aac_vs_ffmpeg.py in the
main repo.
What changed in 0.5.0
Two measured wins shipped, four candidate tools measured and rejected. Δ is
ours − ffmpeg; positive = we sound better.
| content | 0.4.0 (64/96/128/192k) | 0.5.0 | gain |
|---|---|---|---|
| percussive | -1.18 | -1.73 | -1.96 |
| clean speech | -2.03 | -2.90 | -3.05 |
| guitar stereo | -0.55 | -1.34 | -1.32 |
| piano stereo | -1.12 | -2.11 | -1.73 |
1. A level-invariant transient detector. The previous detector guarded its attack ratio with an absolute energy threshold, so it went blind on quiet content — and because its running average decays between attacks, it flagged percussive material zero times at any level. Every such frame coded as a long block and took the full pre-echo hit. The replacement floors the average relative to the clip's own energy. Measured mean +0.267 ODG, worst class +0.000 — it improves the two weakest classes and changes nothing anywhere else.
2. A joint stereo rate loop. A channel pair's two channels each received a
fixed half of the frame budget and ran independent rate loops — so when M/S made
the side channel nearly empty, its bits were simply wasted while the mid channel
starved. On perfectly-correlated stereo (L == R) at 128 kbps that cost
28 dB of reconstruction SNR versus FFmpeg. 0.5.0 runs one rate loop over
the pair at a common base, so bits follow demand. It is routed by inter-channel
correlation, because the change is a large win on correlated stereo and a loss
on genuinely wide stereo.
Rejected after measurement (all built, all measured, all off): TNS (−0.148 mean, and it destroyed the percussive class), PNS (−0.056, damages real tonal music), tonality-adaptive SMR (−0.049), intensity stereo (−0.004, neutral). Shipping a tool that measures worse is not a feature.
Speed — 3.2–7.9× faster (mean 5.0×)
| clip (24 s) | rusty_aac | FFmpeg native AAC | speed-up |
|---|---|---|---|
| piano | 214× realtime | 57× realtime | 3.8× |
| guitar | 306× realtime | 39× realtime | 7.9× |
| vocal | 299× realtime | 93× realtime | 3.2× |
The 0.5.0 quality work cost no measurable speed.
Current standing, honestly
| content | 64k | 96k | 128k | 192k |
|---|---|---|---|---|
| piano (real, CC0) | -1.29 | -0.25 | +0.28 | +0.44 |
| guitar (real, PD) | -1.02 | -0.03 | +0.65 | +0.47 |
| vocal (real, PD) | -1.92 | -0.38 | +0.39 | +0.60 |
| guitar stereo | -0.31 | -0.46 | -0.15 | +0.35 |
| percussive | +0.49 | -0.01 | -0.17 | -0.31 |
| tonal music | +0.30 | -0.00 | -0.13 | -0.29 |
- We beat FFmpeg's native AAC on real mono music at ≥128 kbps, reaching the harness transparency ceiling while FFmpeg sits around −0.3 to −0.6.
- Percussive and clean speech are no longer the disasters they were — 0.4.0 lost by up to 2.2 and 3.0 ODG; 0.5.0 wins percussive at 64 kbps.
- We are still behind overall, principally at ≤96 kbps, on piano stereo, and
on noise-like content. The encoder still has no bit reservoir, no VBR mode and
no absolute-threshold-of-hearing term; those are the next levers, tracked with
per-class evidence in
docs/finished/codec-aac-quality-plan.md. - Rate caveat: at the 64 k target we emit ~89% of FFmpeg's actual bitrate and at 192 k ~107%, so neither extreme is a perfectly clean like-for-like.
- FFmpeg's native AAC encoder is not the strongest AAC encoder in existence (libfdk-aac generally beats it); it is the one available in a permissive default build.
Patents
The encoder implements only AAC-LC coding tools — the oldest corner of the AAC family. The decoder implements the wider family, including SBR and Parametric Stereo (HE-AAC v1/v2) and the error-resilient / low-delay object types, whose patents are considerably younger than AAC-LC's. It does not implement xHE-AAC (USAC). The code is independently written from ISO/IEC 14496-3 and Apache-2.0-licensed, but no patent license is granted or implied by the copyright license. If you distribute products commercially, consult IP counsel about your own position; see the main repo's patent notes. This is engineering context, not legal advice.
Conformance
Every stream in the FFmpeg FATE copy of the ISO/IEC 14496-26 AAC
conformance suite (plus FATE's own AAC streams) is decoded by this crate and by
FFmpeg 8.1.2 (-flags +bitexact) and compared sample by sample; the ISO
reference PCM is checked as a second oracle where FATE ships it.
| verdict | streams | meaning |
|---|---|---|
| EXACT | 81 | peak difference ≤ 1 LSB vs FFmpeg |
| KNOWN | 2 | exact except where FFmpeg deviates: it ignores a CRC-valid PCE height extension (we honour it), and it emits an uninitialised channel for a stereo config carrying one SCE (we emit silence) |
| not AAC | 8 | xHE-AAC / USAC (ISO/IEC 23003-3) — a separate codec, refused cleanly |
By object type: AAC-LC 55, HE-AAC v1 6, HE-AAC v2 15, Main 2, LTP 1, ER AAC-LD 1,
ER AAC-ELD 3 — all EXACT except the two KNOWN above. The census harness is
examples/aacconf.rs.
Decode
use ;
Encode
use ;
Channel layouts
Decoding handles every channel_configuration (1–7, 11–14),
program_config_element layouts (including the CRC-checked height extension),
coupling channel elements, and mid-stream configuration changes; output is in
the standard interleaved order (FL, FR, FC, LFE, BL, BR, …).
Encoding covers mono through 5.1 (channel_configuration 1–6), emitted with
the ISO-correct element sequence — a 5.1 stream is SCE, CPE, CPE, LFE with
the channel reordering AAC requires, not six single-channel elements.
Interleaved PCM is taken in the standard order. Seven or more channels need a
program_config_element on the encode side, which is not implemented, and are
rejected rather than mis-encoded.
LATM / LOAS
use LatmDecoder;
// Decoding an MPEG-TS / broadcast LOAS stream end to end: `LatmDecoder`
// carries the StreamMuxConfig across `useSameStreamMux` frames and rebuilds the
// decoder when the configuration changes mid-stream (stereo -> 5.1, say).
let mut dec = new;
// let (pcm, used) = dec.decode(&loas_bytes, None)?;
// Transport only: `LatmReader::parse` -> full config + raw access unit.
HE-AAC (SBR / PS)
HE-AAC is decoded in full: SBR (dual-rate and downsampled, with the QMF
banks on FFTs) and Parametric Stereo (10/20/34 bands, IPD/OPD), with
signalling in all three forms real streams use — explicit hierarchical
(audioObjectType 5/29), explicit backward-compatible (the 0x2B7 sync
extension), and implicit (SBR payload in the fill element; a mono stream is
output as stereo, as other decoders do, in case PS appears).
The one exception is the low-delay SBR of AAC-ELD, which needs a different
filterbank: such a stream decodes its ELD core at the core rate, and
AacDecoder::sbr_support() reports SbrSupport::CoreOnly rather than leaving
it to be discovered.
let dec = with_config_bytes?;
println!;
Features
| feature | default | effect |
|---|---|---|
simd |
yes | runtime-detected AVX2 quantize/x^0.75 kernels (bit-exact vs scalar) |
simd-avx512 |
no | adds an 8-lane AVX-512 tier (needs Rust ≥ 1.89; falls back at runtime) |
lab |
no | the quality lab: deterministic corpus, NMR metric, bitrate-ladder runner, WAV I/O. Dev/analysis only |
Part of Remade With Rust
rusty_aac is the standalone AAC engine of
remade_ffmpeg_rs — a
ground-up, permissively-licensed Rust rebuild of FFmpeg. Sister project:
FFAI — media for an AI-first
world. More at github.com/remade-with-rust.
Sibling codec crates: rusty_h264,
rusty_vp9,
rusty_mp3,
rusty-opus, rusty_vorbis, and the
rusty-av1-toolkit forks.
About Mata Network
Mata Network builds sovereign, self-hostable infrastructure. Remade With Rust is our open-source home for the permissively-licensed building blocks that work depends on.
License
Apache-2.0. See LICENSE.