Registry / web-framework / mpd-parser

mpd-parser

JSON →
library0.2.0jsnpmunverified

mpd-parser is a JavaScript library specifically designed for parsing MPEG-DASH (Dynamic Adaptive Streaming over HTTP) Media Presentation Description (MPD) manifests. It takes an XML-formatted MPD string and transforms it into a structured, easily consumable JavaScript object. The current stable version is 1.3.1, released in October 2024. The package follows an active, feature- and bugfix-driven release cadence, typically seeing several minor and patch versions annually. A key differentiator is its tight integration within the Video.js ecosystem, providing robust capabilities for handling complex DASH manifests, including support for live streams through the `previousManifest` option for efficient updates, parsing content steering information, processing EventStreams, and extracting DRM-related `mp4protection` tags. It is widely used in web-based video playback solutions requiring DASH support.

npm install mpd-parser
INSTALL
IMPORT
SIG · MPD-PARSER
M
mpd-parser
web-frameworkjavascriptv0.2.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.

mpdParser
import mpdParser from 'mpd-parser';
import { parse } from 'mpd-parser'; // The 'parse' function is a method on the default export, not a named export.
The library exports a default object containing the 'parse' method. This is the recommended ES Module import.
mpdParser
const mpdParser = require('mpd-parser');
const { parse } = require('mpd-parser'); // The 'parse' function is a method on the default export, not a direct property of the CommonJS module. It would be 'require('mpd-parser').parse'.
CommonJS import for Node.js environments. The imported object contains the 'parse' method.
window['mpd-parser']
var mpdParser = window['mpd-parser'];
For direct script tag usage in browsers, the library exposes itself as 'mpd-parser' on the global window object.

Demonstrates how to fetch an MPEG-DASH MPD manifest and parse it using `mpd-parser`, including an event handler and showing the output structure.

import mpdParser from 'mpd-parser'; async function parseMpdManifest(manifestUri) { try { // Fetch the MPD manifest from the given URI const res = await fetch(manifestUri); if (!res.ok) { throw new Error(`Failed to fetch manifest: ${res.statusText}`); } const manifestText = await res.text(); // A callback function to handle events like errors or warnings during parsing const eventHandler = ({ type, message }) => console.log(`[MPD Parser Event] ${type}: ${message}`); // Parse the manifest, providing the manifestUri for relative URL resolution const parsedManifest = mpdParser.parse(manifestText, { manifestUri, eventHandler }); console.log('Parsed Manifest:', parsedManifest); // Example for live streams: on subsequent calls, pass the previous manifest // const newManifestText = await fetch(manifestUri).then(r => r.text()); // const updatedParsedManifest = mpdParser.parse(newManifestText, { manifestUri, previousManifest: parsedManifest, eventHandler }); // console.log('Updated Parsed Manifest (Live):', updatedParsedManifest); return parsedManifest; } catch (error) { console.error('Error parsing MPD manifest:', error); throw error; } } // Example usage: Replace with an actual MPD URI const exampleManifestUri = 'https://dash.akamaized.net/envivio/EnvivioDashVoD.mpd'; parseMpdManifest(exampleManifestUri) .catch(err => console.error('Overall parsing error:', err));
Debug
Known issues
breakingUpgrading from 0.x to 1.x likely introduced breaking changes due to major version bump. Developers should consult the `v1.0.0` release notes (if available) or perform thorough testing when migrating.
fix
Review the changelog or source code for `v1.0.0` for specific breaking changes in API surface or parsed output structure. Adapt consumption code accordingly.
affects: >=1.0.0
gotchaFor live DASH streams, passing the `previousManifest` option to the `parse` function is crucial for correct and efficient parsing of manifest updates (e.g., segment availability, new periods). Omitting it can lead to incorrect state or parsing inefficiencies.
fix
When parsing updated manifests for live streams, always include the previously parsed manifest object as `mpdParser.parse(newManifest, { manifestUri, previousManifest: oldParsedManifest })`.
affects: >=0.1.0
gotchaThe `manifestUri` option is important for resolving relative URLs within the MPD. If not provided, base URLs might not resolve correctly, especially for segment URIs.
fix
Always provide the `manifestUri` option with the URL from which the manifest was fetched: `mpdParser.parse(manifestText, { manifestUri: 'https://example.com/manifest.mpd' })`.
affects: >=0.1.0
gotchaDependency `xmldom` has had security vulnerabilities in past versions (e.g., CVE-2022-37616). While `mpd-parser` regularly updates its dependencies, ensure your project's dependency tree is free of vulnerable `xmldom` versions.
fix
Keep `mpd-parser` updated to the latest version to benefit from patched dependencies. Regularly run `npm audit` and address any reported vulnerabilities.
affects: <1.3.0
Errors
Common errors & fixes
TypeError: mpdParser.parse is not a function
Attempting to call 'parse' directly from a named import (`import { parse } from 'mpd-parser';`) when it is a method on the default export object, or incorrect CommonJS destructuring.
fix
Use `import mpdParser from 'mpd-parser';` and then call `mpdParser.parse(...)`. For CommonJS, use `const mpdParser = require('mpd-parser');` and `mpdParser.parse(...)`.
ReferenceError: mpdParser is not defined
This usually occurs in browser environments where the script tag for `mpd-parser.min.js` has not loaded yet, or `window['mpd-parser']` is being accessed before the script initializes it.
fix
Ensure the `<script>` tag for `mpd-parser` is placed before any inline scripts that attempt to use it, or inside a `DOMContentLoaded` listener.
Error: Failed to parse manifest
The provided MPD XML string is malformed, not valid XML, or does not conform to the DASH schema expected by the parser.
fix
Validate your MPD XML string using an XML linter or a DASH manifest validator. Check console for specific error messages from the `eventHandler` if one is provided to `mpdParser.parse`.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
xmldomrequiredCore dependency for XML parsing of MPD manifests.
vhs-utilsrequiredProvides utilities for Video.js HTTP Streaming (VHS) projects.
Agent activity
8 hits · last 30 days
node
8
Resources
mpd-parser — npm install mpd-parser · libregistry