Ogg objections

The Ogg container format is being promoted by the Xiph Foundation for use with its Vorbis and Theora codecs. Unfortunately, a number of technical shortcomings in the format render it ill-suited to most, if not all, use cases. This article examines the most severe of these flaws.

Overview of Ogg

The basic unit in an Ogg stream is the page consisting of a header followed by one or more packets from a single elementary stream. A page can contain up to 255 packets, and a packet can span any number of pages. The following table describes the page header.

Field Size (bits) Description
capture_pattern 32 magic number “OggS”
version 8 always zero
flags 8
granule_position 64 abstract timestamp
bitstream_serial_number 32 elementary stream number
page_sequence_number 32 incremented by 1 each page
checksum 32 CRC of entire page
page_segments 8 length of segment_table
segment_table variable list of packet sizes

Elementary stream types are identified by looking at the payload of the first few pages, which contain any setup data required by the decoders. For full details, see the official format specification.

Generality

Ogg, legend tells, was designed to be a general-purpose container format. To most multimedia developers, a general-purpose format is one in which encoded data of any type can be encapsulated with a minimum of effort.

The Ogg format defined by the specification does not fit this description. For every format one wishes to use with Ogg, a complex mapping must first be defined. This mapping defines how to identify a codec, how to extract setup data, and even how timestamps are to be interpreted. All this is done differently for every codec. To correctly parse an Ogg stream, every such mapping ever defined must be known.

Under this premise, a centralised repository of codec mappings would seem like a sensible idea, but alas, no such thing exists. It is simply impossible to obtain a exhaustive list of defined mappings, which makes the task of creating a complete implementation somewhat daunting.

One brave soul, Tobias Waldvogel, created a mapping, OGM, capable of storing any Microsoft AVI compatible codec data in Ogg files. This format saw some use in the wild, but was frowned upon by Xiph, and it was eventually displaced by other formats.

True generality is evidently not to be found with the Ogg format.

Overhead

When designing a container format, one important consideration is that of overhead, i.e. the extra space required in addition to the elementary stream data being combined. For any given container, the overhead can be divided into a fixed part, independent of the total file size, and a variable part growing with increasing file size. The fixed overhead is not of much concern, its relative contribution being negligible for typical file sizes.

The variable overhead in the Ogg format comes from the page headers, mostly from the segment_table field. This field uses a most peculiar encoding, somewhat reminiscent of Roman numerals. In Roman times, numbers were written as a sequence of symbols, each representing a value, the combined value being the sum of the constituent values.

The segment_table field lists the sizes of all packets in the page. Each value in the list is coded as a number of bytes equal to 255 followed by a final byte with a smaller value. The packet size is simply the sum of all these bytes. Any strictly additive encoding, such as this, has the distinct drawback of coded length being linearly proportional to the encoded value. A value of 5000, a reasonable packet size for video of moderate bitrate, requires no less than 20 bytes to encode.

On top of this we have the 27-byte page header which, although paling in comparison to the packet size encoding, is still much larger than necessary. Starting at the top of the list:

  • The version field could be disposed of, a single-bit marker being adequate to separate this first version from hypothetical future versions. One of the unused positions in the flags field could be used for this purpose
  • A 64-bit granule_position is completely overkill. 32 bits would be more than enough for the vast majority of use cases. In extreme cases, a one-bit flag could be used to signal an extended timestamp field.
  • 32-bit elementary stream number? Are they anticipating files with four billion elementary streams? An eight-bit field, if not smaller, would seem more appropriate here.
  • The 32-bit page_sequence_number is inexplicable. The intent is to allow detection of page loss due to transmission errors. ISO MPEG-TS uses a 4-bit counter per 188-byte packet for this purpose, and that format is used where packet loss actually happens, unlike any use of Ogg to date.
  • A mandatory 32-bit checksum is nothing but a waste of space when using a reliable storage/transmission medium. Again, a flag could be used to signal the presence of an optional checksum field.

With the changes suggested above, the page header would shrink from 27 bytes to 12 bytes in size.

We thus see that in an Ogg file, the packet size fields alone contribute an overhead of 1/255 or approximately 0.4%. This is a hard lower bound on the overhead, not attainable even in theory. In reality the overhead tends to be closer to 1%.

Contrast this with the ISO MP4 file format, which can easily achieve an overhead of less than 0.05% with a 1 Mbps elementary stream.

Latency

In many applications end-to-end latency is an important factor. Examples include video conferencing, telephony, live sports events, interactive gaming, etc. With the codec layer contributing as little as 10 milliseconds of latency, the amount imposed by the container becomes an important factor.

Latency in an Ogg-based system is introduced at both the sender and the receiver. Since the page header depends on the entire contents of the page (packet sizes and checksum), a full page of packets must be buffered by the sender before a single bit can be transmitted. This sets a lower bound for the sending latency at the duration of a page.

