[theora] Reading framerate, height, width from Theora file

Ralph Giles giles at xiph.org
Wed Dec 30 16:06:26 PST 2009

2009/12/13 G <w3stfa11 at gmail.com>:

> I'd like to get basic information about a Theora file using C# .NET. How can
> I get started on this?

You can just read the information out of the first few KB of
bitstream, but it's a little complicated. The first packet of each
theora stream has the framerate and picture dimensions, and the second
has author/title metadata (if any has been set).

See Figure 6.2 "Identification Header Packet" in
http://theora.org/doc/Theora.pdf for the layout of the first header.
The unscaled frame dimensions are the PICH and PICW fields, each
stored in 24 bits starting at byte offset 14 and 17 from the start of
the packet. The frame rate is stored as a rational number, with the
numerator and denominator as two consecutive 32 bit integers starting
at byte offset 22. This is followed by the pixel aspect ratio as two
24 bit integers; multiply the picture width by their ratio to get the
display size, or multiply the ratio of the frame dimensions by the
pixel aspect ratio to get the frame aspect ratio (e.g. 4:3 or 16:9).

The theora data will be wrapped in a container though, so these data
won't be at a fixed offset in the file. See
http://xiph.org/ogg/doc/rfc3533.txt (or
http://xiph.org/ogg/doc/oggstream.html and
http://xiph.org/ogg/doc/framing.html) for how to parse and verify the
Ogg container theora is usually stored in. If you just want something
quick and dirty, search for the sequence 0x80,"theora" 28 bytes after
the sequence 'OggS' somewhere in the first few KB of the file. the
0x80 is the start of the first theora packet.

Hope that helps,

More information about the theora mailing list