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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@vidterra/misb.js

v0.1.28

Published

Lightweight JavaScript library for parsing and manipulating MISB KLV metadata

Downloads

442

Readme

misb.js

Lightweight JavaScript library for parsing and manipulating MISB KLV metadata

About

misb.js is a dependency free library to parse and create KLV metadata in JavaScript. It supports both front-end web browsers and back-end Node.js implementations. misb.js is not affiliated with or endorsed by the Motion Imagery Standards Board.

Supported standards

Installation

NPM

To install misb.js with npm run

npm install @vidterra/misb.js

misb.js currently requires the use of Node.js 14.x LTS and higher

Web Browser

Not started

Usage Examples

Basic Usage

const { st0601 } = require('@vidterra/misb.js')
const klv =[ 
    '060E2B34020B01010E0103010100000081D2020800046050584E0180030A4D697373696F6E20',
    '3132050271C20602FD3D070208B80A085072656461746F720B07454F204E6F73650C0E47656F',
    '64657469632057475338340D045595B66D0E045B5360C40F02C2211002CD9C1102D917120472',
    '4A0A20130487F84B86140400000000150403830926160212811704F101A229180414BC082B19',
    '0234F3301C01010102010703052F2F5553410C01070D060055005300411602000A4101065E22',
    '0170F592F02373364AF8AA9162C00F2EB2DA16B74341000841A0BE365B5AB96A36450102AA43'
]
const json = st0601.parse(klv.join(''), { debug: true })
console.log(json)

Advanced Usage

See scripts/file.js for an example of programmatically reading KLV from a MPEG-TS transport file. The conceptual workflow looks like:

  1. Extract KLV metadata with ffmpeg using ffmpeg -i <input filename> -map 0:d:0 -codec copy -f data <output filename>
  2. Read the extracted metadata file bytes and search for MISB ST keys
  3. When a matching key is found, parse the KLV
  4. Advance to the next bytes
  5. Repeat steps 2-4 until file end

See scripts/stdin.js for an example of programmatically reading KLV from a ffmpeg pipe

  1. Run the single command ffmpeg -i <input filename> -map 0:d:0 -codec copy -f data - | node stdin.js

Roadmap

  • [ ] Tests
  • [ ] Browser support
  • [ ] JSON to KLV encoding

Modules

The exported misb.js object contains the following modules:

const misb = require('misb.js') // export all modules
const { st0601, st0102, st0903, klv } = require('misb.js') // export the modules you want to use
  • st0601: a module to parse ST 0601 data
  • st0102: a module to parse ST 0102 data
  • st0903: a module to parse ST 0903 data
  • st0806: a module to parse ST 0806 data
  • klv: a module for generic KLV helper functions

ST 0601

st0601.key

Returns a 16 byte Buffer with the ST0601 key

st0601.parse(buffer, options)

Returns a JSON object of parsed metadata

buffer

A string or Node.js Buffer that starts with a fully formed packet of ST 0601 KLV. Embedded KLV within ST 0601, such as ST 0102, will also be parsed.

Invalid KLV will cause an exception to be thrown. The KLV may have extra trailing content after the complete KLV packet, it will be ignored.

options

An object with additional options.

  • debug (default: false): print parsed metadata to standard output

ST 0102

st0102.parse(buffer, options)

Returns a JSON object of parsed metadata

buffer

A string or Node.js Buffer that only contains valid ST 0102 KLV content. Invalid KLV will cause an exception to be thrown. Any additional content other than ST 0102 KLV will cause an exception to be thrown.

options

An object with additional options.

  • debug (default: false): print parsed metadata to standard output

ST 0903

st0903.key

Returns a 16 byte Buffer with the ST0903 key

st0903.parse(buffer, options)

Returns a JSON object of parsed metadata

buffer

A string or Node.js Buffer that starts with a fully formed packet of ST 0903 KLV.

Invalid KLV will cause an exception to be thrown. The KLV may have extra trailing content after the complete KLV packet, it will be ignored.

options

An object with additional options.

  • debug (default: false): print parsed metadata to standard output

KLV

klv.getBer(buffer)

Parses the BER for long-form or short-form encoding.

A short-form encoded BER will return { berHeader: 0, berLength: 1, contentLength: <length of KLV content> }

A long-form encoded BER will return { berHeader: 1, berLength: <length of BER in addition to header>, contentLength: null }. This requires further parsing using the getContentLength function.

buffer

A Buffer with a single byte. Any additional content than the single byte of BER header will cause an exception to be thrown.

klv.getContentLength(buffer)

Parses the content length of a long-form BER.

buffer

A Buffer of bytes that sum to the length of the KLV content. Pass the number of bytes returned by klv.getBer(buffer).berLength into this function.

Contact us

Contact us at [email protected].