draft-terriberry-oggopus.xml 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE rfc SYSTEM 'rfc2629.dtd' [
  3. <!ENTITY rfc2119 PUBLIC '' 'https://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml'>
  4. <!ENTITY rfc3533 PUBLIC '' 'https://xml.resource.org/public/rfc/bibxml/reference.RFC.3533.xml'>
  5. <!ENTITY rfc3534 PUBLIC '' 'https://xml.resource.org/public/rfc/bibxml/reference.RFC.3534.xml'>
  6. <!ENTITY rfc4732 PUBLIC '' 'https://xml.resource.org/public/rfc/bibxml/reference.RFC.4732.xml'>
  7. <!ENTITY rfc3629 PUBLIC '' 'https://xml.resource.org/public/rfc/bibxml/reference.RFC.3629.xml'>
  8. <!ENTITY rfc6381 PUBLIC '' 'https://xml.resource.org/public/rfc/bibxml/reference.RFC.6381.xml'>
  9. <!ENTITY rfc6716 PUBLIC '' 'https://xml.resource.org/public/rfc/bibxml/reference.RFC.6716.xml'>
  10. ]>
  11. <?rfc toc="yes" symrefs="yes" ?>
  12. <rfc ipr="trust200902" category="std" docName="draft-terriberry-oggopus-01">
  13. <front>
  14. <title abbrev="Ogg Opus">Ogg Encapsulation for the Opus Audio Codec</title>
  15. <author initials="T.B." surname="Terriberry" fullname="Timothy B. Terriberry">
  16. <organization>Mozilla Corporation</organization>
  17. <address>
  18. <postal>
  19. <street>650 Castro Street</street>
  20. <city>Mountain View</city>
  21. <region>CA</region>
  22. <code>94041</code>
  23. <country>USA</country>
  24. </postal>
  25. <phone>+1 650 903-0800</phone>
  26. <email>tterribe@xiph.org</email>
  27. </address>
  28. </author>
  29. <author initials="R." surname="Lee" fullname="Ron Lee">
  30. <organization>Voicetronix</organization>
  31. <address>
  32. <postal>
  33. <street>246 Pulteney Street, Level 1</street>
  34. <city>Adelaide</city>
  35. <region>SA</region>
  36. <code>5000</code>
  37. <country>Australia</country>
  38. </postal>
  39. <phone>+61 8 8232 9112</phone>
  40. <email>ron@debian.org</email>
  41. </address>
  42. </author>
  43. <author initials="R." surname="Giles" fullname="Ralph Giles">
  44. <organization>Mozilla Corporation</organization>
  45. <address>
  46. <postal>
  47. <street>163 West Hastings Street</street>
  48. <city>Vancouver</city>
  49. <region>BC</region>
  50. <code>V6B 1H5</code>
  51. <country>Canada</country>
  52. </postal>
  53. <phone>+1 604 778 1540</phone>
  54. <email>giles@xiph.org</email>
  55. </address>
  56. </author>
  57. <date day="16" month="July" year="2012"/>
  58. <area>RAI</area>
  59. <workgroup>codec</workgroup>
  60. <abstract>
  61. <t>
  62. This document defines the Ogg encapsulation for the Opus interactive speech and
  63. audio codec.
  64. This allows data encoded in the Opus format to be stored in an Ogg logical
  65. bitstream.
  66. Ogg encapsulation provides Opus with a long-term storage format supporting
  67. all of the essential features, including metadata, fast and accurate seeking,
  68. corruption detection, recapture after errors, low overhead, and the ability to
  69. multiplex Opus with other codecs (including video) with minimal buffering.
  70. It also provides a live streamable format, capable of delivery over a reliable
  71. stream-oriented transport, without requiring all the data, or even the total
  72. length of the data, up-front, in a form that is identical to the on-disk
  73. storage format.
  74. </t>
  75. </abstract>
  76. </front>
  77. <middle>
  78. <section anchor="intro" title="Introduction">
  79. <t>
  80. The IETF Opus codec is a low-latency audio codec optimized for both voice and
  81. general-purpose audio.
  82. See <xref target="RFC6716"/> for technical details.
  83. This document defines the encapsulation of Opus in a continuous, logical Ogg
  84. bitstream&nbsp;<xref target="RFC3533"/>.
  85. </t>
  86. <t>
  87. Ogg bitstreams are made up of a series of 'pages', each of which contains data
  88. from one or more 'packets'.
  89. Pages are the fundamental unit of multiplexing in an Ogg stream.
  90. Each page is associated with a particular logical stream and contains a capture
  91. pattern and checksum, flags to mark the beginning and end of the logical
  92. stream, and a 'granule position' that represents an absolute position in the
  93. stream, to aid seeking.
  94. A single page can contain up to 65,025 octets of packet data from up to 255
  95. different packets.
  96. Packets may be split arbitrarily across pages, and continued from one page to
  97. the next (allowing packets much larger than would fit on a single page).
  98. Each page contains 'lacing values' that indicate how the data is partitioned
  99. into packets, allowing a demuxer to recover the packet boundaries without
  100. examining the encoded data.
  101. A packet is said to 'complete' on a page when the page contains the final
  102. lacing value corresponding to that packet.
  103. </t>
  104. <t>
  105. This encapsulation defines the required contents of the packet data, including
  106. the necessary headers, the organization of those packets into a logical
  107. stream, and the interpretation of the codec-specific granule position field.
  108. It does not attempt to describe or specify the existing Ogg container format.
  109. Readers unfamiliar with the basic concepts mentioned above are encouraged to
  110. review the details in <xref target="RFC3533"/>.
  111. </t>
  112. </section>
  113. <section anchor="terminology" title="Terminology">
  114. <t>
  115. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
  116. "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be
  117. interpreted as described in <xref target="RFC2119"/>.
  118. </t>
  119. <t>
  120. Implementations that fail to satisfy one or more "MUST" requirements are
  121. considered non-compliant.
  122. Implementations that satisfy all "MUST" requirements, but fail to satisfy one
  123. or more "SHOULD" requirements are said to be "conditionally compliant".
  124. All other implementations are "unconditionally compliant".
  125. </t>
  126. </section>
  127. <section anchor="packet_organization" title="Packet Organization">
  128. <t>
  129. An Opus stream is organized as follows.
  130. </t>
  131. <t>
  132. There are two mandatory header packets.
  133. The granule position of the pages on which these packets complete MUST be zero.
  134. </t>
  135. <t>
  136. The first packet in the logical Ogg bitstream MUST contain the identification
  137. (ID) header, which uniquely identifies a stream as Opus audio.
  138. The format of this header is defined in <xref target="id_header"/>.
  139. It MUST be placed alone (without any other packet data) on the first page of
  140. the logical Ogg bitstream, and must complete on that page.
  141. This page MUST have its 'beginning of stream' flag set.
  142. </t>
  143. <t>
  144. The second packet in the logical Ogg bitstream MUST contain the comment header,
  145. which contains user-supplied metadata.
  146. The format of this header is defined in <xref target="comment_header"/>.
  147. It MAY span one or more pages, beginning on the second page of the logical
  148. stream.
  149. However many pages it spans, the comment header packet MUST finish the page on
  150. which it completes.
  151. </t>
  152. <t>
  153. All subsequent pages are audio data pages, and the Ogg packets they contain are
  154. audio data packets.
  155. Each audio data packet contains one Opus packet for each of N different
  156. streams, where N is typically one for mono or stereo, but may be greater than
  157. one for, e.g., multichannel audio.
  158. The value N is specified in the ID header (see
  159. <xref target="channel_mapping"/>), and is fixed over the entire length of the
  160. logical Ogg bitstream.
  161. </t>
  162. <t>
  163. The first N-1 Opus packets, if any, are packed one after another into the Ogg
  164. packet, using the self-delimiting framing from Appendix&nbsp;B of
  165. <xref target="RFC6716"/>.
  166. The remaining Opus packet is packed at the end of the Ogg packet using the
  167. regular, undelimited framing from Section&nbsp;3 of <xref target="RFC6716"/>.
  168. All of the Opus packets in a single Ogg packet MUST be constrained to have the
  169. same duration.
  170. The duration and coding modes of each Opus packet are contained in the
  171. TOC (table of contents) sequence in the first few bytes.
  172. A decoder SHOULD treat any Opus packet whose duration is different from that of
  173. the first Opus packet in an Ogg packet as if it were an Opus packet with an
  174. illegal TOC sequence.
  175. </t>
  176. <t>
  177. The first audio data page SHOULD NOT have the 'continued packet' flag set
  178. (which would indicate the first audio data packet is continued from a previous
  179. page).
  180. Packets MUST be placed into Ogg pages in order until the end of stream.
  181. Audio packets MAY span page boundaries.
  182. A decoder MUST treat a zero-octet audio data packet as if it were an Opus
  183. packet with an illegal TOC sequence.
  184. The last page SHOULD have the 'end of stream' flag set, but implementations
  185. should be prepared to deal with truncated streams that do not have a page
  186. marked 'end of stream'.
  187. The final packet on the last page SHOULD NOT be a continued packet, i.e., the
  188. final lacing value should be less than 255.
  189. There MUST NOT be any more pages in an Opus logical bitstream after a page
  190. marked 'end of stream'.
  191. </t>
  192. </section>
  193. <section anchor="granpos" title="Granule Position">
  194. <t>
  195. The granule position of an audio data page encodes the total number of PCM
  196. samples in the stream up to and including the last fully-decodable sample from
  197. the last packet completed on that page.
  198. A page that is entirely spanned by a single packet (that completes on a
  199. subsequent page) has no granule position, and the granule position field MUST
  200. be set to the special value '-1' in two's complement.
  201. </t>
  202. <t>
  203. The granule position of an audio data page is in units of PCM audio samples at
  204. a fixed rate of 48&nbsp;kHz (per channel; a stereo stream's granule position
  205. does not increment at twice the speed of a mono stream).
  206. It is possible to run an Opus decoder at other sampling rates, but the value
  207. in the granule position field always counts samples assuming a 48&nbsp;kHz
  208. decoding rate, and the rest of this specification makes the same assumption.
  209. </t>
  210. <t>
  211. The duration of an Opus packet may be any multiple of 2.5&nbsp;ms, up to a
  212. maximum of 120&nbsp;ms.
  213. This duration is encoded in the TOC sequence at the beginning of each packet.
  214. The number of samples returned by a decoder corresponds to this duration
  215. exactly, even for the first few packets.
  216. For example, a 20&nbsp;ms packet fed to a decoder running at 48&nbsp;kHz will
  217. always return 960&nbsp;samples.
  218. A demuxer can parse the TOC sequence at the beginning of each Ogg packet to
  219. work backwards or forwards from a packet with a known granule position (i.e.,
  220. the last packet completed on some page) in order to assign granule positions
  221. to every packet, or even every individual sample.
  222. The one exception is the last page in the stream, as described below.
  223. </t>
  224. <t>
  225. All other pages with completed packets after the first MUST have a granule
  226. position equal to the number of samples contained in packets that complete on
  227. that page plus the granule position of the most recent page with completed
  228. packets.
  229. This guarantees that a demuxer can assign individual packets the same granule
  230. position when working forwards as when working backwards.
  231. For this to work, there cannot be any gaps.
  232. In order to support capturing a stream that uses discontinuous transmission
  233. (DTX), an encoder SHOULD emit packets that explicitly request the use of
  234. Packet Loss Concealment (PLC) (i.e., with a frame length of 0, as defined in
  235. Section 3.2.1 of <xref target="RFC6716"/>) in place of the packets that were
  236. not transmitted.
  237. </t>
  238. <section anchor="preskip" title="Pre-skip">
  239. <t>
  240. There is some amount of latency introduced during the decoding process, to
  241. allow for overlap in the MDCT modes, stereo mixing in the LP modes, and
  242. resampling, and the encoder will introduce even more latency (though the exact
  243. amount is not specified).
  244. Therefore, the first few samples produced by the decoder do not correspond to
  245. real input audio, but are instead composed of padding inserted by the encoder
  246. to compensate for this latency.
  247. These samples need to be stored and decoded, as Opus is an asymptotically
  248. convergent predictive codec, meaning the decoded contents of each frame depend
  249. on the recent history of decoder inputs.
  250. However, a decoder will want to skip these samples after decoding them.
  251. </t>
  252. <t>
  253. A 'pre-skip' field in the ID header (see <xref target="id_header"/>) signals
  254. the number of samples which should be skipped (decoded but discarded) at the
  255. beginning of the stream.
  256. This provides sufficient history to the decoder so that it has already
  257. converged before the stream's output begins.
  258. It may also be used to perform sample-accurate cropping of existing encoded
  259. streams.
  260. This amount need not be a multiple of 2.5&nbsp;ms, may be smaller than a single
  261. packet, or may span the contents of several packets.
  262. </t>
  263. </section>
  264. <section anchor="pcm_sample_position" title="PCM Sample Position">
  265. <t>
  266. The PCM sample position is determined from the granule position using the
  267. formula
  268. <figure align="center">
  269. <artwork align="center"><![CDATA[
  270. 'PCM sample position' = 'granule position' - 'pre-skip' .
  271. ]]></artwork>
  272. </figure>
  273. </t>
  274. <t>
  275. For example, if the granule position of the first audio data page is 59,971,
  276. and the pre-skip is 11,971, then the PCM sample position of the last decoded
  277. sample from that page is 48,000.
  278. This can be converted into a playback time using the formula
  279. <figure align="center">
  280. <artwork align="center"><![CDATA[
  281. 'PCM sample position'
  282. 'playback time' = --------------------- .
  283. 48000.0
  284. ]]></artwork>
  285. </figure>
  286. </t>
  287. <t>
  288. The initial PCM sample position before any samples are played is normally '0'.
  289. In this case, the PCM sample position of the first audio sample to be played
  290. starts at '1', because it marks the time on the clock
  291. <spanx style="emph">after</spanx> that sample has been played, and a stream
  292. that is exactly one second long has a final PCM sample position of '48000',
  293. as in the example here.
  294. </t>
  295. <t>
  296. Vorbis streams use a granule position smaller than the number of audio samples
  297. contained in the first audio data page to indicate that some of those samples
  298. must be trimmed from the output (see <xref target="vorbis-trim"/>).
  299. However, to do so, Vorbis requires that the first audio data page contains
  300. exactly two packets, in order to allow the decoder to perform PCM position
  301. adjustments before needing to return any PCM data.
  302. Opus uses the pre-skip mechanism for this purpose instead, since the encoder
  303. may introduce more than a single packet's worth of latency, and since very
  304. large packets in streams with a very large number of channels might not fit
  305. on a single page.
  306. </t>
  307. </section>
  308. <section anchor="end_trimming" title="End Trimming">
  309. <t>
  310. The page with the 'end of stream' flag set MAY have a granule position that
  311. indicates the page contains less audio data than would normally be returned by
  312. decoding up through the final packet.
  313. This is used to end the stream somewhere other than an even frame boundary.
  314. The granule position of the most recent audio data page with completed packets
  315. is used to make this determination, or '0' is used if there were no previous
  316. audio data pages with a completed packet.
  317. The difference between these granule positions indicates how many samples to
  318. keep after decoding the packets that completed on the final page.
  319. The remaining samples are discarded.
  320. The number of discarded samples SHOULD be no larger than the number decoded
  321. from the last packet.
  322. </t>
  323. </section>
  324. <section anchor="start_granpos_restrictions"
  325. title="Restrictions on the Initial Granule Position">
  326. <t>
  327. The granule position of the first audio data page with a completed packet MAY
  328. be larger than the number of samples contained in packets that complete on
  329. that page, however it MUST NOT be smaller, unless that page has the 'end of
  330. stream' flag set.
  331. Allowing a granule position larger than the number of samples allows the
  332. beginning of a stream to be cropped or a live stream to be joined without
  333. rewriting the granule position of all the remaining pages.
  334. This means that the PCM sample position just before the first sample to be
  335. played may be larger than '0'.
  336. Synchronization when multiplexing with other logical streams still uses the PCM
  337. sample position relative to '0' to compute sample times.
  338. This does not affect the behavior of pre-skip: exactly 'pre-skip' samples
  339. should be skipped from the beginning of the decoded output, even if the
  340. initial PCM sample position is greater than zero.
  341. </t>
  342. <t>
  343. On the other hand, a granule position that is smaller than the number of
  344. decoded samples prevents a demuxer from working backwards to assign each
  345. packet or each individual sample a valid granule position, since granule
  346. positions must be non-negative.
  347. A decoder MUST reject as invalid any stream where the granule position is
  348. smaller than the number of samples contained in packets that complete on the
  349. first audio data page with a completed packet, unless that page has the 'end
  350. of stream' flag set.
  351. It MAY defer this action until it decodes the last packet completed on that
  352. page.
  353. If that page has the 'end of stream' flag set, a demuxer can work forwards from
  354. the granule position '0', but MUST reject as invalid any stream where the
  355. granule position is smaller than the 'pre-skip' amount.
  356. This would indicate that more samples should be skipped from the initial
  357. decoded output than exist in the stream.
  358. </t>
  359. </section>
  360. <section anchor="seeking_and_preroll" title="Seeking and Pre-roll">
  361. <t>
  362. Seeking in Ogg files is best performed using a bisection search for a page
  363. whose granule position corresponds to a PCM position at or before the seek
  364. target.
  365. With appropriately weighted bisection, accurate seeking can be performed with
  366. just three or four bisections even in multi-gigabyte files.
  367. See <xref target="seeking"/> for general implementation guidance.
  368. </t>
  369. <t>
  370. When seeking within an Ogg Opus stream, the decoder SHOULD start decoding (and
  371. discarding the output) at least 3840&nbsp;samples (80&nbsp;ms) prior to the
  372. seek target in order to ensure that the output audio is correct by the time it
  373. reaches the seek target.
  374. This 'pre-roll' is separate from, and unrelated to, the 'pre-skip' used at the
  375. beginning of the stream.
  376. If the point 80&nbsp;ms prior to the seek target comes before the initial PCM
  377. sample position, the decoder SHOULD start decoding from the beginning of the
  378. stream, applying pre-skip as normal, regardless of whether the pre-skip is
  379. larger or smaller than 80&nbsp;ms.
  380. </t>
  381. </section>
  382. </section>
  383. <section anchor="headers" title="Header Packets">
  384. <t>
  385. An Opus stream contains exactly two mandatory header packets.
  386. </t>
  387. <section anchor="id_header" title="Identification Header">
  388. <figure anchor="id_header_packet" title="ID Header Packet" align="center">
  389. <artwork align="center"><![CDATA[
  390. 0 1 2 3
  391. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  392. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  393. | 'O' | 'p' | 'u' | 's' |
  394. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  395. | 'H' | 'e' | 'a' | 'd' |
  396. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  397. | Version = 1 | Channel Count | Pre-skip |
  398. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  399. | Input Sample Rate (Hz) |
  400. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  401. | Output Gain (Q7.8 in dB) | Mapping Family| |
  402. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ :
  403. | |
  404. : Optional Channel Mapping Table... :
  405. | |
  406. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  407. ]]></artwork>
  408. </figure>
  409. <t>
  410. The fields in the identification (ID) header have the following meaning:
  411. <list style="numbers">
  412. <t><spanx style="strong">Magic Signature</spanx>:
  413. <vspace blankLines="1"/>
  414. This is an 8-octet (64-bit) field that allows codec identification and is
  415. human-readable.
  416. It contains, in order, the magic numbers:
  417. <list style="empty">
  418. <t>0x4F 'O'</t>
  419. <t>0x70 'p'</t>
  420. <t>0x75 'u'</t>
  421. <t>0x73 's'</t>
  422. <t>0x48 'H'</t>
  423. <t>0x65 'e'</t>
  424. <t>0x61 'a'</t>
  425. <t>0x64 'd'</t>
  426. </list>
  427. Starting with "Op" helps distinguish it from audio data packets, as this is an
  428. invalid TOC sequence.
  429. <vspace blankLines="1"/>
  430. </t>
  431. <t><spanx style="strong">Version</spanx> (8 bits, unsigned):
  432. <vspace blankLines="1"/>
  433. The version number MUST always be '1' for this version of the encapsulation
  434. specification.
  435. Implementations SHOULD treat streams where the upper four bits of the version
  436. number match that of a recognized specification as backwards-compatible with
  437. that specification.
  438. That is, the version number can be split into "major" and "minor" version
  439. sub-fields, with changes to the "minor" sub-field (in the lower four bits)
  440. signaling compatible changes.
  441. For example, a decoder implementing this specification SHOULD accept any stream
  442. with a version number of '15' or less, and SHOULD assume any stream with a
  443. version number '16' or greater is incompatible.
  444. The initial version '1' was chosen to keep implementations from relying on this
  445. octet as a null terminator for the "OpusHead" string.
  446. <vspace blankLines="1"/>
  447. </t>
  448. <t><spanx style="strong">Output Channel Count</spanx> 'C' (8 bits, unsigned):
  449. <vspace blankLines="1"/>
  450. This is the number of output channels.
  451. This might be different than the number of encoded channels, which can change
  452. on a packet-by-packet basis.
  453. This value MUST NOT be zero.
  454. The maximum allowable value depends on the channel mapping family, and might be
  455. as large as 255.
  456. See <xref target="channel_mapping"/> for details.
  457. <vspace blankLines="1"/>
  458. </t>
  459. <t><spanx style="strong">Pre-skip</spanx> (16 bits, unsigned, little
  460. endian):
  461. <vspace blankLines="1"/>
  462. This is the number of samples (at 48&nbsp;kHz) to discard from the decoder
  463. output when starting playback, and also the number to subtract from a page's
  464. granule position to calculate its PCM sample position.
  465. When constructing cropped Ogg Opus streams, a pre-skip of at least
  466. 3,840&nbsp;samples (80&nbsp;ms) is RECOMMENDED to ensure complete convergence.
  467. <vspace blankLines="1"/>
  468. </t>
  469. <t><spanx style="strong">Input Sample Rate</spanx> (32 bits, unsigned, little
  470. endian):
  471. <vspace blankLines="1"/>
  472. This field is <spanx style="emph">not</spanx> the sample rate to use for
  473. playback of the encoded data.
  474. <vspace blankLines="1"/>
  475. Opus has a handful of coding modes, with internal audio bandwidths of 4, 6, 8,
  476. 12, and 20&nbsp;kHz.
  477. Each packet in the stream may have a different audio bandwidth.
  478. Regardless of the audio bandwidth, the reference decoder supports decoding any
  479. stream at a sample rate of 8, 12, 16, 24, or 48&nbsp;kHz.
  480. The original sample rate of the encoder input is not preserved by the lossy
  481. compression.
  482. <vspace blankLines="1"/>
  483. An Ogg Opus player SHOULD select the playback sample rate according to the
  484. following procedure:
  485. <list style="numbers">
  486. <t>If the hardware supports 48&nbsp;kHz playback, decode at 48&nbsp;kHz.</t>
  487. <t>Otherwise, if the hardware's highest available sample rate is a supported
  488. rate, decode at this sample rate.</t>
  489. <t>Otherwise, if the hardware's highest available sample rate is less than
  490. 48&nbsp;kHz, decode at the highest supported rate above this and resample.</t>
  491. <t>Otherwise, decode at 48&nbsp;kHz and resample.</t>
  492. </list>
  493. However, the 'Input Sample Rate' field allows the encoder to pass the sample
  494. rate of the original input stream as metadata.
  495. This may be useful when the user requires the output sample rate to match the
  496. input sample rate.
  497. For example, a non-player decoder writing PCM format samples to disk might
  498. choose to resample the output audio back to the original input sample rate to
  499. reduce surprise to the user, who might reasonably expect to get back a file
  500. with the same sample rate as the one they fed to the encoder.
  501. <vspace blankLines="1"/>
  502. A value of zero indicates 'unspecified'.
  503. Encoders SHOULD write the actual input sample rate or zero, but decoder
  504. implementations which do something with this field SHOULD take care to behave
  505. sanely if given crazy values (e.g., do not actually upsample the output to
  506. 10 MHz if requested).
  507. <vspace blankLines="1"/>
  508. </t>
  509. <t><spanx style="strong">Output Gain</spanx> (16 bits, signed, little
  510. endian):
  511. <vspace blankLines="1"/>
  512. This is a gain to be applied by the decoder.
  513. It is 20*log10 of the factor to scale the decoder output by to achieve the
  514. desired playback volume, stored in a 16-bit, signed, two's complement
  515. fixed-point value with 8 fractional bits (i.e., Q7.8).
  516. To apply the gain, a decoder could use
  517. <figure align="center">
  518. <artwork align="center"><![CDATA[
  519. sample *= pow(10, output_gain/(20.0*256)) ,
  520. ]]></artwork>
  521. </figure>
  522. where output_gain is the raw 16-bit value from the header.
  523. <vspace blankLines="1"/>
  524. Virtually all players and media frameworks should apply it by default.
  525. If a player chooses to apply any volume adjustment or gain modification, such
  526. as the R128_TRACK_GAIN (see <xref target="comment_header"/>) or a user-facing
  527. volume knob, the adjustment MUST be applied in addition to this output gain in
  528. order to achieve playback at the desired volume.
  529. <vspace blankLines="1"/>
  530. An encoder SHOULD set this field to zero, and instead apply any gain prior to
  531. encoding, when this is possible and does not conflict with the user's wishes.
  532. The output gain should only be nonzero when the gain is adjusted after
  533. encoding, or when the user wishes to adjust the gain for playback while
  534. preserving the ability to recover the original signal amplitude.
  535. <vspace blankLines="1"/>
  536. Although the output gain has enormous range (+/- 128 dB, enough to amplify
  537. inaudible sounds to the threshold of physical pain), most applications can
  538. only reasonably use a small portion of this range around zero.
  539. The large range serves in part to ensure that gain can always be losslessly
  540. transferred between OpusHead and R128_TRACK_GAIN (see below) without
  541. saturating.
  542. <vspace blankLines="1"/>
  543. </t>
  544. <t><spanx style="strong">Channel Mapping Family</spanx> (8 bits,
  545. unsigned):
  546. <vspace blankLines="1"/>
  547. This octet indicates the order and semantic meaning of the various channels
  548. encoded in each Ogg packet.
  549. <vspace blankLines="1"/>
  550. Each possible value of this octet indicates a mapping family, which defines a
  551. set of allowed channel counts, and the ordered set of channel names for each
  552. allowed channel count.
  553. The details are described in <xref target="channel_mapping"/>.
  554. </t>
  555. <t><spanx style="strong">Channel Mapping Table</spanx>:
  556. This table defines the mapping from encoded streams to output channels.
  557. It is omitted when the channel mapping family is 0, but REQUIRED otherwise.
  558. Its contents are specified in <xref target="channel_mapping"/>.
  559. </t>
  560. </list>
  561. </t>
  562. <t>
  563. All fields in the ID headers are REQUIRED, except for the channel mapping
  564. table, which is omitted when the channel mapping family is 0.
  565. Implementations SHOULD reject ID headers which do not contain enough data for
  566. these fields, even if they contain a valid Magic Signature.
  567. Future versions of this specification, even backwards-compatible versions,
  568. might include additional fields in the ID header.
  569. If an ID header has a compatible major version, but a larger minor version,
  570. an implementation MUST NOT reject it for containing additional data not
  571. specified here.
  572. However, implementations MAY reject streams in which the ID header does not
  573. complete on the first page.
  574. </t>
  575. <section anchor="channel_mapping" title="Channel Mapping">
  576. <t>
  577. An Ogg Opus stream allows mapping one number of Opus streams (N) to a possibly
  578. larger number of decoded channels (M+N) to yet another number of output
  579. channels (C), which might be larger or smaller than the number of decoded
  580. channels.
  581. The order and meaning of these channels are defined by a channel mapping,
  582. which consists of the 'channel mapping family' octet and, for channel mapping
  583. families other than family&nbsp;0, a channel mapping table, as illustrated in
  584. <xref target="channel_mapping_table"/>.
  585. </t>
  586. <figure anchor="channel_mapping_table" title="Channel Mapping Table"
  587. align="center">
  588. <artwork align="center"><![CDATA[
  589. 0 1 2 3
  590. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  591. +-+-+-+-+-+-+-+-+
  592. | Stream Count |
  593. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  594. | Coupled Count | Channel Mapping... :
  595. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  596. ]]></artwork>
  597. </figure>
  598. <t>
  599. The fields in the channel mapping table have the following meaning:
  600. <list style="numbers" counter="8">
  601. <t><spanx style="strong">Stream Count</spanx> 'N' (8 bits, unsigned):
  602. <vspace blankLines="1"/>
  603. This is the total number of streams encoded in each Ogg packet.
  604. This value is required to correctly parse the packed Opus packets inside an
  605. Ogg packet, as described in <xref target="packet_organization"/>.
  606. This value MUST NOT be zero, as without at least one Opus packet with a valid
  607. TOC sequence, a demuxer cannot recover the duration of an Ogg packet.
  608. <vspace blankLines="1"/>
  609. For channel mapping family&nbsp;0, this value defaults to 1, and is not coded.
  610. <vspace blankLines="1"/>
  611. </t>
  612. <t><spanx style="strong">Coupled Stream Count</spanx> 'M' (8 bits, unsigned):
  613. This is the number of streams whose decoders should be configured to produce
  614. two channels.
  615. This MUST be no larger than the total number of streams, N.
  616. <vspace blankLines="1"/>
  617. Each packet in an Opus stream has an internal channel count of 1 or 2, which
  618. can change from packet to packet.
  619. This is selected by the encoder depending on the bitrate and the contents being
  620. encoded.
  621. The original channel count of the encoder input is not preserved by the lossy
  622. compression.
  623. <vspace blankLines="1"/>
  624. Regardless of the internal channel count, any Opus stream can be decoded as
  625. mono (a single channel) or stereo (two channels) by appropriate initialization
  626. of the decoder.
  627. The 'coupled stream count' field indicates that the first M Opus decoders are
  628. to be initialized in stereo mode, and the remaining N-M decoders are to be
  629. initialized in mono mode.
  630. The total number of decoded channels, (M+N), MUST be no larger than 255, as
  631. there is no way to index more channels than that in the channel mapping.
  632. <vspace blankLines="1"/>
  633. For channel mapping family&nbsp;0, this value defaults to C-1 (i.e., 0 for mono
  634. and 1 for stereo), and is not coded.
  635. <vspace blankLines="1"/>
  636. </t>
  637. <t><spanx style="strong">Channel Mapping</spanx> (8*C bits):
  638. This contains one octet per output channel, indicating which decoded channel
  639. should be used for each one.
  640. Let 'index' be the value of this octet for a particular output channel.
  641. This value MUST either be smaller than (M+N), or be the special value 255.
  642. If 'index' is less than 2*M, the output MUST be taken from decoding stream
  643. ('index'/2) as stereo and selecting the left channel if 'index' is even, and
  644. the right channel if 'index' is odd.
  645. If 'index' is 2*M or larger, the output MUST be taken from decoding stream
  646. ('index'-M) as mono.
  647. If 'index' is 255, the corresponding output channel MUST contain pure silence.
  648. <vspace blankLines="1"/>
  649. The number of output channels, C, is not constrained to match the number of
  650. decoded channels (M+N).
  651. A single index value MAY appear multiple times, i.e., the same decoded channel
  652. might be mapped to multiple output channels.
  653. Some decoded channels might not be assigned to any output channel, as well.
  654. <vspace blankLines="1"/>
  655. For channel mapping family&nbsp;0, the first index defaults to 0, and if C==2,
  656. the second index defaults to 1.
  657. Neither index is coded.
  658. </t>
  659. </list>
  660. </t>
  661. <t>
  662. After producing the output channels, the channel mapping family determines the
  663. semantic meaning of each one.
  664. Currently there are three defined mapping families, although more may be added:
  665. <list style="symbols">
  666. <t>Family&nbsp;0 (RTP mapping):
  667. <vspace blankLines="1"/>
  668. Allowed numbers of channels: 1 or 2.
  669. <list style="symbols">
  670. <t>1 channel: monophonic (mono).</t>
  671. <t>2 channels: stereo (left, right).</t>
  672. </list>
  673. <spanx style="strong">Special mapping</spanx>: This channel mapping value also
  674. indicates that the contents consists of a single Opus stream that is stereo if
  675. and only if C==2, with stream index 0 mapped to channel 0, and (if stereo)
  676. stream index 1 mapped to channel 1.
  677. When the 'channel mapping family' octet has this value, the channel mapping
  678. table MUST be omitted from the ID header packet.
  679. <vspace blankLines="1"/>
  680. </t>
  681. <t>Family&nbsp;1 (Vorbis channel order):
  682. <vspace blankLines="1"/>
  683. Allowed numbers of channels: 1...8.<vspace/>
  684. Channel meanings depend on the number of channels.
  685. See <xref target="vorbis-mapping"/> for the assignments from output channel
  686. number to specific speaker locations.
  687. <vspace blankLines="1"/>
  688. </t>
  689. <t>Family&nbsp;255 (no defined channel meaning):
  690. <vspace blankLines="1"/>
  691. Allowed numbers of channels: 1...255.<vspace/>
  692. Channels are unidentified.
  693. General-purpose players SHOULD NOT attempt to play these streams, and offline
  694. decoders MAY deinterleave the output into separate PCM files, one per channel.
  695. Decoders SHOULD NOT produce output for channels mapped to stream index 255
  696. (pure silence) unless they have no other way to indicate the index of
  697. non-silent channels.
  698. </t>
  699. </list>
  700. The remaining channel mapping families (2...254) are reserved.
  701. A decoder encountering a reserved channel mapping family value SHOULD act as
  702. though the value is 255.
  703. <vspace blankLines="1"/>
  704. An Ogg Opus player MUST play any Ogg Opus stream with a channel mapping family
  705. of 0 or 1, even if the number of channels does not match the physically
  706. connected audio hardware.
  707. Players SHOULD perform channel mixing to increase or reduce the number of
  708. channels as needed.
  709. </t>
  710. </section>
  711. </section>
  712. <section anchor="comment_header" title="Comment Header">
  713. <figure anchor="comment_header_packet" title="Comment Header Packet"
  714. align="center">
  715. <artwork align="center"><![CDATA[
  716. 0 1 2 3
  717. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  718. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  719. | 'O' | 'p' | 'u' | 's' |
  720. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  721. | 'T' | 'a' | 'g' | 's' |
  722. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  723. | Vendor String Length |
  724. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  725. | |
  726. : Vendor String... :
  727. | |
  728. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  729. | User Comment List Length |
  730. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  731. | User Comment #0 String Length |
  732. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  733. | |
  734. : User Comment #0 String... :
  735. | |
  736. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  737. | User Comment #1 String Length |
  738. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  739. : :
  740. ]]></artwork>
  741. </figure>
  742. <t>
  743. The comment header consists of a 64-bit magic signature, followed by data in
  744. the same format as the <xref target="vorbis-comment"/> header used in Ogg
  745. Vorbis (without the final "framing bit"), Ogg Theora, and Speex.
  746. <list style="numbers">
  747. <t><spanx style="strong">Magic Signature</spanx>:
  748. <vspace blankLines="1"/>
  749. This is an 8-octet (64-bit) field that allows codec identification and is
  750. human-readable.
  751. It contains, in order, the magic numbers:
  752. <list style="empty">
  753. <t>0x4F 'O'</t>
  754. <t>0x70 'p'</t>
  755. <t>0x75 'u'</t>
  756. <t>0x73 's'</t>
  757. <t>0x54 'T'</t>
  758. <t>0x61 'a'</t>
  759. <t>0x67 'g'</t>
  760. <t>0x73 's'</t>
  761. </list>
  762. Starting with "Op" helps distinguish it from audio data packets, as this is an
  763. invalid TOC sequence.
  764. <vspace blankLines="1"/>
  765. </t>
  766. <t><spanx style="strong">Vendor String Length</spanx> (32 bits, unsigned,
  767. little endian):
  768. <vspace blankLines="1"/>
  769. This field gives the length of the following vendor string, in octets.
  770. It MUST NOT indicate that the vendor string is longer than the rest of the
  771. packet.
  772. <vspace blankLines="1"/>
  773. </t>
  774. <t><spanx style="strong">Vendor String</spanx> (variable length, UTF-8 vector):
  775. <vspace blankLines="1"/>
  776. This is a simple human-readable tag for vendor information, encoded as a UTF-8
  777. string&nbsp;<xref target="RFC3629"/>.
  778. No terminating NUL octet is required.
  779. <vspace blankLines="1"/>
  780. This tag is intended to identify the codec encoder and encapsulation
  781. implementations, for tracing differences in technical behavior.
  782. User-facing encoding applications can use the 'ENCODER' user comment tag
  783. to identify themselves.
  784. <vspace blankLines="1"/>
  785. </t>
  786. <t><spanx style="strong">User Comment List Length</spanx> (32 bits, unsigned,
  787. little endian):
  788. <vspace blankLines="1"/>
  789. This field indicates the number of user-supplied comments.
  790. It MAY indicate there are zero user-supplied comments, in which case there are
  791. no additional fields in the packet.
  792. It MUST NOT indicate that there are so many comments that the comment string
  793. lengths would require more data than is available in the rest of the packet.
  794. <vspace blankLines="1"/>
  795. </t>
  796. <t><spanx style="strong">User Comment #i String Length</spanx> (32 bits,
  797. unsigned, little endian):
  798. <vspace blankLines="1"/>
  799. This field gives the length of the following user comment string, in octets.
  800. There is one for each user comment indicated by the 'user comment list length'
  801. field.
  802. It MUST NOT indicate that the string is longer than the rest of the packet.
  803. <vspace blankLines="1"/>
  804. </t>
  805. <t><spanx style="strong">User Comment #i String</spanx> (variable length, UTF-8
  806. vector):
  807. <vspace blankLines="1"/>
  808. This field contains a single user comment string.
  809. There is one for each user comment indicated by the 'user comment list length'
  810. field.
  811. </t>
  812. </list>
  813. </t>
  814. <t>
  815. The vendor string length and user comment list length are REQUIRED, and
  816. implementations SHOULD reject comment headers that do not contain enough data
  817. for these fields, or that do not contain enough data for the corresponding
  818. vendor string or user comments they describe.
  819. Making this check before allocating the associated memory to contain the data
  820. may help prevent a possible Denial-of-Service (DoS) attack from small comment
  821. headers that claim to contain strings longer than the entire packet or more
  822. user comments than than could possibly fit in the packet.
  823. </t>
  824. <t>
  825. The user comment strings follow the NAME=value format described by
  826. <xref target="vorbis-comment"/> with the same recommended tag names.
  827. One new comment tag is introduced for Ogg Opus:
  828. <figure align="center">
  829. <artwork align="left"><![CDATA[
  830. R128_TRACK_GAIN=-573
  831. ]]></artwork>
  832. </figure>
  833. representing the volume shift needed to normalize the track's volume.
  834. The gain is a Q7.8 fixed point number in dB, as in the ID header's 'output
  835. gain' field.
  836. This tag is similar to the REPLAYGAIN_TRACK_GAIN tag in
  837. Vorbis&nbsp;<xref target="replay-gain"/>, except that the normal volume
  838. reference is the <xref target="EBU-R128"/> standard.
  839. </t>
  840. <t>
  841. An Ogg Opus file MUST NOT have more than one such tag, and if present its
  842. value MUST be an integer from -32768 to 32767, inclusive, represented in
  843. ASCII with no whitespace.
  844. If present, it MUST correctly represent the R128 normalization gain relative
  845. to the 'output gain' field specified in the ID header.
  846. If a player chooses to make use of the R128_TRACK_GAIN tag, it MUST be
  847. applied <spanx style="emph">in addition</spanx> to the 'output gain' value.
  848. If an encoder wishes to use R128 normalization, and the output gain is not
  849. otherwise constrained or specified, the encoder SHOULD write the R128 gain
  850. into the 'output gain' field and store a tag containing "R128_TRACK_GAIN=0".
  851. That is, it should assume that by default tools will respect the 'output gain'
  852. field, and not the comment tag.
  853. If a tool modifies the ID header's 'output gain' field, it MUST also update or
  854. remove the R128_TRACK_GAIN comment tag.
  855. </t>
  856. <t>
  857. To avoid confusion with multiple normalization schemes, an Opus comment header
  858. SHOULD NOT contain any of the REPLAYGAIN_TRACK_GAIN, REPLAYGAIN_TRACK_PEAK,
  859. REPLAYGAIN_ALBUM_GAIN, or REPLAYGAIN_ALBUM_PEAK tags.
  860. </t>
  861. <t>
  862. There is no Opus comment tag corresponding to REPLAYGAIN_ALBUM_GAIN.
  863. That information should instead be stored in the ID header's 'output gain'
  864. field.
  865. </t>
  866. </section>
  867. </section>
  868. <section anchor="packet_size_limits" title="Packet Size Limits">
  869. <t>
  870. Technically valid Opus packets can be arbitrarily large due to the padding
  871. format, although the amount of non-padding data they can contain is bounded.
  872. These packets might be spread over a similarly enormous number of Ogg pages.
  873. Encoders SHOULD use no more padding than required to make a variable bitrate
  874. (VBR) stream constant bitrate (CBR).
  875. Decoders SHOULD avoid attempting to allocate excessive amounts of memory when
  876. presented with a very large packet.
  877. The presence of an extremely large packet in the stream could indicate a
  878. memory exhaustion attack or stream corruption.
  879. Decoders SHOULD reject a packet that is too large to process, and display a
  880. warning message.
  881. </t>
  882. <t>
  883. In an Ogg Opus stream, the largest possible valid packet that does not use
  884. padding has a size of (61,298*N&nbsp;-&nbsp;2) octets, or about 60&nbsp;kB per
  885. Opus stream.
  886. With 255&nbsp;streams, this is 15,630,988&nbsp;octets (14.9&nbsp;MB) and can
  887. span up to 61,298&nbsp;Ogg pages, all but one of which will have a granule
  888. position of -1.
  889. This is of course a very extreme packet, consisting of 255&nbsp;streams, each
  890. containing 120&nbsp;ms of audio encoded as 2.5&nbsp;ms frames, each frame
  891. using the maximum possible number of octets (1275) and stored in the least
  892. efficient manner allowed (a VBR code&nbsp;3 Opus packet).
  893. Even in such a packet, most of the data will be zeros, as 2.5&nbsp;ms frames,
  894. which are required to run in the MDCT mode, cannot actually use all
  895. 1275&nbsp;octets.
  896. The largest packet consisting of entirely useful data is
  897. (15,326*N&nbsp;-&nbsp;2) octets, or about 15&nbsp;kB per stream.
  898. This corresponds to 120&nbsp;ms of audio encoded as 10&nbsp;ms frames in either
  899. LP or Hybrid mode, but at a data rate of over 1&nbsp;Mbps, which makes little
  900. sense for the quality achieved.
  901. A more reasonable limit is (7,664*N&nbsp;-&nbsp;2) octets, or about 7.5&nbsp;kB
  902. per stream.
  903. This corresponds to 120&nbsp;ms of audio encoded as 20&nbsp;ms stereo MDCT-mode
  904. frames, with a total bitrate just under 511&nbsp;kbps (not counting the Ogg
  905. encapsulation overhead).
  906. With N=8, the maximum number of channels currently defined by mapping
  907. family&nbsp;1, this gives a maximum packet size of 61,310&nbsp;octets, or just
  908. under 60&nbsp;kB.
  909. This is still quite conservative, as it assumes each output channel is taken
  910. from one decoded channel of a stereo packet.
  911. An implementation could reasonably choose any of these numbers for its internal
  912. limits.
  913. </t>
  914. </section>
  915. <section anchor="security" title="Security Considerations">
  916. <t>
  917. Implementations of the Opus codec need to take appropriate security
  918. considerations into account, as outlined in <xref target="RFC4732"/>.
  919. This is just as much a problem for the container as it is for the codec itself.
  920. It is extremely important for the decoder to be robust against malicious
  921. payloads.
  922. Malicious payloads must not cause the decoder to overrun its allocated memory
  923. or to take an excessive amount of resources to decode.
  924. Although problems in encoders are typically rarer, the same applies to the
  925. encoder.
  926. Malicious audio streams must not cause the encoder to misbehave because this
  927. would allow an attacker to attack transcoding gateways.
  928. </t>
  929. <t>
  930. Like most other container formats, Ogg Opus files should not be used with
  931. insecure ciphers or cipher modes that are vulnerable to known-plaintext
  932. attacks.
  933. Elements such as the Ogg page capture pattern and the magic signatures in the
  934. ID header and the comment header all have easily predictable values, in
  935. addition to various elements of the codec data itself.
  936. </t>
  937. </section>
  938. <section anchor="content_type" title="Content Type">
  939. <t>
  940. An "Ogg Opus file" consists of one or more sequentially multiplexed segments,
  941. each containing exactly one Ogg Opus stream.
  942. The RECOMMENDED mime-type for Ogg Opus files is "audio/ogg".
  943. When Opus is concurrently multiplexed with other streams in an Ogg container,
  944. one SHOULD use one of the "audio/ogg", "video/ogg", or "application/ogg"
  945. mime-types, as defined in <xref target="RFC3534"/>.
  946. </t>
  947. <t>
  948. If more specificity is desired, one MAY indicate the presence of Opus streams
  949. using the codecs parameter defined in <xref target="RFC6381"/>, e.g.,
  950. <figure align="center">
  951. <artwork align="left"><![CDATA[
  952. audio/ogg; codecs=opus
  953. ]]></artwork>
  954. </figure>
  955. for an Ogg Opus file.
  956. </t>
  957. <t>
  958. The RECOMMENDED filename extension for Ogg Opus files is '.opus'.
  959. </t>
  960. </section>
  961. <section title="IANA Considerations">
  962. <t>
  963. This document has no actions for IANA.
  964. </t>
  965. </section>
  966. <section anchor="Acknowledgments" title="Acknowledgments">
  967. <t>
  968. Thanks to Greg Maxwell, Christopher "Monty" Montgomery, and Jean-Marc Valin for
  969. their valuable contributions to this document.
  970. Additional thanks to Andrew D'Addesio, Greg Maxwell, and Vincent Penqeurc'h for
  971. their feedback based on early implementations.
  972. </t>
  973. </section>
  974. <section title="Copying Conditions">
  975. <t>
  976. The authors agree to grant third parties the irrevocable right to copy, use,
  977. and distribute the work, with or without modification, in any medium, without
  978. royalty, provided that, unless separate permission is granted, redistributed
  979. modified works do not contain misleading author, version, name of work, or
  980. endorsement information.
  981. </t>
  982. </section>
  983. </middle>
  984. <back>
  985. <references title="Normative References">
  986. &rfc2119;
  987. &rfc3533;
  988. &rfc3534;
  989. &rfc3629;
  990. &rfc6381;
  991. &rfc6716;
  992. <reference anchor="EBU-R128" target="http://tech.ebu.ch/loudness">
  993. <front>
  994. <title>"Loudness Recommendation EBU R128</title>
  995. <author fullname="EBU Technical Committee"/>
  996. <date month="August" year="2011"/>
  997. </front>
  998. </reference>
  999. <reference anchor="vorbis-comment"
  1000. target="http://www.xiph.org/vorbis/doc/v-comment.html">
  1001. <front>
  1002. <title>Ogg Vorbis I Format Specification: Comment Field and Header
  1003. Specification</title>
  1004. <author initials="C." surname="Montgomery"
  1005. fullname="Christopher &quot;Monty&quot; Montgomery"/>
  1006. <date month="July" year="2002"/>
  1007. </front>
  1008. </reference>
  1009. <reference anchor="vorbis-mapping"
  1010. target="http://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-800004.3.9">
  1011. <front>
  1012. <title>The Vorbis I Specification, Section 4.3.9 Output Channel Order</title>
  1013. <author initials="C." surname="Montgomery"
  1014. fullname="Christopher &quot;Monty&quot; Montgomery"/>
  1015. <date month="January" year="2010"/>
  1016. </front>
  1017. </reference>
  1018. </references>
  1019. <references title="Informative References">
  1020. <!--?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.3550.xml"?-->
  1021. &rfc4732;
  1022. <reference anchor="replay-gain"
  1023. target="http://wiki.xiph.org/VorbisComment#Replay_Gain">
  1024. <front>
  1025. <title>VorbisComment: Replay Gain</title>
  1026. <author initials="C." surname="Parker" fullname="Conrad Parker"/>
  1027. <author initials="M." surname="Leese" fullname="Martin Leese"/>
  1028. <date month="June" year="2009"/>
  1029. </front>
  1030. </reference>
  1031. <reference anchor="seeking"
  1032. target="http://wiki.xiph.org/Seeking">
  1033. <front>
  1034. <title>Granulepos Encoding and How Seeking Really Works</title>
  1035. <author initials="S." surname="Pfeiffer" fullname="Silvia Pfeiffer"/>
  1036. <author initials="C." surname="Parker" fullname="Conrad Parker"/>
  1037. <author initials="G." surname="Maxwell" fullname="Greg Maxwell"/>
  1038. <date month="May" year="2012"/>
  1039. </front>
  1040. </reference>
  1041. <reference anchor="vorbis-trim"
  1042. target="http://xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-130000A.2">
  1043. <front>
  1044. <title>The Vorbis I Specification, Appendix A Embedding Vorbis into an Ogg stream</title>
  1045. <author initials="C." surname="Montgomery"
  1046. fullname="Christopher &quot;Monty&quot; Montgomery"/>
  1047. <date month="November" year="2008"/>
  1048. </front>
  1049. </reference>
  1050. </references>
  1051. </back>
  1052. </rfc>