From XiphWiki
Revision as of 23:30, 18 March 2010 by Rillian (talk | contribs) (→‎Introduction: FRAME header has a newline (0x0A) after it)
Jump to navigation Jump to search

This is a draft spec for encapsulation of the YUV4MPEG2 uncompressed video format in Ogg. This is is primarily useful for multiplexing it with audio for transmission through a single pipe.


The YUV4MPEG format was created and defined by the linux audio/video tools package. It is a combination of text-based headers and 'raw' frame data. This is just an informational summary. See lavtools or this documentation for the complete definition. These files often have the filename extension .y4m.

A YUV4MPEG file begins with a single text line which defined the stream parameters like image size, framerate, chroma subsampling and so on. For example:

YUV4MPEG2 W352 H288 F30000:1001 Ip A128:117

says that this is a yuv4mpeg2 file with 352x288 progressive frames at 29.97 fps (CIF) and matching pixel aspect ratio. Note that the order and locations of the various data in the header packet are arbitrary and must be parsed as text. Each field is prefixed by a single character which defines the field type. The initial space after YUV4MPEG2 is required.

This header is followed by a sequence of frames. Each frame has a text header "FRAME\n", followed by the raw frame data, a plane at a time, in binary.


The first line of a YUV4MPEG stream is the initial packet. Because this line must always start with the 8 character sequence 'YUV4MPEG', this can serve for codec identification, and also contains all the relevent decoder setup data. This is the only header packet and should appear on the first page by itself, with the bos flag set.

Each successive frame, consisting of the 'FRAME' text line followed by the binary data for one frame, is placed into an Ogg packet.

The granulepos field is set based on the count of encoded frames since the beginning of the stream. Thus the first, stream header packet gets a granulepos value of 0, the second packet, containing the first frame gets a granulepos value of 1, and successive frames get a values of 2, 3, 4 and so on until the end of the stream. The last page an encoder produces SHOULD have the eos flag set to indicate encapsulation of the complete data stream. A decoder MUST NOT treat a missing eos flag as an error.


An Ogg-encapsulated YUV4MPEG stream may be multiplexed with other data according to the standard rules. The granulepos may be converted to a timestamp by dividing the granulepos value by the framerate, given as a rational number in the 'F' field of the header packet.