Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

codem-isoboxer

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

codem-isoboxer - npm Package Compare versions

Comparing version 0.2.8 to 0.2.9

.travis.yml

4

CHANGELOG.md

@@ -0,1 +1,5 @@

## codem-isoboxer 0.2.9 (2016/11/29) ##
* `dref`, `url `, `urn `, `smhd` parsing (@bbert)
## codem-isoboxer 0.2.8 (2016/11/23) ##

@@ -2,0 +6,0 @@

127

dist/iso_boxer.js

@@ -1,2 +0,2 @@

/*! codem-isoboxer v0.2.8 https://github.com/madebyhiro/codem-isoboxer/blob/master/LICENSE.txt */
/*! codem-isoboxer v0.2.9 https://github.com/madebyhiro/codem-isoboxer/blob/master/LICENSE.txt */
var ISOBoxer = {};

@@ -63,6 +63,6 @@

exports.Utils = ISOBoxer.Utils;
};
}
ISOBoxer.Cursor = function(initialOffset) {
this.offset = (typeof initialOffset == 'undefined' ? 0 : initialOffset);
};;
};
var ISOFile = function(arrayBuffer) {

@@ -105,3 +105,3 @@ this._raw = new DataView(arrayBuffer);

}
};;
};
var ISOBox = function() {

@@ -245,3 +245,9 @@ this._cursor = new ISOBoxer.Cursor();

// additional parsing
if (!this._incomplete && this._boxParsers[this.type]) this._boxParsers[this.type].call(this);
if (!this._incomplete) {
if (this._boxContainers.indexOf(this.type) !== -1) {
this._parseContainerBox();
} else if (this._boxParsers[this.type]) {
this._boxParsers[this.type].call(this);
}
}
};

@@ -254,3 +260,12 @@

ISOBox.prototype._boxParsers = {};;
ISOBox.prototype._parseContainerBox = function() {
this.boxes = [];
while (this._cursor.offset - this._raw.byteOffset < this._raw.byteLength) {
this.boxes.push(ISOBox.parse(this));
}
};
ISOBox.prototype._boxContainers = ['dinf', 'edts', 'mdia', 'meco', 'mfra', 'minf', 'moof', 'moov', 'mvex', 'stbl', 'strk', 'traf', 'trak', 'tref', 'udta', 'vttc'];
ISOBox.prototype._boxParsers = {};
// ISO/IEC 14496-15:2014 - avc1 box

@@ -291,16 +306,13 @@ ISOBox.prototype._boxParsers['avc1'] = function() {

this.config = this._readData();
};;
// Simple container boxes, all from ISO/IEC 14496-12:2012 except vttc which is from 14496-30.
[
'moov', 'trak', 'tref', 'mdia', 'minf', 'stbl', 'edts', 'dinf',
'mvex', 'moof', 'traf', 'mfra', 'udta', 'meco', 'strk', 'vttc'
].forEach(function(boxType) {
ISOBox.prototype._boxParsers[boxType] = function() {
this.boxes = [];
while (this._cursor.offset - this._raw.byteOffset < this._raw.byteLength) {
this.boxes.push(ISOBox.parse(this));
}
};
});
;
};
// ISO/IEC 14496-12:2012 - 8.7.2 Data Reference Box
ISOBox.prototype._boxParsers['dref'] = function() {
this._parseFullBox();
this.entry_count = this._readUint(32);
this.entries = [];
for (var i = 0; i < this.entry_count ; i++){
this.entries.push(ISOBox.parse(this));
}
};
// ISO/IEC 14496-12:2012 - 8.6.6 Edit List Box

@@ -325,3 +337,3 @@ ISOBox.prototype._boxParsers['elst'] = function() {

}
};;
};
// ISO/IEC 23009-1:2014 - 5.10.3.3 Event Message Box

@@ -337,7 +349,7 @@ ISOBox.prototype._boxParsers['emsg'] = function() {

this.message_data = new DataView(this._raw.buffer, this._cursor.offset, this._raw.byteLength - (this._cursor.offset - this._offset));
};;
};
// ISO/IEC 14496-12:2012 - 8.1.2 Free Space Box
ISOBox.prototype._boxParsers['free'] = ISOBox.prototype._boxParsers['skip'] = function() {
this.data = new DataView(this._raw.buffer, this._cursor.offset, this._raw.byteLength - (this._cursor.offset - this._offset));
};;
};
// ISO/IEC 14496-12:2012 - 4.3 File Type Box / 8.16.2 Segment Type Box

@@ -352,3 +364,3 @@ ISOBox.prototype._boxParsers['ftyp'] = ISOBox.prototype._boxParsers['styp'] = function() {

}
};;
};
// ISO/IEC 14496-12:2012 - 8.4.3 Handler Reference Box

@@ -361,7 +373,7 @@ ISOBox.prototype._boxParsers['hdlr'] = function() {

this.name = this._readTerminatedString();
};;
};
// ISO/IEC 14496-12:2012 - 8.1.1 Media Data Box
ISOBox.prototype._boxParsers['mdat'] = function() {
this.data = this._readData();
};;
};
// ISO/IEC 14496-12:2012 - 8.4.2 Media Header Box

@@ -389,3 +401,3 @@ ISOBox.prototype._boxParsers['mdhd'] = function() {

this.pre_defined = this._readUint(16);
};;
};
// ISO/IEC 14496-12:2012 - 8.8.2 Movie Extends Header Box

@@ -400,3 +412,3 @@ ISOBox.prototype._boxParsers['mehd'] = function() {

}
};;
};
// ISO/IEC 14496-12:2012 - 8.8.5 Movie Fragment Header Box

@@ -406,3 +418,3 @@ ISOBox.prototype._boxParsers['mfhd'] = function() {

this.sequence_number = this._readUint(32);
};;
};
// ISO/IEC 14496-12:2012 - 8.8.11 Movie Fragment Random Access Box

@@ -413,3 +425,3 @@ ISOBox.prototype._boxParsers['mfro'] = function() {

};
;
// ISO/IEC 14496-12:2012 - 8.5.2.2 mp4a box (use AudioSampleEntry definition and naming)

