What is an audio codec?
An audio codec (coder/decoder) is the algorithm that compresses and decompresses sound. It decides how audio is stored or streamed, how large the file is for a given quality, and which devices can play it back. Picking the right codec is a balance of fidelity, bitrate, latency, and compatibility.
Codec vs. container
A codec is not the same thing as a container. A container (such as MP4, MKV, or WebM) is the wrapper that can hold one or more audio and video streams, plus metadata. The codec is the actual compression method used inside that container. For example, an MP4 file often contains AAC audio, while a WebM file typically contains Opus or Vorbis audio.
How audio codecs work
Raw digital audio is usually stored as PCM (pulse‑code modulation). PCM is accurate, but large. A codec reduces size by applying compression. Lossless codecs compress PCM without removing information. Lossy codecs go further by discarding details that are less audible to the human ear (psychoacoustic modeling), which yields much smaller files at the cost of some quality.
Lossy, lossless, and uncompressed
- Lossy: removes data to shrink files. Best for streaming and general listening when size matters. Examples: MP3, AAC, Opus.
- Lossless: preserves all information while still compressing. Best for mastering, archival, and professional workflows. Examples: FLAC, ALAC.
- Uncompressed: uses PCM encoding without compression. Best for editing pipelines that need zero compression overhead. PCM is commonly stored in WAV or AIFF containers; those containers are not codecs.
Key settings that affect quality and size
- Bitrate: the most direct lever for size and quality. Higher bitrate usually means better quality. Variable bitrate (VBR) adapts to complexity; constant bitrate (CBR) is predictable.
- Sample rate: the amount of samples per second (e.g., 44.1 kHz, 48 kHz). Higher rates capture more detail, but increase size.
- Channels: mono, stereo, or multichannel. The more channels, the larger the size.
- Bit depth: mainly relevant for lossless/uncompressed audio (e.g., 16‑bit vs. 24‑bit).
Common audio codecs and when to use them
- AAC: a strong default for music and general playback; excellent compatibility in MP4.
- MP3: legacy, still widely supported, but less efficient than AAC or Opus at the same bitrate.
- Opus: great for voice, real‑time, and low‑bitrate streaming; excellent quality at small sizes.
- FLAC: lossless compression for archiving and distribution of high‑quality audio.
- PCM: uncompressed audio encoding for editing pipelines and interchange, commonly stored in WAV or AIFF containers.
How to choose the right codec
- Streaming or podcasts: AAC or Opus, depending on device support requirements.
- Voice or real‑time: Opus for low latency and efficiency.
- Archival or mastering: FLAC or uncompressed PCM in a WAV container.
- Maximum compatibility: MP3 still wins on legacy devices, but AAC is broadly supported too.
Encode audio using Transloadit
Our 🤖 /audio/encode Robot lets you convert audio to popular codecs with a few parameters. Here’s a minimal example that converts an upload to MP3 at 128 kbps:
For the storage Step, create your own named Amazon S3 Template Credential
and replace YOUR_AWS_CREDENTIALS with its saved name. Use a private bucket with S3 Block Public
Access enabled and do not supply ACL or grant headers. The bucket-default setting omits the
generated ACL header; it does not make a bucket private. Reading private results requires separate
read authorization; a returned URL does not grant access.
{
"steps": {
"encode_mp3": {
"robot": "/audio/encode",
"use": ":original",
"preset": "mp3",
"bitrate": 128000
},
"store": {
"robot": "/s3/store",
"use": "encode_mp3",
"credentials": "YOUR_AWS_CREDENTIALS",
"acl": "bucket-default"
}
}
}
Need lossless output? Choose an appropriate lossless preset; increasing bitrate does not make a
lossy codec lossless. For different sample rates, set sample_rate accordingly.
Audio Encoding
High-quality FLAC encoding
Audio Encoding
Encoding with a specific bit rate
Audio Encoding
Loudness Normalization
Next steps
- Explore Audio Encoding and browse the 🤖 /audio/encode docs.
- Need help choosing a codec? Reach out at hello@transloadit.com.
