Back to Glossary
Video

Opus Codec

Also known as: Opus Interactive Audio Codec, Opus audio format

What Is the Opus Codec?

Opus is an open, royalty-free audio codec that handles speech and music in one format, standardized by the IETF as RFC 6716 in 2012. It is lossy and covers bitrates from 6 to 510 kbps, and the encoder can change its bitrate, audio band and mode from one packet to the next.

Opus joins two older codecs: SILK, which Skype built for speech, and CELT, a low-delay codec from Xiph.Org that also suits music. Every WebRTC endpoint is required to support it, so any browser that makes WebRTC calls can send and receive Opus, and WebM files allow it next to Vorbis.

6 kbps

lowest bitrate

so a call can keep going on a weak connection, in narrowband

510 kbps

highest bitrate

above the 64 to 128 kbps the spec suggests for stereo music

5 ms

shortest delay

in the lowest-delay setting, which leaves SILK out and codes with CELT

20 kHz

top of the audio band

Opus spends no bits on sound above it

What Does Opus Keep at Each Bitrate?

At low bitrates the encoder narrows the audio band, dropping the highest sounds, and it can code a stereo clip as mono to save bits. Move the bitrate below and the readout shows what it chose, read from the first byte of every packet it wrote.

Encode a clip with Opus

Pick a bitrate, a tuning and a frame length, then switch between the Opus version and the original to hear the difference.

Everything runs in your browser with its own Opus encoder, and nothing is uploaded.

How Do the SILK, Hybrid and CELT Modes Differ?

Opus codes each packet in one of three modes and can switch between them from one packet to the next. The first byte of every packet names the mode, the audio band and the frame length, which is how the player above reads them.

SILK codes speech at low bitrates

The layer based on Skype’s speech codec models the voice with linear prediction. It keeps sound up to 4, 6 or 8 kHz in frames of 10 to 60 ms.

Hybrid mode splits the band at 8 kHz

SILK codes the voice below 8 kHz and CELT the sound above it, up to 12 or 20 kHz. Opus uses it for super-wideband and fullband speech at medium bitrates, in frames of 10 or 20 ms.

CELT codes music and the shortest frames

The layer from Xiph.Org codes the spectrum with a transform, from narrowband up to 20 kHz. It is the only mode for frames under 10 ms, down to 2.5 ms, because SILK only takes frames of 10 ms or longer.

What Bitrate Should You Use for Opus?

The Opus specification gives a sweet spot for each kind of audio at 20 ms frames, listed below. A voice-note app, for example, can send wideband speech at 16 to 20 kbps, while a stereo music track sits between 64 and 128 kbps. When speech and music mix, as in a video with a soundtrack, tune the encoder for music: the voice setting filters the sound to bring out speech, so music can come out different from the source even at high bitrates.

  Bitrate Sound kept up to
Calls on a weak connection 8 to 12 kbps 4 kHz (narrowband)
Voice chat and voice notes 16 to 20 kbps 8 kHz (wideband)
Speech in podcasts and videos 28 to 40 kbps 20 kHz (fullband)
Mono music 48 to 64 kbps 20 kHz (fullband)
Stereo music 64 to 128 kbps 20 kHz in both channels

Which Files Can Hold Opus Audio?

Opus has a published mapping for each of the common ways audio travels: files, streams and real-time calls. Ogg Opus files and RTP calls both count time in 48 kHz samples, whatever rate the source was recorded at.

  • .opus files

    Ogg Opus, the extension RFC 7845 recommends

  • WebM and MKV

    Matroska stores it under the codec ID A_OPUS

  • MP4

    Through a mapping the Opus project publishes

  • MPEG-TS

    MPEG transport streams can carry it too

  • RTP for calls

    RFC 7587 sets how WebRTC and other calls carry it

How Opus Works in CE.SDK

Opus is the default audio of the WebM files your users export with video editing in CE.SDK, and MP4 exports fall back to it when the browser has no AAC encoder. Your app can also pick the codec itself, and Opus sound opens again on import.

WebM exports carry Opus by default

Choose WebM as the file type and the audio is Opus unless your app sets a different one. On the web CE.SDK uses the browser’s own encoders, and since none of them writes Vorbis, web exports in WebM always get Opus. On iOS, macOS, Android and @cesdk/node-native, the engine bundles its own encoders, and Vorbis is an option too.

MP4 exports switch to Opus without an AAC encoder

MP4 audio is AAC by default, but where AAC can’t be encoded, as in Firefox or Linux versions of Chrome, the automatic setting writes Opus instead, so the export still works. The finished file opens for editing again on the web, Opus sound included.

Choose the audio codec and check the encoder

With audioCodec, your app sets the codec itself: AAC or Opus in an MP4, and Opus in a WebM, or Vorbis in a WebM outside the web. Once checkCapabilities() has run, getCapabilityState('opusEncode') tells your app whether Opus encoding is available. Asking for a codec the file type can’t hold ends the export in an error that lists the codecs that fit.

Opus sound opens in WebM, MP4 and MKV files

Your users can import WebM, MP4 and MKV videos with Opus sound, and WebM audio files, then edit them on the timeline alongside their other footage. In a web app the decoding is the browser’s job, and getCapabilityState('opusDecode') reports whether it can once the check has run.

FAQs

Each suits a different job. Opus is royalty-free and has less delay: MDN lists a latency of 5 to 66.5 ms for Opus against 20 to 405 ms for AAC, and WebRTC requires Opus for calls. AAC is the usual audio of MP4 files, and as a patented format it leans on the platform in some browsers, so Firefox plays it through the support the operating system provides.

No. Opus is lossy, so the decoded sound comes close to the source without ever matching it bit for bit, and the original sample rate is not kept either. For an exact copy, pick FLAC or uncompressed WAV, which keep every sample.

An Ogg file holding one Opus audio stream. RFC 7845 defines how Opus goes into the Ogg container and recommends the .opus extension for these files. A header at the start names the channel count and the original sample rate, and a second one carries tags such as the title and artist in the same format Ogg Vorbis files use.

Yes, after a resample. The reference encoder takes input at 8, 12, 16, 24 or 48 kHz, so 44.1 kHz audio is converted on the way in, and a player decodes at 48 kHz when the hardware supports it. An Ogg Opus file can store the original rate as metadata for a tool that wants to convert back.

Two features for calls. With in-band forward error correction, the encoder codes the most important parts of the speech, such as the start of a sound, a second time at a lower bitrate inside the next packet, so a decoder can fill in a packet that was lost. With discontinuous transmission, it sends only one frame every 400 ms during silence or background noise.