Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

matroska-subtitles

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

matroska-subtitles

Transform stream for parsing embedded .mkv subtitles.

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
36
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

matroska-subtitles npm dependencies license

Transform stream for parsing embedded .mkv subtitles.

Currently supports extraction of the .srt and .ass format.

install

npm install matroska-subtitles

documetation

The data event of the stream will emit an array that determines the type of the data. When a new subtitle track is encountered a track number and language is emitted:

data = [ 'new', { track: <track number>, language: <string> } ]

Subsequently a specific subtitle track will emit data of this form:

data = [ <track number>, { text: <string>, time: <ms>, duration: <ms> } ]

example

The following is an example of extracting subtitle tracks of an mkv:

const fs = require('fs')
const matroskaSubtitles = require('matroska-subtitles')

var tracks = new Map()
var subs = matroskaSubtitles()

subs.on('data', function (data) {
  if (data[0] === 'new') {
    var key = data[1].track
    tracks.set(key, {
      language: data[1].language,
      subtitles: []
    })
  } else {
    var key = data[0]
    var subtitle = data[1]
    tracks.get(key).subtitles.push(subtitle)
  }
})

subs.on('end', function () {
  tracks.forEach((track) => console.log(track))
})

fs.createReadStream('Sintel.2010.720p.mkv').pipe(subs)

Notice that this example doesn't take advantage of streaming since the subtitles first are being outputted when the stream ends.

response

The response of this example would look like this:

{ language: 'eng',
  subtitles: 
   [ { text: 'This blade has a dark past.',
       time: 107250,
       duration: 1970 },
     { text: 'It has shed much innocent blood.',
       time: 111800,
       duration: 4000 },
     { text: 'You\'re a fool for traveling alone,\r\nso completely unprepared.',
       time: 118000,
       duration: 3450 } ] }

Note that the language might be undefined if the mkv track has not specified it.

contributing

This is still a work in progress.

If you find a bug or have suggestions feel free to create an issue or a pull request!

see also

mkv-subtitle-extractor

license

MIT

Keywords

FAQs

Package last updated on 07 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc