Skip to main content

Ogg Encapsulation for the Opus Audio Codec
draft-ietf-codec-oggopus-04

The information below is for an old version of the document.
Document Type
This is an older version of an Internet-Draft that was ultimately published as RFC 7845.
Authors Timothy B. Terriberry , Ron Lee , Ralph Giles
Last updated 2014-08-08
Replaces draft-terriberry-oggopus
RFC stream Internet Engineering Task Force (IETF)
Formats
Reviews
Additional resources Mailing list discussion
Stream WG state WG Document
Document shepherd (None)
IESG IESG state Became RFC 7845 (Proposed Standard)
Consensus boilerplate Unknown
Telechat date (None)
Responsible AD (None)
Send notices to (None)
draft-ietf-codec-oggopus-04
#x27;      |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                     Vendor String Length                      |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                                                               |
     :                        Vendor String...                       :
     |                                                               |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                   User Comment List Length                    |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                 User Comment #0 String Length                 |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                                                               |
     :                   User Comment #0 String...                   :
     |                                                               |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                 User Comment #1 String Length                 |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     :                                                               :

                      Figure 9: Comment Header Packet

   The comment header consists of a 64-bit magic signature, followed by
   data in the same format as the [vorbis-comment] header used in Ogg
   Vorbis, except (like Ogg Theora and Speex) the final "framing bit"
   specified in the Vorbis spec is not present.

   1.  *Magic Signature*:

       This is an 8-octet (64-bit) field that allows codec
       identification and is human-readable.  It contains, in order, the
       magic numbers:

          0x4F 'O'

          0x70 'p'

          0x75 'u'

          0x73 's'

Terriberry, et al.      Expires February 10, 2015              [Page 20]
Internet-Draft                  Ogg Opus                     August 2014

          0x54 'T'

          0x61 'a'

          0x67 'g'

          0x73 's'

       Starting with "Op" helps distinguish it from audio data packets,
       as this is an invalid TOC sequence.

   2.  *Vendor String Length* (32 bits, unsigned, little endian):

       This field gives the length of the following vendor string, in
       octets.  It MUST NOT indicate that the vendor string is longer
       than the rest of the packet.

   3.  *Vendor String* (variable length, UTF-8 vector):

       This is a simple human-readable tag for vendor information,
       encoded as a UTF-8 string [RFC3629].  No terminating null octet
       is required.

       This tag is intended to identify the codec encoder and
       encapsulation implementations, for tracing differences in
       technical behavior.  User-facing encoding applications can use
       the 'ENCODER' user comment tag to identify themselves.

   4.  *User Comment List Length* (32 bits, unsigned, little endian):

       This field indicates the number of user-supplied comments.  It
       MAY indicate there are zero user-supplied comments, in which case
       there are no additional fields in the packet.  It MUST NOT
       indicate that there are so many comments that the comment string
       lengths would require more data than is available in the rest of
       the packet.

   5.  *User Comment #i String Length* (32 bits, unsigned, little
       endian):

Terriberry, et al.      Expires February 10, 2015              [Page 21]
Internet-Draft                  Ogg Opus                     August 2014

       This field gives the length of the following user comment string,
       in octets.  There is one for each user comment indicated by the
       'user comment list length' field.  It MUST NOT indicate that the
       string is longer than the rest of the packet.

   6.  *User Comment #i String* (variable length, UTF-8 vector):

       This field contains a single user comment string.  There is one
       for each user comment indicated by the 'user comment list length'
       field.

   The vendor string length and user comment list length are REQUIRED,
   and implementations SHOULD reject comment headers that do not contain
   enough data for these fields, or that do not contain enough data for
   the corresponding vendor string or user comments they describe.
   Making this check before allocating the associated memory to contain
   the data helps prevent a possible Denial-of-Service (DoS) attack from
   small comment headers that claim to contain strings longer than the
   entire packet or more user comments than than could possibly fit in
   the packet.

