{"id":13278,"library":"h264-profile-level-id","title":"H264 Profile Level ID Utility","description":"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.","status":"active","version":"2.3.2","language":"javascript","source_language":"en","source_url":"https://github.com/versatica/h264-profile-level-id","tags":["javascript","webrtc","rtp","h264","browser","nodejs","typescript"],"install":[{"cmd":"npm install h264-profile-level-id","lang":"bash","label":"npm"},{"cmd":"yarn add h264-profile-level-id","lang":"bash","label":"yarn"},{"cmd":"pnpm add h264-profile-level-id","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Enums like Profile are named exports. This library is primarily ESM, so CJS `require` should be avoided.","wrong":"import Profile from 'h264-profile-level-id';","symbol":"Profile","correct":"import { Profile } from 'h264-profile-level-id';"},{"note":"The library is ESM-first; direct `require` with named exports is not the idiomatic way to consume it. Use `import`.","wrong":"const ProfileLevelId = require('h264-profile-level-id').ProfileLevelId;","symbol":"ProfileLevelId","correct":"import { ProfileLevelId } from 'h264-profile-level-id';"},{"note":"While `* as` works, directly importing the specific named function is generally preferred for tree-shaking and clarity.","wrong":"import * as H264 from 'h264-profile-level-id'; H264.parseProfileLevelId(...);","symbol":"parseProfileLevelId","correct":"import { parseProfileLevelId } from 'h264-profile-level-id';"}],"quickstart":{"code":"import { \n  Profile,\n  Level,\n  ProfileLevelId,\n  parseProfileLevelId,\n  profileLevelIdToString,\n  profileToString,\n  levelToString,\n  parseSdpProfileLevelId,\n  isSameProfile\n} from 'h264-profile-level-id';\n\n// 1. Create a ProfileLevelId instance\nconst myProfileLevelId = new ProfileLevelId(Profile.High, Level.L4_1);\nconsole.log(`Created: ${profileToString(myProfileLevelId.profile)} Level ${levelToString(myProfileLevelId.level)}`);\n\n// 2. Convert an instance to its canonical string representation\nconst profileLevelString = profileLevelIdToString(myProfileLevelId);\nconsole.log(`Canonical string: ${profileLevelString}`);\n\n// 3. Parse a profile-level-id string\nconst parsedId = parseProfileLevelId('42c01f'); // Example: Constrained Baseline, Level 3.1\nif (parsedId) {\n  console.log(`Parsed '42c01f': Profile ${profileToString(parsedId.profile)}, Level ${levelToString(parsedId.level)}`);\n} else {\n  console.log(\"Could not parse '42c01f'\");\n}\n\n// 4. Parse from an SDP-like parameter object\nconst sdpParams = { 'profile-level-id': '4d0029', 'packetization-mode': '1' }; // Main Profile, Level 4.1\nconst sdpParsedId = parseSdpProfileLevelId(sdpParams);\nif (sdpParsedId) {\n  console.log(`Parsed from SDP: ${profileToString(sdpParsedId.profile)} Level ${levelToString(sdpParsedId.level)}`);\n}\n\n// 5. Compare profiles\nconst profile1 = { 'profile-level-id': '42c01f' };\nconst profile2 = { 'profile-level-id': '42e01f' }; // Different profile\nconst profile3 = { 'profile-level-id': '42c01d' }; // Same profile, different level\n\nconsole.log(`Is profile1 same as profile2 (different profile)? ${isSameProfile(profile1, profile2)}`);\nconsole.log(`Is profile1 same as profile3 (same profile)? ${isSameProfile(profile1, profile3)}`);\n","lang":"typescript","description":"Demonstrates creating, converting, parsing, and comparing H264 profile-level-id values, including SDP parameter handling."},"warnings":[{"fix":"Use conditional checks (e.g., `if (parsedId) { ... }`) or nullish coalescing operators (`??`) to handle potential `undefined` return values.","message":"`parseProfileLevelId()` and `profileLevelIdToString()` return `undefined` for invalid input strings or `ProfileLevelId` instances, rather than throwing an error. Always check the return value.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"`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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"This 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.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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); }`","cause":"Attempting to access properties of a `ProfileLevelId` object that was `undefined` because a parsing function like `parseProfileLevelId()` or `parseSdpProfileLevelId()` received invalid input.","error":"TypeError: Cannot read properties of undefined (reading 'profile')"},{"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(...)`.","cause":"Attempting to `require()` this package in a CommonJS environment, but the package is an ES Module.","error":"ERR_REQUIRE_ESM"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null}