The viewpoint held by Christopher Montgomery, creator of the Ogg format, is that the units of muxed codec data should be a separate abstraction layer from the units of data used by the codec in order to limit the amount of buffering necessary when decoding the contained data. In his opinion, which is supported by other developers working with the Xiph.org Foundation, this gives Ogg a technical advantage over alternative bitstream formats such as AVI, QuickTime, and MPEG.
Each Ogg page also provides the time offset of the contained data which allows efficient seeking which works with streaming and time accurate. In contrast, many other formats seek to byte positions in the stream or rely on a table of contents for seeking information.
Every Ogg page begins with the four-byte magic string "OggS". If sync is lost a decoder can look for the next occurrence of this sequence to begin decoding again. This string is followed by a null byte for Ogg version 0. The version field had originally been intended to allow multiple Ogg page types tuned for different payloads to coexist in the same stream. At the 2000s it became clear that only one page version will be used.
The sixth byte of each page specifies type flags. The value of 1 specifies that contained data is continued from the last page. The value of 2 specifies that this is the first page of the stream, and the value of 4 specifies that this is the last page of the stream. These values can be combined with addition or logical OR.
The next 8 bytes, or 64 bits, is called the absolute granule position which is a synthetic value that encodes the Decode Timestamp, the Presentation time stamp and distance to first-needed reference. The exact encoding of the granule position is up to a specific codec.
The following 4 bytes are the stream serial number to which this page belongs. Each logical stream must have a unique serial number within a physical stream. It is also intended to be used like a weak hash so that a collision is very unlikely when multiplexing different streams, which eliminates the need for continuous recalculation of page headers at every multiplexing step.
The following 4 bytes are the page sequence number within the stream. It's a Page counter that lets you know if a page is lost. In comparison to other container formats, the large number of bits also allows direct UDP unicast/multicast with Ogg handling reordering and reassembly.
Next, the 27th byte of each page specifies the number of segments it contains which ranges from 0 to 255. This is also the size of the following segment table in bytes. Each byte of the segment table provides the length of a segment.
Each segment can be up to 255 bytes in length and is bounded by the page. If a segment is less than 255 it marks the end of a packet, the next segment will begin a new packet. If a packet ends on a multiple of 255, it will end in a segment 0 bytes long. If the last segment of the page is 255 bytes then the last packet is continued on the following page.
Editing with pages
Any series of pages within a stream can be preceded by the stream's header pages (pages with an absolute granule position of 0) and be decoded properly by media players. This technique can be used to losslessly crop a media file.
Multiple cropped segments can be appended to each other with a process known as chaining provided that the serial numbers of these segments are modified to unique numbers. New content can also be inserted between these segments.
- "RFC 3533 - The Ogg Encapsulation Format Version 0".
- Montgomery, Christopher (2010-04-27). "Monty - In Defense of Ogg's Good Name". people.xiph.org/~xiphmont. Retrieved 2010-05-02.
- "ogg-multiplex". Retrieved 2011-03-02.