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

@cryguy/mkv-subtitle-extractor

v1.0.1

Published

Extract subtitle tracks and fonts from MKV files via URL using HTTP Range requests

Downloads

209

Readme

mkv-subtitle-extractor

Extract subtitle tracks and embedded fonts from remote MKV files over HTTP — no ffmpeg required.

Uses HTTP Range requests to download only the bytes needed (typically ~3% of the file), parses the Matroska container at the binary level, and returns each subtitle track as a Uint8Array ready to write to disk or process further. Works in browsers and Node.js 18+.

Install

npm install @cryguy/mkv-subtitle-extractor

Usage

import { extractSubtitles } from "mkv-subtitle-extractor";

const tracks = await extractSubtitles("https://example.com/video.mkv", {
  verbose: true,
});

for (const track of tracks) {
  console.log(track.type);                  // "srt" | "ass" | "ssa" | "vtt"
  console.log(track.metadata.language);     // "eng", "jpn", etc.
  console.log(track.metadata.trackName);    // "English", "Signs & Songs", etc.
  console.log(track.metadata.trackNumber);  // 3, 4, etc.
  console.log(track.output.subtitle);       // Uint8Array containing the subtitle file
  console.log(track.output.fonts);          // FontFile[] for ASS/SSA, null otherwise
}

Writing to disk (Node.js)

import { writeFile } from "node:fs/promises";

for (const track of tracks) {
  const ext = track.type; // "srt", "ass", "ssa", or "vtt"
  await writeFile(`subtitle-${track.metadata.trackNumber}.${ext}`, track.output.subtitle);

  if (track.output.fonts) {
    for (const font of track.output.fonts) {
      await writeFile(font.name, font.data);
    }
  }
}

API

extractSubtitles(url, options?)

function extractSubtitles(url: string, options?: ExtractOptions): Promise<TrackResult[]>

Fetches an MKV file from url, parses the Matroska container, and returns all embedded subtitle tracks.

ExtractOptions

| Field | Type | Default | Description | |-------|------|---------|-------------| | languages | string[] | all | Filter by language tags (e.g. ["eng", "jpn"]) | | allowFullDownload | boolean | false | Allow full file download if the server doesn't support Range requests | | verbose | boolean | false | Log progress and download stats to the console | | concurrency | number | 1 | Max concurrent HTTP requests when fetching subtitle blocks | | fetch | typeof fetch | globalThis.fetch | Custom fetch implementation (e.g. for auth or proxies) | | headers | Record<string, string> | — | Custom HTTP headers sent with every request |

TrackResult

| Field | Type | Description | |-------|------|-------------| | type | SubtitleFormat | "srt", "ass", "ssa", or "vtt" | | metadata.trackNumber | number | Track index within the MKV file | | metadata.language | string \| undefined | BCP 47 / ISO 639 language tag | | metadata.trackName | string \| undefined | Track name from MKV metadata | | output.subtitle | Uint8Array | The complete subtitle file as raw bytes | | output.fonts | FontFile[] \| null | Embedded fonts for ASS/SSA tracks; null for other formats |

FontFile

| Field | Type | Description | |-------|------|-------------| | name | string | Original filename (e.g. "Arial.ttf") | | data | Uint8Array | Raw font file data |

Errors

| Error | Thrown when | |-------|------------| | RangeNotSupportedError | Server doesn't support HTTP Range requests and allowFullDownload is not true | | MkvParseError | The file has an invalid EBML/Matroska structure |

How It Works

  1. Sends an initial Range request to fetch the EBML header and Segment metadata
  2. Parses the SeekHead to locate Tracks, Attachments, Cues, and Cluster positions
  3. Fetches and parses the Tracks element to identify subtitle tracks and their codecs
  4. Extracts embedded fonts from Attachments (if present)
  5. Uses the Cues index (if available) to jump directly to subtitle blocks, or falls back to a linear cluster scan
  6. Assembles complete subtitle files from the extracted blocks

Because only metadata, subtitle data, and fonts are fetched — never the video or audio streams — bandwidth usage is typically ~3% of the total file size.

Supported Formats

  • SRT (SubRip) — S_TEXT/UTF8
  • ASS/SSA (Advanced SubStation Alpha) — S_TEXT/ASS, S_TEXT/SSA
  • WebVTTS_TEXT/WEBVTT

Compatibility

  • Node.js 18+ (uses fetch API)
  • Browsers — any modern browser with fetch and Uint8Array support
  • Dependencies — zero runtime dependencies

License

MIT


Built by shy with Claude Opus 4.5