Ogg media container file: GraphViz block diagram (.dot) source

Ogg is a popular media container format, which provides basic streaming / buffering mechanisms and is content-agnostic. Most popular codecs that are used within Ogg streams are Vorbis (thus making Ogg/Vorbis streams) and Theora (Ogg/Theora).

Ogg stream is a sequence Ogg pages. They can be read sequentially, or one can jump into arbitrary stream location and scan for "OggS" sync code to find the beginning of a new Ogg page and continue decoding the stream contents from that one.

File extension

["ogg", "ogv", "oga", "spx", "ogx"]

KS implementation details

License: CC0-1.0

References

This page hosts a formal specification of Ogg media container file using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

GraphViz block diagram source

ogg.dot

digraph {
	rankdir=LR;
	node [shape=plaintext];
	subgraph cluster__ogg {
		label="Ogg";
		graph[style=dotted];

		ogg__seq [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">pos</TD><TD BGCOLOR="#E0FFE0">size</TD><TD BGCOLOR="#E0FFE0">type</TD><TD BGCOLOR="#E0FFE0">id</TD></TR>
			<TR><TD PORT="pages_pos">0</TD><TD PORT="pages_size">...</TD><TD>Page</TD><TD PORT="pages_type">pages</TD></TR>
			<TR><TD COLSPAN="4" PORT="pages__repeat">repeat to end of stream</TD></TR>
		</TABLE>>];
		subgraph cluster__page {
			label="Ogg::Page";
			graph[style=dotted];

			page__seq [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
				<TR><TD BGCOLOR="#E0FFE0">pos</TD><TD BGCOLOR="#E0FFE0">size</TD><TD BGCOLOR="#E0FFE0">type</TD><TD BGCOLOR="#E0FFE0">id</TD></TR>
				<TR><TD PORT="sync_code_pos">0</TD><TD PORT="sync_code_size">4</TD><TD></TD><TD PORT="sync_code_type">sync_code</TD></TR>
				<TR><TD PORT="version_pos">4</TD><TD PORT="version_size">1</TD><TD></TD><TD PORT="version_type">version</TD></TR>
				<TR><TD PORT="reserved1_pos">5</TD><TD PORT="reserved1_size">5b</TD><TD>b5</TD><TD PORT="reserved1_type">reserved1</TD></TR>
				<TR><TD PORT="is_end_of_stream_pos">5:5</TD><TD PORT="is_end_of_stream_size">1b</TD><TD>BitsType1(BigBitEndian)</TD><TD PORT="is_end_of_stream_type">is_end_of_stream</TD></TR>
				<TR><TD PORT="is_beginning_of_stream_pos">5:6</TD><TD PORT="is_beginning_of_stream_size">1b</TD><TD>BitsType1(BigBitEndian)</TD><TD PORT="is_beginning_of_stream_type">is_beginning_of_stream</TD></TR>
				<TR><TD PORT="is_continuation_pos">5:7</TD><TD PORT="is_continuation_size">1b</TD><TD>BitsType1(BigBitEndian)</TD><TD PORT="is_continuation_type">is_continuation</TD></TR>
				<TR><TD PORT="granule_pos_pos">6</TD><TD PORT="granule_pos_size">8</TD><TD>u8le</TD><TD PORT="granule_pos_type">granule_pos</TD></TR>
				<TR><TD PORT="bitstream_serial_pos">14</TD><TD PORT="bitstream_serial_size">4</TD><TD>u4le</TD><TD PORT="bitstream_serial_type">bitstream_serial</TD></TR>
				<TR><TD PORT="page_seq_num_pos">18</TD><TD PORT="page_seq_num_size">4</TD><TD>u4le</TD><TD PORT="page_seq_num_type">page_seq_num</TD></TR>
				<TR><TD PORT="crc32_pos">22</TD><TD PORT="crc32_size">4</TD><TD>u4le</TD><TD PORT="crc32_type">crc32</TD></TR>
				<TR><TD PORT="num_segments_pos">26</TD><TD PORT="num_segments_size">1</TD><TD>u1</TD><TD PORT="num_segments_type">num_segments</TD></TR>
				<TR><TD PORT="len_segments_pos">27</TD><TD PORT="len_segments_size">1</TD><TD>u1</TD><TD PORT="len_segments_type">len_segments</TD></TR>
				<TR><TD COLSPAN="4" PORT="len_segments__repeat">repeat num_segments times</TD></TR>
				<TR><TD PORT="segments_pos">...</TD><TD PORT="segments_size">len_segments[i]</TD><TD></TD><TD PORT="segments_type">segments</TD></TR>
				<TR><TD COLSPAN="4" PORT="segments__repeat">repeat num_segments times</TD></TR>
			</TABLE>>];
		}
	}
	ogg__seq:pages_type -> page__seq [style=bold];
	page__seq:num_segments_type -> page__seq:len_segments__repeat [color="#404040"];
	page__seq:len_segments_type -> page__seq:segments_size [color="#404040"];
	page__seq:num_segments_type -> page__seq:segments__repeat [color="#404040"];
}