draft-ietf-codec-oggopus.xml 69 KB

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