Ogg Container
Ogg encapsulates codec packets in pages that support continuous delivery, logical streams, and codec-specific timing.
An Ogg file is made of pages, but a decoder consumes codec packets. Understanding that distinction explains how a small audio packet, a large setup packet, and timing information can all share one file.
Vorbis and Opus are coding formats carried through their own Ogg mappings. Ogg supplies the page structure around them; it does not make their decoding rules interchangeable.
Assemble a packet from page segments
A page contains a header, a segment table, and payload. The segment table uses lengths up to 255 bytes to describe how portions of packets occupy the payload. A length below 255 terminates a packet; longer packets use continued segments and can cross a page boundary.
For an invented 600-byte packet fitting on one otherwise empty page, segment lengths 255, 255, and 90 describe its data. The fixed 27-byte header and three-byte segment table add 30 bytes, producing a 630-byte page in this simplified example.
| Page information | Reader use |
|---|---|
| Capture pattern and flags | Recognize boundaries and continuation/start/end conditions |
| Stream serial number | Associate pages with one logical stream |
| Page sequence number | Follow its ordering |
| Checksum | Detect inconsistent page bytes |
| Granule position | Interpret completed media position through the codec mapping |
The decoder sees the reassembled packet, not the Ogg header and segment lengths. Where a packet spans pages, the reader retains its partial bytes until it is complete.
A granule position becomes audio time
The granule field's meaning comes from the codec mapping. Ogg Opus uses a 48 kHz sample-count coordinate even when an implementation outputs audio at another supported rate. The Opus header's pre-skip tells the reader how many initial decoded samples should be discarded.
Take a simple stream with ordinary initial positioning, 48,000 decoded samples represented at the final granule position, and an illustrative pre-skip of 312. The presented length is:
(48,000 − 312) ÷ 48,000 = 0.9935 seconds
The subtraction is not missing audio caused by the container. It is the mapping's way to exclude initial codec delay from the intended output. End-position rules can similarly trim extra decoded samples at the end. The encoded packet duration and presented duration can therefore differ for a legitimate reason.
Logical streams can end before the physical file
Chaining ends one logical stream and begins another, with new headers and identity. A continuous radio archive can consequently contain several linked portions within one physical file. A reader following only the first logical stream can report or play a shorter result than one following the complete chain.
For an Emby source with an unexpected duration or failure at a transition, record the codec, its header timing, and whether the file contains a chain. It targets the actual page/packet/timeline relationship rather than treating .ogg as a complete description of the sound.