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

iso-bmff

v4.1.2

Published

Parse an ISO BMFF using nodejs

Downloads

34

Readme

iso-bmff-parser-stream

Parse an ISO BMFF using nodejs.

Returns a structured javascript object of iso-bmff boxes.

What is ISO-BMFF: tldr version, full version

This is still a work in progress !

Installation

npm install iso-bmff

How to use

Parse a media file

var chunkFile = './media/audio.m4s'

var fs = require('fs');
var isoBmff = require('../index.js');

var chunkStream = fs.createReadStream(chunkFile, {
	flags: 'r',
	encoding: null,
	fd: null,
	mode: 0666,
	autoClose: true
});

var unboxing = new isoBmff.Parser(function (err, data) {
	console.dir(JSON.stringify(data));
})


chunkStream
	.pipe(unboxing);

Output is something like this

[  
   {  
      "id":1,
      "type":"styp"
   },
   {  
      "id":2,
      "type":"sidx",
      "content":{  
         "version":0,
         "flags":0,
         "referenceId":1,
         "timeScale":12800,
         "earliestPresentationTime":2517504,
         "firstOffset":0,
         "entries":[  
            {  
               "referencedSize":815756,
               "subSegmentDuration":25600
            },
            {  
               "referencedSize":117691,
               "subSegmentDuration":5120
            }
         ]
      }
   },
   {  
      "id":3,
      "type":"moof",
      "content":[  
         {  
            "id":4,
            "type":"mfhd"
         },
         {  
            "id":5,
            "type":"traf",
            "content":[  
               {  
                  "id":6,
                  "type":"tfhd"
               },
               {  
                  "id":7,
                  "type":"tfdt",
                  "content":{  
                     "version":0,
                     "flags":0,
                     "baseMediaDecodeTime":2517504
                  }
               },
               {  
                  "id":8,
                  "type":"trun"
               }
            ]
         }
      ]
   },
   {  
      "id":9,
      "type":"mdat",
      "content":"BINARY_DATA"
   },
   {  
      "id":10,
      "type":"moof",
      "content":[  
         {  
            "id":11,
            "type":"mfhd"
         },
         {  
            "id":12,
            "type":"traf",
            "content":[  
               {  
                  "id":13,
                  "type":"tfhd"
               },
               {  
                  "id":14,
                  "type":"tfdt",
                  "content":{  
                     "version":0,
                     "flags":0,
                     "baseMediaDecodeTime":2543104
                  }
               },
               {  
                  "id":15,
                  "type":"trun"
               }
            ]
         }
      ]
   },
   {  
      "id":16,
      "type":"mdat",
      "content":"BINARY_DATA"
   }
]

Build a media file from generated output

iso-bmff can re-generate media files, from it's output. This is handy, if you want to modify something in a media file, and generate it again

var chunkFile = './media/video.m4s'

var fs = require('fs');
var isoBmff = require('iso-bmff');

var chunkStream = fs.createReadStream(chunkFile, {
	flags: 'r',
	encoding: null,
	fd: null,
	mode: 0666,
	autoClose: true
});

var unboxing = new isoBmff.Parser(parseDone);

chunkStream
	.pipe(unboxing);

function parseDone (err, data) {
	new isoBmff.Builder(data, buildDone);
}

function buildDone (err, data) {
	fs.writeFile(chunkFile.replace('media/', ''), data);
}

Extend with boxes

Every box can have it's own parser module, to analyze and parse box binary data, and return something meaningful. Every box has at least two methods, one for parse and one for rebuild, so box data parse/build logic can be contained in small modules.

See the lib/box folder for these modules, and currently supported box types.

Contributions welcome

If you know how a box should be parsed, create a parser module, and send a pull rq. Thanks!