5.2.1.  Tag Definitions

   The user comment strings follow the NAME=value format described by
   [vorbis-comment] with the same recommended tag names: ARTIST, TITLE,
   DATE, ALBUM, and so on.

   Two new comment tags are introduced here:

   An optional gain for track nomalization

     R128_TRACK_GAIN=-573

   representing the volume shift needed to normalize the track's volume
   during isolated playback, in random shuffle, and so on.  The gain is
   a Q7.8 fixed point number in dB, as in the ID header's 'output gain'
   field.

   This tag is similar to the REPLAYGAIN_TRACK_GAIN tag in
   Vorbis [replay-gain], except that the normal volume reference is the
   [EBU-R128] standard.

Terriberry, et al.      Expires February 10, 2015              [Page 22]
Internet-Draft                  Ogg Opus                     August 2014

   An optional gain for album nomalization

     R128_ALBUM_GAIN=111

   representing the volume shift needed to normalize the overall volume
   when played as part of a particular collection of tracks.  The gain
   is also a Q7.8 fixed point number in dB, as in the ID header's
   'output gain' field.

   An Ogg Opus file MUST NOT have more than one of each tag, and if
   present their values MUST be an integer from -32768 to 32767,
   inclusive, represented in ASCII with no whitespace.  If present,
   R128_TRACK_GAIN and R128_ALBUM_GAIN MUST correctly represent the R128
   normalization gain relative to the 'output gain' field specified in
   the ID header.  If a player chooses to make use of the
   R128_TRACK_GAIN tag or the R128_ALBUM_GAIN tag, it MUST apply those
   gains _in addition_ to the 'output gain' value.

   If an encoder wishes to use R128 normalization, and the output gain
   is not otherwise constrained or specified, the encoder SHOULD write
   the R128 gain into the 'output gain' field and store a tag containing
   "R128_TRACK_GAIN=0".  That is, it should assume that by default tools
   will respect the 'output gain' field, and not the comment tag.  If a
   tool modifies the ID header's 'output gain' field, it MUST also
   update or remove the R128_TRACK_GAIN and R128_ALBUM_GAIN comment tags
   if present.

   To avoid confusion with multiple normalization schemes, an Opus
   comment header SHOULD NOT contain any of the REPLAYGAIN_TRACK_GAIN,
   REPLAYGAIN_TRACK_PEAK, REPLAYGAIN_ALBUM_GAIN, or
   REPLAYGAIN_ALBUM_PEAK tags.  [EBU-R128] normalization is preferred to
   the earlier REPLAYGAIN schemes because of its clear definition and
   adoption by industry.  PEAK normalizations are difficult to calculate
   reliably for lossy codecs because of variation in excursion heights
   due to decoder differences.  In the authors' investigations they were
   not applied consistently or broadly enough to merit inclusion here.

6.  Packet Size Limits

   Technically, valid Opus packets can be arbitrarily large due to the
   padding format, although the amount of non-padding data they can
   contain is bounded.  These packets might be spread over a similarly
   enormous number of Ogg pages.  Encoders SHOULD use no more padding
   than required to make a variable bitrate (VBR) stream constant
   bitrate (CBR).  Decoders SHOULD avoid attempting to allocate
   excessive amounts of memory when presented with a very large packet.
   The presence of an extremely large packet in the stream could
   indicate a memory exhaustion attack or stream corruption.  Decoders

