mkv-demuxer
v0.1.0
Published
A javascript library for parsing matroska files
Downloads
28
Maintainers
Readme
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
- ...
- duration
- video
- codecID
String
- codecPrivate
ArrayBuffer
- width
Number
- Height
Number
- displayWidth
Number
- displayHeight
Number
- language
String
- ...
- codecID
- Audio
- codecID
String
- codecPrivate
ArrayBuffer
- bitDepth
Number
- channels
Number
- rate
Number
- ...
- codecID
- info
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
- ...
- cueClusterPosition
- ...
- cueTime
- videoPackets
Array
- start
Number
- end
Number
- size
Number
- timestamp
Number
- isKeyframe
Boolean
- keyframeTimestamp
Number
- start
- audioPackets
Array
- start
Number
- end
Number
- size
Number
- timestamp
Number
- start
- cues
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
- start
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.