a1-encapsulation_ogg.xml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?xml version="1.0" standalone="no"?>
  2. <!DOCTYPE appendix PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
  4. ]>
  5. <appendix id="vorbis-over-ogg">
  6. <appendixinfo>
  7. <releaseinfo>
  8. $Id$
  9. </releaseinfo>
  10. </appendixinfo>
  11. <title>Embedding Vorbis into an Ogg stream</title>
  12. <section>
  13. <title>Overview</title>
  14. <para>
  15. This document describes using Ogg logical and physical transport
  16. streams to encapsulate Vorbis compressed audio packet data into file
  17. form.</para>
  18. <para>
  19. The <xref linkend="vorbis-spec-intro"/> provides an overview of the construction
  20. of Vorbis audio packets.</para>
  21. <para>
  22. The <ulink url="oggstream.html">Ogg
  23. bitstream overview</ulink> and <ulink url="framing.html">Ogg logical
  24. bitstream and framing spec</ulink> provide detailed descriptions of Ogg
  25. transport streams. This specification document assumes a working
  26. knowledge of the concepts covered in these named backround
  27. documents. Please read them first.</para>
  28. <section><title>Restrictions</title>
  29. <para>
  30. The Ogg/Vorbis I specification currently dictates that Ogg/Vorbis
  31. streams use Ogg transport streams in degenerate, unmultiplexed
  32. form only. That is:
  33. <itemizedlist>
  34. <listitem><simpara>
  35. A meta-headerless Ogg file encapsulates the Vorbis I packets
  36. </simpara></listitem>
  37. <listitem><simpara>
  38. The Ogg stream may be chained, i.e. contain multiple, contigous logical streams (links).
  39. </simpara></listitem>
  40. <listitem><simpara>
  41. The Ogg stream must be unmultiplexed (only one stream, a Vorbis audio stream, per link)
  42. </simpara></listitem>
  43. </itemizedlist>
  44. </para>
  45. <para>
  46. This is not to say that it is not currently possible to multiplex
  47. Vorbis with other media types into a multi-stream Ogg file. At the
  48. time this document was written, Ogg was becoming a popular container
  49. for low-bitrate movies consisting of DivX video and Vorbis audio.
  50. However, a 'Vorbis I audio file' is taken to imply Vorbis audio
  51. existing alone within a degenerate Ogg stream. A compliant 'Vorbis
  52. audio player' is not required to implement Ogg support beyond the
  53. specific support of Vorbis within a degenrate Ogg stream (naturally,
  54. application authors are encouraged to support full multiplexed Ogg
  55. handling).
  56. </para>
  57. </section>
  58. <section><title>MIME type</title>
  59. <para>
  60. The MIME type of Ogg files depend on the context. Specifically, complex
  61. multimedia and applications should use <literal>application/ogg</literal>,
  62. while visual media should use <literal>video/ogg</literal>, and audio
  63. <literal>audio/ogg</literal>. Vorbis data encapsulated in Ogg may appear
  64. in any of those types. RTP encapsulated Vorbis should use
  65. <literal>audio/vorbis</literal> + <literal>audio/vorbis-config</literal>.
  66. </para>
  67. </section>
  68. </section>
  69. <section>
  70. <title>Encapsulation</title>
  71. <para>
  72. Ogg encapsulation of a Vorbis packet stream is straightforward.</para>
  73. <itemizedlist>
  74. <listitem><simpara>
  75. The first Vorbis packet (the identification header), which
  76. uniquely identifies a stream as Vorbis audio, is placed alone in the
  77. first page of the logical Ogg stream. This results in a first Ogg
  78. page of exactly 58 bytes at the very beginning of the logical stream.
  79. </simpara></listitem>
  80. <listitem><simpara>
  81. This first page is marked 'beginning of stream' in the page flags.
  82. </simpara></listitem>
  83. <listitem><simpara>
  84. The second and third vorbis packets (comment and setup
  85. headers) may span one or more pages beginning on the second page of
  86. the logical stream. However many pages they span, the third header
  87. packet finishes the page on which it ends. The next (first audio) packet
  88. must begin on a fresh page.
  89. </simpara></listitem>
  90. <listitem><simpara>
  91. The granule position of these first pages containing only headers is zero.
  92. </simpara></listitem>
  93. <listitem><simpara>
  94. The first audio packet of the logical stream begins a fresh Ogg page.
  95. </simpara></listitem>
  96. <listitem><simpara>
  97. Packets are placed into ogg pages in order until the end of stream.
  98. </simpara></listitem>
  99. <listitem><simpara>
  100. The last page is marked 'end of stream' in the page flags.
  101. </simpara></listitem>
  102. <listitem><simpara>
  103. Vorbis packets may span page boundaries.
  104. </simpara></listitem>
  105. <listitem><simpara>
  106. The granule position of pages containing Vorbis audio is in units
  107. of PCM audio samples (per channel; a stereo stream's granule position
  108. does not increment at twice the speed of a mono stream).
  109. </simpara></listitem>
  110. <listitem><simpara>
  111. The granule position of a page represents the end PCM sample
  112. position of the last packet <emphasis>completed</emphasis> on that
  113. page. The 'last PCM sample' is the last complete sample returned by
  114. decode, not an internal sample awaiting lapping with a
  115. subsequent block. A page that is entirely spanned by a single
  116. packet (that completes on a subsequent page) has no granule
  117. position, and the granule position is set to '-1'. </simpara>
  118. <simpara>
  119. Note that the last decoded (fully lapped) PCM sample from a packet
  120. is not necessarily the middle sample from that block. If, eg, the
  121. current Vorbis packet encodes a "long block" and the next Vorbis
  122. packet encodes a "short block", the last decodable sample from the
  123. current packet be at position (3*long_block_length/4) -
  124. (short_block_length/4).
  125. </simpara>
  126. </listitem>
  127. <listitem>
  128. <simpara>
  129. The granule (PCM) position of the first page need not indicate
  130. that the stream started at position zero. Although the granule
  131. position belongs to the last completed packet on the page and a
  132. valid granule position must be positive, by
  133. inference it may indicate that the PCM position of the beginning
  134. of audio is positive or negative.
  135. </simpara>
  136. <itemizedlist>
  137. <listitem><simpara>
  138. A positive starting value simply indicates that this stream begins at
  139. some positive time offset, potentially within a larger
  140. program. This is a common case when connecting to the middle
  141. of broadcast stream.
  142. </simpara></listitem>
  143. <listitem><simpara>
  144. A negative value indicates that
  145. output samples preceeding time zero should be discarded during
  146. decoding; this technique is used to allow sample-granularity
  147. editing of the stream start time of already-encoded Vorbis
  148. streams. The number of samples to be discarded must not exceed
  149. the overlap-add span of the first two audio packets.
  150. </simpara></listitem>
  151. </itemizedlist>
  152. <simpara>
  153. In both of these cases in which the initial audio PCM starting
  154. offset is nonzero, the second finished audio packet must flush the
  155. page on which it appears and the third packet begin a fresh page.
  156. This allows the decoder to always be able to perform PCM position
  157. adjustments before needing to return any PCM data from synthesis,
  158. resulting in correct positioning information without any aditional
  159. seeking logic.
  160. </simpara>
  161. <note><simpara>
  162. Failure to do so should, at worst, cause a
  163. decoder implementation to return incorrect positioning information
  164. for seeking operations at the very beginning of the stream.
  165. </simpara></note>
  166. </listitem>
  167. <listitem><simpara>
  168. A granule position on the final page in a stream that indicates
  169. less audio data than the final packet would normally return is used to
  170. end the stream on other than even frame boundaries. The difference
  171. between the actual available data returned and the declared amount
  172. indicates how many trailing samples to discard from the decoding
  173. process.
  174. </simpara></listitem>
  175. </itemizedlist>
  176. </section>
  177. </appendix>
  178. <!-- end appendix on Vorbis encapsulation in Ogg -->