On the receiving side, playback cannot commence until packets from all elementary streams are available. Hence, with two streams (audio and video) interleaved at the page level, playback is delayed by at least one page duration (two if checksums are verified).

Taking both send and receive latencies into account, the minimum end-to-end latency for Ogg is thus twice the duration of a page, triple if strict checksum verification is required. If page durations are variable, the maximum value must be used in order to avoid buffer underflows.

Minimum latency is clearly achieved by minimising the page duration, which in turn implies sending only one packet per page. This is where the size of the page header becomes important. The header for a single-packet page is 27 + packet_size/255 bytes in size. For a 1 Mbps video stream at 25 fps this gives an overhead of approximately 1%. With a typical audio packet size of 400 bytes, the overhead becomes a staggering 7%. The average overhead for a multiplex of these two streams is 1.4%.

The Ogg format is clearly not a good choice for a low-latency application.

Random access

Any general-purpose container format needs to allow random access for direct seeking to any given position in the file. Despite this goal being explicitly mentioned in the Ogg specification, the format only allows the most crude of random access methods.

While many container formats include an index allowing a time to be directly translated into an offset into the file, Ogg has nothing of this kind, the stated rationale for the omission being that this would require a two-pass multiplexing, the second pass creating the index. This is obviously not true; the index could simply be written at the end of the file. Those objecting that this index would be unavailable in a streaming scenario are forgetting that seeking is impossible there regardless.

The method for seeking suggested by the Ogg documentation is to perform a binary search on the file, after each file-level seek operation scanning for a page header, extracting the timestamp, and comparing it to the desired position. When the elementary stream encoding allows only certain packets as random access points (video key frames), a second search will have to be performed to locate the entry point closest to the desired time. In a large file (sizes upwards of 10 GB are common), 50 seeks might be required to find the correct position.

A typical hard drive has an average seek time of roughly 10 ms, giving a total time for the seek operation of around 500 ms, an annoyingly long time. On a slow medium, such as an optical disc or files served over a network, the times are orders of magnitude longer.

A factor further complicating the seeking process is the possibility of header emulation within the elementary stream data. To safeguard against this, one has to read the entire page and verify the checksum. If the storage medium cannot provide data much faster than during normal playback, this provides yet another substantial delay towards finishing the seeking operation. This too applies to both network delivery and optical discs.

Although optical disc usage is perhaps in decline today, one should bear in mind that the Ogg format was designed at a time when CDs and DVDs were rapidly gaining ground, and network-based storage is most certainly on the rise.

The final nail in the coffin of seeking is the codec-dependent timestamp format. At each step in the seeking process, the timestamp parsing specified by the codec mapping corresponding the current page must be invoked. If the mapping is not known, the best one can do is skip pages until one with a known mapping is found. This delays the seeking and complicates the implementation, both bad things.

Timestamps

A problem old as multimedia itself is that of synchronising multiple elementary streams (e.g. audio and video) during playback; badly synchronised A/V is highly unpleasant to view. By the time Ogg was invented, solutions to this problem were long since explored and well-understood. The key to proper synchronisation lies in tagging elementary stream packets with timestamps, packets carrying the same timestamp intended for simultaneous presentation. The concept is as simple as it seems, so it is astonishing to see the amount of complexity with which the Ogg designers managed to imbue it. So bizarre is it, that I have devoted an entire article to the topic, and will not cover it further here.

Complexity

Video and audio decoding are time-consuming tasks, so containers should be designed to minimise extra processing required. With the data volumes involved, even an act as simple as copying a packet of compressed data can have a significant impact. Once again, however, Ogg lets us down. Despite the brevity of the specification, the format is remarkably complicated to parse properly.

The unusual and inefficient encoding of the packet sizes limits the page size to somewhat less than 64 kB. To still allow individual packets larger than this limit, it was decided to allow packets spanning multiple pages, a decision with unfortunate implications. A page-spanning packet as it arrives in the Ogg stream will be discontiguous in memory, a situation most decoders are unable to handle, and reassembly, i.e. copying, is required.

The knowledgeable reader may at this point remark that the MPEG-TS format also splits packets into pieces requiring reassembly before decoding. There is, however, a significant difference there. MPEG-TS was designed for hardware demultiplexing feeding directly into hardware decoders. In such an implementation the fragmentation is not a problem. Rather, the fine-grained interleaving is a feature allowing smaller on-chip buffers.

Buffering is also an area in which Ogg suffers. To keep the overhead down, pages must be made as large as practically possible, and page size translates directly into demultiplexer buffer size. Playback of a file with two elementary streams thus requires 128 kB of buffer space. On a modern PC this is perhaps nothing to be concerned about, but in a small embedded system, e.g. a portable media player, it can be relevant.

