https://github.com/dmnsgn/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').
https://github.com/dmnsgn/media-codecs
avc codecs mp4 vp webcodecs webm
Last synced: 10 months ago
JSON representation
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').
- Host: GitHub
- URL: https://github.com/dmnsgn/media-codecs
- Owner: dmnsgn
- License: mit
- Created: 2023-04-14T21:31:50.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-02-26T20:45:20.000Z (12 months ago)
- Last Synced: 2025-04-20T22:32:52.466Z (10 months ago)
- Topics: avc, codecs, mp4, vp, webcodecs, webm
- Language: JavaScript
- Homepage: https://dmnsgn.github.io/media-codecs/
- Size: 990 KB
- Stars: 29
- Watchers: 2
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# media-codecs
[](https://www.npmjs.com/package/media-codecs)
[](https://www.npmjs.com/package/media-codecs)
[](https://bundlephobia.com/package/media-codecs)
[](https://github.com/dmnsgn/media-codecs/blob/main/package.json)
[](https://github.com/microsoft/TypeScript)
[](https://conventionalcommits.org)
[](https://github.com/prettier/prettier)
[](https://github.com/eslint/eslint)
[](https://github.com/dmnsgn/media-codecs/blob/main/LICENSE.md)
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](https://developer.mozilla.org/en-US/docs/Web/API/WebCodecs_API) VideoEncoder [configure parameters](https://developer.mozilla.org/en-US/docs/Web/API/VideoEncoder/configure#parameters). Supports Advanced Video Coding ([AVC](https://en.wikipedia.org/wiki/Advanced_Video_Coding)), Video Partition ([VP8/VP9](<(https://www.webmproject.org/vp9/)>)), AOMedia Video ([AV1](https://en.wikipedia.org/wiki/AV1)) and partially High Efficiency Video Coding [HEVC](https://en.wikipedia.org/wiki/High_Efficiency_Video_Coding).
See the [demo](https://dmnsgn.github.io/media-codecs) that checks current browser support of all [video codecs](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Video_codecs#common_codecs) and MDN's [Codecs in common media types](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/codecs_parameter).
[](https://paypal.me/dmnsgn)
[](https://commerce.coinbase.com/checkout/56cbdf28-e323-48d8-9c98-7019e72c97f3)
[](https://twitter.com/dmnsgn)

## Installation
```bash
npm install media-codecs
```
## Usage
```js
import { 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:
- [ ] HEVC compatibility and constraints
- [ ] VP, HEVC and AV1 optional parameters
## API
## Modules
## Typedefs
-
AVProfileItem :object -
VCProfileItem :object -
CodecItem :object -
MediaCodecItem :object -
VPCodecOptions :object -
AVCodecOptions :object -
AVCCodecOptions :object -
HEVCCodecOptions :object
## media-codecs
- [media-codecs](#module_media-codecs)
- [.VP](#module_media-codecs.VP) : [vp](#module_vp)
- [.AV](#module_media-codecs.AV) : [av](#module_av)
- [.AVC](#module_media-codecs.AVC) : [avc](#module_avc)
- [.HEVC](#module_media-codecs.HEVC) : [hevc](#module_hevc)
### media-codecs.VP : [vp](#module_vp)
**Kind**: static property of [media-codecs](#module_media-codecs)
### media-codecs.AV : [av](#module_av)
**Kind**: static property of [media-codecs](#module_media-codecs)
### media-codecs.AVC : [avc](#module_avc)
**Kind**: static property of [media-codecs](#module_media-codecs)
### media-codecs.HEVC : [hevc](#module_hevc)
**Kind**: static property of [media-codecs](#module_media-codecs)
## av
- [av](#module_av)
- [.AV_CODECS](#module_av.AV_CODECS) : [Array.<CodecItem>](#CodecItem)
- [.AV_PROFILES](#module_av.AV_PROFILES) : [Array.<AVProfileItem>](#AVProfileItem)
- [.AV_LEVELS](#module_av.AV_LEVELS) : Array.<string>
- [.AV_TIER](#module_av.AV_TIER) : Array.<string>
- [.AV_BIT_DEPTH](#module_av.AV_BIT_DEPTH) : Array.<number>
- [.getAllItems()](#module_av.getAllItems) ⇒ [Array.<MediaCodecItem>](#MediaCodecItem)
- [.getCodec(options)](#module_av.getCodec) ⇒ string
- [.getCodecName(codec)](#module_av.getCodecName) ⇒ string
### av.AV_CODECS : [Array.<CodecItem>](#CodecItem)
List of codecs
**Kind**: static constant of [av](#module_av)
### av.AV_PROFILES : [Array.<AVProfileItem>](#AVProfileItem)
List of AV profiles numbers
**Kind**: static constant of [av](#module_av)
**See**: [av1-spec](https://aomediacodec.github.io/av1-spec/#profiles)
### av.AV_LEVELS : Array.<string>
AV Levels
**Kind**: static constant of [av](#module_av)
**See**: [av1-spec](https://aomediacodec.github.io/av1-spec/#levels)
### av.AV_TIER : Array.<string>
List of supported tier
**Kind**: static constant of [av](#module_av)
### av.AV_BIT_DEPTH : Array.<number>
List of supported bit depth
**Kind**: static constant of [av](#module_av)
### av.getAllItems() ⇒ [Array.<MediaCodecItem>](#MediaCodecItem)
Return a list of all possible codec parameter string and their human readable names
**Kind**: static method of [av](#module_av)
### av.getCodec(options) ⇒ string
Get a codec parameter string
**Kind**: static method of [av](#module_av)
| Param | Type |
| ------- | ---------------------------------------------- |
| options | [AVCodecOptions](#AVCodecOptions) |
### av.getCodecName(codec) ⇒ string
Get a codec human readbable name
**Kind**: static method of [av](#module_av)
| Param | Type | Description |
| ----- | ------------------- | -------------------------------------------------- |
| codec | string | a codec string (av01.P.LLT.DD eg. "av01.P.LLT.DD") |
## avc
- [avc](#module_avc)
- [.AVC_PROFILES](#module_avc.AVC_PROFILES) : [Array.<VCProfileItem>](#VCProfileItem)
- [.AVC_LEVELS](#module_avc.AVC_LEVELS) : Array.<number>
- [.getAllItems()](#module_avc.getAllItems) ⇒ [Array.<MediaCodecItem>](#MediaCodecItem)
- [.getCodec(options)](#module_avc.getCodec) ⇒ string
- [.getCodecName(codec)](#module_avc.getCodecName) ⇒ string
### avc.AVC_PROFILES : [Array.<VCProfileItem>](#VCProfileItem)
List of profiles with their profile numbers (PP) and the constraints component (CC).
**Kind**: static constant of [avc](#module_avc)
### avc.AVC_LEVELS : Array.<number>
AVC Levels
**Kind**: static constant of [avc](#module_avc)
**See**: [wikipedia.org](https://en.wikipedia.org/wiki/Advanced_Video_Coding#Levels)
### avc.getAllItems() ⇒ [Array.<MediaCodecItem>](#MediaCodecItem)
Return a list of all possible codec parameter string and their human readable names
**Kind**: static method of [avc](#module_avc)
### avc.getCodec(options) ⇒ string
Get a codec parameter string
**Kind**: static method of [avc](#module_avc)
| Param | Type |
| ------- | ------------------------------------------------ |
| options | [AVCCodecOptions](#AVCCodecOptions) |
### avc.getCodecName(codec) ⇒ string
Get a codec human readbable name
**Kind**: static method of [avc](#module_avc)
| Param | Type | Description |
| ----- | ------------------- | -------------------------------------------------- |
| codec | string | a codec string (cccc.PP.LL.DD eg. "vp09.00.10.08") |
## hevc
- [hevc](#module_hevc)
- [.HEVC_PROFILES](#module_hevc.HEVC_PROFILES) : [Array.<VCProfileItem>](#VCProfileItem)
- [.HEVC_PROFILE_COMPATIBILITY](#module_hevc.HEVC_PROFILE_COMPATIBILITY) : Array.<number>
- [.HEVC_LEVELS](#module_hevc.HEVC_LEVELS) : Array.<string>
- [.HEVC_TIER](#module_hevc.HEVC_TIER) : Array.<string>
- [.getAllItems()](#module_hevc.getAllItems) ⇒ [Array.<MediaCodecItem>](#MediaCodecItem)
- [.getCodec(options)](#module_hevc.getCodec) ⇒ string
- [.getCodecName(codec)](#module_hevc.getCodecName) ⇒ string
### hevc.HEVC_PROFILES : [Array.<VCProfileItem>](#VCProfileItem)
List of profiles with their profile numbers (PP) and the compatibility (C).
See Annexe 3 Profiles
**Kind**: static constant of [hevc](#module_hevc)
### hevc.HEVC_PROFILE_COMPATIBILITY : Array.<number>
HEVC Profile Compatibility as a number in the 0..32 range
TODO: is that correct
**Kind**: static constant of [hevc](#module_hevc)
### hevc.HEVC_LEVELS : Array.<string>
HEVC Levels
**Kind**: static constant of [hevc](#module_hevc)
**See**: [hevc-levels](https://en.wikipedia.org/wiki/High_Efficiency_Video_Coding#Tiers_and_levels)
### hevc.HEVC_TIER : Array.<string>
List of supported tier
**Kind**: static constant of [hevc](#module_hevc)
### hevc.getAllItems() ⇒ [Array.<MediaCodecItem>](#MediaCodecItem)
Return a list of all possible codec parameter string and their human readable names
**Kind**: static method of [hevc](#module_hevc)
### hevc.getCodec(options) ⇒ string
Get a codec parameter string
**Kind**: static method of [hevc](#module_hevc)
| Param | Type |
| ------- | -------------------------------------------------- |
| options | [HEVCCodecOptions](#HEVCCodecOptions) |
### hevc.getCodecName(codec) ⇒ string
Get a codec human readbable name
**Kind**: static method of [hevc](#module_hevc)
| Param | Type | Description |
| ----- | ------------------- | ------------------------------------------------------- |
| codec | string | a codec string (cccc.PP.C.TLL.CC eg. "hev1.1.3.H34.B0") |
## vp
- [vp](#module_vp)
- [.VP_CODECS](#module_vp.VP_CODECS) : [Array.<CodecItem>](#CodecItem)
- [.VP_PROFILES](#module_vp.VP_PROFILES) : Array.<number>
- [.VP_LEVELS](#module_vp.VP_LEVELS) : Array.<string>
- [.VP_BIT_DEPTH](#module_vp.VP_BIT_DEPTH) : Array.<number>
- [.getAllItems()](#module_vp.getAllItems) ⇒ [Array.<MediaCodecItem>](#MediaCodecItem)
- [.getCodec(options)](#module_vp.getCodec) ⇒ string
- [.getCodecName(codec)](#module_vp.getCodecName) ⇒ string
### vp.VP_CODECS : [Array.<CodecItem>](#CodecItem)
List of codecs
**Kind**: static constant of [vp](#module_vp)
### vp.VP_PROFILES : Array.<number>
List of VP profiles numbers
**Kind**: static constant of [vp](#module_vp)
### vp.VP_LEVELS : Array.<string>
VP Levels
**Kind**: static constant of [vp](#module_vp)
**See**: [webmproject.org](https://www.webmproject.org/vp9/mp4/)
### vp.VP_BIT_DEPTH : Array.<number>
List of supported bit depth
**Kind**: static constant of [vp](#module_vp)
### vp.getAllItems() ⇒ [Array.<MediaCodecItem>](#MediaCodecItem)
Return a list of all possible codec parameter string and their human readable names
**Kind**: static method of [vp](#module_vp)
### vp.getCodec(options) ⇒ string
Get a codec parameter string
**Kind**: static method of [vp](#module_vp)
| Param | Type |
| ------- | ---------------------------------------------- |
| options | [VPCodecOptions](#VPCodecOptions) |
### vp.getCodecName(codec) ⇒ string
Get a codec human readbable name
**Kind**: static method of [vp](#module_vp)
| Param | Type | Description |
| ----- | ------------------- | ------------------------------------------------ |
| codec | string | a codec string (avc1[.PPCCLL] eg. "avc1.640028") |
## AVProfileItem : object
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| ---- | ------------------- | ----------------------------- |
| name | string | |
| PP | string | profile numbers (seq_profile) |
## VCProfileItem : object
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| ---- | ------------------- | ----------------------------------- |
| name | string | |
| PP | string | profile numbers as hex string |
| CC | string | constraints component as hex string |
## CodecItem : object
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| ---- | ------------------- | ----------------------------------- |
| name | string | |
| cccc | string | the four-character ID for the codec |
## MediaCodecItem : object
**Kind**: global typedef
**Properties**
| Name | Type |
| ----- | ------------------- |
| name | string |
| codec | string |
## VPCodecOptions : object
**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 | |
## AVCodecOptions : object
**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 |
## AVCCodecOptions : object
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| ------- | ------------------- | --------------------------------- |
| profile | string | AVC profile name (eg. "Baseline") |
| level | string | |
## HEVCCodecOptions : object
**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](https://github.com/dmnsgn/media-codecs/blob/main/LICENSE.md).