@@ -436,3 +448,3 @@ ISOBox.prototype._boxParsers['mp4a'] = function() {

this.esds = this._readData();
};;
};
// ISO/IEC 14496-12:2012 - 8.2.2 Movie Header Box

@@ -468,3 +480,3 @@ ISOBox.prototype._boxParsers['mvhd'] = function() {

this.next_track_ID = this._readUint(32);
};;
};
// ISO/IEC 14496-30:2014 - WebVTT Cue Payload Box.

@@ -475,3 +487,3 @@ ISOBox.prototype._boxParsers['payl'] = function() {

};
;
// ISO/IEC 14496-12:2012 - 8.16.3 Segment Index Box

@@ -504,3 +516,11 @@ ISOBox.prototype._boxParsers['sidx'] = function() {

}
};;
};
// ISO/IEC 14496-12:2012 - 8.4.5.3 Sound Media Header Box
ISOBox.prototype._boxParsers['smhd'] = function() {
this._parseFullBox();
this.balance = this._readTemplate(16);
this.reserved = this._readUint(16);
};
// ISO/IEC 14496-12:2012 - 8.16.4 Subsegment Index Box

@@ -525,3 +545,3 @@ ISOBox.prototype._boxParsers['ssix'] = function() {

}
};;
};
// ISO/IEC 14496-12:2012 - 8.5.2 Sample Description Box

@@ -537,3 +557,3 @@ ISOBox.prototype._boxParsers['stsd'] = function() {

};
;
// ISO/IEC 14496-12:2015 - 8.7.7 Sub-Sample Information Box

@@ -566,3 +586,3 @@ ISOBox.prototype._boxParsers['subs'] = function () {

}
};;
};
// ISO/IEC 14496-12:2012 - 8.8.12 Track Fragmnent Decode Time

@@ -576,3 +596,3 @@ ISOBox.prototype._boxParsers['tfdt'] = function() {

}
};;
};
// ISO/IEC 14496-12:2012 - 8.8.7 Track Fragment Header Box

@@ -587,3 +607,3 @@ ISOBox.prototype._boxParsers['tfhd'] = function() {

if (this.flags & 0x20) this.default_sample_flags = this._readUint(32);
};;
};
// ISO/IEC 14496-12:2012 - 8.8.10 Track Fragment Random Access Box

@@ -623,3 +643,3 @@ ISOBox.prototype._boxParsers['tfra'] = function() {

};
;
// ISO/IEC 14496-12:2012 - 8.3.2 Track Header Box

@@ -657,3 +677,3 @@ ISOBox.prototype._boxParsers['tkhd'] = function() {

this.height = this._readTemplate(32);
};;
};
// ISO/IEC 14496-12:2012 - 8.8.3 Track Extends Box

@@ -668,3 +688,3 @@ ISOBox.prototype._boxParsers['trex'] = function() {

this.default_sample_flags = this._readUint(32);
};;
};
// ISO/IEC 14496-12:2012 - 8.8.8 Track Run Box

@@ -693,3 +713,12 @@ // Note: the 'trun' box has a direct relation to the 'tfhd' box for defaults.

}
};;
};
// ISO/IEC 14496-12:2012 - 8.7.2 Data Reference Box
ISOBox.prototype._boxParsers['url '] = ISOBox.prototype._boxParsers['urn '] = function() {
this._parseFullBox();
if (this.type === 'urn ') {
this.name = this._readTerminatedString();
}
this.location = this._readTerminatedString();
};
// ISO/IEC 14496-30:2014 - WebVTT Source Label Box

@@ -700,3 +729,11 @@ ISOBox.prototype._boxParsers['vlab'] = function() {

};
;
// ISO/IEC 14496-12:2012 - 8.4.5.2 Video Media Header Box
ISOBox.prototype._boxParsers['vmhd'] = function() {
this._parseFullBox();
this.graphicsmode = this._readUint(16);
this.opcolor = [this._readUint(16), this._readUint(16), this._readUint(16)];
};
// ISO/IEC 14496-30:2014 - WebVTT Configuration Box

@@ -707,3 +744,3 @@ ISOBox.prototype._boxParsers['vttC'] = function() {

};
;
// ISO/IEC 14496-30:2014 - WebVTT Empty Sample Box

