Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:Vorbis

From ReverseEngineering.wiki
Format
Developer Xiph.Org Foundation
Uses Library:Libvorbis
Versions Vorbis I (vorbis_version 0)
Magic 01 76 6F 72 62 69 73 (01 "vorbis") at the start of the first packet
Extensions .ogg, .oga (in Ogg); .webm, .mka (in Matroska)
Endianness little (LSB-first bit packing)
Website https://xiph.org/vorbis/
On this wiki Facts · Code · Notes · Topics

Xiph.Org's lossy audio codec bitstream (Vorbis I): three header packets that start with a type byte and "vorbis" (01 identification: 30 bytes with channels, rate, bitrates, block sizes; 03 comment: vendor string and TAG=value comments; 05 setup: codebooks with the sync bytes "BCV") followed by LSB-first bit-packed audio packets, almost always carried in Ogg.

Overview

Vorbis I is the Xiph.Org lossy audio codec (specification 2002-2020, royalty-free, reference implementation Library:Libvorbis). A Vorbis stream is three header packets followed by audio packets; the packets are almost always carried in Format:Ogg (.ogg, .oga), and also in Matroska/WebM (CodecPrivate holds the three headers in Xiph lacing; from the Matroska codec mappings, not checked here) and, without any container framing, inside some game-audio middleware banks (unverified). Packets are bit-packed least significant bit first (libogg's oggpack_* functions), so multi-bit fields of the header packets look little endian when they are byte-aligned.

Header packets

Every header packet starts with a packet-type byte (odd: bit 0 = 1 means header) and the six ASCII bytes "vorbis":

Type Bytes Packet Contents
1 01 76 6F 72 62 69 73 identification 30 bytes: version, channels, rate, bitrates, block sizes, framing bit; must be alone on the first Ogg page
3 03 76 6F 72 62 69 73 comment vendor string and user comments ("TAG=value", UTF-8), framing bit
5 05 76 6F 72 62 69 73 setup codebooks, time-domain transforms (placeholders), floors, residues, mappings, modes, framing bit

Audio packets have bit 0 = 0, followed by the mode number (ilog(modes-1) bits). libvorbis's vorbis_synthesis_headerin returns OV_ENOTVORBIS when the "vorbis" text is missing and OV_EBADHEADER for a wrong order (comment before identification, setup before comment).

Identification header (byte-aligned, little endian):

Offset Size Field Notes
0x00 7 01 "vorbis"
0x07 4 vorbis_version must be 0 (OV_EVERSION otherwise)
0x0B 1 audio_channels 1-255
0x0C 4 audio_sample_rate > 0
0x10 4 bitrate_maximum signed; 0 or -1 = unset
0x14 4 bitrate_nominal signed; what tools show as "the bitrate"
0x18 4 bitrate_minimum signed
0x1C 1 blocksize_0 (bits 0-3), blocksize_1 (bits 4-7) exponents: 2^n samples, 64 <= blocksize_0 <= blocksize_1 <= 8192; B8 = 256/2048 (the usual value at 44.1/48 kHz)
0x1D 1 framing flag bit 0 must be 1

Comment header: after 03 "vorbis", a u32 vendor length, the vendor string, a u32 comment count, then u32 length + text for each comment, then a framing bit (one byte 01). The same structure without the framing bit is Opus's "OpusTags" packet and FLAC's VORBIS_COMMENT metadata block. libvorbisenc writes its own vendor string (see Library:Libvorbis#Identification), which dates the encoder; FFmpeg's Ogg muxer writes "Lavf<version>" instead.

Setup header: after 05 "vorbis", the codebook count minus one (8 bits), then each codebook starting with the 24-bit sync pattern 0x564342, which appears in the file as the bytes 42 43 56 ("BCV"). The first one is byte-aligned at offset 8 of the setup packet; the following codebooks start at arbitrary bit positions.

Identification

  • An Ogg page whose body starts with 01 "vorbis" (the BOS page, granule 0, usually 58 bytes in total: 28-byte header with one segment + 30-byte packet).
  • Raw Vorbis without Ogg (extracted from game banks): look for 01/03/05 "vorbis" headers and "BCV" right after 05 "vorbis" + one byte.
  • The decoder needs all three headers. If a format omits them (unverified: some middleware stores only the audio packets and a reference to a built-in setup header), the stream cannot be decoded without recovering the setup header.

Granule position and length

The granule position of an Ogg page is the number of PCM samples (per channel) decoded up to the end of the last packet completed on that page; the last page gives the length: granule / sample rate. Encoders can end a stream in the middle of a block: the last granule is then smaller than the samples the last packet would produce, and decoders drop the excess (end trimming). The first audio packet produces no output (it only primes the overlap).

Code & repositories

  • https://github.com/xiph/vorbis @ 1b75110b5a2754ba1931d82dd83cb822b266a21d · license: BSD-3-Clause
    libvorbis, libvorbisenc and libvorbisfile source (lib/info.c header packing and vendor strings, lib/codebook.c codebook sync, lib/vorbisfile.c), the Vorbis I specification source (doc/Vorbis_I_spec.tex) and CHANGES with every release's vendor string.
    Tested on: Read at this commit; header layouts checked against 7,835 Ogg Vorbis files with the Python dumper on Format:Ogg; vendor and version strings compared with libvorbis DLLs of Unreal Engine 5.8 and The Binding of Isaac: Rebirth and static copies in libsndfile 1.2.2 and FFmpeg 9.0. Not built. · checked 2026-10-17; last activity 2026-08-04; Note: the latest release ships binaries; the wiki links only the source, never the binaries
  • Ogg page and packet dumper (Python) — Dependency-free Ogg reader: lists pages (flags, granule, serial, sequence), verifies every page CRC, rebuilds the packets of each logical stream across pages, identifies the codec of each stream…

Pitfalls

  • bitrate_nominal is a hint; quality-mode (VBR) files can have any actual bitrate, and -1/0 values are common.
  • The header packets are often several kilobytes (the setup header holds the codebooks: 3,908 bytes in a 44.1 kHz stereo file from FFmpeg/libvorbis); they span several Ogg pages, so read packets, not pages.

Evidence & references

  • https://github.com/xiph/vorbis at 1b75110b5a2754ba1931d82dd83cb822b266a21d: lib/info.c (identification header unpack lines 211-245, comment unpack 247-275, header dispatch vorbis_synthesis_headerin 386-452, writers 456-530), lib/codebook.c lines 34 and 151 (sync 0x564342), doc/Vorbis_I_spec.tex (spec source).
  • Checked with the Python dumper of Format:Ogg on 7,835 Ogg Vorbis files of a commercial PC game: every BOS page is 58 bytes, every identification header ends B8 01, every setup packet has "BCV" at offset 8; vendors "Lavf61.7.100" (3,973), "Lavf60.3.100" (3,793), "Xiph.Org libVorbis I 20120203 (Omnipresent)" (68), "Xiph.Org libVorbis I 20200704 (Reducing Environment)" (1).