In addition to the above, a number of other issues, some of them minor, others more severe, make Ogg processing a painful experience. A selection follows:

  • 32-bit random elementary stream identifiers mean a simple table-lookup cannot be used. Instead the list of streams must be searched for a match. While trivial to do in software, it is still annoying, and a hardware demultiplexer would be significantly more complicated than with a smaller identifier.
  • Semantically ambiguous streams are possible. For example, the continuation flag (bit 1) may conflict with continuation (or lack thereof) implied by the segment table on the preceding page. Such invalid files have been spotted in the wild.
  • Concatenating independent Ogg streams forms a valid stream. While finding a use case for this strange feature is difficult, an implementation must of course be prepared to encounter such streams. Detecting and dealing with these adds pointless complexity.
  • Unusual terminology: inventing new terms for well-known concepts is confusing for the developer trying to understand the format in relation to others. A few examples:
    Ogg name Usual name
    logical bitstream elementary stream
    grouping multiplexing
    lacing value packet size (approximately)
    segment imaginary element serving no real purpose
    granule position timestamp

Final words

We have shown the Ogg format to be a dubious choice in just about every situation. Why then do certain organisations and individuals persist in promoting it with such ferocity?

When challenged, three types of reaction are characteristic of the Ogg campaigners.

On occasion, these people will assume an apologetic tone, explaining how Ogg was only ever designed for simple audio-only streams (ignoring it is as bad for these as for anything), and this is no doubt true. Why then, I ask again, do they continue to tout Ogg as the one-size-fits-all solution they already admitted it is not?

More commonly, the Ogg proponents will respond with hand-waving arguments best summarised as Ogg isn’t bad, it’s just different. My reply to this assertion is twofold:

  • Being too different is bad. We live in a world where multimedia files come in many varieties, and a decent media player will need to handle the majority of them. Fortunately, most multimedia file formats share some basic traits, and they can easily be processed in the same general framework, the specifics being taken care of at the input stage. A format deviating too far from the standard model becomes problematic.
  • Ogg is bad. When every angle of examination reveals serious flaws, bad is the only fitting description.

The third reaction bypasses all technical analysis: Ogg is patent-free, a claim I am not qualified to directly discuss. Assuming it is true, it still does not alter the fact that Ogg is a bad format. Being free from patents does not magically make Ogg a good choice as file format. If all the standard formats are indeed covered by patents, the only proper solution is to design a new, good format which is not, this time hopefully avoiding the old mistakes.


