An Ogg file is a sequence of pages. RFC 3533 defines them, and every kind of stream (Vorbis, Opus, Speex, FLAC, Theora) travels in the same pages. A page holds segments of one logical stream. Segments build up into packets, and packets may run across several pages.
Page header
All numbers are little-endian. The header is 27 bytes, then the segment table, then the segments.
| Offset | Size | Name | Description |
|---|---|---|---|
| 0 | 4 | capture_pattern | the ASCII characters OggS (0x4F 0x67 0x67 0x53) |
| 4 | 1 | stream_structure_version | always 0 |
| 5 | 1 | header_type_flag | the flags below |
| 6 | 8 | granule_position | a position defined by the codec, at the end of the last packet finished on this page; −1 when no packet finishes on it. See granule positions |
| 14 | 4 | bitstream_serial_number | the logical stream this page belongs to |
| 18 | 4 | page_sequence_number | counts pages of this stream from 0; a gap means pages were lost |
| 22 | 4 | CRC_checksum | see the checksum |
| 26 | 1 | number_page_segments | entries in the segment table, 0 to 255 |
| 27 | n | segment_table | one lacing value for each segment |
Header type flags
| Bit | Value | Meaning when set |
|---|---|---|
| 0 | 0x01 | the first packet on this page continues one started on the previous page |
| 1 | 0x02 | BOS: the first page of a logical stream. A BOS page must hold no packet but the stream’s first |
| 2 | 0x04 | EOS: the last page of a logical stream |
| 3–7 | reserved; must be 0 |
Lacing
A packet is cut into segments of 255 bytes, and the last segment is shorter. Each segment has one lacing value in the table: its length.
- A lacing value of 255 means the packet carries on in the next segment.
- A value below 255 ends the packet. A packet whose length is an exact multiple of 255 is ended by a value of 0.
- The sum of the lacing values is the length of the page body, up to 65,025 bytes. The largest page is 27 + 255 + 65,025 = 65,307 bytes.
For example, packets of 300 and 20 bytes give the lacing values
255 45 20 (lengths 255 and 45 for the first, 20 for the second).
Packets across pages
A packet does not have to fit on one page. When the last lacing value on a page is 255 the packet carries on, and the next page sets flag 0x01 and starts with the rest of it. Packets may span many pages. A packet that ends exactly on a segment boundary at the end of a page must still get its terminating 0 value, which can sit alone on the next page.
A page may contain the end of one packet, whole packets and the start of another. A page with no packet ending on it has a granule position of −1.
The checksum
A 32-bit CRC with polynomial 0x04C11DB7, initial value 0, no input or output reflection and no final XOR, taken over the whole page with the checksum field itself set to zero.
Finding pages again
A reader that loses its place looks for the next capture pattern OggS, checks
the CRC and carries on. The explorer shows any bytes between pages as unreadable.
In the explorer
Each page appears in the tree with its header fields, segment table and packets, and the Pages tab lists every page with its CRC result.