draft-ietf-codec-oggopus.xml 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE rfc SYSTEM 'rfc2629.dtd' [
  3. <!ENTITY rfc2119 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml'>
  4. <!ENTITY rfc3533 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3533.xml'>
  5. <!ENTITY rfc3629 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3629.xml'>
  6. <!ENTITY rfc4732 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4732.xml'>
  7. <!ENTITY rfc5334 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5334.xml'>
  8. <!ENTITY rfc6381 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.6381.xml'>
  9. <!ENTITY rfc6716 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.6716.xml'>
  10. <!ENTITY rfc6982 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.6982.xml'>
  11. ]>
  12. <?rfc toc="yes" symrefs="yes" ?>
  13. <rfc ipr="trust200902" category="std" docName="draft-ietf-codec-oggopus-08">
  14. <front>
  15. <title abbrev="Ogg Opus">Ogg Encapsulation for the Opus Audio Codec</title>
  16. <author initials="T.B." surname="Terriberry" fullname="Timothy B. Terriberry">
  17. <organization>Mozilla Corporation</organization>
  18. <address>
  19. <postal>
  20. <street>650 Castro Street</street>
  21. <city>Mountain View</city>
  22. <region>CA</region>
  23. <code>94041</code>
  24. <country>USA</country>
  25. </postal>
  26. <phone>+1 650 903-0800</phone>
  27. <email>tterribe@xiph.org</email>
  28. </address>
  29. </author>
  30. <author initials="R." surname="Lee" fullname="Ron Lee">
  31. <organization>Voicetronix</organization>
  32. <address>
  33. <postal>
  34. <street>246 Pulteney Street, Level 1</street>
  35. <city>Adelaide</city>
  36. <region>SA</region>
  37. <code>5000</code>
  38. <country>Australia</country>
  39. </postal>
  40. <phone>+61 8 8232 9112</phone>
  41. <email>ron@debian.org</email>
  42. </address>
  43. </author>
  44. <author initials="R." surname="Giles" fullname="Ralph Giles">
  45. <organization>Mozilla Corporation</organization>
  46. <address>
  47. <postal>
  48. <street>163 West Hastings Street</street>
  49. <city>Vancouver</city>
  50. <region>BC</region>
  51. <code>V6B 1H5</code>
  52. <country>Canada</country>
  53. </postal>
  54. <phone>+1 778 785 1540</phone>
  55. <email>giles@xiph.org</email>
  56. </address>
  57. </author>
  58. <date day="6" month="July" year="2015"/>
  59. <area>RAI</area>
  60. <workgroup>codec</workgroup>
  61. <abstract>
  62. <t>
  63. This document defines the Ogg encapsulation for the Opus interactive speech and
  64. audio codec.
  65. This allows data encoded in the Opus format to be stored in an Ogg logical
  66. bitstream.
  67. Ogg encapsulation provides Opus with a long-term storage format supporting
  68. all of the essential features, including metadata, fast and accurate seeking,
  69. corruption detection, recapture after errors, low overhead, and the ability to
  70. multiplex Opus with other codecs (including video) with minimal buffering.
  71. It also provides a live streamable format, capable of delivery over a reliable
  72. stream-oriented transport, without requiring all the data, or even the total
  73. length of the data, up-front, in a form that is identical to the on-disk
  74. storage format.
  75. </t>
  76. </abstract>
  77. </front>
  78. <middle>
  79. <section anchor="intro" title="Introduction">
  80. <t>
  81. The IETF Opus codec is a low-latency audio codec optimized for both voice and
  82. general-purpose audio.
  83. See <xref target="RFC6716"/> for technical details.
  84. This document defines the encapsulation of Opus in a continuous, logical Ogg
  85. bitstream&nbsp;<xref target="RFC3533"/>.
  86. </t>
  87. <t>
  88. Ogg bitstreams are made up of a series of 'pages', each of which contains data
  89. from one or more 'packets'.
  90. Pages are the fundamental unit of multiplexing in an Ogg stream.
  91. Each page is associated with a particular logical stream and contains a capture
  92. pattern and checksum, flags to mark the beginning and end of the logical
  93. stream, and a 'granule position' that represents an absolute position in the
  94. stream, to aid seeking.
  95. A single page can contain up to 65,025 octets of packet data from up to 255
  96. different packets.
  97. Packets can be split arbitrarily across pages, and continued from one page to
  98. the next (allowing packets much larger than would fit on a single page).
  99. Each page contains 'lacing values' that indicate how the data is partitioned
  100. into packets, allowing a demuxer to recover the packet boundaries without
  101. examining the encoded data.
  102. A packet is said to 'complete' on a page when the page contains the final
  103. lacing value corresponding to that packet.
  104. </t>
  105. <t>
  106. This encapsulation defines the contents of the packet data, including
  107. the necessary headers, the organization of those packets into a logical
  108. stream, and the interpretation of the codec-specific granule position field.
  109. It does not attempt to describe or specify the existing Ogg container format.
  110. Readers unfamiliar with the basic concepts mentioned above are encouraged to
  111. review the details in <xref target="RFC3533"/>.
  112. </t>
  113. </section>
  114. <section anchor="terminology" title="Terminology">
  115. <t>
  116. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
  117. "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this
  118. document are to be interpreted as described in <xref target="RFC2119"/>.
  119. </t>
  120. <t>
  121. Implementations that fail to satisfy one or more "MUST" requirements are
  122. considered non-compliant.
  123. Implementations that satisfy all "MUST" requirements, but fail to satisfy one
  124. or more "SHOULD" requirements are said to be "conditionally compliant".
  125. All other implementations are "unconditionally compliant".
  126. </t>
  127. </section>
  128. <section anchor="packet_organization" title="Packet Organization">
  129. <t>
  130. An Ogg Opus stream is organized as follows.
  131. </t>
  132. <t>
  133. There are two mandatory header packets.
  134. The granule position of the pages on which these packets complete MUST be zero.
  135. </t>
  136. <t>
  137. The first packet in the logical Ogg bitstream MUST contain the identification
  138. (ID) header, which uniquely identifies a stream as Opus audio.
  139. The format of this header is defined in <xref target="id_header"/>.
  140. It MUST be placed alone (without any other packet data) on the first page of
  141. the logical Ogg bitstream, and MUST complete on that page.
  142. This page MUST have its 'beginning of stream' flag set.
  143. </t>
  144. <t>
  145. The second packet in the logical Ogg bitstream MUST contain the comment header,
  146. which contains user-supplied metadata.
  147. The format of this header is defined in <xref target="comment_header"/>.
  148. It MAY span one or more pages, beginning on the second page of the logical
  149. stream.
  150. However many pages it spans, the comment header packet MUST finish the page on
  151. which it completes.
  152. </t>
  153. <t>
  154. All subsequent pages are audio data pages, and the Ogg packets they contain are
  155. audio data packets.
  156. Each audio data packet contains one Opus packet for each of N different
  157. streams, where N is typically one for mono or stereo, but MAY be greater than
  158. one for multichannel audio.
  159. The value N is specified in the ID header (see
  160. <xref target="channel_mapping"/>), and is fixed over the entire length of the
  161. logical Ogg bitstream.
  162. </t>
  163. <t>
  164. The first N-1 Opus packets, if any, are packed one after another into the Ogg
  165. packet, using the self-delimiting framing from Appendix&nbsp;B of
  166. <xref target="RFC6716"/>.
  167. The remaining Opus packet is packed at the end of the Ogg packet using the
  168. regular, undelimited framing from Section&nbsp;3 of <xref target="RFC6716"/>.
  169. All of the Opus packets in a single Ogg packet MUST be constrained to have the
  170. same duration.
  171. A decoder SHOULD treat any Opus packet whose duration is different from that of
  172. the first Opus packet in an Ogg packet as if it were a malformed Opus packet
  173. with an invalid TOC sequence.
  174. </t>
  175. <t>
  176. The coding mode (SILK, Hybrid, or CELT), audio bandwidth, channel count,
  177. duration (frame size), and number of frames per packet, are indicated in the
  178. TOC (table of contents) sequence at the beginning of each Opus packet, as
  179. described in Section&nbsp;3.1 of&nbsp;<xref target="RFC6716"/>.
  180. The combination of mode, audio bandwidth, and frame size is referred to as
  181. the configuration of an Opus packet.
  182. </t>
  183. <t>
  184. The first audio data page SHOULD NOT have the 'continued packet' flag set
  185. (which would indicate the first audio data packet is continued from a previous
  186. page).
  187. Packets MUST be placed into Ogg pages in order until the end of stream.
  188. Audio packets MAY span page boundaries.
  189. A decoder MUST treat a zero-octet audio data packet as if it were a malformed
  190. Opus packet as described in Section&nbsp;3.4 of&nbsp;<xref target="RFC6716"/>.
  191. </t>
  192. <t>
  193. The last page SHOULD have the 'end of stream' flag set, but implementations
  194. need to be prepared to deal with truncated streams that do not have a page
  195. marked 'end of stream'.
  196. The final packet on the last page SHOULD NOT be a continued packet, i.e., the
  197. final lacing value SHOULD be less than 255.
  198. There MUST NOT be any more pages in an Opus logical bitstream after a page
  199. marked 'end of stream'.
  200. </t>
  201. </section>
  202. <section anchor="granpos" title="Granule Position">
  203. <t>
  204. The granule position of an audio data page encodes the total number of PCM
  205. samples in the stream up to and including the last fully-decodable sample from
  206. the last packet completed on that page.
  207. A page that is entirely spanned by a single packet (that completes on a
  208. subsequent page) has no granule position, and the granule position field MUST
  209. be set to the special value '-1' in two's complement.
  210. </t>
  211. <t>
  212. The granule position of an audio data page is in units of PCM audio samples at
  213. a fixed rate of 48&nbsp;kHz (per channel; a stereo stream's granule position
  214. does not increment at twice the speed of a mono stream).
  215. It is possible to run an Opus decoder at other sampling rates, but the value
  216. in the granule position field always counts samples assuming a 48&nbsp;kHz
  217. decoding rate, and the rest of this specification makes the same assumption.
  218. </t>
  219. <t>
  220. The duration of an Opus packet can be any multiple of 2.5&nbsp;ms, up to a
  221. maximum of 120&nbsp;ms.
  222. This duration is encoded in the TOC sequence at the beginning of each packet.
  223. The number of samples returned by a decoder corresponds to this duration
  224. exactly, even for the first few packets.
  225. For example, a 20&nbsp;ms packet fed to a decoder running at 48&nbsp;kHz will
  226. always return 960&nbsp;samples.
  227. A demuxer can parse the TOC sequence at the beginning of each Ogg packet to
  228. work backwards or forwards from a packet with a known granule position (i.e.,
  229. the last packet completed on some page) in order to assign granule positions
  230. to every packet, or even every individual sample.
  231. The one exception is the last page in the stream, as described below.
  232. </t>
  233. <t>
  234. All other pages with completed packets after the first MUST have a granule
  235. position equal to the number of samples contained in packets that complete on
  236. that page plus the granule position of the most recent page with completed
  237. packets.
  238. This guarantees that a demuxer can assign individual packets the same granule
  239. position when working forwards as when working backwards.
  240. For this to work, there cannot be any gaps.
  241. </t>
  242. <section anchor="gap-repair" title="Repairing Gaps in Real-time Streams">
  243. <t>
  244. In order to support capturing a real-time stream that has lost or not
  245. transmitted packets, a muxer SHOULD emit packets that explicitly request the
  246. use of Packet Loss Concealment (PLC) in place of the missing packets.
  247. Only gaps that are a multiple of 2.5&nbsp;ms are repairable, as these are the
  248. only durations that can be created by packet loss or discontinuous
  249. transmission.
  250. Muxers need not handle other gap sizes.
  251. Creating the necessary packets involves synthesizing a TOC byte (defined in
  252. Section&nbsp;3.1 of&nbsp;<xref target="RFC6716"/>)&mdash;and whatever
  253. additional internal framing is needed&mdash;to indicate the packet duration
  254. for each stream.
  255. The actual length of each missing Opus frame inside the packet is zero bytes,
  256. as defined in Section&nbsp;3.2.1 of&nbsp;<xref target="RFC6716"/>.
  257. </t>
  258. <t>
  259. Zero-byte frames MAY be packed into packets using any of codes&nbsp;0, 1,
  260. 2, or&nbsp;3.
  261. When successive frames have the same configuration, the higher code packings
  262. reduce overhead.
  263. Likewise, if the TOC configuration matches, the muxer MAY further combine the
  264. empty frames with previous or subsequent non-zero-length frames (using
  265. code&nbsp;2 or VBR code&nbsp;3).
  266. </t>
  267. <t>
  268. <xref target="RFC6716"/> does not impose any requirements on the PLC, but this
  269. section outlines choices that are expected to have a positive influence on
  270. most PLC implementations, including the reference implementation.
  271. Synthesized TOC sequences SHOULD maintain the same mode, audio bandwidth,
  272. channel count, and frame size as the previous packet (if any).
  273. This is the simplest and usually the most well-tested case for the PLC to
  274. handle and it covers all losses that do not include a configuration switch,
  275. as defined in Section&nbsp;4.5 of&nbsp;<xref target="RFC6716"/>.
  276. </t>
  277. <t>
  278. When a previous packet is available, keeping the audio bandwidth and channel
  279. count the same allows the PLC to provide maximum continuity in the concealment
  280. data it generates.
  281. However, if the size of the gap is not a multiple of the most recent frame
  282. size, then the frame size will have to change for at least some frames.
  283. Such changes SHOULD be delayed as long as possible to simplify
  284. things for PLC implementations.
  285. </t>
  286. <t>
  287. As an example, a 95&nbsp;ms gap could be encoded as nineteen 5&nbsp;ms frames
  288. in two bytes with a single CBR code&nbsp;3 packet.
  289. If the previous frame size was 20&nbsp;ms, using four 20&nbsp;ms frames
  290. followed by three 5&nbsp;ms frames requires 4&nbsp;bytes (plus an extra byte
  291. of Ogg lacing overhead), but allows the PLC to use its well-tested steady
  292. state behavior for as long as possible.
  293. The total bitrate of the latter approach, including Ogg overhead, is about
  294. 0.4&nbsp;kbps, so the impact on file size is minimal.
  295. </t>
  296. <t>
  297. Changing modes is discouraged, since this causes some decoder implementations
  298. to reset their PLC state.
  299. However, SILK and Hybrid mode frames cannot fill gaps that are not a multiple
  300. of 10&nbsp;ms.
  301. If switching to CELT mode is needed to match the gap size, a muxer SHOULD do
  302. so at the end of the gap to allow the PLC to function for as long as possible.
  303. </t>
  304. <t>
  305. In the example above, if the previous frame was a 20&nbsp;ms SILK mode frame,
  306. the better solution is to synthesize a packet describing four 20&nbsp;ms SILK
  307. frames, followed by a packet with a single 10&nbsp;ms SILK
  308. frame, and finally a packet with a 5&nbsp;ms CELT frame, to fill the 95&nbsp;ms
  309. gap.
  310. This also requires four bytes to describe the synthesized packet data (two
  311. bytes for a CBR code 3 and one byte each for two code 0 packets) but three
  312. bytes of Ogg lacing overhead are needed to mark the packet boundaries.
  313. At 0.6 kbps, this is still a minimal bitrate impact over a naive, low quality
  314. solution.
  315. </t>
  316. <t>
  317. Since medium-band audio is an option only in the SILK mode, wideband frames
  318. SHOULD be generated if switching from that configuration to CELT mode, to
  319. ensure that any PLC implementation which does try to migrate state between
  320. the modes will be able to preserve all of the available audio bandwidth.
  321. </t>
  322. </section>
  323. <section anchor="preskip" title="Pre-skip">
  324. <t>
  325. There is some amount of latency introduced during the decoding process, to
  326. allow for overlap in the CELT mode, stereo mixing in the SILK mode, and
  327. resampling.
  328. The encoder might have introduced additional latency through its own resampling
  329. and analysis (though the exact amount is not specified).
  330. Therefore, the first few samples produced by the decoder do not correspond to
  331. real input audio, but are instead composed of padding inserted by the encoder
  332. to compensate for this latency.
  333. These samples need to be stored and decoded, as Opus is an asymptotically
  334. convergent predictive codec, meaning the decoded contents of each frame depend
  335. on the recent history of decoder inputs.
  336. However, a decoder will want to skip these samples after decoding them.
  337. </t>
  338. <t>
  339. A 'pre-skip' field in the ID header (see <xref target="id_header"/>) signals
  340. the number of samples which SHOULD be skipped (decoded but discarded) at the
  341. beginning of the stream.
  342. This amount need not be a multiple of 2.5&nbsp;ms, MAY be smaller than a single
  343. packet, or MAY span the contents of several packets.
  344. These samples are not valid audio, and SHOULD NOT be played.
  345. </t>
  346. <t>
  347. For example, if the first Opus frame uses the CELT mode, it will always
  348. produce 120 samples of windowed overlap-add data.
  349. However, the overlap data is initially all zeros (since there is no prior
  350. frame), meaning this cannot, in general, accurately represent the original
  351. audio.
  352. The SILK mode requires additional delay to account for its analysis and
  353. resampling latency.
  354. The encoder delays the original audio to avoid this problem.
  355. </t>
  356. <t>
  357. The pre-skip field MAY also be used to perform sample-accurate cropping of
  358. already encoded streams.
  359. In this case, a value of at least 3840&nbsp;samples (80&nbsp;ms) provides
  360. sufficient history to the decoder that it will have converged
  361. before the stream's output begins.
  362. </t>
  363. </section>
  364. <section anchor="pcm_sample_position" title="PCM Sample Position">
  365. <t>
  366. <figure align="center">
  367. <preamble>
  368. The PCM sample position is determined from the granule position using the
  369. formula
  370. </preamble>
  371. <artwork align="center"><![CDATA[
  372. 'PCM sample position' = 'granule position' - 'pre-skip' .
  373. ]]></artwork>
  374. </figure>
  375. </t>
  376. <t>
  377. For example, if the granule position of the first audio data page is 59,971,
  378. and the pre-skip is 11,971, then the PCM sample position of the last decoded
  379. sample from that page is 48,000.
  380. <figure align="center">
  381. <preamble>
  382. This can be converted into a playback time using the formula
  383. </preamble>
  384. <artwork align="center"><![CDATA[
  385. 'PCM sample position'
  386. 'playback time' = --------------------- .
  387. 48000.0
  388. ]]></artwork>
  389. </figure>
  390. </t>
  391. <t>
  392. The initial PCM sample position before any samples are played is normally '0'.
  393. In this case, the PCM sample position of the first audio sample to be played
  394. starts at '1', because it marks the time on the clock
  395. <spanx style="emph">after</spanx> that sample has been played, and a stream
  396. that is exactly one second long has a final PCM sample position of '48000',
  397. as in the example here.
  398. </t>
  399. <t>
  400. Vorbis streams use a granule position smaller than the number of audio samples
  401. contained in the first audio data page to indicate that some of those samples
  402. are trimmed from the output (see <xref target="vorbis-trim"/>).
  403. However, to do so, Vorbis requires that the first audio data page contains
  404. exactly two packets, in order to allow the decoder to perform PCM position
  405. adjustments before needing to return any PCM data.
  406. Opus uses the pre-skip mechanism for this purpose instead, since the encoder
  407. MAY introduce more than a single packet's worth of latency, and since very
  408. large packets in streams with a very large number of channels might not fit
  409. on a single page.
  410. </t>
  411. </section>
  412. <section anchor="end_trimming" title="End Trimming">
  413. <t>
  414. The page with the 'end of stream' flag set MAY have a granule position that
  415. indicates the page contains less audio data than would normally be returned by
  416. decoding up through the final packet.
  417. This is used to end the stream somewhere other than an even frame boundary.
  418. The granule position of the most recent audio data page with completed packets
  419. is used to make this determination, or '0' is used if there were no previous
  420. audio data pages with a completed packet.
  421. The difference between these granule positions indicates how many samples to
  422. keep after decoding the packets that completed on the final page.
  423. The remaining samples are discarded.
  424. The number of discarded samples SHOULD be no larger than the number decoded
  425. from the last packet.
  426. </t>
  427. </section>
  428. <section anchor="start_granpos_restrictions"
  429. title="Restrictions on the Initial Granule Position">
  430. <t>
  431. The granule position of the first audio data page with a completed packet MAY
  432. be larger than the number of samples contained in packets that complete on
  433. that page, however it MUST NOT be smaller, unless that page has the 'end of
  434. stream' flag set.
  435. Allowing a granule position larger than the number of samples allows the
  436. beginning of a stream to be cropped or a live stream to be joined without
  437. rewriting the granule position of all the remaining pages.
  438. This means that the PCM sample position just before the first sample to be
  439. played MAY be larger than '0'.
  440. Synchronization when multiplexing with other logical streams still uses the PCM
  441. sample position relative to '0' to compute sample times.
  442. This does not affect the behavior of pre-skip: exactly 'pre-skip' samples
  443. SHOULD be skipped from the beginning of the decoded output, even if the
  444. initial PCM sample position is greater than zero.
  445. </t>
  446. <t>
  447. On the other hand, a granule position that is smaller than the number of
  448. decoded samples prevents a demuxer from working backwards to assign each
  449. packet or each individual sample a valid granule position, since granule
  450. positions are non-negative.
  451. A decoder MUST reject as invalid any stream where the granule position is
  452. smaller than the number of samples contained in packets that complete on the
  453. first audio data page with a completed packet, unless that page has the 'end
  454. of stream' flag set.
  455. It MAY defer this action until it decodes the last packet completed on that
  456. page.
  457. </t>
  458. <t>
  459. If that page has the 'end of stream' flag set, a demuxer MUST reject as invalid
  460. any stream where its granule position is smaller than the 'pre-skip' amount.
  461. This would indicate that there are more samples to be skipped from the initial
  462. decoded output than exist in the stream.
  463. If the granule position is smaller than the number of decoded samples produced
  464. by the packets that complete on that page, then a demuxer MUST use an initial
  465. granule position of '0', and can work forwards from '0' to timestamp
  466. individual packets.
  467. If the granule position is larger than the number of decoded samples available,
  468. then the demuxer MUST still work backwards as described above, even if the
  469. 'end of stream' flag is set, to determine the initial granule position, and
  470. thus the initial PCM sample position.
  471. Both of these will be greater than '0' in this case.
  472. </t>
  473. </section>
  474. <section anchor="seeking_and_preroll" title="Seeking and Pre-roll">
  475. <t>
  476. Seeking in Ogg files is best performed using a bisection search for a page
  477. whose granule position corresponds to a PCM position at or before the seek
  478. target.
  479. With appropriately weighted bisection, accurate seeking can be performed with
  480. just three or four bisections even in multi-gigabyte files.
  481. See <xref target="seeking"/> for general implementation guidance.
  482. </t>
  483. <t>
  484. When seeking within an Ogg Opus stream, the decoder SHOULD start decoding (and
  485. discarding the output) at least 3840&nbsp;samples (80&nbsp;ms) prior to the
  486. seek target in order to ensure that the output audio is correct by the time it
  487. reaches the seek target.
  488. This 'pre-roll' is separate from, and unrelated to, the 'pre-skip' used at the
  489. beginning of the stream.
  490. If the point 80&nbsp;ms prior to the seek target comes before the initial PCM
  491. sample position, the decoder SHOULD start decoding from the beginning of the
  492. stream, applying pre-skip as normal, regardless of whether the pre-skip is
  493. larger or smaller than 80&nbsp;ms, and then continue to discard samples
  494. to reach the seek target (if any).
  495. </t>
  496. </section>
  497. </section>
  498. <section anchor="headers" title="Header Packets">
  499. <t>
  500. An Opus stream contains exactly two mandatory header packets:
  501. an identification header and a comment header.
  502. </t>
  503. <section anchor="id_header" title="Identification Header">
  504. <figure anchor="id_header_packet" title="ID Header Packet" align="center">
  505. <artwork align="center"><![CDATA[
  506. 0 1 2 3
  507. 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
  508. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  509. | 'O' | 'p' | 'u' | 's' |
  510. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  511. | 'H' | 'e' | 'a' | 'd' |
  512. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  513. | Version = 1 | Channel Count | Pre-skip |
  514. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  515. | Input Sample Rate (Hz) |
  516. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  517. | Output Gain (Q7.8 in dB) | Mapping Family| |
  518. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ :
  519. | |
  520. : Optional Channel Mapping Table... :
  521. | |
  522. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  523. ]]></artwork>
  524. </figure>
  525. <t>
  526. The fields in the identification (ID) header have the following meaning:
  527. <list style="numbers">
  528. <t><spanx style="strong">Magic Signature</spanx>:
  529. <vspace blankLines="1"/>
  530. This is an 8-octet (64-bit) field that allows codec identification and is
  531. human-readable.
  532. It contains, in order, the magic numbers:
  533. <list style="empty">
  534. <t>0x4F 'O'</t>
  535. <t>0x70 'p'</t>
  536. <t>0x75 'u'</t>
  537. <t>0x73 's'</t>
  538. <t>0x48 'H'</t>
  539. <t>0x65 'e'</t>
  540. <t>0x61 'a'</t>
  541. <t>0x64 'd'</t>
  542. </list>
  543. Starting with "Op" helps distinguish it from audio data packets, as this is an
  544. invalid TOC sequence.
  545. <vspace blankLines="1"/>
  546. </t>
  547. <t><spanx style="strong">Version</spanx> (8 bits, unsigned):
  548. <vspace blankLines="1"/>
  549. The version number MUST always be '1' for this version of the encapsulation
  550. specification.
  551. Implementations SHOULD treat streams where the upper four bits of the version
  552. number match that of a recognized specification as backwards-compatible with
  553. that specification.
  554. That is, the version number can be split into "major" and "minor" version
  555. sub-fields, with changes to the "minor" sub-field (in the lower four bits)
  556. signaling compatible changes.
  557. For example, a decoder implementing this specification SHOULD accept any stream
  558. with a version number of '15' or less, and SHOULD assume any stream with a
  559. version number '16' or greater is incompatible.
  560. The initial version '1' was chosen to keep implementations from relying on this
  561. octet as a null terminator for the "OpusHead" string.
  562. <vspace blankLines="1"/>
  563. </t>
  564. <t><spanx style="strong">Output Channel Count</spanx> 'C' (8 bits, unsigned):
  565. <vspace blankLines="1"/>
  566. This is the number of output channels.
  567. This might be different than the number of encoded channels, which can change
  568. on a packet-by-packet basis.
  569. This value MUST NOT be zero.
  570. The maximum allowable value depends on the channel mapping family, and might be
  571. as large as 255.
  572. See <xref target="channel_mapping"/> for details.
  573. <vspace blankLines="1"/>
  574. </t>
  575. <t><spanx style="strong">Pre-skip</spanx> (16 bits, unsigned, little
  576. endian):
  577. <vspace blankLines="1"/>
  578. This is the number of samples (at 48&nbsp;kHz) to discard from the decoder
  579. output when starting playback, and also the number to subtract from a page's
  580. granule position to calculate its PCM sample position.
  581. When cropping the beginning of existing Ogg Opus streams, a pre-skip of at
  582. least 3,840&nbsp;samples (80&nbsp;ms) is RECOMMENDED to ensure complete
  583. convergence in the decoder.
  584. <vspace blankLines="1"/>
  585. </t>
  586. <t><spanx style="strong">Input Sample Rate</spanx> (32 bits, unsigned, little
  587. endian):
  588. <vspace blankLines="1"/>
  589. This field is <spanx style="emph">not</spanx> the sample rate to use for
  590. playback of the encoded data.
  591. <vspace blankLines="1"/>
  592. Opus can switch between internal audio bandwidths of 4, 6, 8, 12, and
  593. 20&nbsp;kHz.
  594. Each packet in the stream can have a different audio bandwidth.
  595. Regardless of the audio bandwidth, the reference decoder supports decoding any
  596. stream at a sample rate of 8, 12, 16, 24, or 48&nbsp;kHz.
  597. The original sample rate of the encoder input is not preserved by the lossy
  598. compression.
  599. <vspace blankLines="1"/>
  600. An Ogg Opus player SHOULD select the playback sample rate according to the
  601. following procedure:
  602. <list style="numbers">
  603. <t>If the hardware supports 48&nbsp;kHz playback, decode at 48&nbsp;kHz.</t>
  604. <t>Otherwise, if the hardware's highest available sample rate is a supported
  605. rate, decode at this sample rate.</t>
  606. <t>Otherwise, if the hardware's highest available sample rate is less than
  607. 48&nbsp;kHz, decode at the next highest supported rate above this and
  608. resample.</t>
  609. <t>Otherwise, decode at 48&nbsp;kHz and resample.</t>
  610. </list>
  611. However, the 'Input Sample Rate' field allows the encoder to pass the sample
  612. rate of the original input stream as metadata.
  613. This is useful when the user requires the output sample rate to match the
  614. input sample rate.
  615. For example, a non-player decoder writing PCM format samples to disk might
  616. choose to resample the output audio back to the original input sample rate to
  617. reduce surprise to the user, who might reasonably expect to get back a file
  618. with the same sample rate as the one they fed to the encoder.
  619. <vspace blankLines="1"/>
  620. A value of zero indicates 'unspecified'.
  621. Encoders SHOULD write the actual input sample rate or zero, but decoder
  622. implementations which do something with this field SHOULD take care to behave
  623. sanely if given crazy values (e.g., do not actually upsample the output to
  624. 10 MHz if requested).
  625. Input sample rates between 8&nbsp;kHz and 192&nbsp;kHz (inclusive) SHOULD be
  626. supported.
  627. Rates outside this range MAY be ignored by falling back to the default rate of
  628. 48&nbsp;kHz instead.
  629. <vspace blankLines="1"/>
  630. </t>
  631. <t><spanx style="strong">Output Gain</spanx> (16 bits, signed, little
  632. endian):
  633. <vspace blankLines="1"/>
  634. This is a gain to be applied by the decoder.
  635. It is 20*log10 of the factor to scale the decoder output by to achieve the
  636. desired playback volume, stored in a 16-bit, signed, two's complement
  637. fixed-point value with 8 fractional bits (i.e., Q7.8).
  638. <figure align="center">
  639. <preamble>
  640. To apply the gain, a decoder could use
  641. </preamble>
  642. <artwork align="center"><![CDATA[
  643. sample *= pow(10, output_gain/(20.0*256)) ,
  644. ]]></artwork>
  645. <postamble>
  646. where output_gain is the raw 16-bit value from the header.
  647. </postamble>
  648. </figure>
  649. <vspace blankLines="1"/>
  650. Virtually all players and media frameworks SHOULD apply it by default.
  651. If a player chooses to apply any volume adjustment or gain modification, such
  652. as the R128_TRACK_GAIN (see <xref target="comment_header"/>), the adjustment
  653. MUST be applied in addition to this output gain in order to achieve playback
  654. at the normalized volume.
  655. <vspace blankLines="1"/>
  656. An encoder SHOULD set this field to zero, and instead apply any gain prior to
  657. encoding, when this is possible and does not conflict with the user's wishes.
  658. A nonzero output gain indicates the gain was adjusted after encoding, or that
  659. a user wished to adjust the gain for playback while preserving the ability
  660. to recover the original signal amplitude.
  661. <vspace blankLines="1"/>
  662. Although the output gain has enormous range (+/- 128 dB, enough to amplify
  663. inaudible sounds to the threshold of physical pain), most applications can
  664. only reasonably use a small portion of this range around zero.
  665. The large range serves in part to ensure that gain can always be losslessly
  666. transferred between OpusHead and R128 gain tags (see below) without
  667. saturating.
  668. <vspace blankLines="1"/>
  669. </t>
  670. <t><spanx style="strong">Channel Mapping Family</spanx> (8 bits,
  671. unsigned):
  672. <vspace blankLines="1"/>
  673. This octet indicates the order and semantic meaning of the output channels.
  674. <vspace blankLines="1"/>
  675. Each possible value of this octet indicates a mapping family, which defines a
  676. set of allowed channel counts, and the ordered set of channel names for each
  677. allowed channel count.
  678. The details are described in <xref target="channel_mapping"/>.
  679. </t>
  680. <t><spanx style="strong">Channel Mapping Table</spanx>:
  681. This table defines the mapping from encoded streams to output channels.
  682. It is omitted when the channel mapping family is 0, but REQUIRED otherwise.
  683. Its contents are specified in <xref target="channel_mapping"/>.
  684. </t>
  685. </list>
  686. </t>
  687. <t>
  688. All fields in the ID headers are REQUIRED, except for the channel mapping
  689. table, which is omitted when the channel mapping family is 0.
  690. Implementations SHOULD reject ID headers which do not contain enough data for
  691. these fields, even if they contain a valid Magic Signature.
  692. Future versions of this specification, even backwards-compatible versions,
  693. might include additional fields in the ID header.
  694. If an ID header has a compatible major version, but a larger minor version,
  695. an implementation MUST NOT reject it for containing additional data not
  696. specified here.
  697. However, implementations MAY reject streams in which the ID header does not
  698. complete on the first page.
  699. </t>
  700. <section anchor="channel_mapping" title="Channel Mapping">
  701. <t>
  702. An Ogg Opus stream allows mapping one number of Opus streams (N) to a possibly
  703. larger number of decoded channels (M+N) to yet another number of output
  704. channels (C), which might be larger or smaller than the number of decoded
  705. channels.
  706. The order and meaning of these channels are defined by a channel mapping,
  707. which consists of the 'channel mapping family' octet and, for channel mapping
  708. families other than family&nbsp;0, a channel mapping table, as illustrated in
  709. <xref target="channel_mapping_table"/>.
  710. </t>
  711. <figure anchor="channel_mapping_table" title="Channel Mapping Table"
  712. align="center">
  713. <artwork align="center"><![CDATA[
  714. 0 1 2 3
  715. 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
  716. +-+-+-+-+-+-+-+-+
  717. | Stream Count |
  718. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  719. | Coupled Count | Channel Mapping... :
  720. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  721. ]]></artwork>
  722. </figure>
  723. <t>
  724. The fields in the channel mapping table have the following meaning:
  725. <list style="numbers" counter="8">
  726. <t><spanx style="strong">Stream Count</spanx> 'N' (8 bits, unsigned):
  727. <vspace blankLines="1"/>
  728. This is the total number of streams encoded in each Ogg packet.
  729. This value is necessary to correctly parse the packed Opus packets inside an
  730. Ogg packet, as described in <xref target="packet_organization"/>.
  731. This value MUST NOT be zero, as without at least one Opus packet with a valid
  732. TOC sequence, a demuxer cannot recover the duration of an Ogg packet.
  733. <vspace blankLines="1"/>
  734. For channel mapping family&nbsp;0, this value defaults to 1, and is not coded.
  735. <vspace blankLines="1"/>
  736. </t>
  737. <t><spanx style="strong">Coupled Stream Count</spanx> 'M' (8 bits, unsigned):
  738. This is the number of streams whose decoders are to be configured to produce
  739. two channels.
  740. This MUST be no larger than the total number of streams, N.
  741. <vspace blankLines="1"/>
  742. Each packet in an Opus stream has an internal channel count of 1 or 2, which
  743. can change from packet to packet.
  744. This is selected by the encoder depending on the bitrate and the audio being
  745. encoded.
  746. The original channel count of the encoder input is not preserved by the lossy
  747. compression.
  748. <vspace blankLines="1"/>
  749. Regardless of the internal channel count, any Opus stream can be decoded as
  750. mono (a single channel) or stereo (two channels) by appropriate initialization
  751. of the decoder.
  752. The 'coupled stream count' field indicates that the first M Opus decoders are
  753. to be initialized for stereo output, and the remaining N-M decoders are to be
  754. initialized for mono only.
  755. The total number of decoded channels, (M+N), MUST be no larger than 255, as
  756. there is no way to index more channels than that in the channel mapping.
  757. <vspace blankLines="1"/>
  758. For channel mapping family&nbsp;0, this value defaults to C-1 (i.e., 0 for mono
  759. and 1 for stereo), and is not coded.
  760. <vspace blankLines="1"/>
  761. </t>
  762. <t><spanx style="strong">Channel Mapping</spanx> (8*C bits):
  763. This contains one octet per output channel, indicating which decoded channel
  764. is to be used for each one.
  765. Let 'index' be the value of this octet for a particular output channel.
  766. This value MUST either be smaller than (M+N), or be the special value 255.
  767. If 'index' is less than 2*M, the output MUST be taken from decoding stream
  768. ('index'/2) as stereo and selecting the left channel if 'index' is even, and
  769. the right channel if 'index' is odd.
  770. If 'index' is 2*M or larger, but less than 255, the output MUST be taken from
  771. decoding stream ('index'-M) as mono.
  772. If 'index' is 255, the corresponding output channel MUST contain pure silence.
  773. <vspace blankLines="1"/>
  774. The number of output channels, C, is not constrained to match the number of
  775. decoded channels (M+N).
  776. A single index value MAY appear multiple times, i.e., the same decoded channel
  777. might be mapped to multiple output channels.
  778. Some decoded channels might not be assigned to any output channel, as well.
  779. <vspace blankLines="1"/>
  780. For channel mapping family&nbsp;0, the first index defaults to 0, and if C==2,
  781. the second index defaults to 1.
  782. Neither index is coded.
  783. </t>
  784. </list>
  785. </t>
  786. <t>
  787. After producing the output channels, the channel mapping family determines the
  788. semantic meaning of each one.
  789. There are three defined mapping families in this specification.
  790. </t>
  791. <section anchor="channel_mapping_0" title="Channel Mapping Family 0">
  792. <t>
  793. Allowed numbers of channels: 1 or 2.
  794. RTP mapping.
  795. </t>
  796. <t>
  797. <list style="symbols">
  798. <t>1 channel: monophonic (mono).</t>
  799. <t>2 channels: stereo (left, right).</t>
  800. </list>
  801. <spanx style="strong">Special mapping</spanx>: This channel mapping value also
  802. indicates that the contents consists of a single Opus stream that is stereo if
  803. and only if C==2, with stream index 0 mapped to output channel 0 (mono, or
  804. left channel) and stream index 1 mapped to output channel 1 (right channel)
  805. if stereo.
  806. When the 'channel mapping family' octet has this value, the channel mapping
  807. table MUST be omitted from the ID header packet.
  808. </t>
  809. </section>
  810. <section anchor="channel_mapping_1" title="Channel Mapping Family 1">
  811. <t>
  812. Allowed numbers of channels: 1...8.
  813. Vorbis channel order.
  814. </t>
  815. <t>
  816. Each channel is assigned to a speaker location in a conventional surround
  817. arrangement.
  818. Specific locations depend on the number of channels, and are given below
  819. in order of the corresponding channel indicies.
  820. <list style="symbols">
  821. <t>1 channel: monophonic (mono).</t>
  822. <t>2 channels: stereo (left, right).</t>
  823. <t>3 channels: linear surround (left, center, right)</t>
  824. <t>4 channels: quadraphonic (front&nbsp;left, front&nbsp;right, rear&nbsp;left, rear&nbsp;right).</t>
  825. <t>5 channels: 5.0 surround (front&nbsp;left, front&nbsp;center, front&nbsp;right, rear&nbsp;left, rear&nbsp;right).</t>
  826. <t>6 channels: 5.1 surround (front&nbsp;left, front&nbsp;center, front&nbsp;right, rear&nbsp;left, rear&nbsp;right, LFE).</t>
  827. <t>7 channels: 6.1 surround (front&nbsp;left, front&nbsp;center, front&nbsp;right, side&nbsp;left, side&nbsp;right, rear&nbsp;center, LFE).</t>
  828. <t>8 channels: 7.1 surround (front&nbsp;left, front&nbsp;center, front&nbsp;right, side&nbsp;left, side&nbsp;right, rear&nbsp;left, rear&nbsp;right, LFE)</t>
  829. </list>
  830. </t>
  831. <t>
  832. This set of surround options and speaker location orderings is the same
  833. as those used by the Vorbis codec <xref target="vorbis-mapping"/>.
  834. The ordering is different from the one used by the
  835. WAVE <xref target="wave-multichannel"/> and
  836. FLAC <xref target="flac"/> formats,
  837. so correct ordering requires permutation of the output channels when decoding
  838. to or encoding from those formats.
  839. 'LFE' here refers to a Low Frequency Effects, often mapped to a subwoofer
  840. with no particular spatial position.
  841. Implementations SHOULD identify 'side' or 'rear' speaker locations with
  842. 'surround' and 'back' as appropriate when interfacing with audio formats
  843. or systems which prefer that terminology.
  844. </t>
  845. </section>
  846. <section anchor="channel_mapping_255"
  847. title="Channel Mapping Family 255">
  848. <t>
  849. Allowed numbers of channels: 1...255.
  850. No defined channel meaning.
  851. </t>
  852. <t>
  853. Channels are unidentified.
  854. General-purpose players SHOULD NOT attempt to play these streams, and offline
  855. decoders MAY deinterleave the output into separate PCM files, one per channel.
  856. Decoders SHOULD NOT produce output for channels mapped to stream index 255
  857. (pure silence) unless they have no other way to indicate the index of
  858. non-silent channels.
  859. </t>
  860. </section>
  861. <section anchor="channel_mapping_undefined"
  862. title="Undefined Channel Mappings">
  863. <t>
  864. The remaining channel mapping families (2...254) are reserved.
  865. A decoder encountering a reserved channel mapping family value SHOULD act as
  866. though the value is 255.
  867. </t>
  868. </section>
  869. <section anchor="downmix" title="Downmixing">
  870. <t>
  871. An Ogg Opus player MUST support any valid channel mapping with a channel
  872. mapping family of 0 or 1, even if the number of channels does not match the
  873. physically connected audio hardware.
  874. Players SHOULD perform channel mixing to increase or reduce the number of
  875. channels as needed.
  876. </t>
  877. <t>
  878. Implementations MAY use the following matricies to implement downmixing from
  879. multichannel files using <xref target="channel_mapping_1">Channel Mapping
  880. Family 1</xref>, which are known to give acceptable results for stereo.
  881. Matricies for 3 and 4 channels are normalized so each coefficent row sums
  882. to 1 to avoid clipping.
  883. For 5 or more channels they are normalized to 2 as a compromise between
  884. clipping and dynamic range reduction.
  885. </t>
  886. <t>
  887. In these matricies the front left and front right channels are generally
  888. passed through directly.
  889. When a surround channel is split between both the left and right stereo
  890. channels, coefficients are chosen so their squares sum to 1, which
  891. helps preserve the perceived intensity.
  892. Rear channels are mixed more diffusely or attenuated to maintain focus
  893. on the front channels.
  894. </t>
  895. <figure anchor="downmix-matrix-3"
  896. title="Stereo downmix matrix for the linear surround channel mapping"
  897. align="center">
  898. <artwork align="center"><![CDATA[
  899. L output = ( 0.585786 * left + 0.414214 * center )
  900. R output = ( 0.414214 * center + 0.585786 * right )
  901. ]]></artwork>
  902. <postamble>
  903. Exact coefficient values are 1 and 1/sqrt(2), multiplied by
  904. 1/(1 + 1/sqrt(2)) for normalization.
  905. </postamble>
  906. </figure>
  907. <figure anchor="downmix-matrix-4"
  908. title="Stereo downmix matrix for the quadraphonic channel mapping"
  909. align="center">
  910. <artwork align="center"><![CDATA[
  911. / \ / \ / FL \
  912. | L output | | 0.422650 0.000000 0.366025 0.211325 | | FR |
  913. | R output | = | 0.000000 0.422650 0.211325 0.366025 | | RL |
  914. \ / \ / \ RR /
  915. ]]></artwork>
  916. <postamble>
  917. Exact coefficient values are 1, sqrt(3)/2 and 1/2, multiplied by
  918. 1/(1&nbsp;+&nbsp;sqrt(3)/2&nbsp;+&nbsp;1/2) for normalization.
  919. </postamble>
  920. </figure>
  921. <figure anchor="downmix-matrix-5"
  922. title="Stereo downmix matrix for the 5.0 surround mapping"
  923. align="center">
  924. <artwork align="center"><![CDATA[
  925. / FL \
  926. / \ / \ | FC |
  927. | L | | 0.650802 0.460186 0.000000 0.563611 0.325401 | | FR |
  928. | R | = | 0.000000 0.460186 0.650802 0.325401 0.563611 | | RL |
  929. \ / \ / | RR |
  930. \ /
  931. ]]></artwork>
  932. <postamble>
  933. Exact coefficient values are 1, 1/sqrt(2), sqrt(3)/2 and 1/2, multiplied by
  934. 2/(1&nbsp;+&nbsp;1/sqrt(2)&nbsp;+&nbsp;sqrt(3)/2&nbsp;+&nbsp;1/2)
  935. for normalization.
  936. </postamble>
  937. </figure>
  938. <figure anchor="downmix-matrix-6"
  939. title="Stereo downmix matrix for the 5.1 surround mapping"
  940. align="center">
  941. <artwork align="center"><![CDATA[
  942. /FL \
  943. / \ / \ |FC |
  944. |L| | 0.529067 0.374107 0.000000 0.458186 0.264534 0.374107 | |FR |
  945. |R| = | 0.000000 0.374107 0.529067 0.264534 0.458186 0.374107 | |RL |
  946. \ / \ / |RR |
  947. \LFE/
  948. ]]></artwork>
  949. <postamble>
  950. Exact coefficient values are 1, 1/sqrt(2), sqrt(3)/2 and 1/2, multiplied by
  951. 2/(1&nbsp;+&nbsp;1/sqrt(2)&nbsp;+&nbsp;sqrt(3)/2&nbsp;+&nbsp;1/2 + 1/sqrt(2))
  952. for normalization.
  953. </postamble>
  954. </figure>
  955. <figure anchor="downmix-matrix-7"
  956. title="Stereo downmix matrix for the 6.1 surround mapping"
  957. align="center">
  958. <artwork align="center"><![CDATA[
  959. / \
  960. | 0.455310 0.321953 0.000000 0.394310 0.227655 0.278819 0.321953 |
  961. | 0.000000 0.321953 0.455310 0.227655 0.394310 0.278819 0.321953 |
  962. \ /
  963. ]]></artwork>
  964. <postamble>
  965. Exact coefficient values are 1, 1/sqrt(2), sqrt(3)/2, 1/2 and
  966. sqrt(3)/2/sqrt(2), multiplied by
  967. 2/(1&nbsp;+&nbsp;1/sqrt(2)&nbsp;+&nbsp;sqrt(3)/2&nbsp;+&nbsp;1/2 +
  968. sqrt(3)/2/sqrt(2) + 1/sqrt(2)) for normalization.
  969. The coeffients are in the same order as in <xref target="channel_mapping_1" />,
  970. and the matricies above.
  971. </postamble>
  972. </figure>
  973. <figure anchor="downmix-matrix-8"
  974. title="Stereo downmix matrix for the 7.1 surround mapping"
  975. align="center">
  976. <artwork align="center"><![CDATA[
  977. / \
  978. | .388631 .274804 .000000 .336565 .194316 .336565 .194316 .274804 |
  979. | .000000 .274804 .388631 .194316 .336565 .194316 .336565 .274804 |
  980. \ /
  981. ]]></artwork>
  982. <postamble>
  983. Exact coefficient values are 1, 1/sqrt(2), sqrt(3)/2 and 1/2, multiplied by
  984. 2/(2&nbsp;+&nbsp;2/sqrt(2)&nbsp;+&nbsp;sqrt(3)) for normalization.
  985. The coeffients are in the same order as in <xref target="channel_mapping_1" />,
  986. and the matricies above.
  987. </postamble>
  988. </figure>
  989. </section>
  990. </section> <!-- end channel_mapping_table -->
  991. </section> <!-- end id_header -->
  992. <section anchor="comment_header" title="Comment Header">
  993. <figure anchor="comment_header_packet" title="Comment Header Packet"
  994. align="center">
  995. <artwork align="center"><![CDATA[
  996. 0 1 2 3
  997. 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
  998. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  999. | 'O' | 'p' | 'u' | 's' |
  1000. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1001. | 'T' | 'a' | 'g' | 's' |
  1002. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1003. | Vendor String Length |
  1004. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1005. | |
  1006. : Vendor String... :
  1007. | |
  1008. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1009. | User Comment List Length |
  1010. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1011. | User Comment #0 String Length |
  1012. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1013. | |
  1014. : User Comment #0 String... :
  1015. | |
  1016. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1017. | User Comment #1 String Length |
  1018. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1019. : :
  1020. ]]></artwork>
  1021. </figure>
  1022. <t>
  1023. The comment header consists of a 64-bit magic signature, followed by data in
  1024. the same format as the <xref target="vorbis-comment"/> header used in Ogg
  1025. Vorbis, except (like Ogg Theora and Speex) the final "framing bit" specified
  1026. in the Vorbis spec is not present.
  1027. <list style="numbers">
  1028. <t><spanx style="strong">Magic Signature</spanx>:
  1029. <vspace blankLines="1"/>
  1030. This is an 8-octet (64-bit) field that allows codec identification and is
  1031. human-readable.
  1032. It contains, in order, the magic numbers:
  1033. <list style="empty">
  1034. <t>0x4F 'O'</t>
  1035. <t>0x70 'p'</t>
  1036. <t>0x75 'u'</t>
  1037. <t>0x73 's'</t>
  1038. <t>0x54 'T'</t>
  1039. <t>0x61 'a'</t>
  1040. <t>0x67 'g'</t>
  1041. <t>0x73 's'</t>
  1042. </list>
  1043. Starting with "Op" helps distinguish it from audio data packets, as this is an
  1044. invalid TOC sequence.
  1045. <vspace blankLines="1"/>
  1046. </t>
  1047. <t><spanx style="strong">Vendor String Length</spanx> (32 bits, unsigned,
  1048. little endian):
  1049. <vspace blankLines="1"/>
  1050. This field gives the length of the following vendor string, in octets.
  1051. It MUST NOT indicate that the vendor string is longer than the rest of the
  1052. packet.
  1053. <vspace blankLines="1"/>
  1054. </t>
  1055. <t><spanx style="strong">Vendor String</spanx> (variable length, UTF-8 vector):
  1056. <vspace blankLines="1"/>
  1057. This is a simple human-readable tag for vendor information, encoded as a UTF-8
  1058. string&nbsp;<xref target="RFC3629"/>.
  1059. No terminating null octet is necessary.
  1060. <vspace blankLines="1"/>
  1061. This tag is intended to identify the codec encoder and encapsulation
  1062. implementations, for tracing differences in technical behavior.
  1063. User-facing encoding applications can use the 'ENCODER' user comment tag
  1064. to identify themselves.
  1065. <vspace blankLines="1"/>
  1066. </t>
  1067. <t><spanx style="strong">User Comment List Length</spanx> (32 bits, unsigned,
  1068. little endian):
  1069. <vspace blankLines="1"/>
  1070. This field indicates the number of user-supplied comments.
  1071. It MAY indicate there are zero user-supplied comments, in which case there are
  1072. no additional fields in the packet.
  1073. It MUST NOT indicate that there are so many comments that the comment string
  1074. lengths would require more data than is available in the rest of the packet.
  1075. <vspace blankLines="1"/>
  1076. </t>
  1077. <t><spanx style="strong">User Comment #i String Length</spanx> (32 bits,
  1078. unsigned, little endian):
  1079. <vspace blankLines="1"/>
  1080. This field gives the length of the following user comment string, in octets.
  1081. There is one for each user comment indicated by the 'user comment list length'
  1082. field.
  1083. It MUST NOT indicate that the string is longer than the rest of the packet.
  1084. <vspace blankLines="1"/>
  1085. </t>
  1086. <t><spanx style="strong">User Comment #i String</spanx> (variable length, UTF-8
  1087. vector):
  1088. <vspace blankLines="1"/>
  1089. This field contains a single user comment string.
  1090. There is one for each user comment indicated by the 'user comment list length'
  1091. field.
  1092. </t>
  1093. </list>
  1094. </t>
  1095. <t>
  1096. The vendor string length and user comment list length are REQUIRED, and
  1097. implementations SHOULD reject comment headers that do not contain enough data
  1098. for these fields, or that do not contain enough data for the corresponding
  1099. vendor string or user comments they describe.
  1100. Making this check before allocating the associated memory to contain the data
  1101. helps prevent a possible Denial-of-Service (DoS) attack from small comment
  1102. headers that claim to contain strings longer than the entire packet or more
  1103. user comments than than could possibly fit in the packet.
  1104. </t>
  1105. <t>
  1106. Immediately following the user comment list, the comment header MAY
  1107. contain zero-padding or other binary data which is not specified here.
  1108. If the least-significant bit of the first byte of this data is 1, then editors
  1109. SHOULD preserve the contents of this data when updating the tags, but if this
  1110. bit is 0, all such data MAY be treated as padding, and truncated or discarded
  1111. as desired.
  1112. </t>
  1113. <t>
  1114. The comment header can be arbitrarily large and might be spread over a large
  1115. number of Ogg pages.
  1116. Decoders SHOULD avoid attempting to allocate excessive amounts of memory when
  1117. presented with a very large comment header.
  1118. To accomplish this, decoders MAY reject a comment header larger than
  1119. 125,829,120&nbsp;octets, and MAY ignore individual comments that are not fully
  1120. contained within the first 61,440 octets of the comment header.
  1121. </t>
  1122. <section anchor="comment_format" title="Tag Definitions">
  1123. <t>
  1124. The user comment strings follow the NAME=value format described by
  1125. <xref target="vorbis-comment"/> with the same recommended tag names:
  1126. ARTIST, TITLE, DATE, ALBUM, and so on.
  1127. </t>
  1128. <t>
  1129. Two new comment tags are introduced here:
  1130. </t>
  1131. <figure align="center">
  1132. <preamble>An optional gain for track nomalization</preamble>
  1133. <artwork align="left"><![CDATA[
  1134. R128_TRACK_GAIN=-573
  1135. ]]></artwork>
  1136. <postamble>
  1137. representing the volume shift needed to normalize the track's volume
  1138. during isolated playback, in random shuffle, and so on.
  1139. The gain is a Q7.8 fixed point number in dB, as in the ID header's 'output
  1140. gain' field.
  1141. </postamble>
  1142. </figure>
  1143. <t>
  1144. This tag is similar to the REPLAYGAIN_TRACK_GAIN tag in
  1145. Vorbis&nbsp;<xref target="replay-gain"/>, except that the normal volume
  1146. reference is the <xref target="EBU-R128"/> standard.
  1147. </t>
  1148. <figure align="center">
  1149. <preamble>An optional gain for album nomalization</preamble>
  1150. <artwork align="left"><![CDATA[
  1151. R128_ALBUM_GAIN=111
  1152. ]]></artwork>
  1153. <postamble>
  1154. representing the volume shift needed to normalize the overall volume when
  1155. played as part of a particular collection of tracks.
  1156. The gain is also a Q7.8 fixed point number in dB, as in the ID header's
  1157. 'output gain' field.
  1158. </postamble>
  1159. </figure>
  1160. <t>
  1161. An Ogg Opus stream MUST NOT have more than one of each tag, and if present
  1162. their values MUST be an integer from -32768 to 32767, inclusive,
  1163. represented in ASCII as a base 10 number with no whitespace.
  1164. A leading '+' or '-' character is valid.
  1165. Leading zeros are also permitted, but the value MUST be represented by
  1166. no more than 6 characters.
  1167. Other non-digit characters MUST NOT be present.
  1168. </t>
  1169. <t>
  1170. If present, R128_TRACK_GAIN and R128_ALBUM_GAIN MUST correctly represent
  1171. the R128 normalization gain relative to the 'output gain' field specified
  1172. in the ID header.
  1173. If a player chooses to make use of the R128_TRACK_GAIN tag or the
  1174. R128_ALBUM_GAIN tag, it MUST apply those gains
  1175. <spanx style="emph">in addition</spanx> to the 'output gain' value.
  1176. If a tool modifies the ID header's 'output gain' field, it MUST also update or
  1177. remove the R128_TRACK_GAIN and R128_ALBUM_GAIN comment tags if present.
  1178. An encoder SHOULD assume that by default tools will respect the 'output gain'
  1179. field, and not the comment tag.
  1180. </t>
  1181. <t>
  1182. To avoid confusion with multiple normalization schemes, an Opus comment header
  1183. SHOULD NOT contain any of the REPLAYGAIN_TRACK_GAIN, REPLAYGAIN_TRACK_PEAK,
  1184. REPLAYGAIN_ALBUM_GAIN, or REPLAYGAIN_ALBUM_PEAK tags.
  1185. <xref target="EBU-R128"/> normalization is preferred to the earlier
  1186. REPLAYGAIN schemes because of its clear definition and adoption by industry.
  1187. Peak normalizations are difficult to calculate reliably for lossy codecs
  1188. because of variation in excursion heights due to decoder differences.
  1189. In the authors' investigations they were not applied consistently or broadly
  1190. enough to merit inclusion here.
  1191. </t>
  1192. </section> <!-- end comment_format -->
  1193. </section> <!-- end comment_header -->
  1194. </section> <!-- end headers -->
  1195. <section anchor="packet_size_limits" title="Packet Size Limits">
  1196. <t>
  1197. Technically, valid Opus packets can be arbitrarily large due to the padding
  1198. format, although the amount of non-padding data they can contain is bounded.
  1199. These packets might be spread over a similarly enormous number of Ogg pages.
  1200. Encoders SHOULD limit the use of padding in audio data packets to no more than
  1201. is necessary to make a variable bitrate (VBR) stream constant bitrate (CBR).
  1202. Decoders SHOULD reject audio data packets larger than 61,440 octets per Opus
  1203. stream.
  1204. Such packets necessarily contain more padding than needed for this purpose.
  1205. Decoders SHOULD avoid attempting to allocate excessive amounts of memory when
  1206. presented with a very large packet.
  1207. Decoders MAY reject or partially process audio data packets larger than
  1208. 61,440&nbsp;octets in an Ogg Opus stream with channel mapping families&nbsp;0
  1209. or&nbsp;1.
  1210. Decoders MAY reject or partially process audio data packets in any Ogg Opus
  1211. stream if the packet is larger than 61,440&nbsp;octets and also larger than
  1212. 7,680&nbsp;octets per Opus stream.
  1213. The presence of an extremely large packet in the stream could indicate a
  1214. memory exhaustion attack or stream corruption.
  1215. </t>
  1216. <t>
  1217. In an Ogg Opus stream, the largest possible valid packet that does not use
  1218. padding has a size of (61,298*N&nbsp;-&nbsp;2) octets.
  1219. With 255&nbsp;streams, this is 15,630,988&nbsp;octets and can
  1220. span up to 61,298&nbsp;Ogg pages, all but one of which will have a granule
  1221. position of -1.
  1222. This is of course a very extreme packet, consisting of 255&nbsp;streams, each
  1223. containing 120&nbsp;ms of audio encoded as 2.5&nbsp;ms frames, each frame
  1224. using the maximum possible number of octets (1275) and stored in the least
  1225. efficient manner allowed (a VBR code&nbsp;3 Opus packet).
  1226. Even in such a packet, most of the data will be zeros as 2.5&nbsp;ms frames
  1227. cannot actually use all 1275&nbsp;octets.
  1228. </t>
  1229. <t>
  1230. The largest packet consisting of entirely useful data is
  1231. (15,326*N&nbsp;-&nbsp;2) octets.
  1232. This corresponds to 120&nbsp;ms of audio encoded as 10&nbsp;ms frames in either
  1233. SILK or Hybrid mode, but at a data rate of over 1&nbsp;Mbps, which makes little
  1234. sense for the quality achieved.
  1235. </t>
  1236. <t>
  1237. A more reasonable limit is (7,664*N&nbsp;-&nbsp;2) octets.
  1238. This corresponds to 120&nbsp;ms of audio encoded as 20&nbsp;ms stereo CELT mode
  1239. frames, with a total bitrate just under 511&nbsp;kbps (not counting the Ogg
  1240. encapsulation overhead).
  1241. For channel mapping family 1, N=8 provides a reasonable upper bound, as it
  1242. allows for each of the 8 possible output channels to be decoded from a
  1243. separate stereo Opus stream.
  1244. This gives a size of 61,310&nbsp;octets, which is rounded up to a multiple of
  1245. 1,024&nbsp;octets to yield the audio data packet size of 61,440&nbsp;octets
  1246. that any implementation is expected to be able to process successfully.
  1247. </t>
  1248. </section>
  1249. <section anchor="encoder" title="Encoder Guidelines">
  1250. <t>
  1251. When encoding Opus streams, Ogg muxers SHOULD take into account the
  1252. algorithmic delay of the Opus encoder.
  1253. </t>
  1254. <figure align="center">
  1255. <preamble>
  1256. In encoders derived from the reference implementation, the number of
  1257. samples can be queried with:
  1258. </preamble>
  1259. <artwork align="center"><![CDATA[
  1260. opus_encoder_ctl(encoder_state, OPUS_GET_LOOKAHEAD(&delay_samples));
  1261. ]]></artwork>
  1262. </figure>
  1263. <t>
  1264. To achieve good quality in the very first samples of a stream, the Ogg encoder
  1265. MAY use linear predictive coding (LPC) extrapolation
  1266. <xref target="linear-prediction"/> to generate at least 120 extra samples at
  1267. the beginning to avoid the Opus encoder having to encode a discontinuous
  1268. signal.
  1269. For an input file containing 'length' samples, the Ogg encoder SHOULD set the
  1270. pre-skip header value to delay_samples+extra_samples, encode at least
  1271. length+delay_samples+extra_samples samples, and set the granulepos of the last
  1272. page to length+delay_samples+extra_samples.
  1273. This ensures that the encoded file has the same duration as the original, with
  1274. no time offset. The best way to pad the end of the stream is to also use LPC
  1275. extrapolation, but zero-padding is also acceptable.
  1276. </t>
  1277. <section anchor="lpc" title="LPC Extrapolation">
  1278. <t>
  1279. The first step in LPC extrapolation is to compute linear prediction
  1280. coefficients. <xref target="lpc-sample"/>
  1281. When extending the end of the signal, order-N (typically with N ranging from 8
  1282. to 40) LPC analysis is performed on a window near the end of the signal.
  1283. The last N samples are used as memory to an infinite impulse response (IIR)
  1284. filter.
  1285. </t>
  1286. <figure align="center">
  1287. <preamble>
  1288. The filter is then applied on a zero input to extrapolate the end of the signal.
  1289. Let a(k) be the kth LPC coefficient and x(n) be the nth sample of the signal,
  1290. each new sample past the end of the signal is computed as:
  1291. </preamble>
  1292. <artwork align="center"><![CDATA[
  1293. N
  1294. ---
  1295. x(n) = \ a(k)*x(n-k)
  1296. /
  1297. ---
  1298. k=1
  1299. ]]></artwork>
  1300. </figure>
  1301. <t>
  1302. The process is repeated independently for each channel.
  1303. It is possible to extend the beginning of the signal by applying the same
  1304. process backward in time.
  1305. When extending the beginning of the signal, it is best to apply a "fade in" to
  1306. the extrapolated signal, e.g. by multiplying it by a half-Hanning window
  1307. <xref target="hanning"/>.
  1308. </t>
  1309. </section>
  1310. <section anchor="continuous_chaining" title="Continuous Chaining">
  1311. <t>
  1312. In some applications, such as Internet radio, it is desirable to cut a long
  1313. stream into smaller chains, e.g. so the comment header can be updated.
  1314. This can be done simply by separating the input streams into segments and
  1315. encoding each segment independently.
  1316. The drawback of this approach is that it creates a small discontinuity
  1317. at the boundary due to the lossy nature of Opus.
  1318. An encoder MAY avoid this discontinuity by using the following procedure:
  1319. <list style="numbers">
  1320. <t>Encode the last frame of the first segment as an independent frame by
  1321. turning off all forms of inter-frame prediction.
  1322. De-emphasis is allowed.</t>
  1323. <t>Set the granulepos of the last page to a point near the end of the last
  1324. frame.</t>
  1325. <t>Begin the second segment with a copy of the last frame of the first
  1326. segment.</t>
  1327. <t>Set the pre-skip value of the second stream in such a way as to properly
  1328. join the two streams.</t>
  1329. <t>Continue the encoding process normally from there, without any reset to
  1330. the encoder.</t>
  1331. </list>
  1332. </t>
  1333. <figure align="center">
  1334. <preamble>
  1335. In encoders derived from the reference implementation, inter-frame prediction
  1336. can be turned off by calling:
  1337. </preamble>
  1338. <artwork align="center"><![CDATA[
  1339. opus_encoder_ctl(encoder_state, OPUS_SET_PREDICTION_DISABLED(1));
  1340. ]]></artwork>
  1341. <postamble>
  1342. For best results, this implementation requires that prediction be explicitly
  1343. enabled again before resuming normal encoding, even after a reset.
  1344. </postamble>
  1345. </figure>
  1346. </section>
  1347. </section>
  1348. <section anchor="implementation" title="Implementation Status">
  1349. <t>
  1350. A brief summary of major implementations of this draft is available
  1351. at <eref target="https://wiki.xiph.org/OggOpusImplementation"/>,
  1352. along with their status.
  1353. </t>
  1354. <t>
  1355. [Note to RFC Editor: please remove this entire section before
  1356. final publication per <xref target="RFC6982"/>.]
  1357. </t>
  1358. </section>
  1359. <section anchor="security" title="Security Considerations">
  1360. <t>
  1361. Implementations of the Opus codec need to take appropriate security
  1362. considerations into account, as outlined in <xref target="RFC4732"/>.
  1363. This is just as much a problem for the container as it is for the codec itself.
  1364. It is extremely important for the decoder to be robust against malicious
  1365. payloads.
  1366. Malicious payloads MUST NOT cause the decoder to overrun its allocated memory
  1367. or to take an excessive amount of resources to decode.
  1368. Although problems in encoders are typically rarer, the same applies to the
  1369. encoder.
  1370. Malicious audio streams MUST NOT cause the encoder to misbehave because this
  1371. would allow an attacker to attack transcoding gateways.
  1372. </t>
  1373. <t>
  1374. Like most other container formats, Ogg Opus streams SHOULD NOT be used with
  1375. insecure ciphers or cipher modes that are vulnerable to known-plaintext
  1376. attacks.
  1377. Elements such as the Ogg page capture pattern and the magic signatures in the
  1378. ID header and the comment header all have easily predictable values, in
  1379. addition to various elements of the codec data itself.
  1380. </t>
  1381. </section>
  1382. <section anchor="content_type" title="Content Type">
  1383. <t>
  1384. An "Ogg Opus file" consists of one or more sequentially multiplexed segments,
  1385. each containing exactly one Ogg Opus stream.
  1386. The RECOMMENDED mime-type for Ogg Opus files is "audio/ogg".
  1387. </t>
  1388. <figure>
  1389. <preamble>
  1390. If more specificity is desired, one MAY indicate the presence of Opus streams
  1391. using the codecs parameter defined in <xref target="RFC6381"/>, e.g.,
  1392. </preamble>
  1393. <artwork align="center"><![CDATA[
  1394. audio/ogg; codecs=opus
  1395. ]]></artwork>
  1396. <postamble>
  1397. for an Ogg Opus file.
  1398. </postamble>
  1399. </figure>
  1400. <t>
  1401. The RECOMMENDED filename extension for Ogg Opus files is '.opus'.
  1402. </t>
  1403. <t>
  1404. When Opus is concurrently multiplexed with other streams in an Ogg container,
  1405. one SHOULD use one of the "audio/ogg", "video/ogg", or "application/ogg"
  1406. mime-types, as defined in <xref target="RFC5334"/>.
  1407. Such streams are not strictly "Ogg Opus files" as described above,
  1408. since they contain more than a single Opus stream per sequentially
  1409. multiplexed segment, e.g. video or multiple audio tracks.
  1410. In such cases the the '.opus' filename extension is NOT RECOMMENDED.
  1411. </t>
  1412. </section>
  1413. <section title="IANA Considerations">
  1414. <t>
  1415. This document has no actions for IANA.
  1416. </t>
  1417. </section>
  1418. <section anchor="Acknowledgments" title="Acknowledgments">
  1419. <t>
  1420. Thanks to Mark Harris, Greg Maxwell, Christopher "Monty" Montgomery, and
  1421. Jean-Marc Valin for their valuable contributions to this document.
  1422. Additional thanks to Andrew D'Addesio, Greg Maxwell, and Vincent Penquerc'h for
  1423. their feedback based on early implementations.
  1424. </t>
  1425. </section>
  1426. <section title="Copying Conditions">
  1427. <t>
  1428. The authors agree to grant third parties the irrevocable right to copy, use,
  1429. and distribute the work, with or without modification, in any medium, without
  1430. royalty, provided that, unless separate permission is granted, redistributed
  1431. modified works do not contain misleading author, version, name of work, or
  1432. endorsement information.
  1433. </t>
  1434. </section>
  1435. </middle>
  1436. <back>
  1437. <references title="Normative References">
  1438. &rfc2119;
  1439. &rfc3533;
  1440. &rfc3629;
  1441. &rfc5334;
  1442. &rfc6381;
  1443. &rfc6716;
  1444. <reference anchor="EBU-R128" target="https://tech.ebu.ch/loudness">
  1445. <front>
  1446. <title>Loudness Recommendation EBU R128</title>
  1447. <author>
  1448. <organization>EBU Technical Committee</organization>
  1449. </author>
  1450. <date month="August" year="2011"/>
  1451. </front>
  1452. </reference>
  1453. <reference anchor="vorbis-comment"
  1454. target="https://www.xiph.org/vorbis/doc/v-comment.html">
  1455. <front>
  1456. <title>Ogg Vorbis I Format Specification: Comment Field and Header
  1457. Specification</title>
  1458. <author initials="C." surname="Montgomery"
  1459. fullname="Christopher &quot;Monty&quot; Montgomery"/>
  1460. <date month="July" year="2002"/>
  1461. </front>
  1462. </reference>
  1463. </references>
  1464. <references title="Informative References">
  1465. <!--?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.3550.xml"?-->
  1466. &rfc4732;
  1467. &rfc6982;
  1468. <reference anchor="flac"
  1469. target="https://xiph.org/flac/format.html">
  1470. <front>
  1471. <title>FLAC - Free Lossless Audio Codec Format Description</title>
  1472. <author initials="J." surname="Coalson" fullname="Josh Coalson"/>
  1473. <date month="January" year="2008"/>
  1474. </front>
  1475. </reference>
  1476. <reference anchor="hanning"
  1477. target="https://en.wikipedia.org/wiki/Hamming_function#Hann_.28Hanning.29_window">
  1478. <front>
  1479. <title>Hann window</title>
  1480. <author>
  1481. <organization>Wikipedia</organization>
  1482. </author>
  1483. <date month="May" year="2013"/>
  1484. </front>
  1485. </reference>
  1486. <reference anchor="linear-prediction"
  1487. target="https://en.wikipedia.org/wiki/Linear_predictive_coding">
  1488. <front>
  1489. <title>Linear Predictive Coding</title>
  1490. <author>
  1491. <organization>Wikipedia</organization>
  1492. </author>
  1493. <date month="January" year="2014"/>
  1494. </front>
  1495. </reference>
  1496. <reference anchor="lpc-sample"
  1497. target="https://svn.xiph.org/trunk/vorbis/lib/lpc.c">
  1498. <front>
  1499. <title>Autocorrelation LPC coeff generation algorithm
  1500. (Vorbis source code)</title>
  1501. <author initials="J." surname="Degener" fullname="Jutta Degener"/>
  1502. <author initials="C." surname="Bormann" fullname="Carsten Bormann"/>
  1503. <date month="November" year="1994"/>
  1504. </front>
  1505. </reference>
  1506. <reference anchor="replay-gain"
  1507. target="https://wiki.xiph.org/VorbisComment#Replay_Gain">
  1508. <front>
  1509. <title>VorbisComment: Replay Gain</title>
  1510. <author initials="C." surname="Parker" fullname="Conrad Parker"/>
  1511. <author initials="M." surname="Leese" fullname="Martin Leese"/>
  1512. <date month="June" year="2009"/>
  1513. </front>
  1514. </reference>
  1515. <reference anchor="seeking"
  1516. target="https://wiki.xiph.org/Seeking">
  1517. <front>
  1518. <title>Granulepos Encoding and How Seeking Really Works</title>
  1519. <author initials="S." surname="Pfeiffer" fullname="Silvia Pfeiffer"/>
  1520. <author initials="C." surname="Parker" fullname="Conrad Parker"/>
  1521. <author initials="G." surname="Maxwell" fullname="Greg Maxwell"/>
  1522. <date month="May" year="2012"/>
  1523. </front>
  1524. </reference>
  1525. <reference anchor="vorbis-mapping"
  1526. target="https://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-810004.3.9">
  1527. <front>
  1528. <title>The Vorbis I Specification, Section 4.3.9 Output Channel Order</title>
  1529. <author initials="C." surname="Montgomery"
  1530. fullname="Christopher &quot;Monty&quot; Montgomery"/>
  1531. <date month="January" year="2010"/>
  1532. </front>
  1533. </reference>
  1534. <reference anchor="vorbis-trim"
  1535. target="https://xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-132000A.2">
  1536. <front>
  1537. <title>The Vorbis I Specification, Appendix&nbsp;A: Embedding Vorbis
  1538. into an Ogg stream</title>
  1539. <author initials="C." surname="Montgomery"
  1540. fullname="Christopher &quot;Monty&quot; Montgomery"/>
  1541. <date month="November" year="2008"/>
  1542. </front>
  1543. </reference>
  1544. <reference anchor="wave-multichannel"
  1545. target="http://msdn.microsoft.com/en-us/windows/hardware/gg463006.aspx">
  1546. <front>
  1547. <title>Multiple Channel Audio Data and WAVE Files</title>
  1548. <author>
  1549. <organization>Microsoft Corporation</organization>
  1550. </author>
  1551. <date month="March" year="2007"/>
  1552. </front>
  1553. </reference>
  1554. </references>
  1555. </back>
  1556. </rfc>