@@ -710,0 +747,0 @@ ISOBox.prototype._boxParsers['vtte'] = function() {

@@ -1,2 +0,2 @@

/*! codem-isoboxer v0.2.8 https://github.com/madebyhiro/codem-isoboxer/blob/master/LICENSE.txt */
var ISOBoxer={};ISOBoxer.parseBuffer=function(a){return new ISOFile(a).parse()},ISOBoxer.addBoxParser=function(a,b){"string"==typeof a&&"function"==typeof b&&(ISOBox.prototype._boxParsers[a]=b)},ISOBoxer.Utils={},ISOBoxer.Utils.dataViewToString=function(a,b){var c=b||"utf-8";if("undefined"!=typeof TextDecoder)return new TextDecoder(c).decode(a);var d=[],e=0;if("utf-8"===c)for(;e<a.byteLength;){var f=a.getUint8(e++);f<128||(f<224?(f=(31&f)<<6,f|=63&a.getUint8(e++)):f<240?(f=(15&f)<<12,f|=(63&a.getUint8(e++))<<6,f|=63&a.getUint8(e++)):(f=(7&f)<<18,f|=(63&a.getUint8(e++))<<12,f|=(63&a.getUint8(e++))<<6,f|=63&a.getUint8(e++))),d.push(String.fromCharCode(f))}else for(;e<a.byteLength;)d.push(String.fromCharCode(a.getUint8(e++)));return d.join("")},"undefined"!=typeof exports&&(exports.parseBuffer=ISOBoxer.parseBuffer,exports.addBoxParser=ISOBoxer.addBoxParser,exports.Utils=ISOBoxer.Utils),ISOBoxer.Cursor=function(a){this.offset="undefined"==typeof a?0:a};var ISOFile=function(a){this._raw=new DataView(a),this._cursor=new ISOBoxer.Cursor,this.boxes=[]};ISOFile.prototype.fetch=function(a){var b=this.fetchAll(a,!0);return b.length?b[0]:null},ISOFile.prototype.fetchAll=function(a,b){var c=[];return ISOFile._sweep.call(this,a,c,b),c},ISOFile.prototype.parse=function(){for(this._cursor.offset=0,this.boxes=[];this._cursor.offset<this._raw.byteLength;){var a=ISOBox.parse(this);if("undefined"==typeof a.type)break;this.boxes.push(a)}return this},ISOFile._sweep=function(a,b,c){this.type&&this.type==a&&b.push(this);for(var d in this.boxes){if(b.length&&c)return;ISOFile._sweep.call(this.boxes[d],a,b,c)}};var ISOBox=function(){this._cursor=new ISOBoxer.Cursor};ISOBox.parse=function(a){var b=new ISOBox;return b._offset=a._cursor.offset,b._root=a._root?a._root:a,b._raw=a._raw,b._parent=a,b._parseBox(),a._cursor.offset=b._raw.byteOffset+b._raw.byteLength,b},ISOBox.prototype._readInt=function(a){var b=null;switch(a){case 8:b=this._raw.getInt8(this._cursor.offset-this._raw.byteOffset);break;case 16:b=this._raw.getInt16(this._cursor.offset-this._raw.byteOffset);break;case 32:b=this._raw.getInt32(this._cursor.offset-this._raw.byteOffset);break;case 64:var c=this._raw.getInt32(this._cursor.offset-this._raw.byteOffset),d=this._raw.getInt32(this._cursor.offset-this._raw.byteOffset+4);b=c*Math.pow(2,32)+d}return this._cursor.offset+=a>>3,b},ISOBox.prototype._readUint=function(a){var b,c,d=null;switch(a){case 8:d=this._raw.getUint8(this._cursor.offset-this._raw.byteOffset);break;case 16:d=this._raw.getUint16(this._cursor.offset-this._raw.byteOffset);break;case 24:b=this._raw.getUint16(this._cursor.offset-this._raw.byteOffset),c=this._raw.getUint8(this._cursor.offset-this._raw.byteOffset+2),d=(b<<8)+c;break;case 32:d=this._raw.getUint32(this._cursor.offset-this._raw.byteOffset);break;case 64:b=this._raw.getUint32(this._cursor.offset-this._raw.byteOffset),c=this._raw.getUint32(this._cursor.offset-this._raw.byteOffset+4),d=b*Math.pow(2,32)+c}return this._cursor.offset+=a>>3,d},ISOBox.prototype._readString=function(a){for(var b="",c=0;c<a;c++){var d=this._readUint(8);b+=String.fromCharCode(d)}return b},ISOBox.prototype._readTerminatedString=function(){for(var a="";this._cursor.offset-this._offset<this._raw.byteLength;){var b=this._readUint(8);if(0===b)break;a+=String.fromCharCode(b)}return a},ISOBox.prototype._readTemplate=function(a){var b=this._readUint(a/2),c=this._readUint(a/2);return b+c/Math.pow(2,a/2)},ISOBox.prototype._readData=function(a){var b=a>0?a:this._raw.byteLength-(this._cursor.offset-this._offset),c=new DataView(this._raw.buffer,this._cursor.offset,b);return this._cursor.offset+=b,c},ISOBox.prototype._parseBox=function(){if(this._cursor.offset=this._offset,this._offset+8>this._raw.buffer.byteLength)return void(this._root._incomplete=!0);switch(this.size=this._readUint(32),this.type=this._readString(4),1==this.size&&(this.largesize=this._readUint(64)),"uuid"==this.type&&(this.usertype=this._readString(16)),this.size){case 0:this._raw=new DataView(this._raw.buffer,this._offset,this._raw.byteLength-this._cursor.offset);break;case 1:this._offset+this.size>this._raw.buffer.byteLength?(this._incomplete=!0,this._root._incomplete=!0):this._raw=new DataView(this._raw.buffer,this._offset,this.largesize);break;default:this._offset+this.size>this._raw.buffer.byteLength?(this._incomplete=!0,this._root._incomplete=!0):this._raw=new DataView(this._raw.buffer,this._offset,this.size)}!this._incomplete&&this._boxParsers[this.type]&&this._boxParsers[this.type].call(this)},ISOBox.prototype._parseFullBox=function(){this.version=this._readUint(8),this.flags=this._readUint(24)},ISOBox.prototype._boxParsers={},ISOBox.prototype._boxParsers.avc1=function(){this.reserved1=[this._readUint(8),this._readUint(8),this._readUint(8),this._readUint(8),this._readUint(8),this._readUint(8)],this.data_reference_index=this._readUint(16),this.pre_defined1=this._readUint(16),this.reserved2=this._readUint(16),this.pre_defined2=[this._readUint(32),this._readUint(32),this._readUint(32)],this.width=this._readUint(16),this.height=this._readUint(16),this.horizresolution=this._readTemplate(32),this.vertresolution=this._readTemplate(32),this.reserved3=this._readUint(32),this.frame_count=this._readUint(16);var a=this._readUint(8);this.compressorname=this._readString(a);for(var b=0;b<31-a;b++)this._readUint(8);this.depth=this._readUint(16),this.pre_defined3=this._readInt(16),this.config=this._readData()},["moov","trak","tref","mdia","minf","stbl","edts","dinf","mvex","moof","traf","mfra","udta","meco","strk","vttc"].forEach(function(a){ISOBox.prototype._boxParsers[a]=function(){for(this.boxes=[];this._cursor.offset-this._raw.byteOffset<this._raw.byteLength;)this.boxes.push(ISOBox.parse(this))}}),ISOBox.prototype._boxParsers.elst=function(){this._parseFullBox(),this.entry_count=this._readUint(32),this.entries=[];for(var a=1;a<=this.entry_count;a++){var b={};1==this.version?(b.segment_duration=this._readUint(64),b.media_time=this._readInt(64)):(b.segment_duration=this._readUint(32),b.media_time=this._readInt(32)),b.media_rate_integer=this._readInt(16),b.media_rate_fraction=this._readInt(16),this.entries.push(b)}},ISOBox.prototype._boxParsers.emsg=function(){this._parseFullBox(),this.scheme_id_uri=this._readTerminatedString(),this.value=this._readTerminatedString(),this.timescale=this._readUint(32),this.presentation_time_delta=this._readUint(32),this.event_duration=this._readUint(32),this.id=this._readUint(32),this.message_data=new DataView(this._raw.buffer,this._cursor.offset,this._raw.byteLength-(this._cursor.offset-this._offset))},ISOBox.prototype._boxParsers.free=ISOBox.prototype._boxParsers.skip=function(){this.data=new DataView(this._raw.buffer,this._cursor.offset,this._raw.byteLength-(this._cursor.offset-this._offset))},ISOBox.prototype._boxParsers.ftyp=ISOBox.prototype._boxParsers.styp=function(){for(this.major_brand=this._readString(4),this.minor_version=this._readUint(32),this.compatible_brands=[];this._cursor.offset-this._raw.byteOffset<this._raw.byteLength;)this.compatible_brands.push(this._readString(4))},ISOBox.prototype._boxParsers.hdlr=function(){this._parseFullBox(),this.pre_defined=this._readUint(32),this.handler_type=this._readString(4),this.reserved=[this._readUint(32),this._readUint(32),this._readUint(32)],this.name=this._readTerminatedString()},ISOBox.prototype._boxParsers.mdat=function(){this.data=this._readData()},ISOBox.prototype._boxParsers.mdhd=function(){this._parseFullBox(),1==this.version?(this.creation_time=this._readUint(64),this.modification_time=this._readUint(64),this.timescale=this._readUint(32),this.duration=this._readUint(64)):(this.creation_time=this._readUint(32),this.modification_time=this._readUint(32),this.timescale=this._readUint(32),this.duration=this._readUint(32));var a=this._readUint(16);this.pad=a>>15,this.language=String.fromCharCode((a>>10&31)+96,(a>>5&31)+96,(31&a)+96),this.pre_defined=this._readUint(16)},ISOBox.prototype._boxParsers.mehd=function(){this._parseFullBox(),1==this.version?this.fragment_duration=this._readUint(64):this.fragment_duration=this._readUint(32)},ISOBox.prototype._boxParsers.mfhd=function(){this._parseFullBox(),this.sequence_number=this._readUint(32)},ISOBox.prototype._boxParsers.mfro=function(){this._parseFullBox(),this.mfra_size=this._readUint(32)},ISOBox.prototype._boxParsers.mp4a=function(){this.reserved1=[this._readUint(8),this._readUint(8),this._readUint(8),this._readUint(8),this._readUint(8),this._readUint(8)],this.data_reference_index=this._readUint(16),this.reserved2=[this._readUint(32),this._readUint(32)],this.channelcount=this._readUint(16),this.samplesize=this._readUint(16),this.pre_defined=this._readUint(16),this.reserved3=this._readUint(16),this.samplerate=this._readTemplate(32),this.esds=this._readData()},ISOBox.prototype._boxParsers.mvhd=function(){this._parseFullBox();var a;for(1==this.version?(this.creation_time=this._readUint(64),this.modification_time=this._readUint(64),this.timescale=this._readUint(32),this.duration=this._readUint(64)):(this.creation_time=this._readUint(32),this.modification_time=this._readUint(32),this.timescale=this._readUint(32),this.duration=this._readUint(32)),this.rate=this._readTemplate(32),this.volume=this._readTemplate(16),this.reserved1=this._readUint(16),this.reserved2=[this._readUint(32),this._readUint(32)],this.matrix=[],a=0;a<9;a++)this.matrix.push(this._readTemplate(32));for(this.pre_defined=[],a=0;a<6;a++)this.pre_defined.push(this._readUint(32));this.next_track_ID=this._readUint(32)},ISOBox.prototype._boxParsers.payl=function(){var a=new DataView(this._raw.buffer,this._cursor.offset,this._raw.byteLength-(this._cursor.offset-this._offset));this.cue_text=ISOBoxer.Utils.dataViewToString(a)},ISOBox.prototype._boxParsers.sidx=function(){this._parseFullBox(),this.reference_ID=this._readUint(32),this.timescale=this._readUint(32),0===this.version?(this.earliest_presentation_time=this._readUint(32),this.first_offset=this._readUint(32)):(this.earliest_presentation_time=this._readUint(64),this.first_offset=this._readUint(64)),this.reserved=this._readUint(16),this.reference_count=this._readUint(16),this.references=[];for(var a=0;a<this.reference_count;a++){var b={},c=this._readUint(32);b.reference_type=c>>31&1,b.referenced_size=2147483647&c,b.subsegment_duration=this._readUint(32);var d=this._readUint(32);b.starts_with_SAP=d>>31&1,b.SAP_type=d>>28&7,b.SAP_delta_time=268435455&d,this.references.push(b)}},ISOBox.prototype._boxParsers.ssix=function(){this._parseFullBox(),this.subsegment_count=this._readUint(32),this.subsegments=[];for(var a=0;a<this.subsegment_count;a++){var b={};b.ranges_count=this._readUint(32),b.ranges=[];for(var c=0;c<b.ranges_count;c++){var d={};d.level=this._readUint(8),d.range_size=this._readUint(24),b.ranges.push(d)}this.subsegments.push(b)}},ISOBox.prototype._boxParsers.stsd=function(){this._parseFullBox(),this.entry_count=this._readUint(32),this.entries=[];for(var a=0;a<this.entry_count;a++)this.entries.push(ISOBox.parse(this))},ISOBox.prototype._boxParsers.subs=function(){this._parseFullBox(),this.entry_count=this._readUint(32),this.samples_with_subsamples=[];for(var a=0,b=0;b<this.entry_count;b++){var c=this._readUint(32);a+=c;var d=this._readUint(16);if(d>0){for(var e={nr:a,subsamples:[]},f=0;f<d;f++){var g={};1&this.version?g.size=this._readUint(32):g.size=this._readUint(16),g.priority=this._readUint(8),g.discardable=this._readUint(8),g.codec_specific_parameters=this._readUint(32),e.subsamples.push(g)}this.samples_with_subsamples.push(e)}}},ISOBox.prototype._boxParsers.tfdt=function(){this._parseFullBox(),1==this.version?this.baseMediaDecodeTime=this._readUint(64):this.baseMediaDecodeTime=this._readUint(32)},ISOBox.prototype._boxParsers.tfhd=function(){this._parseFullBox(),this.track_ID=this._readUint(32),1&this.flags&&(this.base_data_offset=this._readUint(64)),2&this.flags&&(this.sample_description_offset=this._readUint(32)),8&this.flags&&(this.default_sample_duration=this._readUint(32)),16&this.flags&&(this.default_sample_size=this._readUint(32)),32&this.flags&&(this.default_sample_flags=this._readUint(32))},ISOBox.prototype._boxParsers.tfra=function(){this._parseFullBox(),this.track_ID=this._readUint(32),this._packed=this._readUint(32),this.reserved=this._packed>>>6,this.length_size_of_traf_num=(this._packed&&0xffff00000000)>>>4,this.length_size_of_trun_num=(this._packed&&4294901760)>>>2,this.length_size_of_sample_num=this._packed&&255,this.number_of_entry=this._readUint(32),this.entries=[];for(var a=0;a<this.number_of_entry;a++){var b={};1==this.version?(b.time=this._readUint(64),b.moof_offset=this._readUint(64)):(b.time=this._readUint(32),b.moof_offset=this._readUint(32)),b.traf_number=this._readUint(8*(this.length_size_of_traf_num+1)),b.trun_number=this._readUint(8*(this.length_size_of_trun_num+1)),b.sample_number=this._readUint(8*(this.length_size_of_sample_num+1)),this.entries.push(b)}},ISOBox.prototype._boxParsers.tkhd=function(){this._parseFullBox(),1==this.version?(this.creation_time=this._readUint(64),this.modification_time=this._readUint(64),this.track_ID=this._readUint(32),this.reserved1=this._readUint(32),this.duration=this._readUint(64)):(this.creation_time=this._readUint(32),this.modification_time=this._readUint(32),this.track_ID=this._readUint(32),this.reserved1=this._readUint(32),this.duration=this._readUint(32)),this.reserved2=[this._readUint(32),this._readUint(32)],this.layer=this._readUint(16),this.alternate_group=this._readUint(16),this.volume=this._readTemplate(16),this.reserved3=this._readUint(16),this.matrix=[];for(var a=0;a<9;a++)this.matrix.push(this._readTemplate(32));this.width=this._readTemplate(32),this.height=this._readTemplate(32)},ISOBox.prototype._boxParsers.trex=function(){this._parseFullBox(),this.track_ID=this._readUint(32),this.default_sample_description_index=this._readUint(32),this.default_sample_duration=this._readUint(32),this.default_sample_size=this._readUint(32),this.default_sample_flags=this._readUint(32)},ISOBox.prototype._boxParsers.trun=function(){this._parseFullBox(),this.sample_count=this._readUint(32),1&this.flags&&(this.data_offset=this._readInt(32)),4&this.flags&&(this.first_sample_flags=this._readUint(32)),this.samples=[];for(var a=0;a<this.sample_count;a++){var b={};256&this.flags&&(b.sample_duration=this._readUint(32)),512&this.flags&&(b.sample_size=this._readUint(32)),1024&this.flags&&(b.sample_flags=this._readUint(32)),2048&this.flags&&(0===this.version?b.sample_composition_time_offset=this._readUint(32):b.sample_composition_time_offset=this._readInt(32)),this.samples.push(b)}},ISOBox.prototype._boxParsers.vlab=function(){var a=new DataView(this._raw.buffer,this._cursor.offset,this._raw.byteLength-(this._cursor.offset-this._offset));this.source_label=ISOBoxer.Utils.dataViewToString(a)},ISOBox.prototype._boxParsers.vttC=function(){var a=new DataView(this._raw.buffer,this._cursor.offset,this._raw.byteLength-(this._cursor.offset-this._offset));this.config=ISOBoxer.Utils.dataViewToString(a)},ISOBox.prototype._boxParsers.vtte=function(){};
/*! codem-isoboxer v0.2.9 https://github.com/madebyhiro/codem-isoboxer/blob/master/LICENSE.txt */
var ISOBoxer={};ISOBoxer.parseBuffer=function(a){return new ISOFile(a).parse()},ISOBoxer.addBoxParser=function(a,b){"string"==typeof a&&"function"==typeof b&&(ISOBox.prototype._boxParsers[a]=b)},ISOBoxer.Utils={},ISOBoxer.Utils.dataViewToString=function(a,b){var c=b||"utf-8";if("undefined"!=typeof TextDecoder)return new TextDecoder(c).decode(a);var d=[],e=0;if("utf-8"===c)for(;e<a.byteLength;){var f=a.getUint8(e++);f<128||(f<224?(f=(31&f)<<6,f|=63&a.getUint8(e++)):f<240?(f=(15&f)<<12,f|=(63&a.getUint8(e++))<<6,f|=63&a.getUint8(e++)):(f=(7&f)<<18,f|=(63&a.getUint8(e++))<<12,f|=(63&a.getUint8(e++))<<6,f|=63&a.getUint8(e++))),d.push(String.fromCharCode(f))}else for(;e<a.byteLength;)d.push(String.fromCharCode(a.getUint8(e++)));return d.join("")},"undefined"!=typeof exports&&(exports.parseBuffer=ISOBoxer.parseBuffer,exports.addBoxParser=ISOBoxer.addBoxParser,exports.Utils=ISOBoxer.Utils),ISOBoxer.Cursor=function(a){this.offset="undefined"==typeof a?0:a};var ISOFile=function(a){this._raw=new DataView(a),this._cursor=new ISOBoxer.Cursor,this.boxes=[]};ISOFile.prototype.fetch=function(a){var b=this.fetchAll(a,!0);return b.length?b[0]:null},ISOFile.prototype.fetchAll=function(a,b){var c=[];return ISOFile._sweep.call(this,a,c,b),c},ISOFile.prototype.parse=function(){for(this._cursor.offset=0,this.boxes=[];this._cursor.offset<this._raw.byteLength;){var a=ISOBox.parse(this);if("undefined"==typeof a.type)break;this.boxes.push(a)}return this},ISOFile._sweep=function(a,b,c){this.type&&this.type==a&&b.push(this);for(var d in this.boxes){if(b.length&&c)return;ISOFile._sweep.call(this.boxes[d],a,b,c)}};var ISOBox=function(){this._cursor=new ISOBoxer.Cursor};ISOBox.parse=function(a){var b=new ISOBox;return b._offset=a._cursor.offset,b._root=a._root?a._root:a,b._raw=a._raw,b._parent=a,b._parseBox(),a._cursor.offset=b._raw.byteOffset+b._raw.byteLength,b},ISOBox.prototype._readInt=function(a){var b=null;switch(a){case 8:b=this._raw.getInt8(this._cursor.offset-this._raw.byteOffset);break;case 16:b=this._raw.getInt16(this._cursor.offset-this._raw.byteOffset);break;case 32:b=this._raw.getInt32(this._cursor.offset-this._raw.byteOffset);break;case 64:var c=this._raw.getInt32(this._cursor.offset-this._raw.byteOffset),d=this._raw.getInt32(this._cursor.offset-this._raw.byteOffset+4);b=c*Math.pow(2,32)+d}return this._cursor.offset+=a>>3,b},ISOBox.prototype._readUint=function(a){var b,c,d=null;switch(a){case 8:d=this._raw.getUint8(this._cursor.offset-this._raw.byteOffset);break;case 16:d=this._raw.getUint16(this._cursor.offset-this._raw.byteOffset);break;case 24:b=this._raw.getUint16(this._cursor.offset-this._raw.byteOffset),c=this._raw.getUint8(this._cursor.offset-this._raw.byteOffset+2),d=(b<<8)+c;break;case 32:d=this._raw.getUint32(this._cursor.offset-this._raw.byteOffset);break;case 64:b=this._raw.getUint32(this._cursor.offset-this._raw.byteOffset),c=this._raw.getUint32(this._cursor.offset-this._raw.byteOffset+4),d=b*Math.pow(2,32)+c}return this._cursor.offset+=a>>3,d},ISOBox.prototype._readString=function(a){for(var b="",c=0;c<a;c++){var d=this._readUint(8);b+=String.fromCharCode(d)}return b},ISOBox.prototype._readTerminatedString=function(){for(var a="";this._cursor.offset-this._offset<this._raw.byteLength;){var b=this._readUint(8);if(0===b)break;a+=String.fromCharCode(b)}return a},ISOBox.prototype._readTemplate=function(a){var b=this._readUint(a/2),c=this._readUint(a/2);return b+c/Math.pow(2,a/2)},ISOBox.prototype._readData=function(a){var b=a>0?a:this._raw.byteLength-(this._cursor.offset-this._offset),c=new DataView(this._raw.buffer,this._cursor.offset,b);return this._cursor.offset+=b,c},ISOBox.prototype._parseBox=function(){if(this._cursor.offset=this._offset,this._offset+8>this._raw.buffer.byteLength)return void(this._root._incomplete=!0);switch(this.size=this._readUint(32),this.type=this._readString(4),1==this.size&&(this.largesize=this._readUint(64)),"uuid"==this.type&&(this.usertype=this._readString(16)),this.size){case 0:this._raw=new DataView(this._raw.buffer,this._offset,this._raw.byteLength-this._cursor.offset);break;case 1:this._offset+this.size>this._raw.buffer.byteLength?(this._incomplete=!0,this._root._incomplete=!0):this._raw=new DataView(this._raw.buffer,this._offset,this.largesize);break;default:this._offset+this.size>this._raw.buffer.byteLength?(this._incomplete=!0,this._root._incomplete=!0):this._raw=new DataView(this._raw.buffer,this._offset,this.size)}this._incomplete||(this._boxContainers.indexOf(this.type)!==-1?this._parseContainerBox():this._boxParsers[this.type]&&this._boxParsers[this.type].call(this))},ISOBox.prototype._parseFullBox=function(){this.version=this._readUint(8),this.flags=this._readUint(24)},ISOBox.prototype._parseContainerBox=function(){for(this.boxes=[];this._cursor.offset-this._raw.byteOffset<this._raw.byteLength;)this.boxes.push(ISOBox.parse(this))},ISOBox.prototype._boxContainers=["dinf","edts","mdia","meco","mfra","minf","moof","moov","mvex","stbl","strk","traf","trak","tref","udta","vttc"],ISOBox.prototype._boxParsers={},ISOBox.prototype._boxParsers.avc1=function(){this.reserved1=[this._readUint(8),this._readUint(8),this._readUint(8),this._readUint(8),this._readUint(8),this._readUint(8)],this.data_reference_index=this._readUint(16),this.pre_defined1=this._readUint(16),this.reserved2=this._readUint(16),this.pre_defined2=[this._readUint(32),this._readUint(32),this._readUint(32)],this.width=this._readUint(16),this.height=this._readUint(16),this.horizresolution=this._readTemplate(32),this.vertresolution=this._readTemplate(32),this.reserved3=this._readUint(32),this.frame_count=this._readUint(16);var a=this._readUint(8);this.compressorname=this._readString(a);for(var b=0;b<31-a;b++)this._readUint(8);this.depth=this._readUint(16),this.pre_defined3=this._readInt(16),this.config=this._readData()},ISOBox.prototype._boxParsers.dref=function(){this._parseFullBox(),this.entry_count=this._readUint(32),this.entries=[];for(var a=0;a<this.entry_count;a++)this.entries.push(ISOBox.parse(this))},ISOBox.prototype._boxParsers.elst=function(){this._parseFullBox(),this.entry_count=this._readUint(32),this.entries=[];for(var a=1;a<=this.entry_count;a++){var b={};1==this.version?(b.segment_duration=this._readUint(64),b.media_time=this._readInt(64)):(b.segment_duration=this._readUint(32),b.media_time=this._readInt(32)),b.media_rate_integer=this._readInt(16),b.media_rate_fraction=this._readInt(16),this.entries.push(b)}},ISOBox.prototype._boxParsers.emsg=function(){this._parseFullBox(),this.scheme_id_uri=this._readTerminatedString(),this.value=this._readTerminatedString(),this.timescale=this._readUint(32),this.presentation_time_delta=this._readUint(32),this.event_duration=this._readUint(32),this.id=this._readUint(32),this.message_data=new DataView(this._raw.buffer,this._cursor.offset,this._raw.byteLength-(this._cursor.offset-this._offset))},ISOBox.prototype._boxParsers.free=ISOBox.prototype._boxParsers.skip=function(){this.data=new DataView(this._raw.buffer,this._cursor.offset,this._raw.byteLength-(this._cursor.offset-this._offset))},ISOBox.prototype._boxParsers.ftyp=ISOBox.prototype._boxParsers.styp=function(){for(this.major_brand=this._readString(4),this.minor_version=this._readUint(32),this.compatible_brands=[];this._cursor.offset-this._raw.byteOffset<this._raw.byteLength;)this.compatible_brands.push(this._readString(4))},ISOBox.prototype._boxParsers.hdlr=function(){this._parseFullBox(),this.pre_defined=this._readUint(32),this.handler_type=this._readString(4),this.reserved=[this._readUint(32),this._readUint(32),this._readUint(32)],this.name=this._readTerminatedString()},ISOBox.prototype._boxParsers.mdat=function(){this.data=this._readData()},ISOBox.prototype._boxParsers.mdhd=function(){this._parseFullBox(),1==this.version?(this.creation_time=this._readUint(64),this.modification_time=this._readUint(64),this.timescale=this._readUint(32),this.duration=this._readUint(64)):(this.creation_time=this._readUint(32),this.modification_time=this._readUint(32),this.timescale=this._readUint(32),this.duration=this._readUint(32));var a=this._readUint(16);this.pad=a>>15,this.language=String.fromCharCode((a>>10&31)+96,(a>>5&31)+96,(31&a)+96),this.pre_defined=this._readUint(16)},ISOBox.prototype._boxParsers.mehd=function(){this._parseFullBox(),1==this.version?this.fragment_duration=this._readUint(64):this.fragment_duration=this._readUint(32)},ISOBox.prototype._boxParsers.mfhd=function(){this._parseFullBox(),this.sequence_number=this._readUint(32)},ISOBox.prototype._boxParsers.mfro=function(){this._parseFullBox(),this.mfra_size=this._readUint(32)},ISOBox.prototype._boxParsers.mp4a=function(){this.reserved1=[this._readUint(8),this._readUint(8),this._readUint(8),this._readUint(8),this._readUint(8),this._readUint(8)],this.data_reference_index=this._readUint(16),this.reserved2=[this._readUint(32),this._readUint(32)],this.channelcount=this._readUint(16),this.samplesize=this._readUint(16),this.pre_defined=this._readUint(16),this.reserved3=this._readUint(16),this.samplerate=this._readTemplate(32),this.esds=this._readData()},ISOBox.prototype._boxParsers.mvhd=function(){this._parseFullBox();var a;for(1==this.version?(this.creation_time=this._readUint(64),this.modification_time=this._readUint(64),this.timescale=this._readUint(32),this.duration=this._readUint(64)):(this.creation_time=this._readUint(32),this.modification_time=this._readUint(32),this.timescale=this._readUint(32),this.duration=this._readUint(32)),this.rate=this._readTemplate(32),this.volume=this._readTemplate(16),this.reserved1=this._readUint(16),this.reserved2=[this._readUint(32),this._readUint(32)],this.matrix=[],a=0;a<9;a++)this.matrix.push(this._readTemplate(32));for(this.pre_defined=[],a=0;a<6;a++)this.pre_defined.push(this._readUint(32));this.next_track_ID=this._readUint(32)},ISOBox.prototype._boxParsers.payl=function(){var a=new DataView(this._raw.buffer,this._cursor.offset,this._raw.byteLength-(this._cursor.offset-this._offset));this.cue_text=ISOBoxer.Utils.dataViewToString(a)},ISOBox.prototype._boxParsers.sidx=function(){this._parseFullBox(),this.reference_ID=this._readUint(32),this.timescale=this._readUint(32),0===this.version?(this.earliest_presentation_time=this._readUint(32),this.first_offset=this._readUint(32)):(this.earliest_presentation_time=this._readUint(64),this.first_offset=this._readUint(64)),this.reserved=this._readUint(16),this.reference_count=this._readUint(16),this.references=[];for(var a=0;a<this.reference_count;a++){var b={},c=this._readUint(32);b.reference_type=c>>31&1,b.referenced_size=2147483647&c,b.subsegment_duration=this._readUint(32);var d=this._readUint(32);b.starts_with_SAP=d>>31&1,b.SAP_type=d>>28&7,b.SAP_delta_time=268435455&d,this.references.push(b)}},ISOBox.prototype._boxParsers.smhd=function(){this._parseFullBox(),this.balance=this._readTemplate(16),this.reserved=this._readUint(16)},ISOBox.prototype._boxParsers.ssix=function(){this._parseFullBox(),this.subsegment_count=this._readUint(32),this.subsegments=[];for(var a=0;a<this.subsegment_count;a++){var b={};b.ranges_count=this._readUint(32),b.ranges=[];for(var c=0;c<b.ranges_count;c++){var d={};d.level=this._readUint(8),d.range_size=this._readUint(24),b.ranges.push(d)}this.subsegments.push(b)}},ISOBox.prototype._boxParsers.stsd=function(){this._parseFullBox(),this.entry_count=this._readUint(32),this.entries=[];for(var a=0;a<this.entry_count;a++)this.entries.push(ISOBox.parse(this))},ISOBox.prototype._boxParsers.subs=function(){this._parseFullBox(),this.entry_count=this._readUint(32),this.samples_with_subsamples=[];for(var a=0,b=0;b<this.entry_count;b++){var c=this._readUint(32);a+=c;var d=this._readUint(16);if(d>0){for(var e={nr:a,subsamples:[]},f=0;f<d;f++){var g={};1&this.version?g.size=this._readUint(32):g.size=this._readUint(16),g.priority=this._readUint(8),g.discardable=this._readUint(8),g.codec_specific_parameters=this._readUint(32),e.subsamples.push(g)}this.samples_with_subsamples.push(e)}}},ISOBox.prototype._boxParsers.tfdt=function(){this._parseFullBox(),1==this.version?this.baseMediaDecodeTime=this._readUint(64):this.baseMediaDecodeTime=this._readUint(32)},ISOBox.prototype._boxParsers.tfhd=function(){this._parseFullBox(),this.track_ID=this._readUint(32),1&this.flags&&(this.base_data_offset=this._readUint(64)),2&this.flags&&(this.sample_description_offset=this._readUint(32)),8&this.flags&&(this.default_sample_duration=this._readUint(32)),16&this.flags&&(this.default_sample_size=this._readUint(32)),32&this.flags&&(this.default_sample_flags=this._readUint(32))},ISOBox.prototype._boxParsers.tfra=function(){this._parseFullBox(),this.track_ID=this._readUint(32),this._packed=this._readUint(32),this.reserved=this._packed>>>6,this.length_size_of_traf_num=(this._packed&&0xffff00000000)>>>4,this.length_size_of_trun_num=(this._packed&&4294901760)>>>2,this.length_size_of_sample_num=this._packed&&255,this.number_of_entry=this._readUint(32),this.entries=[];for(var a=0;a<this.number_of_entry;a++){var b={};1==this.version?(b.time=this._readUint(64),b.moof_offset=this._readUint(64)):(b.time=this._readUint(32),b.moof_offset=this._readUint(32)),b.traf_number=this._readUint(8*(this.length_size_of_traf_num+1)),b.trun_number=this._readUint(8*(this.length_size_of_trun_num+1)),b.sample_number=this._readUint(8*(this.length_size_of_sample_num+1)),this.entries.push(b)}},ISOBox.prototype._boxParsers.tkhd=function(){this._parseFullBox(),1==this.version?(this.creation_time=this._readUint(64),this.modification_time=this._readUint(64),this.track_ID=this._readUint(32),this.reserved1=this._readUint(32),this.duration=this._readUint(64)):(this.creation_time=this._readUint(32),this.modification_time=this._readUint(32),this.track_ID=this._readUint(32),this.reserved1=this._readUint(32),this.duration=this._readUint(32)),this.reserved2=[this._readUint(32),this._readUint(32)],this.layer=this._readUint(16),this.alternate_group=this._readUint(16),this.volume=this._readTemplate(16),this.reserved3=this._readUint(16),this.matrix=[];for(var a=0;a<9;a++)this.matrix.push(this._readTemplate(32));this.width=this._readTemplate(32),this.height=this._readTemplate(32)},ISOBox.prototype._boxParsers.trex=function(){this._parseFullBox(),this.track_ID=this._readUint(32),this.default_sample_description_index=this._readUint(32),this.default_sample_duration=this._readUint(32),this.default_sample_size=this._readUint(32),this.default_sample_flags=this._readUint(32)},ISOBox.prototype._boxParsers.trun=function(){this._parseFullBox(),this.sample_count=this._readUint(32),1&this.flags&&(this.data_offset=this._readInt(32)),4&this.flags&&(this.first_sample_flags=this._readUint(32)),this.samples=[];for(var a=0;a<this.sample_count;a++){var b={};256&this.flags&&(b.sample_duration=this._readUint(32)),512&this.flags&&(b.sample_size=this._readUint(32)),1024&this.flags&&(b.sample_flags=this._readUint(32)),2048&this.flags&&(0===this.version?b.sample_composition_time_offset=this._readUint(32):b.sample_composition_time_offset=this._readInt(32)),this.samples.push(b)}},ISOBox.prototype._boxParsers["url "]=ISOBox.prototype._boxParsers["urn "]=function(){this._parseFullBox(),"urn "===this.type&&(this.name=this._readTerminatedString()),this.location=this._readTerminatedString()},ISOBox.prototype._boxParsers.vlab=function(){var a=new DataView(this._raw.buffer,this._cursor.offset,this._raw.byteLength-(this._cursor.offset-this._offset));this.source_label=ISOBoxer.Utils.dataViewToString(a)},ISOBox.prototype._boxParsers.vmhd=function(){this._parseFullBox(),this.graphicsmode=this._readUint(16),this.opcolor=[this._readUint(16),this._readUint(16),this._readUint(16)]},ISOBox.prototype._boxParsers.vttC=function(){var a=new DataView(this._raw.buffer,this._cursor.offset,this._raw.byteLength-(this._cursor.offset-this._offset));this.config=ISOBoxer.Utils.dataViewToString(a)},ISOBox.prototype._boxParsers.vtte=function(){};

@@ -47,3 +47,3 @@ module.exports = function(grunt) {

banner: banner,
separator: ';\n'
separator: '\n'
},

@@ -50,0 +50,0 @@ dist: {

{
"name": "codem-isoboxer",
"version": "0.2.8",
"version": "0.2.9",
"description": "A lightweight JavaScript MP4 (MPEG-4, ISOBMFF) file/box parser.",

@@ -32,3 +32,3 @@ "keywords": [

"scripts": {
"test": "jasmine-node test/spec",
"test": "npm run grunt && jasmine-node test/spec",
"jshint": "jshint src/*.js src/**/*.js",

@@ -35,0 +35,0 @@ "grunt": "grunt",

# codem-isoboxer
[![Build Status](https://travis-ci.org/madebyhiro/codem-isoboxer.svg?branch=master)](https://travis-ci.org/madebyhiro/codem-isoboxer)
* http://github.com/madebyhiro/codem-isoboxer

@@ -4,0 +6,0 @@

@@ -139,3 +139,9 @@ var ISOBox = function() {

// additional parsing
if (!this._incomplete && this._boxParsers[this.type]) this._boxParsers[this.type].call(this);
if (!this._incomplete) {
if (this._boxContainers.indexOf(this.type) !== -1) {
this._parseContainerBox();
} else if (this._boxParsers[this.type]) {
this._boxParsers[this.type].call(this);
}
}
};

@@ -148,2 +154,11 @@

ISOBox.prototype._parseContainerBox = function() {
this.boxes = [];
while (this._cursor.offset - this._raw.byteOffset < this._raw.byteLength) {
this.boxes.push(ISOBox.parse(this));
}
};
ISOBox.prototype._boxContainers = ['dinf', 'edts', 'mdia', 'meco', 'mfra', 'minf', 'moof', 'moov', 'mvex', 'stbl', 'strk', 'traf', 'trak', 'tref', 'udta', 'vttc'];
ISOBox.prototype._boxParsers = {};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc