a1-encapsulation-ogg.tex 6.3 KB

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