Definition of the Opus Audio Codec
updated by
- rfc-8251 — Updates to the Opus Audio Codec
Extracted elements (28)
Both the SILK (LP) and CELT (MDCT) layers share the same entropy coder, eliminating wasted padding bits between them. In Hybrid mode this allows the MDCT layer to consume all bits left unused by the LP layer, making CBR operation straightforward.
CBR mode is recommended when the transport requires fixed-size frames or when encryption is used for highly sensitive or highly constrained audio streams, because VBR bitrate variation driven by speech content can leak information through traffic analysis.
Packing multiple SILK frames into a single Opus packet saves on average half a byte per SILK frame by eliminating inter-frame padding in the range coder, and allows some parameters to be predicted across frames without degrading packet-loss robustness.
Super-wideband (SWB) uses a 24 kHz effective sample rate rather than 32 kHz because the MDCT band layout allows cleanly skipping frequencies above 12 kHz but not those above 16 kHz, and 24 evenly divides 48 kHz. Experimental changes to support a 16 kHz cutoff showed quality degradations at other sample rates and saved negligible bits at typical bitrates.
The primary normative specification for Opus is the source code in Appendix A; only the decoder portion is normative. The C reference implementation takes priority over any conflict with the prose description because it provides bit-exact fixed-point arithmetic and is both human-readable and unambiguous.
Opus Custom (Section 6.2) allows negotiation of non-standard frame sizes and sample rates outside the main specification. Conformance testing for Opus Custom is separate from standard Opus conformance; implementations MUST clearly distinguish the two.
The sample rate can be chosen independently on the encoder and decoder side; e.g., a fullband signal may be decoded as wideband or vice versa. This ensures sender and receiver can always interoperate regardless of actual audio hardware capabilities.
The version of SILK used inside Opus is substantially modified from and not compatible with the stand-alone SILK codec previously deployed by Skype. Implementors interested in the original stand-alone SILK codec must refer to the SILK reference separately.
A decoder implementation MUST support the internal framing described in Section 3. Support for the self-delimiting framing variant in Appendix B is OPTIONAL.
A receiver MUST NOT process packets that violate any of the well-formedness constraints [R1]–[R7] as normal Opus packets; they are reserved for future applications such as in-band metadata headers.
Decoder conformance is verified by running the reference decoder against test vectors; a conforming decoder MUST produce output that is bit-for-bit identical to the reference implementation output for all test vectors provided in Appendix A.
If the range decoder consumes all bytes in the current frame, it MUST continue to use zero for any further required input bytes, even if additional data from padding or other frames is present in the packet.
Opus padding bytes appended at the end of a Code 3 packet MUST be set to zero by the encoder to avoid creating a covert channel. The decoder MUST accept any value for the padding bytes.
The length of any individual Opus frame MUST NOT exceed 1275 bytes [R2], to allow repacketization by gateways and conference bridges.
When ec_dec_uint() decodes a value t that is >= ft (indicating a corrupt frame), the decoder SHOULD take measures to conceal the error, such as saturating to ft−1 or invoking Packet Loss Concealment (PLC), and/or report the error to the application.
Discontinuous Transmission (DTX) reduces bitrate during silence or background noise by encoding only one frame every 400 milliseconds when enabled.
Forward Error Correction (FEC) is implemented via in-band LBRR frames: packets containing perceptually important speech (onsets, transients) are re-encoded at a lower bitrate and the result is appended to a subsequent packet, providing redundancy against packet loss.
Opus defines five audio bandwidths: NB (4 kHz / 8 kHz sample rate), MB (6 kHz / 12 kHz), WB (8 kHz / 16 kHz), SWB (12 kHz / 24 kHz), and FB (20 kHz / 48 kHz). Audio above 20 kHz is never coded.
The 32 TOC configurations (0–31) map to three operating modes—SILK-only (configs 0–11, NB/MB/WB), Hybrid SILK+CELT (configs 12–15, SWB/FB), and CELT-only (configs 16–31, NB/WB/SWB/FB)—each paired with frame sizes of 10/20/40/60 ms for SILK and 2.5/5/10/20 ms for CELT.
The SILK LP layer of an Opus frame may contain one 10 ms or up to three 20 ms regular SILK frames, optionally preceded by Low Bit-Rate Redundancy (LBRR) frames encoding previous frames at reduced bitrate for packet-loss recovery. For stereo, mid and side channel frames are interleaved.
Well-formedness constraints R1–R7 cover: minimum one byte per packet; max 1275-byte frame; Code 1 even payload; Code 2 valid length fields; Code 3 non-zero frame count and max 120 ms audio; Code 3 CBR divisibility; and Code 3 VBR sufficient header bytes plus frame lengths.
Implementations must carefully validate all length fields in Opus packets before use, as malformed packets with inconsistent or oversized frame lengths could cause buffer overreads or overflows in a decoder. The constraints R1–R7 in Section 3.4 are the normative guard against such attacks.
Variable bitrate operation can leak information about audio content through traffic analysis. For sensitive or highly constrained audio (e.g., yes/no prompts), CBR mode SHOULD be used to prevent an observer from inferring content from packet sizes.
The range decoder maintains a two-tuple state (val, rng), both 32-bit unsigned integers. Initialization sets rng = 128 and val = 127 − (b0 >> 1). After each symbol decode, renormalization repeats until rng > 2^23 by left-shifting rng by 8 and consuming 7 bits from the next input byte.
Code 3 packets include a frame count byte following the TOC byte: bit 0 ('v') signals VBR, bit 1 ('p') signals Opus padding presence, and bits 2–7 ('M') encode the frame count. M MUST NOT be zero and total audio duration MUST NOT exceed 120 ms [R5].
The range coder and raw bits occupy the same byte sequence within a CELT frame: range coder data is packed MSB-to-LSB from the start of the frame, while raw bits are packed LSB-to-MSB from the end; the two regions may overlap, and a decoder MUST allow this overlap.
The TOC byte occupies the first byte of every Opus packet and encodes: a 5-bit 'config' field (bits 0–4) selecting one of 32 mode/bandwidth/frame-size configurations, a 1-bit stereo flag 's' (bit 5), and a 2-bit frame-count code 'c' (bits 6–7) indicating 1 frame, 2 equal-size frames, 2 variable-size frames, or an arbitrary number of frames.
Variable-length frame length coding uses 1 or 2 bytes: values 1–251 encode the length directly; values 252–255 signal a second byte, with total length = (second_byte × 4) + first_byte; value 0 indicates no frame (DTX or lost). Maximum representable length is 1275 bytes.