Code Monkey home page Code Monkey logo

id3-ts-lib's Introduction

ID3-TS-LIB

The fat-free ID3-only MPEG2TS segment generator library!

Installation

As a library (into your fancy project):

$> npm install @brightcove/id3-ts-lib

Usage:

const fs = require('fs');

// The whole library exposes just a single function:
const generateID3Segment = require('id3-ts-lib');

// If a PID is falsey, then that track will not be included in the generated PMT
const options = {
  pmtPid: 0x100,
  id3Pid: 0x103,
  videoPid: null,
  audioPid: null,
  id3PTS: 282743,
  data: 'This is just some example payload...',
};

// The function returns a promise that resolves to a buffer
generateID3Segment(options).then((segment) => {
  fs.writeFileSync('test.ts', segment);
});

As a very rudimentary executable:

$> npm install -g @brightcove/id3-ts-lib

$> id3-ts 'This is just some example payload...' > test.ts

Performance

The entire segment construction process is performed using a single Buffer allocation. All operations are done in place including the ID3-creation which is "chunked" so that the ID3 can be created in-place "around" the TS packet headers. As a result, this code can generate an entire segment for a 4kb payload in about 9.6µs!

id3-ts-lib's People

Contributors

gkatsev avatar imbcmdth avatar tedk avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

id3-ts-lib's Issues

error example code

Hello,
i have error in your same code:

const fs = require('fs');

// The whole library exposes just a single function:
const generateID3Segment = require('id3-ts-lib');

// If a PID is falsey, then that track will not be included in the generated PMT
const options = {
pmtPid: 0x100,
id3Pid: 0x103,
videoPid: null,
audioPid: null,
id3PTS: 282743,
data: 'This is just some example payload...',
};

// The function returns a promise that resolves to a buffer
generateID3Segment(options).then((segment) => {
fs.writeSync('test.ts', segment);
});

Return this error.

(node:1776) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "fd" argument must be of type number. Received type string
at Object.writeSync (fs.js:552:3)
at generateID3Segment.then (/root/id3/id3.js:18:6)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
(node:1776) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1776) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

is this an error in the sample code?
or in your library?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.