OGG Container: Vorbis and Opus Audio Explained
OGG is an open, patent-free multimedia container format developed by Xiph.Org Foundation, first released in 2000. The name "OGG" refers to the container — the audio codecs that typically ride inside it are Vorbis (the original lossy codec) and Opus (the modern successor). Both are royalty-free alternatives to MP3 and AAC. Understanding the distinction between OGG (the container) and the codecs it carries is essential for choosing the right format for music streaming, podcasting, gaming, and web audio.
OGG: The Container
The OGG container uses a bitstream format based on pages:
OGG Bitstream:
[OGG Page] [OGG Page] [OGG Page] ...
OGG Page:
capture_pattern: "OggS" (4 bytes)
version: 0x00 (1 byte)
header_type: continued/first/last packet flags (1 byte)
granule_position: current logical position (8 bytes)
serial_number: unique stream identifier (4 bytes)
page_sequence_no: monotonically increasing (4 bytes)
checksum: CRC-32 of page content (4 bytes)
segments: number of lace segments (1 byte)
lace_values: segment lengths (1-255 bytes per segment)
data: compressed audio payload
OGG can multiplex multiple logical bitstreams (audio + subtitles + video) in a single file through unique serial numbers. For audio-only OGG files, a single logical stream contains the Vorbis or Opus codec data.
Vorbis: The Original OGG Audio Codec
Vorbis was developed by Christopher "Monty" Montgomery and released in 2000. It was designed as a direct open-source replacement for MP3, using a psychoacoustic model to remove perceptually irrelevant audio information.
Vorbis Compression Pipeline
-
MDCT transform: Audio frames of 2048 or 512 samples are transformed using the Modified Discrete Cosine Transform into frequency domain coefficients. The sliding 50% overlap between frames avoids blocking artifacts.
-
Psychoacoustic masking: Vorbis applies a masking model to determine which frequency components are audible at each moment. Sounds masked by louder adjacent sounds (temporal and simultaneous masking) are allocated fewer or zero bits.
-
Residue vectors: The masked spectrum is encoded using a combination of vector quantization (codebook lookup) and scalar quantization for residual values.
-
Entropy coding: The final output uses Huffman-like coding tuned to the statistical distribution of Vorbis coefficients.
Vorbis Quality Modes
Vorbis uses a quality level (-q flag in oggenc) from -1 to 10:
| Quality | Bitrate | Use Case |
|---|---|---|
| -q -1 | ~45 kbps | Not recommended |
| -q 0 | ~64 kbps | Speech, podcasts |
| -q 2 | ~96 kbps | Acceptable music |
| -q 4 | ~128 kbps | Good music streaming |
| -q 6 | ~192 kbps | High quality |
| -q 8 | ~256 kbps | Very high quality |
| -q 10 | ~500 kbps | Near lossless |
Vorbis at -q4 (~128 kbps) is generally considered transparent for most listeners with typical playback equipment. At -q6 (~192 kbps), it matches or exceeds MP3 at 320 kbps in double-blind listening tests.
Vorbis vs. MP3 vs. AAC
| Codec | Bitrate for Transparency | Open/Free | Browser Support |
|---|---|---|---|
| Vorbis | ~160-192 kbps | ✅ | Firefox, Chrome, Opera (not Safari) |
| MP3 | ~256-320 kbps | ✅ (patents expired 2017) | Universal |
| AAC | ~128-160 kbps | ❌ (patents, licensing) | Universal (except some Linux) |
| Opus | ~64-128 kbps | ✅ | Near-universal |
Opus: The Modern Open Audio Codec
Opus was standardized by the IETF as RFC 6716 in 2012 and is the definitive replacement for Vorbis (and much more). It was designed to be the single codec that performs best across all audio use cases — from 6 kbps telephony to 510 kbps high-quality stereo music.
How Opus Works
Opus is a hybrid codec combining two underlying algorithms:
SILK (originally developed by Skype): Optimized for speech signals. Uses Linear Predictive Coding (LPC) to model the vocal tract, then encodes the residual with a CELP (Code Excited Linear Prediction) approach. Best at low bitrates (6–25 kbps) for voice.
CELT (Constrained Energy Lapped Transform): A transform codec using MDCT similar to Vorbis, but much more sophisticated. Best for music and general audio (20–510 kbps).
Opus dynamically selects between SILK, CELT, or a hybrid mode (used at speech-friendly bitrates where both modes are applied and combined) based on the audio content:
6-8 kbps: SILK only (narrowband speech)
8-24 kbps: SILK only (wideband/fullband speech)
24-32 kbps: Hybrid SILK+CELT (speech with music-like content)
32+ kbps: CELT only (music, general audio)
Opus Key Features
- Variable frame size: 2.5ms to 60ms frames; shorter frames = lower latency
- Network resilience: Built-in FEC (Forward Error Correction) for packet loss recovery — critical for VoIP
- Stereo and multi-channel: Up to 255 channels, including 5.1 surround
- In-band FEC: Redundant audio data encoded within the packet for recovery without retransmission
- Audio bandwidth: Narrowband (8 kHz), Mediumband (12 kHz), Wideband (16 kHz), Super-wideband (24 kHz), Fullband (48 kHz)
Opus Bitrate Recommendations
| Use Case | Bitrate | Notes |
|---|---|---|
| Voice calls | 6–12 kbps | Mono, narrowband |
| Podcast/speech | 24–32 kbps | Mono, fullband |
| Music streaming (good) | 64–96 kbps | Stereo |
| Music streaming (high) | 128–192 kbps | Stereo |
| Transparent music | 192–256 kbps | Stereo |
| Near-lossless music | 320–450 kbps | Stereo |
Opus at 128 kbps consistently outperforms MP3 at 320 kbps and AAC at 192 kbps in perceptual quality tests.
ffmpeg Commands
# OGG Vorbis encoding
ffmpeg -i input.mp3 -c:a libvorbis -q:a 4 output.ogg
ffmpeg -i input.mp3 -c:a libvorbis -b:a 192k output.ogg
# OGG Opus encoding (preferred for new content)
ffmpeg -i input.mp3 -c:a libopus -b:a 128k output.opus
# Or in OGG container:
ffmpeg -i input.mp3 -c:a libopus -b:a 128k output.ogg
# High quality Opus
ffmpeg -i input.wav -c:a libopus -b:a 192k output.opus
# Convert Opus to MP3
ffmpeg -i input.opus -c:a libmp3lame -b:a 320k output.mp3
# Convert Vorbis OGG to AAC
ffmpeg -i input.ogg -c:a aac -b:a 192k output.m4a
# Check audio codec in OGG file
ffprobe -v quiet -print_format json -show_streams input.ogg | grep codec_name
Browser Support
| Format | Chrome | Firefox | Safari | Edge |
|---|---|---|---|---|
| OGG Vorbis | ✅ | ✅ | ❌ | ✅ |
| Opus (.opus) | ✅ | ✅ | ✅ (15.4+) | ✅ |
| Opus in OGG | ✅ | ✅ | ✅ (15.4+) | ✅ |
| MP3 | ✅ | ✅ | ✅ | ✅ |
| AAC | ✅ | ✅ | ✅ | ✅ |
For web audio delivery, Opus in OGG (.opus or .ogg) with MP3/AAC fallback covers all browsers.
Metadata in OGG
OGG uses Vorbis Comment for metadata (compatible with both Vorbis and Opus):
# Read OGG metadata
vorbiscomment -l input.ogg
# or with ffprobe:
ffprobe -v quiet -print_format json -show_format input.ogg | jq '.format.tags'
# Write metadata (ffmpeg)
ffmpeg -i input.ogg -c copy \
-metadata title="Song Title" \
-metadata artist="Artist Name" \
-metadata album="Album Name" \
-metadata date="2024" \
output.ogg
Vorbis Comment stores metadata as UTF-8 key=value pairs, supporting arbitrary tags unlike ID3's fixed tag set. Common tags: TITLE, ARTIST, ALBUM, TRACKNUMBER, DATE, GENRE, COMMENT, DESCRIPTION.
Summary
OGG/Vorbis was the original royalty-free alternative to MP3 and remains viable for audio that needs to avoid patent licensing while maintaining broad compatibility. Opus has superseded Vorbis in every technical respect — it matches AAC quality at half the bitrate for music, and surpasses any existing codec for voice at low bitrates. For new projects, choose Opus with MP3 fallback for maximum compatibility. For voice communication (WebRTC, VoIP, podcast streaming), Opus is the definitive choice.
Related conversions
Audio format pairs that come up most often: