项目作者: mathiasvr

项目描述 :
💬 Streaming parser for embedded .mkv subtitles.
高级语言: JavaScript
项目地址: git://github.com/mathiasvr/matroska-subtitles.git
创建时间: 2016-06-30T17:33:46Z
项目社区:https://github.com/mathiasvr/matroska-subtitles

开源协议:MIT License

下载


matroska-subtitles

NPM
Downloads
Dependency status
License
forthebadge

Streaming parser for embedded .mkv subtitles.

Supported formats: .srt, .ssa, .ass.

install

  1. $ npm install matroska-subtitles

or include it directly:

  1. <script src="https://cdn.jsdelivr.net/npm/matroska-subtitles@3.x/dist/matroska-subtitles.min.js"></script>

example

  1. const fs = require('fs')
  2. const { SubtitleParser } = require('matroska-subtitles')
  3. const parser = new SubtitleParser()
  4. // first an array of subtitle track information is emitted
  5. parser.once('tracks', (tracks) => console.log(tracks))
  6. // afterwards each subtitle is emitted
  7. parser.on('subtitle', (subtitle, trackNumber) =>
  8. console.log('Track ' + trackNumber + ':', subtitle))
  9. fs.createReadStream('Sintel.2010.720p.mkv').pipe(parser)

See examples folder for more examples.

tracks event response format

  1. [
  2. { number: 3, language: 'eng', type: 'utf8', name: 'English(US)' },
  3. { number: 4, language: 'jpn', type: 'ass', header: '[Script Info]\r\n...' }
  4. ]
  • The language attribute can be undefined if the mkv track does not specify it, this is often interpreted as eng.
  • The name attribute is not standard but may provide language info.

subtitle event response format

  1. {
  2. text: 'This blade has a dark past.',
  3. time: 107250, // ms
  4. duration: 1970 // ms
  5. }

attached files

The parser now also has a file event that emits embedded mkv files, mainly to be used to extract embedded subtitle fonts.

  1. parser.on('file', file => console.log('file:', file))

Output:

  1. {
  2. filename: 'Arial.ttf',
  3. mimetype: 'application/x-truetype-font',
  4. data: Buffer() [Uint8Array]
  5. }

random access

This module also includes a SubtitleStream class for intercepting subtitles
in mkv streams with support for seeking.

  1. const { SubtitleStream } = require('matroska-subtitles')
  2. let subtitleStream = new SubtitleStream()
  3. subtitleStream.once('tracks', (tracks) => {
  4. // close the old subtitle stream and open a new at a different stream offset
  5. subtitleStream = new SubtitleStream(subtitleStream)
  6. })

See examples/random-access.js for a detailed example.

see also

mkv-subtitle-extractor

license

MIT