Back to Glossary
Video

Audio Codec

What Is an Audio Codec?

An audio codec is the pair of programs that compresses sound for storage or sending and turns it back into samples a speaker can play: the encoder packs the audio, the decoder unpacks it. The Opus and FLAC specs define the decoder exactly and leave the encoder’s choices open, so two encoders can turn one recording into different files that both play.

A codec is not a file type. The file around the audio holds the encoded stream along with timing and tags, and one kind of file can carry several codecs. Some names cover both, MP3 among them.

Lossy codecs drop the least audible detail

They decode to an approximation of the recording, leaving out or coarsening the parts a listener is least likely to notice.

MP3
AAC
Vorbis
Opus

Lossless codecs decode to the exact original

They make the file smaller, and decoding gives back audio bit for bit identical to what went in.

FLAC
ALAC

Uncompressed PCM stores the raw signal

Linear PCM measures the sound at regular intervals and stores each measurement as a number. Audio CDs use it at 16 bits, and it is what nearly every WAV file holds.

8-bit PCM
16-bit PCM
24-bit PCM

How Does a Lossy Codec Decide What to Drop?

Lossy encoders lean on psychoacoustics, the study of what people hear. A loud sound can hide a quieter one close to it in pitch, an effect called masking, which weakens as the two sounds move apart. The encoder estimates that masking threshold as it goes and keeps the noise its compression adds below it, where it can’t be heard.

Hide a quiet tone under noise

The noise plays around 1 kHz with a quiet tone inside it. Switch the tone off and on, then move it two octaves up and try again.

Where the noise and the tone sit, from 250 Hz to 8 kHz. Heights show shape only.

The tone sits at 1 kHz, in the middle of the noise, 18 dB quieter than the noise. Switch the tone off and on: if you can’t pick out the change, an encoder could drop that tone and you wouldn’t miss it.

The sound is made in your browser as it plays. No codec runs here.

Audio Codec vs File Format: What’s the Difference?

The codec decides how the sound is compressed, and the file format decides how it is packed, with timing, tags and sometimes a video track alongside. An extension names the file, not the codec, so the same AAC audio can arrive as an .m4a, an .mp4 or an .aac file. Video files follow the same split, as the WebM vs MP4 and MKV vs MP4 pages show.

MP3 is the name of a codec and of a file

MP3 audio usually travels as an .mp3 file, which wraps the stream and often adds ID3 tags for its metadata. The same audio can also sit inside an MP4, Matroska or 3GP file, and then the extension no longer says MP3.

An .m4a file is an MP4 holding AAC or ALAC

The audio in an .m4a can be lossy AAC or lossless ALAC, and the extension doesn’t say which. A .aac file is something else again: a nearly bare AAC stream in a thin wrapper called ADTS.

A WAV file wraps sound that is almost always uncompressed PCM

WAV is a RIFF container, and RIFF lets it carry several codecs. In practice nearly every WAV file holds linear PCM, which is why WAV and uncompressed audio tend to mean the same thing.

Which Audio Codec Should You Use?

The job decides, and one product may need several. A podcast app might keep each host’s raw recording as a FLAC master, publish the episode as AAC in an .m4a file and run live call-ins over Opus.

  Use Why
Video for the web and social apps AAC The usual pairing for video, and Apple's HLS spec requires a stereo AAC track
Calls and live voice Opus A low-delay codec, built for live audio
Music downloads and podcasts AAC or MP3 Both play in every major browser, though Firefox plays AAC only in an MP4 file
Editing masters and archives FLAC, or WAV with PCM Lossless, so every later export starts from the full recording
Lossless audio for Apple devices ALAC in .m4a Apple's own lossless codec
Surround sound for TVs E-AC-3 or AC-3 The Dolby codecs HLS lists for multichannel audio; AC-3 is also widespread on DVDs and digital TV
Speech on phone networks AMR in .3gp Made for speech sampled at 8 kHz, at 12.2 kbps or less

Can a Device Play a Codec It Can’t Encode?

Yes. Decoding and encoding are separate pieces of software, and a platform can ship one without the other. Android’s own media support table lists MP3 and Vorbis as formats it decodes with no encoder for either, so an Android app can play both but can’t write them with the built-in encoders.

For an app, that makes the question two questions: can this device play the format, and can it create one. In a browser, the media element’s canPlayType() answers the first, and WebCodecs answers the second.

Does Bluetooth Use the File’s Audio Codec?

No. Wireless headphones receive sound through a link codec of their own, which the phone and headphones agree on when they connect: SBC, plus AAC, aptX, aptX HD or LDAC on Android. The phone decodes the file and passes the audio through that encoder, so the two codecs are separate stages.

That is why a FLAC or ALAC file usually reaches wireless headphones in lossy form. Apple’s lossless audio page, for one, says many AirPods and Beats models use its AAC Bluetooth codec, and that Bluetooth connections aren’t lossless.

How Audio Codecs Work in CE.SDK

Music tracks, voice recordings and the sound of your users’ video clips all pass through CE.SDK’s video editing, which decodes each one as it loads and encodes the finished mix on export. Your app picks the audio codec of that export or leaves it on Auto.

Opening audio files and video soundtracks

WAV, MP3 and M4A files open as audio, and video files bring their sound along: AAC or MP3 in MP4 and MOV, Opus or Vorbis in WebM, and Opus in MP4. A WAV file needs PCM or floating-point samples inside, at 8, 16, 24 or 32 bits.

AC-3 sound stopped an MP4 from opening in our web test

In our test of the web editor, an MP4 whose audio was AC-3 failed to load as a whole. The message in the browser console listed the audio codecs the editor accepts in an MP4 and suggested re-encoding the audio to AAC, which is the fix to give your users.

Exporting with AAC or Opus

On Auto, MP4 exports carry AAC and WebM exports carry Opus. In the browser the encoders are the browser’s own, and since Firefox, like Chrome on Linux, can’t encode AAC, MP4 exports made in those browsers carry Opus audio. The iOS and Android SDKs and @cesdk/node-native carry their own Opus and Vorbis encoders. The audio bitrate has its own setting.

FAQs

No. WAV is a container, a RIFF file that can hold several codecs. Nearly every WAV file holds uncompressed linear PCM, though, which is why the two names often get used as if they meant the same thing.

For storing a master, FLAC gives up nothing: it decodes to exactly the audio a PCM WAV holds, in a smaller file. Choose WAV when the app or device that receives the file reads only uncompressed audio.

AAC and MP3, which both play in every major browser. AAC is also the usual soundtrack for video: Apple's HLS spec requires a stereo AAC track, and MDN names AAC the likely best choice for a site that can support just one audio format. Firefox plays AAC only inside an MP4 file.

Yes. The FLAC spec points to a separate definition for storing FLAC in MP4, next to its own mappings for Ogg and Matroska, and MDN lists FLAC among the audio codecs browsers support in MP4 files. A .flac file, by contrast, holds only FLAC audio.

AAC-LC, Opus or Eclipsa Audio, according to YouTube's recommended upload settings, with stereo or stereo plus 5.1 channels at a 48 kHz sample rate.