Matroska and EBML Schema Definitions
This package, `matroska-schema`, provides the official Matroska and EBML (Extensible Binary Meta Language) schema definitions for JavaScript environments. It serves as an MIT-licensed alternative to the previously GPL-licensed `schema.js` embedded within the `node-matroska` project, addressing licensing compatibility concerns for developers. The schema is automatically generated directly from the latest Matroska and EBML specifications maintained by the IETF-WG-CELLAR group, ensuring it remains current with the evolving standards for multimedia container formats. Currently at version 2.1.0, the package's release cadence is directly tied to updates in the upstream specifications, providing a reliable and permissively licensed data structure for libraries that parse, validate, or generate Matroska files, such as `node-matroska` or `node-ebml`.
Common errors
-
TypeError: Cannot read properties of undefined (reading 'find')
cause Attempting to call `find` on an undefined or incorrectly imported schema object.fixEnsure `matroska-schema` is correctly installed (`npm install matroska-schema`) and imported as a default export: `import matroskaSchema from 'matroska-schema';` or `const matroskaSchema = require('matroska-schema');` -
ERR_REQUIRE_ESM: require() of ES Module ... matroska-schema/schema.js not supported.
cause Attempting to `require()` the package in an environment configured for ES Modules where the package might be treated as ESM-only, or when the `package.json` specifies `"type": "module"` and a direct `require()` is used on a file that only exposes ESM.fixIf your project is ES Modules-based, use `import matroskaSchema from 'matroska-schema';`. If using CommonJS, ensure your Node.js version supports interop, or check if an older version of `matroska-schema` (if applicable) is strictly CommonJS. -
Cannot find module 'matroska-schema'
cause The package is not installed or not resolvable from the current working directory or `NODE_PATH`.fixRun `npm install matroska-schema` or `yarn add matroska-schema` in your project directory.
Warnings
- gotcha This package was created as an MIT-licensed alternative to a GPL-licensed schema. If migrating from older `node-matroska` versions, ensure you are using this package for broader license compatibility.
- breaking The schema is automatically generated from official Matroska and EBML specifications. While the package API remains stable, changes in the underlying specifications may alter the structure or available elements within the schema data itself. This could implicitly break parsers relying on a fixed schema structure.
- gotcha As a data-only package, `matroska-schema` doesn't enforce strict ESM/CJS compatibility beyond what Node.js provides. While `require()` and `import` generally work, ensure your project's module resolution is correctly configured, especially in bundled environments.
Install
-
npm install matroska-schema -
yarn add matroska-schema -
pnpm add matroska-schema
Imports
- matroskaSchema
import { matroskaSchema } from 'matroska-schema';import matroskaSchema from 'matroska-schema';
- matroskaSchema
const matroskaSchema = require('matroska-schema'); - SchemaEntry
import matroskaSchema from 'matroska-schema'; const ebmlHeader = matroskaSchema.find(entry => entry.name === 'EBMLHeader');
Quickstart
import matroskaSchema from 'matroska-schema';
console.log('Successfully loaded Matroska schema. Total entries:', matroskaSchema.length);
// Example: Find the 'Segment' top-level element definition
const segmentElement = matroskaSchema.find(entry => entry.name === 'Segment');
if (segmentElement) {
console.log('Found Segment element:', segmentElement.name, 'ID:', segmentElement.id.toString(16));
console.log('Segment element description:', segmentElement.description.substring(0, 70) + '...');
} else {
console.log('Segment element not found in schema.');
}
// To see a specific part of the schema, e.g., the EBML Header definition
const ebmlHeader = matroskaSchema.find(entry => entry.name === 'EBMLHeader');
if (ebmlHeader) {
console.log('\nEBMLHeader definition:');
console.dir(ebmlHeader, { depth: 2 });
}