20 Responses to “Ogg objections”

  • Anonymous Says:

    I’d love to see your analysis of the Matroska container format.

  • bramp Says:

    Thanks for your analysis. For many years I’ve read on the FFmpeg mailing list that Ogg is a terrible format, but no one has ever explained why they think so.

    I’m now curious to see any response from the Ogg guys justifying their design.

    Also it might be interesting to hear your recommendation for a good container format, or if one doesn’t exist, what would it look like?

  • Travis Berry Says:

    Great write up. I complained about this recently. I added HTML5 video to my site and the Ogg videos look horrible. The animation is super stuttery. It has nothing on H264 at this point.

  • Ant Says:

    Serving MPEG4 files costs something like 5 million dollars per year, only to be allowed to use it without being sued. Ogg is free. That’s the killer feature. It’s not because MP4 is better that Ogg is bad. It gets the job done, for free. Companies like Spotify are quite happy with it.

    • Mans Says:

      Do you have a reference for that claim?

    • bd_ Says:

      This is only talking about the container, not the codec. There’s no reason you shouldn’t be able to mux theora and vorbis in a mp4 container, avoiding the h264 patents while still getting a good container.

  • Jeff Carr Says:

    Your assessment of the failures of OGG’s current design could be valid.

    As things pertain to the history of OGM, it might be noteworthy that OGM was initially only usable with closed source windows tools. (See wikipedia)

    • Mans Says:

      False. Although Tobias’ tools may have been closed source, anyone could have created open source alternatives. I don’t know if that happened for writing, but open source readers sure existed. I wrote one myself.

  • kL Says:

    This presentation nicely summarizes MPEG-LA licensing costs:

    http://www.mpegla.com/main/programs/avc/Documents/avcweb.ppt

    $5M is a cap that applies to large volume distributors, like browser vendors.

    • Mans Says:

      That is talking about MPEG4 part 10, aka AVC, aka H.264. The MP4 file format I mentioned is part 12+14 and has nothing to do with H.264/AVC.

  • someone else Says:

    License terms: http://www.mpegla.com/main/programs/AVC/Documents/AVC_TermsSummary.pdf

    Free video distribution doesn’t cost anything until 31. Dec. 2010, but you nonetheless have to get a license or you will be sued. Later it can/will cost up to 5 Mio. $ per year. Providers of paid video already must pay for the license. And creators of en-/decoders have to pay 5 Mio. $ a year, too.

  • Kevin Granade Says:

    Many of your points sound reasonable, but your argument is strongly undermined by the fact that you offer not a single apples-to-apples comparison between ogg and any other container format in your article. On a section-by-section basis:
    Generalities/codec mapping:
    You complain about how there is no global mapping, but do not assert that other containers have one.
    Overhead:
    The breakdown of where space is wasted is informative and mostly reasonable, but some of them seem to be a reach, such as the checksum being unneeded, and your suggestion of implementing the functionality in optional fields seems like a bad idea to me in general, since it will make the header variable-length, which is something to strongly avoid in my experience. Finally, when you do “compare” ogg to mp4, you compare some rather hand-wavey numbers for ogg to a different scenario for mp4.
    Latency:
    You fire off a bunch of numbers here, but then offer no comparison to the alternatives. In fact you don’t even provide an explanation of how other formats avoid this latency in theory, much less in practice, and instead of showing how bad the latency is, you use it as a platform to show that a naive reaction to the issue will cause bad header overhead.
    Random Access:
    In this section you list quite a few worst-case numbers for disk accesses (why isn’t it being pre-cached by the filesystem?) and then end with no comparison to alternatives at all.
    Complexity:
    Once again you have a bunch of statements of problems you have with the format, but no comparisons to “good” formats, in addition this section is particularly weak, with statements like, “implementation is annoying”, and “ambiguity is bad”.
    Final Words:
    “We have shown” is a rather specific claim to make, which you have not remotely achieved. This pretty much sums up the whole article, which is titled “Ogg objections”, but then tries in the text to bill itself as a rigorous analysis of ogg, which it is not.

    If you had matched the tone of the article to the title, this would be reasonable, but you only hurt your position when you throw around phrases like, “True generality is evidently not to be found with the Ogg format.”, “The Ogg format is clearly not a good choice for a low-latency application.”, and “We have shown the Ogg format to be a dubious choice in just about every situation.”. You have demonstrated NONE of the above claims, and by making them you have rendered me skeptical of the rest of your claims.

  • Michael Stanley Says:

    Lacking an index is not a fatal design flaw for the container. It can be added afterwards with no incompatible changes and minimal disruption. In fact, Ogg is growing an index for fast seeking over high latency connections right now: http://wiki.xiph.org/Ogg_Index

  • toots Says:

    I agree with the comment on Matroska.

    Discarding the issue of the patent is not serious and, I may add, probably biased.

    This discussion cannot be done only on the basis of technical qualities.

    There is a loong list of situations where the worse technical solution was chosed based on arguments completely out of the technical debate, for instance the use of MS DOS in the first IBM PC, which has led to the monopoly of the worst OS technology ever, and it still holds…

    The fact that ogg is patent-free is a tremendous argument for ogg and the key reason for its support, no matter what are the technical issue. If you don’t see it, you’re either blind or purposly naive.

    Now, I agree on the technical side. Ogg is not a good container, at least for the broad purpose the xiph fundations pushes.

    A critical example is streaming. The fact that the first page needs to be passed means that building a streaming server for ogg is incredibly complicated, generates unregular streams (page 0 and then page 13542 for instance), and prevents any implementation using UDP (and I do not mention the issues with page numbering in the various logical streams and the implied latency).

    When you compare to the amount of work needed to stream a headerless container such as mpeg, this simply becomes ridiculous.

    Hence, yes, we need a light versatile headerless container. But, no, some patent-encumbered solution, such as mpeg, despite its great technical advantages, is not an option.

    The next step would probably be a proposal for such a container. And, instead of whining here (which includes me), someone to do the job and bring on the proposal…

  • james Says:

    the container and format wars are not about technology, they are about control. whether your analysis is valid or not is mostly irrelevant. what is relevant is whether one company is controlling the rights to dominant standardized codecs. the single most important issue to me is getting decoders and encoders under a royalty-free [a|l]gpl style license. fwiw, hth.

    _J

    • Mans Says:

      You are correct, it is almost certainly more about control and less about technology. Am I the only one to see the hypocrisy in an organisation like Xiph, ostensibly campaigners for freedom, engaging in a battle for control in this manner?

  • Torrance Says:

    I think you should update the section on the index. The ogg container does indeed have a newly-implemented seek index to avoid precisely the kind of b-search you describe. The specification (http://wiki.xiph.org/Ogg_Index) is still a work in progress, but it’s implemented in ffmpeg2theora and Firefox nightlies are ‘index-aware’ too.

Leave a Reply