xaac-rs
High-level Rust bindings for AAC and xHE-AAC encoding and decoding built on top
of libxaac-sys.
An optional python feature also exposes the full high-level API as a PyO3
extension module importable as xaac_rs.
This crate wraps the low-level FFI API exposed by the libxaac-sys
crate and provides a safer, more idiomatic Rust interface for:
- AAC-LC encoding
- HE-AACv1 and HE-AACv2 encoding
- AAC-LD and AAC-ELD encoding
- USAC/xHE-AAC encoder configuration
- Streaming decoder initialization and frame decoding
- Decoder stream metadata and DRC status reporting
- Optional MPEG-D DRC sidecar handling for streams that expose DRC payloads
Example
Basic AAC-LC ADTS encoding:
use ;
let mut encoder = new?;
let pcm = vec!;
let packet = encoder.encode_i16_interleaved?;
assert!;
# Ok::
Chunked AAC decoding:
use ;
let mut decoder = new?;
let data: & = &;
match decoder.decode_stream_chunk?
# Ok::
WAV Conversion Example
The crate includes a runnable example that converts a typical PCM WAV file to AAC ADTS:
The example:
- parses RIFF/WAVE input directly
- supports PCM WAV and
WAVE_FORMAT_EXTENSIBLE - supports 16-bit, 24-bit, and 32-bit PCM
- zero-pads the final partial frame before encoding
See examples/convert_wav_to_aac.rs. The Python equivalent lives at examples/python/convert_wav_to_aac.py.
Decode Examples
Inspect stream metadata:
Decode a stream incrementally:
Python equivalents:
The decoder API now supports:
decode_stream_chunkfor incremental inputfinishto flush/end the stream explicitlyDecodeStatusforFrame,NeedMoreInput, andEndOfStream- richer
StreamInforeporting, including channel mode, DRC state, preroll, and gain payload metadata
Raw and Mp4Raw decoder modes remain explicit through DecoderTransport plus RawStreamConfig.
Python Bindings
Build and install the Python module locally with maturin:
VIRTUAL_ENV="/.venv"
Example:
=
=
=
= *
=
=
=
Public API
Main exported types:
EncoderEncoderConfigProfileOutputFormatDecoderDecoderConfigDecoderDrcConfigDecodeStatusDecodeProgressDecodedFrameEncodedPacketEncodedFrameEncoderDrcConfigInverseQuantizationModeError
Validation
Verified locally with: