Skip to content

bilibili/mkv-demuxer

Repository files navigation

Mkv Demuxer

mkv-demuxer is a javascript library for demuxing matroska, webm files in the browser. It can be used to:

  • Get media information of a video
  • Get all frames of a video
  • Get a certain frame at a given timestamp of a video

Installation

npm install mkv-demuxer -S

Usage

Constructor

import MkvDemuxer from 'mkv-demuxer'
const demuxer = new MkvDemuxer()

API

initFile(file, filePieceSize)

Params: file, filePieceSize

  • file File - The file to be parsed
  • filePieceSize Number - The file piece size parsed each time
const filePieceSize = 1 * 1024 * 1024
await demuxer.initFile(file, filePieceSize)

getMeta()

Returns: Promise<meta>

  • meta - The meta infomation of the file
    • info
      • duration Number
      • title String
      • ...
    • video
      • codecID String
      • codecPrivate ArrayBuffer
      • width Number
      • Height Number
      • displayWidth Number
      • displayHeight Number
      • language String
      • ...
    • Audio
      • codecID String
      • codecPrivate ArrayBuffer
      • bitDepth Number
      • channels Number
      • rate Number
      • ...
const meta = await demuxer.getMeta()

getData()

To get all frames of a video.

Returns: Promise<data>

  • data - The video data of the file
    • cues Array - The keyframes of the file
      • cueTime Number
      • cueTrackPositions
        • cueClusterPosition Number
        • cueRelativePosition Number
        • cueTrack Number
        • ...
      • ...
    • videoPackets Array
      • start Number
      • end Number
      • size Number
      • timestamp Number
      • isKeyframe Boolean
      • keyframeTimestamp Number
    • audioPackets Array
      • start Number
      • end Number
      • size Number
      • timestamp Number
const data = await demuxer.getData()

seekFrame(timestamp)

Params: timestamp

  • timestamp number

Returns: Promise<frame>

  • frame
    • start Number
    • end Number
    • size Number
    • timestamp Number
    • isKeyframe Boolean
    • keyframeTimestamp Number
const frame = await demuxer.seekFrame(10)

reset()

To reset the demuxer.

Example

import MkvDemuxer from 'mkv-demuxer'
const demuxer = new MkvDemuxer()
const filePieceSize = 1 * 1024 * 1024
await demuxer.initFile(file, filePieceSize)
const meta = await demuxer.getMeta()
const data = await demuxer.getData()
const frame = await demuxer.seekFrame(10)

Additional notes

This library is based on jswebm and has made a series of optimizations. It solves the memory problem, optimizes exception handling, and provides several useful APIs.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published