Registry / http-networking / h264-profile-level-id

h264-profile-level-id

JSON →
library1.0.0jsnpmunverified

The `h264-profile-level-id` package is a TypeScript utility designed to accurately process H.264 `profile-level-id` values, which are critical in WebRTC SDP negotiation. It is based on the robust C++ implementation found in Google's `libwebrtc` project, ensuring compatibility and correctness with widely used WebRTC stacks. Currently at version `2.3.2`, the library maintains active development, aligning with updates in the WebRTC ecosystem. Its primary differentiator is its direct lineage from `libwebrtc`, providing a reliable, type-safe API for parsing, serializing, and comparing H.264 profile and level identifiers, including specialized functions for SDP parameter handling. It supports Node.js environments `>=20` and ships with comprehensive TypeScript types, making it suitable for modern JavaScript and TypeScript projects that interact with H.264 video codecs.

npm install h264-profile-level-id
INSTALL
IMPORT
SIG · H264-PROFILE-LEVEL
H
h264-profile-level-id
http-networkingjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Profile
import { Profile } from 'h264-profile-level-id';
import Profile from 'h264-profile-level-id';
Enums like Profile are named exports. This library is primarily ESM, so CJS `require` should be avoided.
ProfileLevelId
import { ProfileLevelId } from 'h264-profile-level-id';
const ProfileLevelId = require('h264-profile-level-id').ProfileLevelId;
The library is ESM-first; direct `require` with named exports is not the idiomatic way to consume it. Use `import`.
parseProfileLevelId
import { parseProfileLevelId } from 'h264-profile-level-id';
import * as H264 from 'h264-profile-level-id'; H264.parseProfileLevelId(...);
While `* as` works, directly importing the specific named function is generally preferred for tree-shaking and clarity.

Demonstrates creating, converting, parsing, and comparing H264 profile-level-id values, including SDP parameter handling.

import { Profile, Level, ProfileLevelId, parseProfileLevelId, profileLevelIdToString, profileToString, levelToString, parseSdpProfileLevelId, isSameProfile } from 'h264-profile-level-id'; // 1. Create a ProfileLevelId instance const myProfileLevelId = new ProfileLevelId(Profile.High, Level.L4_1); console.log(`Created: ${profileToString(myProfileLevelId.profile)} Level ${levelToString(myProfileLevelId.level)}`); // 2. Convert an instance to its canonical string representation const profileLevelString = profileLevelIdToString(myProfileLevelId); console.log(`Canonical string: ${profileLevelString}`); // 3. Parse a profile-level-id string const parsedId = parseProfileLevelId('42c01f'); // Example: Constrained Baseline, Level 3.1 if (parsedId) { console.log(`Parsed '42c01f': Profile ${profileToString(parsedId.profile)}, Level ${levelToString(parsedId.level)}`); } else { console.log("Could not parse '42c01f'"); } // 4. Parse from an SDP-like parameter object const sdpParams = { 'profile-level-id': '4d0029', 'packetization-mode': '1' }; // Main Profile, Level 4.1 const sdpParsedId = parseSdpProfileLevelId(sdpParams); if (sdpParsedId) { console.log(`Parsed from SDP: ${profileToString(sdpParsedId.profile)} Level ${levelToString(sdpParsedId.level)}`); } // 5. Compare profiles const profile1 = { 'profile-level-id': '42c01f' }; const profile2 = { 'profile-level-id': '42e01f' }; // Different profile const profile3 = { 'profile-level-id': '42c01d' }; // Same profile, different level console.log(`Is profile1 same as profile2 (different profile)? ${isSameProfile(profile1, profile2)}`); console.log(`Is profile1 same as profile3 (same profile)? ${isSameProfile(profile1, profile3)}`);
Debug
Known issues
gotcha`parseProfileLevelId()` and `profileLevelIdToString()` return `undefined` for invalid input strings or `ProfileLevelId` instances, rather than throwing an error. Always check the return value.
fix
Use conditional checks (e.g., `if (parsedId) { ... }`) or nullish coalescing operators (`??`) to handle potential `undefined` return values.
affects: >=1.0.0
gotcha`parseSdpProfileLevelId()` returns a default `ProfileLevelId` if the `'profile-level-id'` key is missing from the input `params` object, but returns `undefined` if the key is present but its value is an invalid H264 profile-level-id string. This asymmetric behavior can be a source of bugs if not handled carefully.
fix
Explicitly check for the presence of the `'profile-level-id'` key if distinguishing between missing and invalid input is critical. Always check for `undefined` return.
affects: >=1.0.0
gotchaThis library is ESM-first and targets Node.js `>=20` as indicated by `engines` in `package.json`. While it may transpile for older Node.js versions or CJS, the recommended usage is with native ES Modules.
fix
Ensure your project is configured for ESM (`"type": "module"` in `package.json`) and use `import` statements. For CJS, dynamic `import()` or transpilation might be required, but it's not the primary intended usage.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'profile')
Attempting to access properties of a `ProfileLevelId` object that was `undefined` because a parsing function like `parseProfileLevelId()` or `parseSdpProfileLevelId()` received invalid input.
fix
Always check the return value of parsing functions before attempting to access its properties, as they return `undefined` for invalid inputs. For example: `const parsed = parseProfileLevelId(str); if (parsed) { console.log(parsed.profile); }`
ERR_REQUIRE_ESM
Attempting to `require()` this package in a CommonJS environment, but the package is an ES Module.
fix
Configure your project to use ES Modules by adding `"type": "module"` to your `package.json`, or if strictly in a CJS file, use dynamic `import('h264-profile-level-id').then(...)`.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
h264-profile-level-id — npm install h264-profile-level-id · libregistry