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.
npm install media-codecsimport { AVC } from "media-codecs";
const codec = AVC.getCodec({ profile: "Main", level: "4.2" });
// => avc1.4d002a
const mimeType = `video/mp4;codecs="${codec}"`;
console.log(MediaSource.isTypeSupported(mimeType));Roadmap:
- VP and AV1 optional parameters
- AVProfileItem :
object - AVCProfileItem :
object - HEVCProfileItem :
object - CodecItem :
object - MediaCodecItem :
object - VPCodecOptions :
object - AVCodecOptions :
object - AVCCodecOptions :
object - HEVCCodecOptions :
object
media-codecs.VP : vp
Kind: static property of media-codecs
media-codecs.AV : av
Kind: static property of media-codecs
media-codecs.AVC : avc
Kind: static property of media-codecs
media-codecs.HEVC : hevc
Kind: static property of media-codecs
- av
- .AV_CODECS :
Array.<CodecItem> - .AV_PROFILES :
Array.<AVProfileItem> - .AV_LEVELS :
Array.<string> - .AV_TIER :
Array.<string> - .AV_BIT_DEPTH :
Array.<number> - .getAllItems() ⇒
Array.<MediaCodecItem> - .getCodec(options) ⇒
string - .getCodecName(codec) ⇒
string
- .AV_CODECS :
av.AV_CODECS : Array.<CodecItem>
List of codecs
Kind: static constant of av
av.AV_PROFILES : Array.<AVProfileItem>
List of AV profiles numbers
Kind: static constant of av
See: av1-spec
AV Levels
Kind: static constant of av
See: av1-spec
List of supported tier
Kind: static constant of av
List of supported bit depth
Kind: static constant of av
av.getAllItems() ⇒ Array.<MediaCodecItem>
Return a list of all possible codec parameter string and their human readable names
Kind: static method of av
Get a codec parameter string
Kind: static method of av
| Param | Type |
|---|---|
| options | AVCodecOptions |
Get a codec human readbable name
Kind: static method of av
| Param | Type | Description |
|---|---|---|
| codec | string |
a codec string (av01.P.LLT.DD eg. "av01.P.LLT.DD") |
- avc
- .AVC_PROFILES :
Array.<AVCProfileItem> - .AVC_LEVELS :
Array.<number> - .getAllItems() ⇒
Array.<MediaCodecItem> - .getCodec(options) ⇒
string - .getCodecName(codec) ⇒
string
- .AVC_PROFILES :
avc.AVC_PROFILES : Array.<AVCProfileItem>
List of profiles with their profile numbers (PP) and the constraints component (CC).
Kind: static constant of avc
AVC Levels
Kind: static constant of avc
See: wikipedia.org
avc.getAllItems() ⇒ Array.<MediaCodecItem>
Return a list of all possible codec parameter string and their human readable names
Kind: static method of avc
Get a codec parameter string
Kind: static method of avc
| Param | Type |
|---|---|
| options | AVCCodecOptions |
Get a codec human readbable name
Kind: static method of avc
| Param | Type | Description |
|---|---|---|
| codec | string |
a codec string (cccc.PP.LL.DD eg. "vp09.00.10.08") |
- hevc
- .HEVC_PROFILES :
Array.<HEVCProfileItem> - .HEVC_CONSTRAINTS :
Array.<Array.<string>> - .HEVC_REXT_CONSTRAINTS :
Array.<Array.<string>> - .HEVC_HT_CONSTRAINTS :
Array.<Array.<string>> - .HEVC_LEVELS :
Array.<string> - .HEVC_TIER :
Array.<string> - .formatConstraints(constraints) ⇒
string - .getAllItems([defaultConstraints]) ⇒
Array.<MediaCodecItem> - .getCodec(options) ⇒
string - .getCodecName(codec) ⇒
string
- .HEVC_PROFILES :
hevc.HEVC_PROFILES : Array.<HEVCProfileItem>
List of profiles with their profile numbers (PP), profile compatibility flags (C), and default constraint bytes.
C is a hex string where bit N being set means the stream conforms to HEVC profile N. constraints holds up to 6 bytes encoding general source and profile-specific constraint flags; trailing zero bytes are omitted when formatted.
Kind: static constant of hevc
See: hevc-spec
Constraint arrays for standard profiles (PP 1, 2, 3).
Only byte 0 is used; its layout is: bit 7: general_progressive_source_flag bit 6: general_interlaced_source_flag bit 5: general_non_packed_constraint_flag bit 4: general_frame_only_constraint_flag bit 3: general_one_picture_only_constraint_flag bits 2–0: reserved zero 32 entries covering all combinations of bits 7–3.
Kind: static constant of hevc
Constraint arrays for RExt non-HT profiles (PP 4, 6, 7, 8).
Byte 0: bits 7–4: source flags (progressive, interlaced, non_packed, frame_only) bit 3: general_max_12bit_constraint_flag bit 2: general_max_10bit_constraint_flag (implies max_12bit) bit 1: general_max_8bit_constraint_flag (implies max_10bit) bit 0: general_max_422chroma_constraint_flag
Byte 1 (omitted when all zero): bit 7: general_max_420chroma_constraint_flag (implies max_422chroma) bit 6: general_max_monochrome_constraint_flag (implies max_420chroma) bit 5: general_intra_constraint_flag bit 4: general_one_picture_only_constraint_flag bit 3: general_lower_bit_rate_constraint_flag bits 2–0: reserved zero
Monotonic depth: max_8bit → max_10bit → max_12bit (4 valid combos). Monotonic chroma: max_monochrome → max_420chroma → max_422chroma (4 valid combos). 2048 entries total (16 source × 4 depth × 4 chroma × 2 intra × 2 opo × 2 lbr).
Kind: static constant of hevc
Constraint arrays for HT profiles (PP 5, 9, 10, 11).
Same byte layout as HEVC_REXT_CONSTRAINTS but byte 1 bit 2 carries general_max_14bit_constraint_flag, extending the depth hierarchy: max_8bit → max_10bit → max_12bit → max_14bit (5 valid depth combos). 2560 entries total (16 source × 5 depth × 4 chroma × 2 intra × 2 opo × 2 lbr).
Kind: static constant of hevc
HEVC Levels
Kind: static constant of hevc
See: hevc-levels
List of supported tier
Kind: static constant of hevc
Format up to 6 constraint bytes as a dot-separated lowercase hex string, omitting trailing zero bytes.
Kind: static method of hevc
| Param | Type |
|---|---|
| constraints | Array.<string> |
hevc.getAllItems([defaultConstraints]) ⇒ Array.<MediaCodecItem>
Return a list of all possible codec parameter string and their human readable names
Kind: static method of hevc
| Param | Type | Default | Description |
|---|---|---|---|
| [defaultConstraints] | boolean |
false |
when true, return only items using each profile's default constraints |
Get a codec parameter string
Kind: static method of hevc
| Param | Type |
|---|---|
| options | HEVCCodecOptions |
Get a codec human readable name
Kind: static method of hevc
| Param | Type | Description |
|---|---|---|
| codec | string |
a codec string (eg. "hev1.1.6.L93.b0") |
- vp
- .VP_CODECS :
Array.<CodecItem> - .VP_PROFILES :
Array.<number> - .VP_LEVELS :
Array.<string> - .VP_BIT_DEPTH :
Array.<number> - .getAllItems() ⇒
Array.<MediaCodecItem> - .getCodec(options) ⇒
string - .getCodecName(codec) ⇒
string
- .VP_CODECS :
vp.VP_CODECS : Array.<CodecItem>
List of codecs
Kind: static constant of vp
List of VP profiles numbers
Kind: static constant of vp
VP Levels
Kind: static constant of vp
See: webmproject.org
List of supported bit depth
Kind: static constant of vp
vp.getAllItems() ⇒ Array.<MediaCodecItem>
Return a list of all possible codec parameter string and their human readable names
Kind: static method of vp
Get a codec parameter string
Kind: static method of vp
| Param | Type |
|---|---|
| options | VPCodecOptions |
Get a codec human readbable name
Kind: static method of vp
| Param | Type | Description |
|---|---|---|
| codec | string |
a codec string (avc1[.PPCCLL] eg. "avc1.640028") |
Kind: global typedef Properties
| Name | Type | Description |
|---|---|---|
| name | string |
|
| P | string |
profile numbers (seq_profile) |
Kind: global typedef Properties
| Name | Type | Description |
|---|---|---|
| name | string |
|
| PP | string |
profile numbers as hex string |
| CC | string |
constraints component as hex string |
Kind: global typedef Properties
| Name | Type | Description |
|---|---|---|
| name | string |
|
| PP | string |
profile numbers as decimal string |
| C | string |
profile compatibility flags as hex string (bit N set = conforms to HEVC profile N) |
| constraints | Array.<string> |
default constraint bytes as hex strings (up to 6); trailing "00" bytes are omitted when formatted |
Kind: global typedef Properties
| Name | Type | Description |
|---|---|---|
| name | string |
|
| cccc | string |
the four-character ID for the codec |
Kind: global typedef Properties
| Name | Type |
|---|---|
| name | string |
| codec | string |
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 |
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 |
Kind: global typedef Properties
| Name | Type | Description |
|---|---|---|
| profile | string |
AVC profile name (eg. "Baseline") |
| level | string |
Kind: global typedef Properties
| Name | Type | Description |
|---|---|---|
| profile | string |
HEVC profile name (eg. "Main 10") |
| level | string |
|
| tier | string |
"Main" or "High" |
| [constraints] | Array.<string> |
up to 6 constraint bytes as hex strings; defaults to the profile's standard constraints |
MIT. See license file.
