npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

dasha

v4.6.0

Published

Streaming manifest parser

Readme

dasha

npm version npm downloads/month npm downloads

Library for working with MPEG-DASH (.mpd) manifests and HLS (.m3u8) playlists through a Mediabunny-compatible Input API. Made with the purpose of obtaining a simplified representation convenient for further downloading of segments by URLs and getting basic metadata about the tracks.

Install

npm install dasha

Usage

Reading HLS

In the example below, we read the segment information for a specific video track and save it to a file.

import fs from 'node:fs/promises';
import { desc, HLS_FORMATS, Input, UrlSource } from 'dasha';

async function saveVideo() {
  const input = new Input({
    source: new UrlSource(
      'https://storage.googleapis.com/shaka-demo-assets/angel-one-widevine-hls/hls.m3u8',
      { requestInit: { headers: { Referer: 'https://bitmovin.com/' } } },
    ),
    formats: HLS_FORMATS,
  });

  const videoTracks = await input.getVideoTracks({
    sortBy: async (track) => [
      desc(await track.getDisplayHeight()),
      // Tracks with matching resolution are sorted by bitrate
      desc(await track.getBitrate()),
    ],
    // Filter out #EXT-X-I-FRAME-STREAM-INF tracks
    filter: async (track) => !(await track.hasOnlyKeyPackets()),
  });

  const bestVideoTrack = videoTracks[0];
  console.log('Dynamic range:', await bestVideoTrack.getDynamicRange()); // sdr

  const segments = await bestVideoTrack.getSegments();

  const outputPath = 'output.mp4';
  const urls = segments.map((segment) => segment.location.path);
  const initSegment = segments[0]?.initSegment;
  if (initSegment) urls.unshift(initSegment.location.path);
  for (const url of urls) {
    const content = await fetch(url).then((res) => res.arrayBuffer());
    await fs.appendFile(outputPath, new Uint8Array(content));
  }
};

Reading DASH

Everything here is identical to the example above, with the sole exception that an URL to a DASH manifest is used instead of an HLS playlist.

import fs from 'node:fs/promises';
import { DASH_FORMATS, Input, UrlSource, desc } from 'dasha';

async function saveDashVideo() {
  const input = new Input({
    source: new UrlSource(
      'https://dash.akamaized.net/dash264/TestCases/1a/netflix/exMPD_BIP_TC1.mpd',
    ),
    formats: DASH_FORMATS,
  });

  const videoTracks = await input.getVideoTracks({
    sortBy: async (track) => [
      desc(await track.getDisplayHeight()),
      desc(await track.getBitrate()),
    ],
  });

  const bestVideoTrack = videoTracks[0];
  const segments = await bestVideoTrack.getSegments();

  const outputPath = 'output.m4s';
  const urls = segments.map((segment) => segment.location.path);
  const initSegment = segments[0]?.initSegment;
  if (initSegment) urls.unshift(initSegment.location.path);
  for (const url of urls) {
    const content = await fetch(url).then((res) => res.arrayBuffer());
    await fs.appendFile(outputPath, new Uint8Array(content));
  }
}

Adding external subtitle tracks

addSubtitleTrack() is useful when subtitle URLs are provided separately from the HLS/DASH manifest. Added subtitles become part of the same Input, so they can be queried, filtered and downloaded through the regular subtitle track API.

import { DASH_FORMATS, Input, UrlSource } from 'dasha';

async function getEnglishSubtitles() {
  const input = new Input({
    source: new UrlSource('https://example.com/manifest.mpd'),
    formats: DASH_FORMATS,
  });

  const primaryVideoTrack = await input.getPrimaryVideoTrack();
  if (!primaryVideoTrack) {
    throw new Error('No video tracks found');
  }

  input.addSubtitleTrack(new UrlSource('https://cdn.example.com/subtitles/en.vtt'), {
    languageCode: 'en',
    name: 'English',
    pairWith: primaryVideoTrack,
  });

  const englishSubtitleTracks = await input.getSubtitleTracks({
    filter: async (track) => (await track.getLanguageCode()) === 'en',
  });

  const englishSubtitleTrack = englishSubtitleTracks[0];
  if (!englishSubtitleTrack) {
    return [];
  }

  return await englishSubtitleTrack.getSegments();
}

Overriding track metadata

Some services expose track metadata outside the manifest. You can override the parsed language code on any dasha track, and the updated value will be visible through the regular query/filter APIs.

import { DASH_FORMATS, Input, UrlSource } from 'dasha';

async function getFrenchAudioTrack() {
  const input = new Input({
    source: new UrlSource('https://example.com/manifest.mpd'),
    formats: DASH_FORMATS,
  });

  const audioTracks = await input.getAudioTracks();
  const apiLanguageCode = 'fr';

  audioTracks[0]?.setLanguageCode(apiLanguageCode);

  return await input.getAudioTracks({
    filter: async (track) => (await track.getLanguageCode()) === apiLanguageCode,
  });
}

Removing audio and subtitle tracks

Manifest tracks and tracks added through Dasha can be excluded from later queries. This is useful when a manifest advertises empty or otherwise unusable renditions.

const subtitleTracks = await input.getSubtitleTracks();

for (const track of subtitleTracks) {
  if ((await track.getSegments()).length === 0) {
    input.removeSubtitleTrack(track);
  }
}

Mediabunny with DASH support

Only reading is supported

Similar to downloading an HLS playlist as an MP4 you can do this:

import { Conversion, FilePathTarget, Mp4OutputFormat, Output, Input, UrlSource } from 'mediabunny';
import { DASH_FORMATS } from 'dasha';

const input = new Input({
	source: new UrlSource('https://example.com/manifest.mpd'),
	formats: DASH_FORMATS,
});

const output = new Output({
	format: new Mp4OutputFormat(),
	target: new FilePathTarget('output.mp4'),
});

const conversion = await Conversion.init({ input, output });
await conversion.execute();

// Done

See reading HLS guide for more use cases (many things can be used with DASH as well).

Credits

mediabunny