Ogg carries more than audio codecs. The first bytes of a stream’s first packet identify it. These are the other stream types the explorer names. Skeleton, OggPCM, OGM, Kate, VP8, Dirac, CELT and Theora are read field by field as far as their Ogg mapping goes (their identification and comment headers, packet types, granule rule and, for Kate, each text event down to its text), and OggPCM and OGM audio are played. What each mapping leaves to the codec itself is set out under scope.
Stream types
| First bytes | Stream | What it is |
|---|---|---|
0x80 theora | Theora | video, from On2’s VP3 |
fishead\0 | Ogg Skeleton | metadata about the other streams and their timing; fisbone\0 and index\0 packets give each stream’s details and seek indexes |
BBCD\0 | Dirac | video, in Dirac (VC-2) sequence framing |
0x80 kate\0\0\0 | Kate | karaoke and text overlay streams |
PCM | OggPCM | uncompressed PCM audio |
CELT | CELT | the CELT codec before it became a layer of Opus. Its header is read; its bit stream changed with nearly every release and was never frozen or published as a specification, so its frames are shown as bytes. Opus’s CELT layer is its successor |
OVP80 | VP8 | video |
OggMIDI\0 | OggMIDI | MIDI events, from a 2001 proposal |
0x01 video, audio or text | OGM | Ogg Media streams, an older DirectShow-based extension for AVI-style video, audio and subtitles |
fLaC | FLAC, older mapping | Ogg FLAC from FLAC 1.0.1 to 1.1.0, before the 0x7F FLAC header: the native stream cut into packets, decoded by joining them |
CMML\0\0\0\0 | CMML | timed XML annotations; an Annodex file is a Skeleton stream plus a CMML stream |
UVS and five spaces | OggUVS | uncompressed video fields (a draft) |
0x00 YUV or 0x00 UVS | OggYUV | two older uncompressed video drafts, named only |
Ogg Skeleton
Skeleton describes the other streams of its link. Its first packet, fishead,
is on the link’s first page (Skeleton’s BOS page comes before every other stream’s). A
fisbone for each other stream follows among the secondary header pages, then,
in version 4, index packets, and the Skeleton stream ends with an empty packet on
its EOS page before any data page. Its pages have granule position 0. Numbers are
little-endian.
fishead
| Offset | Size | Name | Description |
|---|---|---|---|
| 0 | 8 | identifier | fishead\0 |
| 8 | 2 | version major | 3 or 4 |
| 10 | 2 | version minor | 0 |
| 12 | 8 | presentation time numerator | with the denominator, when to start presenting the streams, in seconds |
| 20 | 8 | presentation time denominator | |
| 28 | 8 | base time numerator | with the denominator, the time that granule position 0 stands for |
| 36 | 8 | base time denominator | |
| 44 | 20 | UTC | the wall-clock time of the base time, as YYYYMMDDTHHMMSS.sssZ, or zero bytes |
| 64 | 8 | segment length | version 4: the length of the whole link in bytes, so a reader can tell a cut file |
| 72 | 8 | content byte offset | version 4: where the first data page starts |
fisbone
| Offset | Size | Name | Description |
|---|---|---|---|
| 0 | 8 | identifier | fisbone\0 |
| 8 | 4 | message header offset | where the message headers start, counted from this field: 44 |
| 12 | 4 | serial number | the stream this bone describes |
| 16 | 4 | header packets | how many header packets that stream has |
| 20 | 8 | granule rate numerator | with the denominator, granule positions a second |
| 28 | 8 | granule rate denominator | |
| 36 | 8 | base granule | the granule position at the base time |
| 44 | 4 | pre-roll | how many packets before a seek point must be decoded first |
| 48 | 1 | granule shift | for two-part granule positions (Theora, Dirac): the bits of the low part |
| 49 | 3 | padding | zero |
| 52 | n | message headers | Name: value lines, each ending CR LF. Content-Type is required (such as audio/vorbis); Role, Name, Language and Title are common |
index (version 4)
| Offset | Size | Name | Description |
|---|---|---|---|
| 0 | 6 | identifier | index\0 |
| 6 | 4 | serial number | the stream the index is for |
| 10 | 8 | key points | how many follow |
| 18 | 8 | timestamp denominator | for every time in the index |
| 26 | 8 | first sample time | numerator of the stream’s start time |
| 34 | 8 | last sample end time | numerator of the time the stream ends |
| 42 | n | key points | for each, the byte offset of a page and the time of a key frame on it, each a difference from the previous key point, in a variable-length code of 7 bits a byte |
Skeleton 3 and 4 are specified on the Xiph wiki. Version 4 added the two fishead fields at 64 and 72 and the index packet; a version 3 fishead ends at 64.
OggPCM
OggPCM is a Xiph draft mapping for uncompressed audio. Its first packet is 28 bytes, big-endian; the second is a Vorbis comment structure without a framing bit; any extra header packets the first one counts follow, then packets of interleaved samples, each holding whole sample frames. The draft does not state a granule position rule; the explorer counts sample frames.
| Offset | Size | Name | Description |
|---|---|---|---|
| 0 | 8 | identifier | PCM and five spaces |
| 8 | 2 | version major | 0 |
| 10 | 2 | version minor | 0 |
| 12 | 4 | PCM format | the sample format, below |
| 16 | 4 | sample rate | sample frames a second |
| 20 | 1 | significant bits | how many bits of each sample carry the signal, justified to the most significant bits with the rest zero; 0 means all the bits of the format |
| 21 | 1 | channels | interleaved in each packet |
| 22 | 2 | maximum frames a packet | the most sample frames in any packet; 0 means 65,536 |
| 24 | 4 | extra headers | header packets after the comments, such as a channel map |
| Format | Samples |
|---|---|
| 0x00, 0x01 | 8-bit signed, unsigned |
| 0x02, 0x03 | 16-bit signed, little- and big-endian |
| 0x04, 0x05 | 24-bit signed, little- and big-endian |
| 0x06, 0x07 | 32-bit signed, little- and big-endian |
| 0x10, 0x11 | G.711 µ-law, A-law |
| 0x20, 0x21 | 32-bit IEEE float, little- and big-endian |
| 0x22, 0x23 | 64-bit IEEE float, little- and big-endian |
Format numbers below 0x80000000 are reserved for Xiph, those above for applications. Extra headers each start with a 32-bit header ID; the draft defines two, 0 (channel mapping) and 1 (channel conversion), which the explorer counts and shows as bytes.
Source: the OggPCM draft on the Xiph wiki (wiki.xiph.org/OggPCM, read through a Wayback copy of 2023; the page calls itself a draft that is not an official Xiph spec), compared field by field by scripts/ogg/spec-check-mappings.mjs.
OGM (Ogg Media)
OGM comes from the DirectShow filters of OggDS and OGMtools, which put AVI-style video,
audio and subtitles in Ogg. The OggDS author wrote a short packet-format page, and the OGMtools source
and readers such as FFmpeg fill in the rest. Each stream starts with a stream header
(first byte 1), then a comment packet (first
byte 3, then vorbis, the comments and a final framing byte of 1), then data
packets. Numbers are little-endian, and times are in units of 100 ns.
| Offset | Size | Name | Description |
|---|---|---|---|
| 0 | 1 | packet type | 1: the stream header (header packets have bit 0 set) |
| 1 | 8 | stream type | video, audio or text, padded with zero bytes |
| 9 | 4 | subtype | video: the codec’s FourCC; audio: the WAVE format tag as four hexadecimal digits, such as 0055 for MP3 |
| 13 | 4 | size | the size of this structure |
| 17 | 8 | time unit | the length of a unit, in 100 ns steps |
| 25 | 8 | samples per unit | granules in a unit: audio’s sample rate is samples per unit × 10,000,000 ÷ time unit |
| 33 | 4 | default length | the duration of a data packet that does not state one, in granules |
| 37 | 4 | buffer size | for the DirectShow filter |
| 41 | 2 | bits per sample | audio: bits per sample; video: bits per pixel |
| 43 | 2 | padding | |
| 45 | 8 | video: width, height; audio: channels (2), block align (2), average bytes a second (4) | text has nothing here |
A data packet’s first byte has bit 0 clear. Bit 3 marks a key frame, and bits 7, 6 and 1
give how many bytes of duration follow (0 to 7): ((b & 2) << 1) | (b >> 6).
The duration, little-endian, is the packet’s length in granules (frames for video,
samples for audio, milliseconds for text); then the payload, which
for audio runs on as the codec’s own stream. For AAC (format tag 00ff) each
payload is one raw access unit, and when the stream header’s size is 56 or more, its codec
data (an AudioSpecificConfig) starts 4 bytes later, at 57. The explorer plays OGM audio
holding PCM, G.711, MPEG audio (Layers I to III), AC-3 and AAC, and names the rest.
Source: the OggDS author’s own packet-format page (“Tobias’ DirectShow Filter, Packet format”, read through a Wayback copy of
tobias.everwicked.com/packfmt.htm, saved as research/ogg/spec/mappings/OGM-packfmt.html), which gives the two
header packets (type 1 with the stream header structure, type 3 with the Vorbis comment data), the data packet byte (bit 3 key
frame, bit 6 and bit 7 the low bits and bit 1 the third bit of the length-byte count, then the length in frames, samples or
milliseconds of text) and the structure above, field by field, in the order and sizes of the table; it is silent on the two
padding bytes at offset 43, which come from the OGMtools source. Also the OGMtools 1.5 source (ogmstreams.h, p_pcm.cpp, vorbis_header_utils.c) and FFmpeg 8.0 oggparseogm.c, both read from the source archives saved in this project. ogmstreams.h declares two layouts of the stream header; the table follows old_stream_header, in which the 8-byte video or audio part starts at offset 45, as FFmpeg reads it. Compared by scripts/ogg/spec-check-mappings.mjs.
The oldest OggDS header
The first OggDS filters wrote a different first packet, which FFmpeg and VLC still read. It is
at least 142 bytes long; byte 0 is 1 and bytes 1 to 35 are the text
Direct Show Samples embedded in Ogg. The rest is a copy of a DirectShow media type,
little-endian. The dword at offset 96 tells which: 0x05589F80 (the first dword of the
DirectShow format type for a video information header) means video and
0x05589F81 (that of a wave format) means audio. Video, 184 bytes or more: the
codec’s FourCC at 68, the time of one frame in 100 ns units (64 bits) at 164, the width at 176
and the height at 180, each 32 bits (these are the fields of a BITMAPINFOHEADER
from 168 on). Audio: a WAVEFORMATEX from 124: format tag (16 bits), channels (16),
samples a second (32) at 128, average bytes a second (32) at 132, block align (16) at 136, bits
a sample (16) at 138, then the size of the extra data (16) at 140 and the extra data from 142.
FFmpeg stops reading at 136 and VLC at 142. The later packets are the same as for the newer
header: bit 0 clear, the length bytes, then the payload.
Source: FFmpeg libavformat/ogg/demuxer/ogm.c lines 131 to 170 (ogm_dshow_header)
and VLC modules/demux/ogg.c lines 1900 to 2000, both saved in
research/oss/. Two independent readers give the same offsets for every field that both
read (96, 68, 164, 176, 180; 124, 126, 128, 132); block align, bits a sample and the extra data are
VLC’s alone. VLC reads a video bit count at 182, inside the height field, which is not a
BITMAPINFOHEADER offset; this page does not use it. That the dword at 96 is the start of a
DirectShow format-type GUID is an inference from the values (not stated in either source), and no
real OggDS-1 file was available to confirm any of this.
Theora identification header
The first packet of a Theora stream is 42 bytes. Numbers are big-endian.
| Offset | Size | Name | Description |
|---|---|---|---|
| 0 | 1 | header type | 0x80; 0x81 is the comment and 0x82 the setup header |
| 1 | 6 | codec name | theora |
| 7 | 1 | VMAJ | major version: 3 |
| 8 | 1 | VMIN | minor version: 2 |
| 9 | 1 | VREV | revision; above 1 may carry features of a later specification, and a decoder still reads the stream |
| 10 | 2 | FMBW | frame width, in 16-pixel macroblocks |
| 12 | 2 | FMBH | frame height, in macroblocks |
| 14 | 3 | PICW | picture width in pixels (24 bits are read though 20 would do, to keep the header byte aligned) |
| 17 | 3 | PICH | picture height in pixels |
| 20 | 1 | PICX | picture X offset |
| 21 | 1 | PICY | picture Y offset |
| 22 | 4 | FRN | frame rate numerator |
| 26 | 4 | FRD | frame rate denominator |
| 30 | 3 | PARN | pixel aspect numerator |
| 33 | 3 | PARD | pixel aspect denominator |
| 36 | 1 | CS | colour space: 0 undefined, 1 Rec. 470 M, 2 Rec. 470 B/G, 3 to 255 reserved |
| 37 | 3 | NOMBR | nominal bit rate in bits a second, a hint only; 16,777,215 stands for that rate or more, 0 for not stated |
| 40 | 6 bits | QUAL | quality hint |
| 40 | 5 bits | KFGSHIFT | the shift used in granule positions |
| 41 | 2 bits | PF | pixel format: 0 is 4:2:0, 2 is 4:2:2, 3 is 4:4:4, 1 reserved |
| 41 | 3 bits | reserved | zero |
A Theora stream has three header packets (identification, comment and setup) before
its video packets. Its comment packet uses the same
Vorbis comment structure, without a framing bit.
Its granule positions have two parts split by KFGSHIFT, and streams from before
Theora 3.2.1 (VREV 0) count them differently: see
granule positions. The header
pages have granule position 0, and the identification header is alone on the first page.
The rules of section 6.2 that make a stream undecodable are checked and shown as issues: VMAJ is not 3, VMIN is not 2, FMBW or FMBH is 0, PICW or PICH is larger than the frame (16 times FMBW or FMBH), a frame rate with a zero part, pixel format 1, and non-zero reserved bits. The explorer also works out the block counts from FMBW, FMBH and PF: macro blocks (FMBW times FMBH), super blocks and blocks, as given by tables 6.5 and 6.6 of the specification.
Source: the Theora Specification (Theora.pdf from xiph.org, 210 pages), sections 6.1 to 6.3 and appendix A.2, compared by scripts/ogg/spec-check-mappings.mjs and scripts/ogg/spec-check-theora.mjs: every field width in the order the specification reads them, the colour space and pixel format tables, and a header built from those widths and read back through the explorer.
Theora setup header
The third header packet starts with 0x82 and theora and holds the tables every video packet is decoded with. Unlike Vorbis, Theora packs bits from the most significant bit of each byte. The fields follow each other without padding, and the unused bits at the end of the last byte are zero.
| Part | Bits | What it holds |
|---|---|---|
LFLIMS | 3, then 64 values of that width | The first 3 bits give the width, NBITS. The 64 values are the loop filter limit for each quantiser index qi (0 to 63). |
ACSCALE | 4, then 64 values | The 4 bits plus one give NBITS; 64 scale values for the AC coefficients, one per qi. |
DCSCALE | 4, then 64 values | The same for the DC coefficient. |
NBMS | 9 | The number of base matrices less one. It must not be greater than 384 once the one is added. |
BMS | 8 each, 64 per matrix | The base matrices, 64 bytes each, indexed by coefficient number. |
| quant ranges | see below | For quantisation type 0 (intra) then 1 (inter), and for each of the three colour planes in turn (Y, Cb, Cr): a set of ranges that divides qi 0 to 63 and names the base matrix at each end of each range. |
| Huffman tables | 80 trees | The code tables for the 32 DCT tokens, one tree after another. |
A set of quant ranges starts with a 1-bit flag, except for the first set (intra, plane Y), which is always new. A flag of 0 means the set copies an earlier one. For an inter set a second bit says which: 1 copies the set of the same plane for the intra type, 0 copies the set read just before. For the intra type there is no second bit and the copy is the set read just before. A new set is read as: a base matrix index of ilog(NBMS-1) bits, then a range size of ilog(62-qi) bits plus one, which moves qi on, then the next base matrix index, and so on until qi reaches 63. Going past 63, or naming a base matrix that does not exist, makes the stream undecodable. Here ilog(n) is the number of bits needed to write n, and 0 for 0.
The quantisation matrix for a type, plane and qi is found by locating the range that holds qi, mixing the base matrices at its two ends in proportion to where qi lies, scaling by ACSCALE or DCSCALE (DCSCALE for coefficient 0), dividing by 100, multiplying by 4 and limiting the result to between a minimum and 4096. The minimum is 16 for the intra DC value, 8 for other intra values, 32 for the inter DC value and 16 for other inter values. The explorer shows the matrix at qi 0 and 63 for the intra luma plane.
Each Huffman tree is a depth-first walk. A 1 bit marks a leaf and is followed by a 5-bit token; a 0 bit marks a branch, followed by the 0 subtree and then the 1 subtree. A code may not be longer than 32 bits and a tree may not hold more than 32 leaves. Tokens may appear in any order, may repeat, and need not all appear. The explorer lists the codes of every table.
The explorer stops at the first rule the stream breaks and shows what it read up to there. The numbered steps for the loop filter limits (LFLIMS) are missing from the text layer of the specification PDF; the layout above is the one libavcodec's vp3.c reads, and the setup header of every real file checked ends exactly on its last bit when read this way.
Source: the Theora Specification sections 6.4.1 to 6.4.5, compared by scripts/ogg/spec-check-theora.mjs, which also builds a setup header from the specification's field widths, reads it back, and compares the matrix code with a separate transcription of the section 6.4.3 steps.
Theora video packets
A packet whose first bit is 0 is a video packet (a header packet has it set). The frame header that follows is read from the most significant bit down:
| Field | Bits | Meaning |
|---|---|---|
| packet bit | 1 | 0 for a video packet |
FTYPE | 1 | 0 is an intra frame (a key frame), 1 an inter frame. The first frame of a stream must be intra. |
QIS[0] | 6 | The first quantiser index. It is used for all DC coefficients. |
MOREQIS | 1 | 1 if another qi follows |
QIS[1] | 6 | Only if MOREQIS is 1; followed by another MOREQIS bit |
QIS[2] | 6 | Only if the second MOREQIS is 1. The list never has more than three values. |
| reserved | 3 | Only in an intra frame; must be zero |
A packet of zero bytes is not an error: the specification treats it as an inter frame in which no block is coded, which repeats the previous picture. The explorer reads the frame header of every video packet, shows the frame type and qi values, and reports a first frame that is not intra and non-zero reserved bits.
The rest of a video packet is decoded as the specification describes, in this order. Pixels are numbered from the lower left corner, so row 0 is the bottom row:
- the coded block flags: an intra frame codes every block; an inter frame sends one run-length bit string for the partially coded super blocks, one for the fully coded ones and a short-run string for the blocks of the partial ones (7.2, 7.3);
- the macro block coding modes: a scheme number, then one mode per macro block that has a coded luma block (7.4);
- the motion vectors, in half-pixel units of the luma plane, with the last two vectors remembered for the "last" modes and averaged for the chroma blocks of a four-vector macro block (7.5);
- the block-level
qivalues, one run-length string per extraqi(7.6); - the DCT tokens, 64 passes over the coded blocks using the 80 Huffman tables of the setup header, with end-of-block runs shared between blocks (7.7);
- undoing DC prediction from the left, lower-left, lower and lower-right blocks that use the same reference frame (7.8);
- reconstruction: the predictor (flat 128, whole-pixel or half-pixel copy of the previous or golden frame), dequantisation, the 8×8 inverse DCT in 16-bit integer steps, then the loop filter along block edges (7.9, 7.10).
The explorer runs this for the first 200 video packets of a stream, because each frame needs the frames before it, and shows on the Frame data row how many blocks are coded, how many carry only a DC value, how many AC coefficients are non-zero and the loop filter limit; the note lists the mode counts, token counts and the qi use. It reports a packet that cannot be decoded and the end-of-block and token-count rules of 7.7.3. The decoded pictures are not displayed. Frames after the first 200 stay as bytes.
The decoder reproduces the pictures ffmpeg writes for the four sample files (real-theora-*.ogv in the project's samples/ogg: 4:2:0 and 4:4:4, a cropped picture, zero-length packets) sample for sample. The tables are compared with the specification text by scripts/ogg/spec-check-theora-frame.mjs, the header rules by scripts/ogg/spec-check-theora.mjs.
Source: the Theora Specification sections 7.1 to 7.11.
Kate
Kate carries timed text, karaoke and image overlays. Its header packets have the top bit of
the type byte set and then the seven bytes kate\0\0\0; numbers are
little-endian. The first packet is 64 bytes:
| Offset | Size | Name | Description |
|---|---|---|---|
| 0 | 1 | packet type | 0x80 identification header |
| 1 | 7 | magic | kate\0\0\0 |
| 8 | 1 | reserved | zero |
| 9 | 1 | version major | bitstream major version (0) |
| 10 | 1 | version minor | a higher minor version may use bytes marked reserved |
| 11 | 1 | number of headers | header packets before the data (libkate rejects 0) |
| 12 | 1 | text encoding | 0 is UTF-8 |
| 13 | 1 | text directionality | 0 left to right then top to bottom, 1 right to left then top to bottom, 2 top to bottom then right to left, 3 top to bottom then left to right |
| 14 | 1 | reserved | zero |
| 15 | 1 | granule shift | bits of a granule position that hold the offset part |
| 16 | 2 | canvas width | bits are packed least significant first: the low 4 bits of byte 16 are a left shift, the other 12 bits (the high 4 bits of byte 16, then byte 17) the number to shift; 0 is unset |
| 18 | 2 | canvas height | the same for the height |
| 20 | 4 | reserved | zero |
| 24 | 4 | granule rate numerator | granules in a span of the denominator’s seconds (libkate rejects 0) |
| 28 | 4 | granule rate denominator | seconds (libkate rejects 0) |
| 32 | 16 | language | NUL-terminated default language tag; empty is unset |
| 48 | 16 | category | NUL-terminated category, such as subtitles or lyrics |
Every Kate header is the type byte, the seven magic bytes and one reserved zero byte (the
identification header’s byte 8). The second packet (type 0x81) is a Vorbis comment structure
after that 9-byte prefix, without a framing bit. Types 0x82 to 0x88 are the optional definition tables (regions, styles, curves,
motions, palettes, bitmaps, font ranges). Data packets start with their type: 0x00 a text
event, 0x01 a keepalive (one byte, placed to help seeking), 0x02 a repeat of an earlier event
and 0x7F the end of the stream (one byte, on the EOS page). A text event is the type byte,
then three 64-bit values (the start, the duration and the start of the earliest event still
active, all in granule units), a 32-bit text length and the text; bit-packed attributes
follow. A granule position is a base in the high bits and an offset in the low
granule shift bits, at the granule rate. The viewer reads all of this down to the
text and shows the bit-packed attributes as bytes. Each definition table starts with the number of
definitions it holds, a variable-length value (4 bits, or the value 15, a sign bit, a 5-bit
length minus one and that many bits, least significant bit first); the viewer reads that count. The definitions after it
are not decoded and are shown as bytes.
Source: libkate 0.4.1 (the format documents doc/kate-format-id-header.doc, kate-format-vorbis-comment-header.doc, kate-format-text-data.doc, kate-granule.doc, and the encoder and decoder src/kate_encode.c, src/kate_decode.c, src/kate_bitwise.c, whose bit order decides the canvas fields), compared by scripts/ogg/spec-check-mappings.mjs.
VP8
The VP8 mapping has an identification header of 26 bytes and a comment header; numbers are big-endian. Each later packet is one VP8 frame (RFC 6386).
| Offset | Size | Name | Description |
|---|---|---|---|
| 0 | 5 | magic | 0x4F VP80 |
| 5 | 1 | header type | 1 identification, 2 comment |
| 6 | 1 | version major | 1 |
| 7 | 1 | version minor | |
| 8 | 2 | frame width | pixels |
| 10 | 2 | frame height | pixels |
| 12 | 3 | pixel aspect numerator | |
| 15 | 3 | pixel aspect denominator | |
| 18 | 4 | frame rate numerator | |
| 22 | 4 | frame rate denominator |
The comment header is the magic, type 2, the byte 0x20 and then a Vorbis comment
structure without a framing bit. A granule position holds the frame number in its upper 32
bits, the distance from the last key frame in bits 3 to 29 (0 on a key frame), and in bits 30 and 31 the
value 3 for a visible frame; for an invisible frame it is the number of invisible frames so far minus one,
so the first invisible frame has 0. The low three bits are not used by the readers. The first byte of every frame is the VP8 frame tag: bit 0
clear for a key frame, bits 1 to 3 the version, bit 4 show_frame.
Source: the OggVP8 page of the Xiph wiki (read through a Wayback copy of 2023) gives the identification header, VMAJ 1 and VMIN 0, with a bit diagram whose row labels are loose; the field widths, the comment header (type 2, byte 0x20) and the granule layout are taken from FFmpeg 8.0 oggparsevp8.c, which is code, not a specification; the frame tag is RFC 6386 section 9.1. Compared by scripts/ogg/spec-check-mappings.mjs.
Second reader: VLC modules/demux/ogg.c lines 3072 to 3101 (Ogg_ReadVP8Header) reads the same
offsets (width 8, height 10, aspect 12 and 15, frame rate 18 and 22; comment header at 7) and requires version 1.0
where FFmpeg only requires major version 1 (oggparsevp8.c lines 49 to 53); it sets a granule shift of 32 and
does not read the distance or the invisible-frame count. Third reader: GStreamer gst-plugins-base/ext/ogg/gstoggstream.c
(setup_vp8_mapper, vp8_fill_header, granule_to_granulepos_vp8,
extract_tags_vp8), saved in research/ogg/src/gst/: the same 26-byte identification layout, the comment
header as OVP80 followed by 2 and 0x20, the frame count in bits 32 to 63, the distance in bits 3 to 29 and a
value of 3 in bits 30 and 31 for a visible frame, otherwise the invisible-frame count minus one. FFmpeg and GStreamer agree on
every granule field. No specification text exists beyond the Xiph wiki’s header diagram (the current wiki page is still
revision 12171), so these fields rest on three independent players, not on a document. VLC reads the 24-bit aspect numbers through a mask of 12 bits, which
looks like a defect; this page keeps all 24 bits as FFmpeg does.
Dirac
The first packet of a Dirac stream is a sequence header inside a 13-byte parse-info header
(the mapping says it should be followed by an end of sequence unit, and advises repeating the
sequence header in the next packet); the packet starts with the bytes BBCD. A
packet holds zero or more non-picture units and then one picture unit or an end of sequence
unit; the last page ends with an end of sequence unit. The Ogg Dirac mapping does not use
Vorbis comments. Parse info: the prefix BBCD, a parse-code byte, the offset of
the next unit and the offset of the previous one (both 32-bit big-endian; 0 only at the ends
of the stream). Parse codes (Dirac 2.2.3, Table 9.1): 0x00 sequence header, 0x10 end of
sequence, 0x20 auxiliary data, 0x30 padding, and the picture codes: the low two bits give the
number of reference pictures, bits 2 and 3 (0x0C) set mean the picture is itself a
reference, bit 6 set means no arithmetic coding, and 0xC8 and 0xCC are the low-delay syntax
(intra pictures). VC-2’s high-quality picture, 0xE8, is named only by FFmpeg and is not in
that specification.
The sequence header starts with five interleaved exp-Golomb numbers: major version, minor version, profile, level and the base video format, an index (0 to 20) into the specification’s table of formats from custom through QSIF525, CIF, SD, HD 720, HD 1080, digital cinema and UHDTV, which fixes the frame size; the optional overrides and the picture coding mode follow. A stream written to the 2.2.3 specification has major version 2 and minor version 2.
The granule position applies to the picture in the first packet that ends on a page (a page
where no packet ends has granule position −1). Its parts: pt, the picture
number in display order, which rises by 2 for each progressive picture and by 1 for each
field; dist, the number of pictures in coded order since a sync point that
allows pt to be decoded correctly; and delay, the number of pictures
between decoding and presentation. Packed: pt − delay from bit 31 upward,
dist_h in bits 22 to 29, delay in bits 9 to 21,
dist_l in bits 0 to 7, bits 30 and 8 zero; the granule shift is 22 and
dist is (dist_h << 8) | dist_l. The viewer shows
the parse info, the parse code and the first five numbers, and the rest as bytes.
Source: Encapsulation of Dirac in Ogg v1.0 (BBC, 2008; the mapping document linked from the Xiph wiki’s OggDirac page, read through a Wayback copy) and the Dirac Specification 2.2.3 (Tables 9.1 and 10.1, Annex C, section 9.6, A.3.2; read through a Wayback copy of diracvideo.org), compared by scripts/ogg/spec-check-mappings.mjs: the parse-code table, all 21 base video formats with their frame sizes and the interleaved exp-Golomb examples of Table A.1.
Second reader: FFmpeg libavformat/ogg/demuxer/dirac.c lines 66 to 85 (dirac_gptopts) unpacks the
granule as a signed number the same way: dist = ((granule >> 14) & 0xFF00) | (granule & 0xFF),
pt − delay = granule >> 31, delay = (granule >> 9) & 0x1FFF, and a picture is a
sync point when dist is 0; its time base counts two units a frame (line 60), the reason for the rule that
pt rises by 2 for a progressive picture. This agrees with the mapping document above.
The older mapping, KW-DIRAC
Before the mapping above, the first packet of a Dirac stream started with the text KW-DIRAC
(the first byte is K). FFmpeg dirac.c lines 87 to 115 reads from it a frame rate numerator
(32 bits, big-endian) at offset 8 and a denominator at offset 12; and its granule is two counts, the pictures of
earlier sync points in bits 30 upward and the pictures since the sync point in bits 0 to 29, the picture
number being their sum and a sync point being a granule whose low 30 bits are 0. VLC ogg.c (lines 1840 to
1851 and 3500 to 3503) recognises the same text but then parses the sequence header as the newer mapping does.
Single source for the layout (FFmpeg); no old-mapping file was available to test it, and no specification of this
mapping was found.
CELT (before Opus)
An Ogg CELT stream has a 60-byte header, a comment packet and then one CELT frame a packet; numbers are little-endian.
| Offset | Size | Name | Description |
|---|---|---|---|
| 0 | 8 | magic | CELT and four spaces |
| 8 | 20 | version string | the libcelt release that wrote it |
| 28 | 4 | bit stream version | which libcelt can decode the frames |
| 32 | 4 | header size | 56 in files written by libcelt (the packet is 60 bytes) |
| 36 | 4 | sample rate | Hz |
| 40 | 4 | channels | |
| 44 | 4 | frame size | samples |
| 48 | 4 | overlap | samples |
| 52 | 4 | bytes a packet | -1 (0xFFFFFFFF) when it varies, as libcelt writes it |
| 56 | 4 | extra headers | header packets after the comments |
The frames themselves are not specified anywhere: the CELT bit stream was experimental and changed with nearly every libcelt release (the header carries the bit stream version for that reason), and Xiph.Org stopped it when CELT became a layer of Opus (RFC 6716). No document describes the old frames, and the viewer shows them as bytes. Opus’s own CELT layer is fully described and decoded.
Source: the header layout on the Xiph wiki’s OggCELT page (read through a Wayback copy of 2023; the page says it is obsolete because CELT was merged into Opus) and FFmpeg 8.0 oggparsecelt.c, which reads the header at these offsets and treats the header size and bytes-a-packet fields as unused. Compared by scripts/ogg/spec-check-mappings.mjs. The field values (size 56, bytes a packet -1, version string “experimental”) are what libcelt 0.11.3 writes in libcelt/header.c (celt_header_init) and celt_header.h, the reference implementation from Xiph’s release archive.
OggMIDI
OggMIDI is a 2001 proposal by Jack Moffitt for sending MIDI next to a Vorbis stream. It has one header packet of 12 bytes, then data packets; the data packets of a stream hold roughly 512 bytes each, cut on MIDI event boundaries, and come from a format 0 MIDI file (a format 1 file has to be merged into one track first). The granule position is the time in microseconds since the start of the stream.
| Offset | Size | Name | Description |
|---|---|---|---|
| 0 | 8 | magic | OggMIDI and a zero byte |
| 8 | 1 | version | 0 is the only version described |
| 9 | 1 | time format | 1: ticks per quarter note; 24, 25, 29 and 30: SMPTE frames a second; other values are undefined |
| 10 | 2 | timebase | ticks per quarter note, or subdivisions of an SMPTE frame |
The proposal does not give the byte order of the timebase, and says nothing about how events are
timed inside a packet (<midi event><midi event>…). The viewer reads the
timebase little-endian, as Ogg headers are, and shows the packet bytes as they are.
Source: Jack Moffitt, “Ogg MIDI proposal”, vorbis-dev mailing list, 25 August 2001
(research/ogg/spec/mappings/OggMIDI-mail.html), and the Xiph wiki page OggMIDI (revision 9574,
OggMIDI.html). The wiki text agrees on the sizes, but its bit diagram draws the version and time format
16 bits wide and the header 14 bytes long; this page follows the mailing-list text and the wiki’s prose, which both say
8 bits.
CMML and Annodex
An Annodex file is not a stream type of its own. It is an Ogg file whose first page is a
Skeleton fishead page, whose second page is the CMML
identification header, followed by the other streams, with the CMML clips multiplexed by time. CMML
(Continuous Media Markup Language) is XML text: a head element for the whole file and a clip element for
each time span. The Annodex .anx type is recognised by CMML and four zero bytes
at byte 104 (28 + 48 + 28) of the file.
| Offset | Size | Name | Description |
|---|---|---|---|
| 0 | 8 | magic | CMML and four zero bytes |
| 8 | 2 | version major | 2 (little-endian, as every field of more than one byte) |
| 10 | 2 | version minor | 1 |
| 12 | 8 | granule rate numerator | default 1 000 |
| 20 | 8 | granule rate denominator | default 1 |
| 28 | 1 | granule shift | low bits of a granule position that point back to the previous clip; default 32 |
The second packet holds the XML preamble (the XML declaration, the document type declaration and the
cmml start tag rewritten as a <?cmml …?> instruction), the third holds the
head element. Every later packet is one clip element in UTF-8 with line ends as LF only; a clip’s
start and end attributes are left out, because the page’s granule position carries the time.
A clip that has an end gets a second packet with an empty clip element at that time, and the last page holds a packet with an
empty clip element. A granule position is the time of the clip in its upper bits (granule shift bits cut off at the
bottom) and the time of the previous clip in its lower bits.
Source: Internet-Draft draft-pfeiffer-cmml-03 (sections 7.1 to 7.3 and 8.1) and draft-pfeiffer-annodex-02 (section on the
Annodex bitstream, and the magic number text), both from the Annodex site through Wayback copies, and the Xiph wiki page CMML,
saved in research/ogg/spec/mappings/. The draft’s diagram of the Ogg identification header puts the numerator at
bytes 12 to 15 and 16 to 19 and calls them 8-byte values; the text, the wiki page and the denominator at 20 to 27 give 8 bytes
each and 29 in all, which is what the viewer reads. Whether the lower granule bits hold a granule position or a
time of the previous clip is worded loosely in the draft; the viewer does not split the granule position.
No Annodex stream has a magic of its own.
OggUVS and OggYUV
OggUVS is a draft for uncompressed video that the Xiph wiki marks as “not an official Xiph spec”. All
multi-byte fields are big-endian. The stream is field based: one field is one packet, a top field
(FLD0 and the samples) and a bottom field (FLD1). The first packet is the 48-byte main
header, the second the comment packet (undefined in the draft), then the extra headers the main header counts, normally
one data layout packet, then the fields. Every data packet is exactly the field image size plus four bytes.
| Offset | Size | Name | Description |
|---|---|---|---|
| 0 | 8 | magic | UVS and five spaces |
| 8 | 2 + 2 | version | major, minor |
| 12 | 2 + 2 | display width, height | pixels |
| 16 | 2 + 2 | pixel aspect | numerator, denominator |
| 20 | 2 + 2 | field rate | numerator, denominator; 0/0 for a variable rate |
| 24 | 4 | timebase | Hz; 0 means one over the field rate; the time is the granule position divided by it |
| 28 | 4 | field image size | bytes |
| 32 | 4 | extra headers | packets between the comment packet and the data |
| 36 | 4 | colourspace | 1 unspecified R′G′B′, 2 unspecified Y′CbCr |
| 40 | 4 | reserved and interlaced | 31 reserved bits, then the interlaced flag |
| 44 | 4 | layout ID | 0 (a layout packet follows), a fourcc (YV12 0x32315659, IYUV 0x56555949, YUY2 0x32595559, UYVY 0x59565955, YVYU 0x55595659) or 0x80808081 RGB24 DIB, 0x80808082 RGB32 DIB, 0x80808083 ARGB DIB; a top byte of 0xFF is application specific |
The data layout packet starts with the number 1 (4 bytes), then version major and minor, luma height and width and chroma height and width (2 bytes each), and then, for each of alpha, Y/R, U/G and V/B, a 4-byte offset, then the four Y strides (signed) and the Y/R, U/G and V/B X strides (signed); 60 bytes in all, and for interlaced storage the last 44 bytes come twice.
The two OggYUV drafts on the Xiph wiki (marked there as incomplete and “at worst completely broken”) start with a zero byte
and YUV or UVS. Their bit fields are not complete enough to read with certainty; the viewer
names the stream and shows the packets as bytes.
Source: Xiph wiki pages OggUVS (revision 9316, OggUVS.html) and OggYUV (revision 12222, OggYUV.html),
saved in research/ogg/spec/mappings/. They are drafts, so nothing was compared with a player that writes
them. “YUV4MPEG” is not an Ogg stream type: it is a separate file format that OggYUV was meant to replace.
Scope
This record is Ogg Vorbis audio and the audio family around it. For every stream type here the Ogg part is complete: how a stream is recognised, its header packets, packet types, granule-position rule and comments. What a stream’s packets contain is the business of that codec’s own format: the Theora setup header and video frames (Theora specification), Dirac pictures (Dirac specification), VP8 frames (RFC 6386), Kate’s bit-packed event attributes and definition tables (libkate’s format documents) and the sample layout of OggUVS fields. They are not Ogg structure, and the viewer shows them as labelled bytes. CMML’s XML and OggMIDI’s event bytes are shown as text and bytes.
Links
- Theora specification – the Xiph.Org Foundation’s full description (PDF)
- OggKate – the Kate mapping; the bit stream is documented in libkate’s
doc/folder - RFC 6386 – the VP8 data format
- Ogg Skeleton 4 – the Skeleton fishead, fisbone and index packets
- OggPCM – the draft mapping for uncompressed audio
- OggMIDI – the MIDI mapping proposal
- CMML – the Continuous Media Markup Language mapping (Annodex)
- OggUVS – the draft mapping for uncompressed video
Source: Skeleton 3.0 (xiph.org/ogg/doc/skeleton.html) and Skeleton 4.0 (wiki.xiph.org/Ogg_Skeleton_4, read through a Wayback copy, revision 16372; the Xiph wiki’s certificate had expired): the fishead, fisbone and index layouts are compared byte by byte by scripts/ogg/spec-check.mjs. The other mappings on this page (Theora, Kate, VP8, CELT, Dirac, OggPCM, OGM) are compared by scripts/ogg/spec-check-mappings.mjs with the texts named in each section, saved in research/ogg/spec/mappings/ and research/ogg/src/. No text exists for OGM beyond the OGMtools and FFmpeg source, for CELT’s frames, or for the Dirac high-quality picture code (VC-2, SMPTE ST 2042, not open).