MDN / Codecs in common media types
MDN / Codecs in common media types
At a fundamental level, you can specify the type of a media file using a basic type, such as video/mp4 or audio/mpeg. However, many media types—especially those that support video tracks—can benefit from the ability to more precisely describe the format of the data within them. For instance, just describing a video in an MPEG-4 file with the MIME type video/mp4 doesn’t say anything about what format the actual media within takes.
For that reason, the codecs parameter can be added to the MIME type describing media content. With it, container-specific information can be provided. This information may include things like the profile of the video codec, the type used for the audio tracks, and so forth.
This guide briefly examines the syntax of the media type codecs parameter and how it’s used with the MIME type string to provide details about the contents of audio or video media beyond indicating the container type.
Container format MIME types
The MIME type for a container format is expressed by stating the type of media (audio, video, etc.), then a slash character (/), then the format used to contain the media:
audio/mpeg: An audio file using the MPEG file type, such as an MP3.
video/ogg: A video file using the Ogg file type.
video/mp4: A video file using the MPEG-4 file type.
video/quicktime: A video file in Apple’s QuickTime format. As noted elsewhere, this format was once commonly used on the web but no longer is, since it required a plugin to use.
However, each of these MIME types is vague. All of these file types support a variety of codecs, and those codecs may have any number of profiles, levels, and other configuration factors. For this reason, you may want to include the codecs parameter along with the media type.
Basic syntax
You can add the codecs parameter to the media type. To do so, append a semicolon (;) followed by codecs= and then the string describing the format of the contents of the file. Some media types only let you specify the names of the codecs to use, while others allow you to specify various constraints on those codecs as well. You can specify multiple codecs by separating them with commas.
audio/ogg; codecs=vorbisvideo/webm; codecs="vp8, vorbis"video/mp4; codecs="avc1.4d002a"
As is the case with any MIME type parameter, codecs must be changed to codecs* (note the asterisk character, *) if any of the properties of the codec use special characters which must be percent-encoded per . You can use the JavaScript encodeURI() function to encode the parameter list; similarly, you can use decodeURI() to decode a previously encoded parameter list.
When the codecs parameter is used, the specified list of codecs must include every codec used for the contents of the file. The list may also contain codecs not present in the file.
Codec options by container
The containers below support extended codec options in their codecs parameters:
Several of the links above go to the same section; that’s because those media types are all based on ISO Base Media File Format (ISO BMFF), so they share the same syntax.
AV1
The syntax of the codecs parameter for AV1 is defined in the AV1 Codec ISO Media File Format Binding specification, section 5: Codecs Parameter String.
av01.P.LLT.DD[.M.CCC.cp.tc.mc.F]
Chromium-based browsers will accept any subset of the optional parameters (rather than all or none, as required by the specification).
This codec parameter string’s components are described in more detail in the table below. Each component is a fixed number of characters long; if the value is less than that length, it must be padded with leading zeros.
All fields from M (monochrome flag) onward are optional; you may stop including fields at any point (but can’t arbitrarily leave out fields). The default values are included in the table above. Some example AV1 codec strings:
av01.2.15M.10.0.100.09.16.09.0: AV1 Professional Profile, level 5.3, Main tier, 10 bits per color component, 4:2:2 chroma subsampling using ITU-R BT.2100 color primaries, transfer characteristics, and YCbCr color matrix. The studio swing representation is indicated.
av01.0.15M.10: AV1 Main Profile, level 5.3, Main tier, 10 bits per color component. The remaining properties are taken from the defaults: 4:2:0 chroma subsampling, BT.709 color primaries, transfer characteristics, and matrix coefficients. Studio swing representation.
VP9
ISO Base Media File Format syntax
The syntax of the codecs parameter for VP9 is defined in the VP Codec ISO Media File Format Binding specification, in the Codecs Parameter String section.
In this format, the codecs parameter’s value begins with a four-character code identifying the codec being used in the container, which is then followed by a series of period (.) separated two-digit values.
cccc.PP.LL.DD
cccc.PP.LL.DD.CC.cp.tc.mc.FF
The first four components are required; everything from CC (chroma subsampling) onward is optional, but all or nothing. Each of these components is described in the following table. Following the table are some examples.
Examples
video/webm;codecs="vp09.02.10.10.01.09.16.09.01,opus": VP9 video, profile 2 level 1.0, with 10-bit YUV content using 4:2:0 chroma subsampling, BT.2020 primaries, ST 2084 EOTF (HDR SMPTE), BT.2020 non-constant luminance color matrix, and full-range chroma and luma encoding. The audio is in Opus format.
ISO Base Media File Format: MP4, QuickTime, and 3GP
All media types based upon the ISO Base Media File Format (ISO BMFF) share the same syntax for the codecs parameter. These media types include MPEG-4 (and, in fact, the QuickTime file format upon which MPEG-4 is based) as well as 3GP. Both video and audio tracks can be described using the codecs parameter with the following MIME types:
MIME typeDescriptionaudio/3gpp3GP audio ()video/3gpp3GP video ()audio/3gp23GP2 audio ()video/3gp23GP2 video ()audio/mp4MP4 audio ()video/mp4MP4 video ()application/mp4Non-audiovisual media encapsulated in MPEG-4Each codec described by the codecs parameter can be specified either as the container’s name (3gp, mp4, quicktime, etc.) or as the container name plus additional parameters to specify the codec and its configuration. Each entry in the codec list may contain some number of components, separated by periods (.).
The syntax for the value of codecs varies by codec; however, it always starts with the codec’s case-sensitive four-character sample entry code. Some codecs append a period separator (.) followed by additional parameters, such as an Object Type Indication (OTI) value or details about the codec’s profile. For most codecs that use an OTI, the value is a two-digit hexadecimal number; however, AVC (H.264) uses six hexadecimal digits to identify the profile.
Thus, the syntaxes for each of the supported codecs look like this:
cccc[.pp]*(Generic ISO BMFF): Where
ccccis the four-character ID for the codec andppis where zero or more two-character encoded property values go.
mp4a.oo[.A](MPEG-4 audio): Where
oois the Object Type Indication value describing the contents of the media more precisely andAis the one-digit audio OTI. The possible values for the OTI can be found on the MP4 Registration Authority website’s Object Types page. For example, AAC-LC audio in an MP4 file ismp4a.40.2. For further details, see MPEG-4 audio.
mp4v.oo[.V](MPEG-4 video): Here,
oois again the OTI describing the contents more precisely, whileVis the one-digit video OTI.
avc1[.PPCCLL](AVC video):
PPCCLLare six hexadecimal digits specifying the profile number (PP), constraint set flags (CC), and level (LL). See AVC profiles for the possible values ofPP.The constraint set flags byte is comprised of one-bit Boolean flags, with the most significant bit being referred to as flag 0 (or
constraint_set0_flag, in some resources), and each successive bit being numbered one higher. Currently, only flags 0 through 2 are used; the other five bits must be zero. The meanings of the flags vary depending on the profile being used.The level is a fixed-point number, so a value of
14(decimal 20) means level 2.0 while a value of3D(decimal 61) means level 6.1. Generally speaking, the higher the level number, the more bandwidth the stream will use and the higher the maximum video dimensions are supported.
avc3[.PPCCLL](Variable resolution AVC): The
avc3codec parameters have the same syntax as theavc1codec parameters.
AVC profiles
The following are the AVC profiles and their profile numbers for use in the codecs parameter, as well as the value to specify for the constraints component, CC.
ProfileNumber (Hex)Constraints byteConstrained Baseline Profile (CBP) CBP is primarily a solution for scenarios in which resources are constrained, or resource use needs to be controlled to minimize the odds of the media performing poorly.4240Baseline Profile (BP) Similar to CBP but with more data loss protections and recovery capabilities. This is not as widely used as it was before CBP was introduced. All CBP streams are considered to also be BP streams.4200Extended Profile (XP) Designed for streaming video over the network, with high compression capability and further improvements to data robustness and stream switching.5800Main Profile (MP) The profile used for standard-definition digital television being broadcast in MPEG-4 format. Not used for high-definition television broadcasts. This profile’s importance has faded since the introduction of the High Profile—which was added for HDTV use—in 2004.4D00High Profile (HiP) Currently, HiP is the primary profile used for broadcast and disc-based HD video; it’s used both for HD TV broadcasts and for Blu-Ray video.6400Progressive High Profile (PHiP) Essentially High Profile without support for field coding.6408Constrained High Profile PHiP, but without support for bi-predictive slices (“B-slices”).640CHigh 10 Profile (Hi10P) High Profile, but with support for up to 10 bits per color component.6E00High 4:2:2 Profile (Hi422P) Expands upon Hi10P by adding support for 4:2:2 chroma subsampling along with up to10 bits per color component.7A00High 4:4:4 Predictive Profile (Hi444PP) In addition to the capabilities included in Hi422P, Hi444PP adds support for 4:4:4 chroma subsampling (in which no color information is discarded). Also includes support for up to 14 bits per color sample and efficient lossless region coding. The option to encode each frame as three separate color planes (that is, each color’s data is stored as if it were a single monochrome frame).F400High 10 Intra Profile High 10 constrained to all-intra-frame use. Primarily used for professional apps.6E10High 4:2:2 Intra Profile The Hi422 Profile with all-intra-frame use.7A10High 4:4:4 Intra Profile The High 4:4:4 Profile constrained to use only intra frames.F410CAVLC 4:4:4 Intra Profile The High 4:4:4 Profile constrained to all-intra use, and to using only CAVLC entropy coding.2C10Scalable Baseline Profile Intended for use with video conferencing as well as surveillance and mobile uses, the SVC Baseline Profile is based on AVC’s Constrained Baseline profile. The base layer within the stream is provided at a high quality level, with some number of secondary substreams that offer alternative forms of the same video for use in various constrained environments. These may include any combination of reduced resolution, reduced frame rate, or increased compression levels.5300Scalable Constrained Baseline Profile Primarily used for real-time communication applications. Not yet supported by WebRTC, but an extension to the WebRTC API to allow SVC is in development.5304Scalable High Profile Meant mostly for use in broadcast and streaming applications. The base (or highest quality) layer must conform to the AVC High Profile.5600Scalable Constrained High Profile A subset of the Scalable High Profile designed mainly for real-time communication.5604Scalable High Intra Profile Primarily useful only for production applications, this profile supports only all-intra usage.5610Stereo High Profile The Stereo High Profile provides stereoscopic video using two renderings of the scene (left eye and right eye). Otherwise, provides the same features as the High profile.8000Multiview High Profile Supports two or more views using both temporal and MVC inter-view prediction. Does not support field pictures or macroblock-adaptive frame-field coding.7600Multiview Depth High Profile Based on the High Profile, to which the main substream must adhere. The remaining substreams must match the Stereo High Profile.8A00
MPEG-4 audio
When the value of an entry in the codecs list begins with mp4a, the syntax of the value should be:
mp4a.oo[.A]
Here, oo is the two-digit hexadecimal Object Type Indication which specifies the codec class being used for the media. The OTIs are assigned by the MP4 Registration Authority, which maintains a list of the possible OTI values. A special value is 40; this indicates that the media is MPEG-4 audio (ISO/IEC 14496 Part 3). In order to be more specific still, a third component—the Audio Object Type—is added for OTI 40 to narrow the type down to a specific subtype of MPEG-4.
The Audio Object Type is specified as a one or two digit decimal value (unlike most other values in the codecs parameter, which use hexadecimal). For example, MPEG-4’s AAC-LC has an audio object type number of 2, so the full codecs value representing AAC-LC is mp4a.40.2.
Thus, ER AAC LC, whose Audio Object Type is 17, can be represented using the full codecs value mp4a.40.17. Single digit values can be given either as one digit (which is the best choice, since it will be the most broadly compatible) or with a leading zero padding it to two digits, such as mp4a.40.02.
The specification originally mandated that the Audio Object Type number in the third component be only one decimal digit. However, amendments to the specification over time extended the range of these values well beyond one decimal digit, so now the third parameter may be either one or two digits. Padding values below 10 with a leading 0 is optional. Older implementations of MPEG-4 codecs may not support two-digit values, however, so using a single digit when possible will maximize compatibility.
The Audio Object Types are defined in ISO/IEC 14496-3 subpart 1, section 1.5.1. The table below provides a basic list of the Audio Object Types and in the case of the more common object types provides a list of the profiles supporting it, but you should refer to the specification for details if you need to know more about the inner workings of any given MPEG-4 audio type.
Opus
Opus audio in an ISO BMFF container uses Opus as its sample entry and codecs value. The value is case-sensitive. Although the MP4 Registration Authority assigns the Object Type Indication 0xAD to Opus, the Opus encapsulation specification does not define an MP4AudioSampleEntry using that value, so mp4a.ad is not used.
audio/mp4;codecs=Opus
video/mp4;codecs=avc1.4D401E,Opus
HEVC: MP4, Quicktime, Matroska
The High Efficiency Video Coding codec, also known as H.265 and MPEG-H Part 2, can be included in the MP4 (video/mp4), Quicktime (video/quicktime), and Matroska (video/matroska) containers.
Use of HEVC is generally described using a supporting MIME type with the codecs parameter appended; syntax examples are as follows:
video/mp4;codecs=hvc1.1.6.L186.B0,mp4a.40.2
video/mp4;codecs=hvc1.1.6.L186.B0,Opus
video/mp4;codecs=hev1.1.6.L186.B0,mp4a.40.2
video/mp4;codecs=hev1.1.6.L186.B0,Opus
The syntaxes for each of the supported codecs look like this:
hvc1[.A.B.C.D](HEVC video): The value starts with the codec’s four-character identifier (
hvc1), followed by four or more values separated by periods (.):A: The
general_profile_space. This is encoded as one or two characters:The first character is
A,B, orC, representinggeneral_profile_space1,2, or3, or no character, representinggeneral_profile_space0.The second character is a decimal number representing the
general_profile_idc.In the above examples, the value1meansgeneral_profile_space === 0(no character) andgeneral_profile_idc === 1.
B: A 32-bit value representing one or more general profile compatibility flags (
general_profile_compatibility_flag), encoded in hexadecimal (leading zeroes may be omitted), and specified in reverse bit order from most to least significant. The values can range from31(most significant) to0(least significant), and are specified in ISO/IEC 23008-2.In the above examples, the value
6meansgeneral_profile_compatibility_flag === 6.
C: The
general_tier_flag, encoded asL(general_tier_flag === 0) orH(general_tier_flag === 1), followed by thegeneral_level_idc, encoded as a decimal number.In the above examples, the value
L186meansgeneral_tier_flag === 0followed bygeneral_level_idc === 186.
D: One or more 6-byte constraint flags. Note that each flag is encoded as a hexadecimal number, and separated by an additional period; trailing bytes that are zero may be omitted.
In the above examples, there is only one constraint flag present —
B0.
hev1[.A.B.C.D](Variable resolution HEVC): The
hev1codec parameters have the same syntax as thehvc1codec parameters.
WebM
The basic form for a WebM codecs parameter is to list one or more of the four WebM codecs by name, separated by commas. The table below shows some examples:
MIME typeDescriptionvideo/webm;codecs="vp8"A WebM video with VP8 video in it; no audio is specified.video/webm;codecs="vp9"A WebM video with VP9 video in it.audio/webm;codecs="vorbis"Vorbis audio in a WebM container.audio/webm;codecs="opus"Opus audio in a WebM container.video/webm;codecs="vp8,vorbis"A WebM container with VP8 video and Vorbis audio.video/webm;codecs="vp9,opus"A WebM container with VP9 video and Opus audio.The strings vp8.0 and vp9.0 also work, but are not recommended.
Using the codecs parameter
You can use the codecs parameter in a few situations. Firstly, you can use it with the <source> element when creating an <audio> or <video> element, in order to establish a group of options for the browser to choose from when selecting the format of the media to present to the user in the element.
You can also use the codecs parameter when specifying a MIME media type to the MediaSource/isTypeSupported() method; this method returns a Boolean which indicates whether or not the media is likely to work on the current device.
See also
The
<source>element, child of the<audio>and<video>elementsHigh Efficiency Video Coding on Wikipedia