Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Vanilagy/mediabunny/llms.txt
Use this file to discover all available pages before exploring further.
What is @mediabunny/ac3?
@mediabunny/ac3 is an extension package that adds AC-3 (Dolby Digital) and E-AC-3 (Dolby Digital Plus) support to Mediabunny. Browsers have no support for these codecs in their WebCodecs implementations. This package provides both a decoder and encoder, implemented using Mediabunny’s custom coder API.
Under the hood, it uses a fast, size-optimized WASM build of FFmpeg’s AC-3 and E-AC-3 coders.
AC-3 and E-AC-3 support
AC-3 (Dolby Digital) is a widely-used audio codec in:- DVD and Blu-ray discs
- Digital television broadcasts
- Streaming services
- Cinema sound systems
- Better compression efficiency
- Support for more channels (up to 15.1)
- Higher quality at lower bitrates
- Common in streaming platforms like Netflix and Amazon Prime
Installation
This library peer-depends on Mediabunny. Install both packages:Alternatively, you can include them directly using script tags. Download the distribution files from the releases page.
Usage
Registering the decoder
Register the AC-3 and E-AC-3 decoder before starting any decoding tasks:Registering the encoder
To enable encoding to AC-3 or E-AC-3 formats:Registering both
You can register both the decoder and encoder in a single setup:Decoding AC-3 audio
Once registered, Mediabunny automatically uses the AC-3 decoder when processing AC-3 or E-AC-3 audio:- Supports both
'ac3'and'eac3'codecs - Decodes compressed packets to PCM audio samples
- Handles timestamps and sample rate conversions automatically
- Runs in a worker thread for optimal performance
Encoding to AC-3
To encode audio to AC-3 or E-AC-3 format:Encoder configuration
The AC-3 encoder (defined in encoder.ts:20) supports: AC-3:- Channels: 1-8 channels
- Sample rates: 48000 Hz, 44100 Hz, 32000 Hz
- Bitrate: Required (e.g., 192000 for 192 kbps)
- Channels: 1-8 channels
- Sample rates: Standard rates (48000, 44100, 32000) plus reduced rates (24000, 22050, 16000)
- Bitrate: Required
Implementation details
The package uses a shared worker architecture:- Worker client (worker-client.ts): Manages communication with the worker
- Decoder class (decoder.ts:18): Handles decoding workflow
- Encoder class (encoder.ts:20): Handles encoding workflow
- Worker thread (codec.worker.ts): Loads FFmpeg WASM and processes audio
- Accumulates incoming audio samples until a full frame is ready
- Converts samples to f32 interleaved format (required by FFmpeg)
- Encodes complete frames and outputs timestamped packets
- Pads the final frame with silence if needed during flush
- Receives compressed AC-3/E-AC-3 packets
- Decodes them to PCM audio samples
- Preserves timestamps and sample rate information
The WASM build is highly optimized for size and performance, using FFmpeg with only AC-3 and E-AC-3 codecs enabled. This keeps the bundle size minimal while providing full codec support.