Terriberry, et al.      Expires February 10, 2015              [Page 23]
Internet-Draft                  Ogg Opus                     August 2014

   SHOULD reject a packet that is too large to process, and display a
   warning message.

   In an Ogg Opus stream, the largest possible valid packet that does
   not use padding has a size of (61,298*N - 2) octets, or about 60 kB
   per Opus stream.  With 255 streams, this is 15,630,988 octets
   (14.9 MB) and can span up to 61,298 Ogg pages, all but one of which
   will have a granule position of -1.  This is of course a very extreme
   packet, consisting of 255 streams, each containing 120 ms of audio
   encoded as 2.5 ms frames, each frame using the maximum possible
   number of octets (1275) and stored in the least efficient manner
   allowed (a VBR code 3 Opus packet).  Even in such a packet, most of
   the data will be zeros as 2.5 ms frames cannot actually use all
   1275 octets.  The largest packet consisting of entirely useful data
   is (15,326*N - 2) octets, or about 15 kB per stream.  This
   corresponds to 120 ms of audio encoded as 10 ms frames in either SILK
   or Hybrid mode, but at a data rate of over 1 Mbps, which makes little
   sense for the quality achieved.  A more reasonable limit is
   (7,664*N - 2) octets, or about 7.5 kB per stream.  This corresponds
   to 120 ms of audio encoded as 20 ms stereo CELT mode frames, with a
   total bitrate just under 511 kbps (not counting the Ogg encapsulation
   overhead).  With N=8, the maximum number of channels currently
   defined by mapping family 1, this gives a maximum packet size of
   61,310 octets, or just under 60 kB.  This is still quite
   conservative, as it assumes each output channel is taken from one
   decoded channel of a stereo packet.  An implementation could
   reasonably choose any of these numbers for its internal limits.

7.  Encoder Guidelines

   When encoding Opus files, Ogg encoders should take into account the
   algorithmic delay of the Opus encoder.

   In encoders derived from the reference implementation, the number of
   samples can be queried with:

    opus_encoder_ctl(encoder_state, OPUS_GET_LOOKAHEAD, &delay_samples);

   To achieve good quality in the very first samples of a stream, the
   Ogg encoder MAY use linear predictive coding (LPC) extrapolation
   [linear-prediction] to generate at least 120 extra samples at the
   beginning to avoid the Opus encoder having to encode a discontinuous
   signal.  For an input file containing 'length' samples, the Ogg
   encoder SHOULD set the pre-skip header value to
   delay_samples+extra_samples, encode at least
   length+delay_samples+extra_samples samples, and set the granulepos of
   the last page to length+delay_samples+extra_samples.  This ensures
   that the encoded file has the same duration as the original, with no

Terriberry, et al.      Expires February 10, 2015              [Page 24]
Internet-Draft                  Ogg Opus                     August 2014

   time offset.  The best way to pad the end of the stream is to also
   use LPC extrapolation, but zero-padding is also acceptable.

7.1.  LPC Extrapolation

   The first step in LPC extrapolation is to compute linear prediction
   coefficients. [lpc-sample] When extending the end of the signal,
   order-N (typically with N ranging from 8 to 40) LPC analysis is
   performed on a window near the end of the signal.  The last N samples
   are used as memory to an infinite impulse response (IIR) filter.

   The filter is then applied on a zero input to extrapolate the end of
   the signal.  Let a(k) be the kth LPC coefficient and x(n) be the nth
   sample of the signal, each new sample past the end of the signal is
   computed as:

                                  N
                                 ---
                          x(n) = \   a(k)*x(n-k)
                                 /
                                 ---
                                 k=1

   The process is repeated independently for each channel.  It is
   possible to extend the beginning of the signal by applying the same
   process backward in time.  When extending the beginning of the
   signal, it is best to apply a "fade in" to the extrapolated signal,
   e.g. by multiplying it by a half-Hanning window [hanning].

7.2.  Continuous Chaining

   In some applications, such as Internet radio, it is desirable to cut
   a long stream into smaller chains, e.g. so the comment header can be
   updated.  This can be done simply by separating the input streams
   into segments and encoding each segment independently.  The drawback
   of this approach is that it creates a small discontinuity at the
   boundary due to the lossy nature of Opus.  An encoder MAY avoid this
   discontinuity by using the following procedure:

   1.  Encode the last frame of the first segment as an independent
       frame by turning off all forms of inter-frame prediction.  De-
       emphasis is allowed.

   2.  Set the granulepos of the last page to a point near the end of
       the last frame.

   3.  Begin the second segment with a copy of the last frame of the
       first segment.

