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 !
npm install iso-bmff
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"
}
]
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);
}
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.
If you know how a box should be parsed, create a parser module, and send a pull rq. Thanks!