media-codecs
Get a codec parameter string (like "avc1.4d002a"
) from human readable options (like { name: "Main", level: "4.2" }
) and back to a descriptive name ("AVC Main Profile Level 4.2").
Useful for checking supported codecs with HTMLMediaElement.canPlayType
/ MediaSource.isTypeSupported
and to pass as option for the WebCodecs API VideoEncoder configure parameters. Supports Advanced Video Coding (AVC), Video Partition (VP8/VP9), AOMedia Video (AV1) and partially High Efficiency Video Coding HEVC.
See the demo that checks current browser support of all video codecs and MDN's Codecs in common media types.
Installation
npm install media-codecs
Usage
import { AVC } from "media-codecs";
const codec = AVC.getCodec({ name: "Main", level: "4.2" });
// => avc1.4d002a
const mimeType = `video/mp4;codecs="${codec}"`;
console.log(MediaSource.isTypeSupported(mimeType));
Roadmap:
- [ ] HEVC compatibility and constraints
- [ ] VP, HEVC and AV1 optional parameters
API
Modules
Typedefs
-
VCProfileItem :
Object
-
CodecItem :
Object
-
MediaCodecItem :
Object
-
VPCodecOptions :
Object
-
AVCodecOptions :
Object
-
AVCCodecOptions :
Object
-
HEVCCodecOptions :
Object
index
vp
-
vp
-
~VP_CODECS :
Array.<CodecItem>
-
~VP_PROFILES :
Array.<number>
-
~VP_LEVELS :
Array.<number>
-
~VP_BIT_DEPTH :
Array.<number>
-
~getAllItems() ⇒
Array.<MediaCodecItem>
-
~getCodec(options) ⇒
string
-
~getCodecName(codec) ⇒
string
-
~VP_CODECS :
Array.<CodecItem>
vp~VP_CODECS : List of codecs
Kind: inner constant of vp
Array.<number>
vp~VP_PROFILES : List of VP profiles numbers
Kind: inner constant of vp
Array.<number>
vp~VP_LEVELS : VP Levels
Kind: inner constant of vp
See: webmproject.org
Array.<number>
vp~VP_BIT_DEPTH : List of supported bit depth
Kind: inner constant of vp
Array.<MediaCodecItem>
vp~getAllItems() ⇒ Return a list of all possible codec parameter string and their human readable names
Kind: inner method of vp
string
vp~getCodec(options) ⇒ Get a codec parameter string
Kind: inner method of vp
Param | Type |
---|---|
options | VPCodecOptions |
string
vp~getCodecName(codec) ⇒ Get a codec human readbable name
Kind: inner method of vp
Param | Type | Description |
---|---|---|
codec | string |
a codec string (avc1[.PPCCLL] eg. "avc1.640028") |
hevc
-
hevc
-
~See :
Array.<VCProfileItem>
-
~HEVC_PROFILE_COMPATIBILITY :
Array.<number>
-
~HEVC_LEVELS :
Array.<number>
-
~HEVC_TIER :
Array.<number>
-
~getAllItems() ⇒
Array.<MediaCodecItem>
-
~getCodec(options) ⇒
string
-
~getCodecName(codec) ⇒
string
-
~See :
Array.<VCProfileItem>
hevc~See : List of profiles with their profile numbers (PP) and the compatibility (C).
Kind: inner constant of hevc
Array.<number>
hevc~HEVC_PROFILE_COMPATIBILITY : HEVC Profile Compatibility as a number in the 0..32 range TODO: is that correct
Kind: inner constant of hevc
Array.<number>
hevc~HEVC_LEVELS : HEVC Levels
Kind: inner constant of hevc
See: hevc-levels
Array.<number>
hevc~HEVC_TIER : List of supported tier
Kind: inner constant of hevc
Array.<MediaCodecItem>
hevc~getAllItems() ⇒ Return a list of all possible codec parameter string and their human readable names
Kind: inner method of hevc
string
hevc~getCodec(options) ⇒ Get a codec parameter string
Kind: inner method of hevc
Param | Type |
---|---|
options | HEVCCodecOptions |
string
hevc~getCodecName(codec) ⇒ Get a codec human readbable name
Kind: inner method of hevc
Param | Type | Description |
---|---|---|
codec | string |
a codec string (cccc.PP.C.TLL.CC eg. "hev1.1.3.H34.B0") |
avc
-
avc
-
~AVC_PROFILES :
Array.<VCProfileItem>
-
~AVC_LEVELS :
Array.<number>
-
~getAllItems() ⇒
Array.<MediaCodecItem>
-
~getCodec(options) ⇒
string
-
~getCodecName(codec) ⇒
string
-
~AVC_PROFILES :
Array.<VCProfileItem>
avc~AVC_PROFILES : List of profiles with their profile numbers (PP) and the constraints component (CC).
Kind: inner constant of avc
Array.<number>
avc~AVC_LEVELS : AVC Levels
Kind: inner constant of avc
See: wikipedia.org
Array.<MediaCodecItem>
avc~getAllItems() ⇒ Return a list of all possible codec parameter string and their human readable names
Kind: inner method of avc
string
avc~getCodec(options) ⇒ Get a codec parameter string
Kind: inner method of avc
Param | Type |
---|---|
options | AVCCodecOptions |
string
avc~getCodecName(codec) ⇒ Get a codec human readbable name
Kind: inner method of avc
Param | Type | Description |
---|---|---|
codec | string |
a codec string (cccc.PP.LL.DD eg. "vp09.00.10.08") |
av
-
av
-
~AV_CODECS :
Array.<CodecItem>
-
~AV_PROFILES :
Array.<number>
-
~AV_LEVELS :
Array.<number>
-
~AV_TIER :
Array.<number>
-
~AV_BIT_DEPTH :
Array.<number>
-
~getAllItems() ⇒
Array.<MediaCodecItem>
-
~getCodec(options) ⇒
string
-
~getCodecName(codec) ⇒
string
-
~AV_CODECS :
Array.<CodecItem>
av~AV_CODECS : List of codecs
Kind: inner constant of av
Array.<number>
av~AV_PROFILES : List of AV profiles numbers
Kind: inner constant of av
See: av1-spec
Array.<number>
av~AV_LEVELS : AV Levels
Kind: inner constant of av
See: av1-spec
Array.<number>
av~AV_TIER : List of supported tier
Kind: inner constant of av
Array.<number>
av~AV_BIT_DEPTH : List of supported bit depth
Kind: inner constant of av
Array.<MediaCodecItem>
av~getAllItems() ⇒ Return a list of all possible codec parameter string and their human readable names
Kind: inner method of av
string
av~getCodec(options) ⇒ Get a codec parameter string
Kind: inner method of av
Param | Type |
---|---|
options | AVCodecOptions |
string
av~getCodecName(codec) ⇒ Get a codec human readbable name
Kind: inner method of av
Param | Type | Description |
---|---|---|
codec | string |
a codec string (av01.P.LLT.DD eg. "av01.P.LLT.DD") |
Object
VCProfileItem : Kind: global typedef Properties
Name | Type | Description |
---|---|---|
name | string |
|
PP | string |
profile numbers as hex string |
CC | string |
constraints component as hex string |
Object
CodecItem : Kind: global typedef Properties
Name | Type | Description |
---|---|---|
name | string |
|
cccc | string |
the four-character ID for the codec |
Object
MediaCodecItem : Kind: global typedef Properties
Name | Type |
---|---|
name | string |
codec | string |
Object
VPCodecOptions : Kind: global typedef Properties
Name | Type | Description |
---|---|---|
name | string |
Human readable codec name: "VP8" or "VP9" |
profile | number |
0, 1, 2 or 3 |
level | string |
|
bitDepth | number |
Object
AVCodecOptions : Kind: global typedef Properties
Name | Type | Description |
---|---|---|
name | string |
Human readable codec name: "AV1", potentially AV2 in the future |
profile | string |
AV profile name: "Main", "High" or "Professional" |
level | string |
|
tier | string |
"Main" or "High" |
bitDepth | number |
8, 10 or 12 |
Object
AVCCodecOptions : Kind: global typedef Properties
Name | Type | Description |
---|---|---|
profile | string |
AVC profile name (eg. "Baseline") |
level | string |
Object
HEVCCodecOptions : Kind: global typedef Properties
Name | Type | Description |
---|---|---|
profile | string |
HEVC profile name (eg. "Main 10") |
compatibility | number |
|
level | string |
|
tier | string |
"Main" or "High" |
constraint | string |
TODO |
License
MIT. See license file.