Terriberry, et al.      Expires February 10, 2015              [Page 25]
Internet-Draft                  Ogg Opus                     August 2014

   4.  Set the pre-skip value of the second stream in such a way as to
       properly join the two streams.

   5.  Continue the encoding process normally from there, without any
       reset to the encoder.

    In encoders derived from the reference implementation, inter-frame
    prediction can be turned off by calling:

     opus_encoder_ctl(encoder_state, OPUS_SET_PREDICTION_DISABLED, 1);

    Prediction should be enabled again before resuming normal encoding,
    even after a reset.

8.  Implementation Status

   A brief summary of major implementations of this draft is available
   at [1], along with their status.

   [Note to RFC Editor: please remove this entire section before final
   publication per [RFC6982].]

9.  Security Considerations

   Implementations of the Opus codec need to take appropriate security
   considerations into account, as outlined in [RFC4732].  This is just
   as much a problem for the container as it is for the codec itself.
   It is extremely important for the decoder to be robust against
   malicious payloads.  Malicious payloads must not cause the decoder to
   overrun its allocated memory or to take an excessive amount of
   resources to decode.  Although problems in encoders are typically
   rarer, the same applies to the encoder.  Malicious audio streams must
   not cause the encoder to misbehave because this would allow an
   attacker to attack transcoding gateways.

   Like most other container formats, Ogg Opus files should not be used
   with insecure ciphers or cipher modes that are vulnerable to known-
   plaintext attacks.  Elements such as the Ogg page capture pattern and
   the magic signatures in the ID header and the comment header all have
   easily predictable values, in addition to various elements of the
   codec data itself.

10.  Content Type

   An "Ogg Opus file" consists of one or more sequentially multiplexed
   segments, each containing exactly one Ogg Opus stream.  The
   RECOMMENDED mime-type for Ogg Opus files is "audio/ogg".

Terriberry, et al.      Expires February 10, 2015              [Page 26]
Internet-Draft                  Ogg Opus                     August 2014

   If more specificity is desired, one MAY indicate the presence of Opus
   streams using the codecs parameter defined in [RFC6381], e.g.,

     audio/ogg; codecs=opus

   for an Ogg Opus file.

   The RECOMMENDED filename extension for Ogg Opus files is '.opus'.

   When Opus is concurrently multiplexed with other streams in an Ogg
   container, one SHOULD use one of the "audio/ogg", "video/ogg", or
   "application/ogg" mime-types, as defined in [RFC5334].  Such streams
   are not strictly "Ogg Opus files" as described above, since they
   contain more than a single Opus stream per sequentially multiplexed
   segment, e.g. video or multiple audio tracks.  In such cases the the
   '.opus' filename extension is NOT RECOMMENDED.

11.  IANA Considerations

   This document has no actions for IANA.

12.  Acknowledgments

   Thanks to Greg Maxwell, Christopher "Monty" Montgomery, and Jean-Marc
   Valin for their valuable contributions to this document.  Additional
   thanks to Andrew D'Addesio, Greg Maxwell, and Vincent Penqeurc'h for
   their feedback based on early implementations.

13.  Copying Conditions

   The authors agree to grant third parties the irrevocable right to
   copy, use, and distribute the work, with or without modification, in
   any medium, without royalty, provided that, unless separate
   permission is granted, redistributed modified works do not contain
   misleading author, version, name of work, or endorsement information.

14.  References

14.1.  Normative References

   [RFC2119]  Bradner, S., "Key words for use in RFCs to Indicate
              Requirement Levels", BCP 14, RFC 2119, March 1997.

   [RFC3533]  Pfeiffer, S., "The Ogg Encapsulation Format Version 0",
              RFC 3533, May 2003.

   [RFC3629]  Yergeau, F., "UTF-8, a transformation format of ISO
              10646", STD 63, RFC 3629, November 2003.

