What Are OGG and Vorbis?
OGG and Vorbis are two distinct but related technologies from the Xiph.Org Foundation:
- Ogg is a container format (like MKV or MP4) — a bitstream multiplexer that packages one or more logical bitstreams (audio, video, metadata) into a single file or network stream. It is patent-free and royalty-free.
- Vorbis is an audio codec — a lossy compression algorithm similar in goal to MP3 and AAC. It operates inside the Ogg container.
When people say "OGG file," they almost always mean "Vorbis audio in an Ogg container" — an .ogg file. But Ogg can also contain Theora video, Opus audio, FLAC audio (OggFLAC), Speex speech audio, and other codecs. The combination is always codec/container, so Opus/Ogg and FLAC/Ogg are equally valid Ogg files.
Vorbis was developed by Christopher Montgomery (Monty) starting in 1998 and reached stable 1.0 status in 2002. It was revolutionary at the time: a free, high-quality alternative to the patent-encumbered MP3, achieving better quality at equivalent bitrates through superior psychoacoustic modeling.
The Ogg Container Format
Page Structure
Ogg bitstreams are divided into pages — the fundamental unit of the Ogg container. Each page is:
capture_pattern: 4 bytes "OggS" (0x4F676753)
stream_structure_version: 1 byte (always 0)
header_type_flag: 1 byte
bit 0: continued packet
bit 1: first page (bos — beginning of stream)
bit 2: last page (eos — end of stream)
granule_position: 8 bytes (sample position, codec-defined)
bitstream_serial_number: 4 bytes (identifies logical stream)
page_sequence_number: 4 bytes
checksum: 4 bytes (CRC-32)
number_of_segments: 1 byte
segment_table: [number_of_segments] bytes (segment sizes, 0–255 each)
data: [sum of segment sizes] bytes
Maximum page size is 65,536 bytes. The granule position stores the timestamp/sample position in a codec-specific interpretation — for Vorbis, it is the PCM sample number.
Logical Bitstreams and Chaining
Each logical bitstream has a unique serial number. Multiple streams can be:
- Multiplexed: interleaved within the same file (e.g., audio + chapter markers)
- Chained: appended sequentially (concatenating two
.oggfiles creates a valid chained Ogg stream)
The beginning-of-stream (BOS) page contains codec identification headers. For Vorbis, the first three pages are always headers: identification header, comment header, and setup header.
Vorbis Codec
Psychoacoustic Foundation
Like MP3 and AAC, Vorbis exploits human auditory perception:
- Masking model: Loud sounds mask quieter sounds at nearby frequencies (simultaneous masking) and shortly before/after (temporal masking). Masked sounds can be discarded without perceptual loss.
- Critical bands: The auditory system processes sound in overlapping frequency bands of roughly constant width. Vorbis models 25 critical bands (Bark scale).
- Absolute hearing threshold: Very soft sounds below the ear's detection threshold can be omitted entirely.
MDCT Transform
Vorbis uses the Modified Discrete Cosine Transform (MDCT) with two window sizes:
- Short window: 256 samples (128 MDCT coefficients) — captures transients with high time resolution
- Long window: 2048 samples (1024 MDCT coefficients) — captures sustained tones with high frequency resolution
Window switching happens automatically based on transient detection. The MDCT is overlapped 50% and windowed with a Kaiser-Bessel-derived (KBD) window for smooth transitions between frames.
Residue Coding
After psychoacoustic analysis removes inaudible components, remaining frequency coefficients are encoded using:
- Floor curve: A piecewise linear envelope (Floor type 1) or LSP-based spectral envelope (Floor type 0, deprecated) that models the spectral shape
- Residue: The difference between the floor and actual spectrum, vector-quantized using codebooks
- Huffman coding: Final entropy coding of the quantized residues
Quality Modes
Vorbis uses a quality-based VBR system rather than a fixed bitrate:
| Quality | Approx. Bitrate | Use Case |
|---|---|---|
| -q 0 | ~64 kbps | Low bandwidth streaming |
| -q 2 | ~96 kbps | Basic streaming |
| -q 4 | ~128 kbps | Standard quality |
| -q 5 | ~160 kbps | Good quality |
| -q 6 | ~192 kbps | High quality |
| -q 8 | ~256 kbps | Very high quality |
| -q 10 | ~500 kbps | Archival quality |
The default is -q 3 (~112 kbps). Fractional quality values are allowed (e.g., -q 4.5).
Encoding and Decoding
FFmpeg (Most Common)
# Convert MP3 to OGG Vorbis (default quality ~128 kbps)
ffmpeg -i input.mp3 -c:a libvorbis output.ogg
# Specific quality level
ffmpeg -i input.wav -c:a libvorbis -q:a 6 output.ogg
# Specific bitrate (ABR mode)
ffmpeg -i input.wav -c:a libvorbis -b:a 192k output.ogg
# OGG to MP3
ffmpeg -i input.ogg -c:a libmp3lame -q:a 2 output.mp3
# OGG to AAC (M4A)
ffmpeg -i input.ogg -c:a aac -b:a 192k output.m4a
oggenc/oggdec (Reference Tools)
# Encode WAV to OGG
oggenc -q 6 input.wav -o output.ogg
# Batch encode all WAV in directory
oggenc -q 5 *.wav
# Decode OGG to WAV
oggdec input.ogg -o output.wav
Python (mutagen for tags, soundfile for audio)
import mutagen.ogg
import mutagen.oggvorbis
# Read OGG tags
audio = mutagen.oggvorbis.OggVorbis('song.ogg')
print(audio['title'])
print(audio['artist'])
print(audio.info.length) # duration in seconds
print(audio.info.bitrate) # nominal bitrate
# Set tags
audio['album'] = ['My Album']
audio.save()
Vorbis Comment (Metadata)
Vorbis uses a simple key=value metadata system called Vorbis Comment (stored in the comment header page):
TITLE=Bohemian Rhapsody
ARTIST=Queen
ALBUM=A Night at the Opera
DATE=1975
TRACKNUMBER=11
GENRE=Rock
COMMENT=Remastered 2011
Keys are case-insensitive, may repeat (multiple ARTIST values), and can hold any UTF-8 string. There is no defined maximum length. Common tags: TITLE, VERSION, ALBUM, TRACKNUMBER, ARTIST, PERFORMER, COPYRIGHT, LICENSE, ORGANIZATION, DESCRIPTION, GENRE, DATE, LOCATION, CONTACT, ISRC.
Streaming with Ogg/Vorbis
Ogg was designed for streaming from its inception — page structure allows seeking without full index, and the container is streamable from any byte position given a resync mechanism.
Icecast internet radio server natively streams Ogg/Vorbis (and Ogg/Opus):
# ices2 — Ogg/Vorbis streaming source client
ices2 /etc/ices2.xml
# FFmpeg → Icecast
ffmpeg -re -i input.ogg -c:a libvorbis -q:a 4 \
-f ogg icecast://source:password@localhost:8000/stream
Browser support for OGG streaming: Firefox and Chrome support <audio> with OGG natively. Safari requires a fallback.
OGG/Vorbis vs Competitors
| Feature | OGG/Vorbis | MP3 | AAC (M4A) | Opus |
|---|---|---|---|---|
| License | Patent-free, royalty-free | Patent expired (2017) | Patent, royalty-free playback | Patent-free |
| Quality at 128 kbps | Very good | Good | Better | Best |
| Quality at 64 kbps | Fair | Poor | Fair | Excellent |
| Latency | High (2048-sample frames) | Medium | Medium | Very low (20ms) |
| Streaming suitability | Good | Good | Good | Excellent |
| Browser support | Firefox, Chrome | Universal | Universal | Firefox, Chrome, Edge |
| Seeking | Yes | Yes (with index) | Yes | Yes |
| Hardware decode | Limited | Universal | Common | Growing |
| Best for | Desktop/Linux audio | Legacy compatibility | Apple ecosystem | Modern streaming |
Key takeaway: Vorbis was the best free audio codec from 2002–2012. For new projects, Opus (also in an Ogg container, .opus extension) is strictly superior — better quality at all bitrates, especially below 128 kbps, with lower latency and equal patent freedom. Vorbis remains excellent for existing content and workflows.
OGG/Vorbis in Practice
Game audio: The Vorbis codec is used extensively in games — it's included in Unity, Unreal Engine, and countless game SDKs as the preferred format for music and long sound effects (short effects use uncompressed WAV for zero-latency playback).
Linux desktop: OGG/Vorbis is the default audio format for many Linux distributions, supported natively in GTK, Qt applications, and GStreamer pipelines.
Wikipedia: All audio on Wikipedia is served as OGG/Vorbis for legal (patent-free) reasons.
Converting existing MP3 libraries: Transcoding MP3→OGG incurs generational quality loss — avoid unless necessary. Always transcode from lossless sources (FLAC, WAV).
OGG/Vorbis remains a landmark achievement in open-source codec development, and the Ogg container standard continues to serve as the backbone of the Xiph.Org codec ecosystem including Opus, Theora, and FLAC.
Related conversions
Audio format pairs that come up most often: