codem-isoboxer
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -0,1 +1,5 @@ | ||
## codem-isoboxer 0.2.3 (2016/03/29) ## | ||
* Added support for mehd, mfro, stsd (partial), tfra and trex (@danotrilogic) | ||
## codem-isoboxer 0.2.2 (2016/02/01) ## | ||
@@ -2,0 +6,0 @@ |
@@ -1,2 +0,2 @@ | ||
/*! codem-isoboxer v0.2.2 https://github.com/madebyhiro/codem-isoboxer/blob/master/LICENSE.txt */ | ||
/*! codem-isoboxer v0.2.3 https://github.com/madebyhiro/codem-isoboxer/blob/master/LICENSE.txt */ | ||
var ISOBoxer = {}; | ||
@@ -329,2 +329,12 @@ | ||
}; | ||
// ISO/IEC 14496-12:2012 - 8.8.2 Movie Extends Header Box | ||
ISOBox.prototype._boxParsers['mehd'] = function() { | ||
this._parseFullBox(); | ||
if (this.version == 1) { | ||
this.fragment_duration = this._readUint(64); | ||
} else { // version==0 | ||
this.fragment_duration = this._readUint(32); | ||
} | ||
}; | ||
// ISO/IEC 14496-12:2012 - 8.8.5 Movie Fragment Header Box | ||
@@ -335,2 +345,8 @@ ISOBox.prototype._boxParsers['mfhd'] = function() { | ||
}; | ||
// ISO/IEC 14496-12:2012 - 8.8.11 Movie Fragment Random Access Box | ||
ISOBox.prototype._boxParsers['mfro'] = function() { | ||
this._parseFullBox(); | ||
this.mfra_size = this._readUint(32); // Called mfra_size to distinguish from the normal "size" attribute of a box | ||
} | ||
; | ||
// ISO/IEC 14496-12:2012 - 8.2.2 Movie Header Box | ||
@@ -420,2 +436,51 @@ ISOBox.prototype._boxParsers['mvhd'] = function() { | ||
}; | ||
// ISO/IEC 14496-12:2012 - 8.5.2 Sample Description Box | ||
// TODO: This needs cleanup and a much more complete implementation | ||
ISOBox.prototype._boxParsers['stsd'] = function() { | ||
this._parseFullBox(); | ||
this.entry_count = this._readUint(32); | ||
this.entries = []; | ||
for (var i = 0; i < this.entry_count ; i++){ | ||
var entry = {}; | ||
entry.size = this._readUint(32); | ||
entry.char_code = this._readString(4); | ||
entry.reserved = [ this._readUint(16), this._readUint(16), this._readUint(16) ] | ||
entry.data_reference_index = this._readUint(16); | ||
// common data audio / video | ||
entry.version = this._readUint(16); | ||
entry.revision_level = this._readUint(16); | ||
entry.vendor = this._readUint(32); | ||
if (entry.char_code == "avc1"){ | ||
//avc | ||
entry.temporal_quality = this._readUint(32); | ||
entry.spatial_quality = this._readUint(32); | ||
entry.width = this._readUint(16); | ||
entry.height = this._readUint(16); | ||
entry.horizontal_resolution = this._readUint(32); | ||
entry.vertical_resolution = this._readUint(32); | ||
entry.data_size = this._readUint(32); // must be 0x0 | ||
entry.frame_count = this._readUint(16); // frames per sample | ||
entry.compressor_name = this._readUint(32); | ||
entry.depth = this._readUint(16); | ||
entry.color_table_id = this._readUint(16); | ||
}else if(entry.char_code == "mp4a"){ | ||
//mp4a | ||
entry.channels = this._readUint(16); | ||
entry.sample_size = this._readUint(16); // 8 or 16 | ||
entry.compression_id = this._readUint(16); | ||
entry.packet_size = this._readUint(16); // should be 0x0 | ||
entry.sample_rate = this._readUint(32); | ||
} | ||
//entry.data = this.data = new DataView(this._raw.buffer, this._cursor.offset, entry.size - 8); | ||
this.entries.push(entry); | ||
} | ||
} | ||
; | ||
// ISO/IEC 14496-12:2012 - 8.8.12 Track Fragmnent Decode Time | ||
@@ -440,2 +505,37 @@ ISOBox.prototype._boxParsers['tfdt'] = function() { | ||
}; | ||
// ISO/IEC 14496-12:2012 - 8.8.10 Track Fragment Random Access Box | ||
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 && 0xFFFF0000) >>> 2; | ||
this.length_size_of_sample_num = this._packed && 0xFF; | ||
this.number_of_entry = this._readUint(32); | ||
this.entries = []; | ||
for (var i = 0; i < this.number_of_entry ; i++){ | ||
var entry = {}; | ||
if(this.version==1){ | ||
entry.time = this._readUint(64); | ||
entry.moof_offset = this._readUint(64); | ||
}else{ | ||
entry.time = this._readUint(32); | ||
entry.moof_offset = this._readUint(32); | ||
} | ||
entry.traf_number = this._readUint((this.length_size_of_traf_num + 1) * 8); | ||
entry.trun_number = this._readUint((this.length_size_of_trun_num + 1) * 8); | ||
entry.sample_number = this._readUint((this.length_size_of_sample_num + 1) * 8); | ||
this.entries.push(entry); | ||
} | ||
} | ||
; | ||
// ISO/IEC 14496-12:2012 - 8.3.2 Track Header Box | ||
@@ -474,2 +574,12 @@ ISOBox.prototype._boxParsers['tkhd'] = function() { | ||
}; | ||
// ISO/IEC 14496-12:2012 - 8.8.3 Track Extends Box | ||
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); | ||
}; | ||
// ISO/IEC 14496-12:2012 - 8.8.8 Track Run Box | ||
@@ -476,0 +586,0 @@ // Note: the 'trun' box has a direct relation to the 'tfhd' box for defaults. |
@@ -1,2 +0,2 @@ | ||
/*! codem-isoboxer v0.2.2 https://github.com/madebyhiro/codem-isoboxer/blob/master/LICENSE.txt */ | ||
var ISOBoxer={};ISOBoxer.parseBuffer=function(a){return new ISOFile(a).parse()},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++);128>f||(224>f?(f=(31&f)<<6,f|=63&a.getUint8(e++)):240>f?(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.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=null;switch(a){case 8:b=this._raw.getUint8(this._cursor.offset-this._raw.byteOffset);break;case 16:b=this._raw.getUint16(this._cursor.offset-this._raw.byteOffset);break;case 24:var c=this._raw.getUint16(this._cursor.offset-this._raw.byteOffset),d=this._raw.getUint8(this._cursor.offset-this._raw.byteOffset+2);b=(c<<8)+d;break;case 32:b=this._raw.getUint32(this._cursor.offset-this._raw.byteOffset);break;case 64:var c=this._raw.getUint32(this._cursor.offset-this._raw.byteOffset),d=this._raw.getUint32(this._cursor.offset-this._raw.byteOffset+4);b=c*Math.pow(2,32)+d}return this._cursor.offset+=a>>3,b},ISOBox.prototype._readString=function(a){for(var b="",c=0;a>c;c++){var d=this._readUint(8);b+=String.fromCharCode(d)}return b},ISOBox.prototype._readTerminatedString=function(){for(var a="";;){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._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={},["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_versions=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=new DataView(this._raw.buffer,this._cursor.offset,this._raw.byteLength-(this._cursor.offset-this._offset))},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.mfhd=function(){this._parseFullBox(),this.sequence_number=this._readUint(32)},ISOBox.prototype._boxParsers.mvhd=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)),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=[];for(var a=0;9>a;a++)this.matrix.push(this._readTemplate(32));this.pre_defined=[];for(var a=0;6>a;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.tfdt=function(){this._parseFullBox(),this.baseMediaDecodeTime=this._readUint(1==this.version?64: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.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;9>a;a++)this.matrix.push(this._readTemplate(32));this.width=this._readUint(32),this.height=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&&(b.sample_composition_time_offset=0==this.version?this._readUint(32):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.3 https://github.com/madebyhiro/codem-isoboxer/blob/master/LICENSE.txt */ | ||
var ISOBoxer={};ISOBoxer.parseBuffer=function(a){return new ISOFile(a).parse()},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++);128>f||(224>f?(f=(31&f)<<6,f|=63&a.getUint8(e++)):240>f?(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.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=null;switch(a){case 8:b=this._raw.getUint8(this._cursor.offset-this._raw.byteOffset);break;case 16:b=this._raw.getUint16(this._cursor.offset-this._raw.byteOffset);break;case 24:var c=this._raw.getUint16(this._cursor.offset-this._raw.byteOffset),d=this._raw.getUint8(this._cursor.offset-this._raw.byteOffset+2);b=(c<<8)+d;break;case 32:b=this._raw.getUint32(this._cursor.offset-this._raw.byteOffset);break;case 64:var c=this._raw.getUint32(this._cursor.offset-this._raw.byteOffset),d=this._raw.getUint32(this._cursor.offset-this._raw.byteOffset+4);b=c*Math.pow(2,32)+d}return this._cursor.offset+=a>>3,b},ISOBox.prototype._readString=function(a){for(var b="",c=0;a>c;c++){var d=this._readUint(8);b+=String.fromCharCode(d)}return b},ISOBox.prototype._readTerminatedString=function(){for(var a="";;){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._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={},["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_versions=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=new DataView(this._raw.buffer,this._cursor.offset,this._raw.byteLength-(this._cursor.offset-this._offset))},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(),this.fragment_duration=this._readUint(1==this.version?64: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.mvhd=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)),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=[];for(var a=0;9>a;a++)this.matrix.push(this._readTemplate(32));this.pre_defined=[];for(var a=0;6>a;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++){var b={};b.size=this._readUint(32),b.char_code=this._readString(4),b.reserved=[this._readUint(16),this._readUint(16),this._readUint(16)],b.data_reference_index=this._readUint(16),b.version=this._readUint(16),b.revision_level=this._readUint(16),b.vendor=this._readUint(32),"avc1"==b.char_code?(b.temporal_quality=this._readUint(32),b.spatial_quality=this._readUint(32),b.width=this._readUint(16),b.height=this._readUint(16),b.horizontal_resolution=this._readUint(32),b.vertical_resolution=this._readUint(32),b.data_size=this._readUint(32),b.frame_count=this._readUint(16),b.compressor_name=this._readUint(32),b.depth=this._readUint(16),b.color_table_id=this._readUint(16)):"mp4a"==b.char_code&&(b.channels=this._readUint(16),b.sample_size=this._readUint(16),b.compression_id=this._readUint(16),b.packet_size=this._readUint(16),b.sample_rate=this._readUint(32)),this.entries.push(b)}},ISOBox.prototype._boxParsers.tfdt=function(){this._parseFullBox(),this.baseMediaDecodeTime=this._readUint(1==this.version?64: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;9>a;a++)this.matrix.push(this._readTemplate(32));this.width=this._readUint(32),this.height=this._readUint(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&&(b.sample_composition_time_offset=0==this.version?this._readUint(32):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(){}; |
{ | ||
"name": "codem-isoboxer", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Browser-based MPEG-4 (ISOBMFF) file/box parsing.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69757
37
1174