rusty_mp3
A pure-Rust MP3 (MPEG-1/2/2.5 Audio Layer III) decoder and encoder. Zero dependencies, no C, no FFI, Apache-2.0. MP3's patents expired in 2017 — the format is royalty-free everywhere.
- Decoder: full MPEG-1/2/2.5 Layer III — bit reservoir, all stereo modes (including mid/side and intensity), alias reduction, hybrid IMDCT, polyphase synthesis. Bit-exact against FFmpeg on our conformance corpus.
- Encoder: to our knowledge the first pure-Rust MP3 encoder on crates.io — existing options are FFI bindings to LAME. MPEG-1/2/2.5, CBR and VBR, mono/stereo/joint (mid/side) stereo, psychoacoustic model with transient block switching, and a bit reservoir (default-on for MPEG-1 CBR ≤ 256 kbps) that puts it at PEAQ parity with LAME across 96–256 kbps on the content we've measured. Known gap: the reservoir is disabled at 320 kbps and for MPEG-2/2.5 (fixed-frame path is used there instead).
Decode
use ;
Encode
use ;
The pull calls follow FFmpeg's EAGAIN/EOF drain protocol: Err(Error::Again)
means "feed more input", Err(Error::Eof) means the flushed stream is fully
drained. Lower-level building blocks (frame-level Mp3Decode/Mp3Encode,
header::FrameHeader, bit I/O, ISO tables) are public too.
Performance
Measured on a real 6:53 stereo 44.1 kHz music track (412.9 s, 15,806 frames) at CBR 192 kbps.
0.4.0 caches the psychoacoustic model's FFT twiddle factors — they depend
only on the transform size, but were rebuilt on every call, which cost ~1.26 M
cos/sin evaluations across the track to produce ten distinct values — and
reuses the mid/side scratch across frames instead of reallocating it:
| before | after | |
|---|---|---|
| encode CPU (median of 41 pairs) | 7,047 ms | 6,766 ms |
| allocations per frame | 32.06 | 21.06 |
| zero-filled allocations / 800 frames | 8,000 | 2 |
1.045× faster encode, 33/41 paired wins, z = 3.90. The output is byte-identical across the change (same md5 over the full track), so both arms are provably doing the same work rather than one of them doing less. Decode is untouched at 5.04 allocations per frame — its per-block path was already allocation-free.
Method: pinned to one core at High priority, CPU time rather than wall, arms ABBA-interleaved, 41 pairs, with a null arm (the same binary against itself) reading 1.017 as the session's resolution floor. This is a same-binary-family delta, not a cross-implementation ratio.
The allocation counts are reproducible with the bundled instrument, which counts through whichever global allocator the binary sets:
Part of Remade With Rust
This crate is the standalone MP3 engine of
remade_ffmpeg_rs — a
ground-up, permissively-licensed Rust rebuild of FFmpeg: a drop-in
ffmpeg/ffprobe CLI on pure-Rust codecs, with no copyleft. Also check out our
sister project FFAI — media for
an AI-first world — and the rest of
github.com/remade-with-rust, including
the sibling codec crates
rusty_h264,
rusty_vp9,
rusty_aac,
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 the workspace LICENSE.