Terriberry, et al.      Expires February 10, 2015              [Page 27]
Internet-Draft                  Ogg Opus                     August 2014

   [RFC5334]  Goncalves, I., Pfeiffer, S., and C. Montgomery, "Ogg Media
              Types", RFC 5334, September 2008.

   [RFC6381]  Gellens, R., Singer, D., and P. Frojdh, "The 'Codecs' and
              'Profiles' Parameters for "Bucket" Media Types", RFC 6381,
              August 2011.

   [RFC6716]  Valin, JM., Vos, K., and T. Terriberry, "Definition of the
              Opus Audio Codec", RFC 6716, September 2012.

   [EBU-R128]
              EBU Technical Committee, "Loudness Recommendation EBU
              R128", August 2011, <https://tech.ebu.ch/loudness>.

   [vorbis-comment]
              Montgomery, C., "Ogg Vorbis I Format Specification:
              Comment Field and Header Specification", July 2002,
              <https://www.xiph.org/vorbis/doc/v-comment.html>.

14.2.  Informative References

   [RFC4732]  Handley, M., Rescorla, E., and IAB, "Internet Denial-of-
              Service Considerations", RFC 4732, December 2006.

   [RFC6982]  Sheffer, Y. and A. Farrel, "Improving Awareness of Running
              Code: The Implementation Status Section", RFC 6982, July
              2013.

   [flac]     Coalson, J., "FLAC - Free Lossless Audio Codec Format
              Description", January 2008, <https://xiph.org/flac/
              format.html>.

   [hanning]  Wikipedia, "Hann window", May 2013,
              <https://en.wikipedia.org/wiki/
              Hamming_function#Hann_.28Hanning.29_window>.

   [linear-prediction]
              Wikipedia, "Linear Predictive Coding", January 2014,
              <https://en.wikipedia.org/wiki/Linear_predictive_coding>.

   [lpc-sample]
              Degener, J. and C. Bormann, "Autocorrelation LPC coeff
              generation algorithm (Vorbis source code)", November 1994,
              <https://svn.xiph.org/trunk/vorbis/lib/lpc.c>.

Terriberry, et al.      Expires February 10, 2015              [Page 28]
Internet-Draft                  Ogg Opus                     August 2014

   [replay-gain]
              Parker, C. and M. Leese, "VorbisComment: Replay Gain",
              June 2009, <https://wiki.xiph.org/
              VorbisComment#Replay_Gain>.

   [seeking]  Pfeiffer, S., Parker, C., and G. Maxwell, "Granulepos
              Encoding and How Seeking Really Works", May 2012,
              <https://wiki.xiph.org/Seeking>.

   [vorbis-mapping]
              Montgomery, C., "The Vorbis I Specification, Section 4.3.9
              Output Channel Order", January 2010,
              <https://www.xiph.org/vorbis/doc/
              Vorbis_I_spec.html#x1-800004.3.9>.

   [vorbis-trim]
              Montgomery, C., "The Vorbis I Specification, Appendix A:
              Embedding Vorbis into an Ogg stream", November 2008,
              <https://xiph.org/vorbis/doc/
              Vorbis_I_spec.html#x1-130000A.2>.

   [wave-multichannel]
              Microsoft Corporation, "Multiple Channel Audio Data and
              WAVE Files", March 2007, <http://msdn.microsoft.com/en-
              us/windows/hardware/gg463006.aspx>.

14.3.  URIs

   [1] https://wiki.xiph.org/OggOpusImplementation

Authors' Addresses

   Timothy B. Terriberry
   Mozilla Corporation
   650 Castro Street
   Mountain View, CA  94041
   USA

   Phone: +1 650 903-0800
   Email: tterribe@xiph.org

Terriberry, et al.      Expires February 10, 2015              [Page 29]
Internet-Draft                  Ogg Opus                     August 2014

   Ron Lee
   Voicetronix
   246 Pulteney Street, Level 1
   Adelaide, SA  5000
   Australia

   Phone: +61 8 8232 9112
   Email: ron@debian.org

   Ralph Giles
   Mozilla Corporation
   163 West Hastings Street
   Vancouver, BC  V6B 1H5
   Canada

   Phone: +1 778 785 1540
   Email: giles@xiph.org

Terriberry, et al.      Expires February 10, 2015              [Page 30]