text: /*! mp4box 12-11-2019 */
  
  var Log=console;Log.setLogLevel=function(e){};var MP4BoxStream=function(e){if(!(e instanceof ArrayBuffer))throw"Needs an array buffer";this.buffer=e,this.dataview=new DataView(e),this.position=0};MP4BoxStream.prototype.getPosition=function(){return this.position},MP4BoxStream.prototype.getEndPosition=function(){return this.buffer.byteLength},MP4BoxStream.prototype.getLength=function(){return this.buffer.byteLength},MP4BoxStream.prototype.seek=function(e){var t=Math.max(0,Math.min(this.buffer.byteLength,e));return this.position=isNaN(t)||!isFinite(t)?0:t,!0},MP4BoxStream.prototype.isEos=function(){return this.getPosition()>=this.getEndPosition()},MP4BoxStream.prototype.readAnyInt=function(e,t){var r=0;if(this.position+e<=this.buffer.byteLength){switch(e){case 1:r=t?this.dataview.getInt8(this.position):this.dataview.getUint8(this.position);break;case 2:r=t?this.dataview.getInt16(this.position):this.dataview.getUint16(this.position);break;case 3:if(t)throw"No method for reading signed 24 bits values";r=this.dataview.getUint8(this.position)<<16,r|=this.dataview.getUint8(this.position)<<8,r|=this.dataview.getUint8(this.position);break;case 4:r=t?this.dataview.getInt32(this.position):this.dataview.getUint32(this.position);break;case 8:if(t)throw"No method for reading signed 64 bits values";r=this.dataview.getUint32(this.position)<<32,r|=this.dataview.getUint32(this.position);break;default:throw"readInt method not implemented for size: "+e}return this.position+=e,r}throw"Not enough bytes in buffer"},MP4BoxStream.prototype.readUint8=function(){return this.readAnyInt(1,!1)},MP4BoxStream.prototype.readUint16=function(){return this.readAnyInt(2,!1)},MP4BoxStream.prototype.readUint24=function(){return this.readAnyInt(3,!1)},MP4BoxStream.prototype.readUint32=function(){return this.readAnyInt(4,!1)},MP4BoxStream.prototype.readUint64=function(){return this.readAnyInt(8,!1)},MP4BoxStream.prototype.readString=function(e){if(this.position+e<=this.buffer.byteLength){for(var t="",r=0;r<e;r++)t+=String.fromCharCode(this.readUint8());return t}throw"Not enough bytes in buffer"},MP4BoxStream.prototype.readCString=function(){for(var e=[];;){var t=this.readUint8();if(0===t)break;e.push(t)}return String.fromCharCode.apply(null,e)},MP4BoxStream.prototype.readInt8=function(){return this.readAnyInt(1,!0)},MP4BoxStream.prototype.readInt16=function(){return this.readAnyInt(2,!0)},MP4BoxStream.prototype.readInt32=function(){return this.readAnyInt(4,!0)},MP4BoxStream.prototype.readInt64=function(){return this.readAnyInt(8,!1)},MP4BoxStream.prototype.readUint8Array=function(e){for(var t=new Uint8Array(e),r=0;r<e;r++)t[r]=this.readUint8();return t},MP4BoxStream.prototype.readInt16Array=function(e){for(var t=new Int16Array(e),r=0;r<e;r++)t[r]=this.readInt16();return t},MP4BoxStream.prototype.readUint16Array=function(e){for(var t=new Int16Array(e),r=0;r<e;r++)t[r]=this.readUint16();return t},MP4BoxStream.prototype.readUint32Array=function(e){for(var t=new Uint32Array(e),r=0;r<e;r++)t[r]=this.readUint32();return t},MP4BoxStream.prototype.readInt32Array=function(e){for(var t=new Int32Array(e),r=0;r<e;r++)t[r]=this.readInt32();return t},"undefined"!=typeof exports&&(exports.MP4BoxStream=MP4BoxStream);var BoxParser={ERR_INVALID_DATA:-1,ERR_NOT_ENOUGH_DATA:0,OK:1,BASIC_BOXES:["mdat","idat","free","skip","meco","strk"],FULL_BOXES:["hmhd","nmhd","iods","xml ","bxml","ipro","mere"],CONTAINER_BOXES:[["moov",["trak","pssh"]],["trak"],["edts"],["mdia"],["minf"],["dinf"],["stbl",["sgpd","sbgp"]],["mvex",["trex"]],["moof",["traf"]],["traf",["trun","sgpd","sbgp"]],["vttc"],["tref"],["iref"],["mfra",["tfra"]],["meco"],["hnti"],["hinf"],["strk"],["strd"],["sinf"],["rinf"],["schi"],["trgr"],["udta",["kind"]],["iprp",["ipma"]],["ipco"]],boxCodes:[],fullBoxCodes:[],containerBoxCodes:[],sampleEntryCodes:{},sampleGroupEntryCodes:[],trackGroupTypes:[],UUIDBoxes:{},UUIDs:[],initialize:function(){BoxParser.FullBox.prototype=new BoxParser.Box,BoxParser.ContainerBox.prototype=new BoxParser.Box,BoxParser.SampleEntry.prototype=new BoxParser.Box,BoxParser.TrackGroupTypeBox.prototype=new BoxParser.FullBox,BoxParser.BASIC_BOXES.forEach(function(e){BoxParser.createBoxCtor(e)}),BoxParser.FULL_BOXES.forEach(function(e){BoxParser.createFullBoxCtor(e)}),BoxParser.CONTAINER_BOXES.forEach(function(e){BoxParser.createContainerBoxCtor(e[0],null,e[1])})},Box:function(e,t,r){this.type=e,this.size=t,this.uuid=r},FullBox:function(e,t,r){BoxParser.Box.call(this,e,t,r),this.flags=0,this.version=0},ContainerBox:function(e,t,r){BoxParser.Box.call(this,e,t,r),this.boxes=[]},SampleEntry:function(e,t,r,i){BoxParser.ContainerBox.call(this,e,t),this.hdr_size=r,this.start=i},SampleGroupEntry:function(e){this.grouping_type=e},TrackGroupTypeBox:function(e,t){BoxParser.FullBox.call(this,e,t)},createBoxCtor:function(t,e){BoxParser.boxCodes.push(t),BoxParser[t+"Box"]=function(e){BoxParser.Box.call(this,t,e)},BoxParser[t+"Box"].prototype=new BoxParser.Box,e&&(BoxParser[t+"Box"].prototype.parse=e)},createFullBoxCtor:function(t,r){BoxParser[t+"Box"]=function(e){BoxParser.FullBox.call(this,t,e)},BoxParser[t+"Box"].prototype=new BoxParser.FullBox,BoxParser[t+"Box"].prototype.parse=function(e){this.parseFullHeader(e),r&&r.call(this,e)}},addSubBoxArrays:function(e){if(e)for(var t=(this.subBoxNames=e).length,r=0;r<t;r++)this[e[r]+"s"]=[]},createContainerBoxCtor:function(t,e,r){BoxParser[t+"Box"]=function(e){BoxParser.ContainerBox.call(this,t,e),BoxParser.addSubBoxArrays.call(this,r)},BoxParser[t+"Box"].prototype=new BoxParser.ContainerBox,e&&(BoxParser[t+"Box"].prototype.parse=e)},createMediaSampleEntryCtor:function(e,t,r){BoxParser.sampleEntryCodes[e]=[],BoxParser[e+"SampleEntry"]=function(e,t){BoxParser.SampleEntry.call(this,e,t),BoxParser.addSubBoxArrays.call(this,r)},BoxParser[e+"SampleEntry"].prototype=new BoxParser.SampleEntry,t&&(BoxParser[e+"SampleEntry"].prototype.parse=t)},createSampleEntryCtor:function(t,r,e,i){BoxParser.sampleEntryCodes[t].push(r),BoxParser[r+"SampleEntry"]=function(e){BoxParser[t+"SampleEntry"].call(this,r,e),BoxParser.addSubBoxArrays.call(this,i)},BoxParser[r+"SampleEntry"].prototype=new BoxParser[t+"SampleEntry"],e&&(BoxParser[r+"SampleEntry"].prototype.parse=e)},createEncryptedSampleEntryCtor:function(e,t,r){BoxParser.createSampleEntryCtor.call(this,e,t,r,["sinf"])},createSampleGroupCtor:function(t,e){BoxParser[t+"SampleGroupEntry"]=function(e){BoxParser.SampleGroupEntry.call(this,t,e)},BoxParser[t+"SampleGroupEntry"].prototype=new BoxParser.SampleGroupEntry,e&&(BoxParser[t+"SampleGroupEntry"].prototype.parse=e)},createTrackGroupCtor:function(t,e){BoxParser[t+"TrackGroupTypeBox"]=function(e){BoxParser.TrackGroupTypeBox.call(this,t,e)},BoxParser[t+"TrackGroupTypeBox"].prototype=new BoxParser.TrackGroupTypeBox,e&&(BoxParser[t+"TrackGroupTypeBox"].prototype.parse=e)},createUUIDBox:function(t,r,i,s){BoxParser.UUIDs.push(t),BoxParser.UUIDBoxes[t]=function(e){r?BoxParser.FullBox.call(this,"uuid",e,t):i?BoxParser.ContainerBox.call(this,"uuid",e,t):BoxParser.Box.call(this,"uuid",e,t)},BoxParser.UUIDBoxes[t].prototype=r?new BoxParser.FullBox:i?new BoxParser.ContainerBox:new BoxParser.Box,s&&(BoxParser.UUIDBoxes[t].prototype.parse=r?function(e){this.parseFullHeader(e),s&&s.call(this,e)}:s)}};BoxParser.initialize(),BoxParser.TKHD_FLAG_ENABLED=1,BoxParser.TKHD_FLAG_IN_MOVIE=2,BoxParser.TKHD_FLAG_IN_PREVIEW=4,BoxParser.TFHD_FLAG_BASE_DATA_OFFSET=1,BoxParser.TFHD_FLAG_SAMPLE_DESC=2,BoxParser.TFHD_FLAG_SAMPLE_DUR=8,BoxParser.TFHD_FLAG_SAMPLE_SIZE=16,BoxParser.TFHD_FLAG_SAMPLE_FLAGS=32,BoxParser.TFHD_FLAG_DUR_EMPTY=65536,BoxParser.TFHD_FLAG_DEFAULT_BASE_IS_MOOF=131072,BoxParser.TRUN_FLAGS_DATA_OFFSET=1,BoxParser.TRUN_FLAGS_FIRST_FLAG=4,BoxParser.TRUN_FLAGS_DURATION=256,BoxParser.TRUN_FLAGS_SIZE=512,BoxParser.TRUN_FLAGS_FLAGS=1024,BoxParser.TRUN_FLAGS_CTS_OFFSET=2048,BoxParser.Box.prototype.add=function(e){return this.addBox(new BoxParser[e+"Box"])},BoxParser.Box.prototype.addBox=function(e){return this.boxes.push(e),this[e.type+"s"]?this[e.type+"s"].push(e):this[e.type]=e,e},BoxParser.Box.prototype.set=function(e,t){return this[e]=t,this},BoxParser.Box.prototype.addEntry=function(e,t){var r=t||"entries";return this[r]||(this[r]=[]),this[r].push(e),this},"undefined"!=typeof exports&&(exports.BoxParser=BoxParser),BoxParser.parseUUID=function(e){return BoxParser.parseHex16(e)},BoxParser.parseHex16=function(e){for(var t="",r=0;r<16;r++){var i=e.readUint8().toString(16);t+=1===i.length?"0"+i:i}return t},BoxParser.parseOneBox=function(e,t,r){var i,s,a,o=e.getPosition(),n=0;if(e.getEndPosition()-o<8)return Log.debug("BoxParser","Not enough data in stream to parse the type and size of the box"),{code:BoxParser.ERR_NOT_ENOUGH_DATA};if(r&&r<8)return Log.debug("BoxParser","Not enough bytes left in the parent box to parse a new box"),{code:BoxParser.ERR_NOT_ENOUGH_DATA};var h=e.readUint32(),d=e.readString(4),l=d;if(Log.debug("BoxParser","Found box of type '"+d+"' and size "+h+" at position "+o),n=8,"uuid"==d){if(e.getEndPosition()-e.getPosition()<16||r-n<16)return e.seek(o),Log.debug("BoxParser","Not enough bytes left in the parent box to parse a UUID box"),{code:BoxParser.ERR_NOT_ENOUGH_DATA};n+=16,l=a=BoxParser.parseUUID(e)}if(1==h){if(e.getEndPosition()-e.getPosition()<8||r&&r-n<8)return e.seek(o),Log.warn("BoxParser",'Not enough data in stream to parse the extended size of the "'+d+'" box'),{code:BoxParser.ERR_NOT_ENOUGH_DATA};h=e.readUint64(),n+=8}else if(0===h)if(r)h=r;else if("mdat"!==d)return Log.error("BoxParser","Unlimited box size not supported for type: '"+d+"'"),i=new BoxParser.Box(d,h),{code:BoxParser.OK,box:i,size:i.size};return h<n?(Log.error("BoxParser","Box of type "+d+" has an invalid size "+h+" (too small to be a box)"),{code:BoxParser.ERR_NOT_ENOUGH_DATA,type:d,size:h,hdr_size:n,start:o}):r&&r<h?(Log.error("BoxParser","Box of type '"+d+"' has a size "+h+" greater than its container size "+r),{code:BoxParser.ERR_NOT_ENOUGH_DATA,type:d,size:h,hdr_size:n,start:o}):o+h>e.getEndPosition()?(e.seek(o),Log.info("BoxParser","Not enough data in stream to parse the entire '"+d+"' box"),{code:BoxParser.ERR_NOT_ENOUGH_DATA,type:d,size:h,hdr_size:n,start:o}):t?{code:BoxParser.OK,type:d,size:h,hdr_size:n,start:o}:(BoxParser[d+"Box"]?i=new BoxParser[d+"Box"](h):"uuid"!==d?(Log.warn("BoxParser","Unknown box type: '"+d+"'"),(i=new BoxParser.Box(d,h)).has_unparsed_data=!0):BoxParser.UUIDBoxes[a]?i=new BoxParser.UUIDBoxes[a](h):(Log.warn("BoxParser","Unknown uuid type: '"+a+"'"),(i=new BoxParser.Box(d,h)).uuid=a,i.has_unparsed_data=!0),i.hdr_size=n,i.start=o,i.write===BoxParser.Box.prototype.write&&"mdat"!==i.type&&(Log.info("BoxParser","'"+l+"' box writing not yet implemented, keeping unparsed data in memory for later write"),i.parseDataAndRewind(e)),i.parse(e),(s=e.getPosition()-(i.start+i.size))<0?(Log.warn("BoxParser","Parsing of box '"+l+"' did not read the entire indicated box data size (missing "+-s+" bytes), seeking forward"),e.seek(i.start+i.size)):0<s&&(Log.error("BoxParser","Parsing of box '"+l+"' read "+s+" more bytes than the indicated box data size, seeking backwards"),e.seek(i.start+i.size)),{code:BoxParser.OK,box:i,size:i.size})},BoxParser.Box.prototype.parse=function(e){"mdat"!=this.type?this.data=e.readUint8Array(this.size-this.hdr_size):0===this.size?e.seek(e.getEndPosition()):e.seek(this.start+this.size)},BoxParser.Box.prototype.parseDataAndRewind=function(e){this.data=e.readUint8Array(this.size-this.hdr_size),e.position-=this.size-this.hdr_size},BoxParser.FullBox.prototype.parseDataAndRewind=function(e){this.parseFullHeader(e),this.data=e.readUint8Array(this.size-this.hdr_size),this.hdr_size-=4,e.position-=this.size-this.hdr_size},BoxParser.FullBox.prototype.parseFullHeader=function(e){this.version=e.readUint8(),this.flags=e.readUint24(),this.hdr_size+=4},BoxParser.FullBox.prototype.parse=function(e){this.parseFullHeader(e),this.data=e.readUint8Array(this.size-this.hdr_size)},BoxParser.ContainerBox.prototype.parse=function(e){for(var t,r;e.getPosition()<this.start+this.size;){if((t=BoxParser.parseOneBox(e,!1,this.size-(e.getPosition()-this.start))).code!==BoxParser.OK)return;if(r=t.box,this.boxes.push(r),this.subBoxNames&&-1!=this.subBoxNames.indexOf(r.type))this[this.subBoxNames[this.subBoxNames.indexOf(r.type)]+"s"].push(r);else{var i="uuid"!==r.type?r.type:r.uuid;this[i]?Log.warn("Box of type "+i+" already stored in field of this type"):this[i]=r}}},BoxParser.Box.prototype.parseLanguage=function(e){this.language=e.readUint16();var t=[];t[0]=this.language>>10&31,t[1]=this.language>>5&31,t[2]=31&this.language,this.languageString=String.fromCharCode(t[0]+96,t[1]+96,t[2]+96)},BoxParser.createFullBoxCtor("emsg",function(e){this.scheme_id_uri=e.readCString(),this.value=e.readCString(),this.timescale=e.readUint32(),this.presentation_time_delta=e.readUint32(),this.event_duration=e.readUint32(),this.id=e.readUint32();var t=this.size-this.hdr_size-(16+(this.scheme_id_uri.length+1)+(this.value.length+1));this.message_data=e.readUint8Array(t)}),BoxParser.createBoxCtor("styp",function(e){BoxParser.ftypBox.prototype.parse.call(this,e)}),BoxParser.createBoxCtor("ftyp",function(e){var t=this.size-this.hdr_size;this.major_brand=e.readString(4),this.minor_version=e.readUint32(),t-=8,this.compatible_brands=[];for(var r=0;4<=t;)this.compatible_brands[r]=e.readString(4),t-=4,r++}),BoxParser.createFullBoxCtor("mdhd",function(e){1==this.version?(this.creation_time=e.readUint64(),this.modification_time=e.readUint64(),this.timescale=e.readUint32(),this.duration=e.readUint64()):(this.creation_time=e.readUint32(),this.modification_time=e.readUint32(),this.timescale=e.readUint32(),this.duration=e.readUint32()),this.parseLanguage(e),e.readUint16()}),BoxParser.createFullBoxCtor("mfhd",function(e){this.sequence_number=e.readUint32()}),BoxParser.createFullBoxCtor("mvhd",function(e){1==this.version?(this.creation_time=e.readUint64(),this.modification_time=e.readUint64(),this.timescale=e.readUint32(),this.duration=e.readUint64()):(this.creation_time=e.readUint32(),this.modification_time=e.readUint32(),this.timescale=e.readUint32(),this.duration=e.readUint32()),this.rate=e.readUint32(),this.volume=e.readUint16()>>8,e.readUint16(),e.readUint32Array(2),this.matrix=e.readUint32Array(9),e.readUint32Array(6),this.next_track_id=e.readUint32()}),BoxParser.createFullBoxCtor("sidx",function(e){this.reference_ID=e.readUint32(),this.timescale=e.readUint32(),0===this.version?(this.earliest_presentation_time=e.readUint32(),this.first_offset=e.readUint32()):(this.earliest_presentation_time=e.readUint64(),this.first_offset=e.readUint64()),e.readUint16(),this.references=[];for(var t=e.readUint16(),r=0;r<t;r++){var i={};this.references.push(i);var s=e.readUint32();i.reference_type=s>>31&1,i.referenced_size=2147483647&s,i.subsegment_duration=e.readUint32(),s=e.readUint32(),i.starts_with_SAP=s>>31&1,i.SAP_type=s>>28&7,i.SAP_delta_time=268435455&s}}),BoxParser.createFullBoxCtor("ssix",function(e){this.subsegments=[];for(var t=e.readUint32(),r=0;r<t;r++){var i={};this.subsegments.push(i),i.ranges=[];for(var s=e.readUint32(),a=0;a<s;a++){var o={};i.ranges.push(o),o.level=e.readUint8(),o.range_size=e.readUint24()}}}),BoxParser.createFullBoxCtor("tkhd",function(e){1==this.version?(this.creation_time=e.readUint64(),this.modification_time=e.readUint64(),this.track_id=e.readUint32(),e.readUint32(),this.duration=e.readUint64()):(this.creation_time=e.readUint32(),this.modification_time=e.readUint32(),this.track_id=e.readUint32(),e.readUint32(),this.duration=e.readUint32()),e.readUint32Array(2),this.layer=e.readInt16(),this.alternate_group=e.readInt16(),this.volume=e.readInt16()>>8,e.readUint16(),this.matrix=e.readInt32Array(9),this.width=e.readUint32(),this.height=e.readUint32()}),BoxParser.createFullBoxCtor("tfhd",function(e){var t=0;this.track_id=e.readUint32(),this.size-this.hdr_size>t&&this.flags&BoxParser.TFHD_FLAG_BASE_DATA_OFFSET?(this.base_data_offset=e.readUint64(),t+=8):this.base_data_offset=0,this.size-this.hdr_size>t&&this.flags&BoxParser.TFHD_FLAG_SAMPLE_DESC?(this.default_sample_description_index=e.readUint32(),t+=4):this.default_sample_description_index=0,this.size-this.hdr_size>t&&this.flags&BoxParser.TFHD_FLAG_SAMPLE_DUR?(this.default_sample_duration=e.readUint32(),t+=4):this.default_sample_duration=0,this.size-this.hdr_size>t&&this.flags&BoxParser.TFHD_FLAG_SAMPLE_SIZE?(this.default_sample_size=e.readUint32(),t+=4):this.default_sample_size=0,this.size-this.hdr_size>t&&this.flags&BoxParser.TFHD_FLAG_SAMPLE_FLAGS?(this.default_sample_flags=e.readUint32(),t+=4):this.default_sample_flags=0}),BoxParser.createFullBoxCtor("tfdt",function(e){1==this.version?this.baseMediaDecodeTime=e.readUint64():this.baseMediaDecodeTime=e.readUint32()}),BoxParser.createFullBoxCtor("trun",function(e){var t=0;if(this.sample_count=e.readUint32(),t+=4,this.size-this.hdr_size>t&&this.flags&BoxParser.TRUN_FLAGS_DATA_OFFSET?(this.data_offset=e.readInt32(),t+=4):this.data_offset=0,this.size-this.hdr_size>t&&this.flags&BoxParser.TRUN_FLAGS_FIRST_FLAG?(this.first_sample_flags=e.readUint32(),t+=4):this.first_sample_flags=0,this.sample_duration=[],this.sample_size=[],this.sample_flags=[],this.sample_composition_time_offset=[],this.size-this.hdr_size>t)for(var r=0;r<this.sample_count;r++)this.flags&BoxParser.TRUN_FLAGS_DURATION&&(this.sample_duration[r]=e.readUint32()),this.flags&BoxParser.TRUN_FLAGS_SIZE&&(this.sample_size[r]=e.readUint32()),this.flags&BoxParser.TRUN_FLAGS_FLAGS&&(this.sample_flags[r]=e.readUint32()),this.flags&BoxParser.TRUN_FLAGS_CTS_OFFSET&&(0===this.version?this.sample_composition_time_offset[r]=e.readUint32():this.sample_composition_time_offset[r]=e.readInt32())});var ISOFile=function(e){this.stream=e||new MultiBufferStream,this.boxes=[],this.mdats=[],this.moofs=[],this.isProgressive=!1,this.moovStartFound=!1,this.onMoovStart=null,this.moovStartSent=!1,this.onReady=null,this.readySent=!1,this.onSegment=null,this.onSamples=null,this.onError=null,this.sampleListBuilt=!1,this.fragmentedTracks=[],this.extractedTracks=[],this.isFragmentationInitialized=!1,this.sampleProcessingStarted=!1,this.nextMoofNumber=0,this.itemListBuilt=!1,this.onSidx=null,this.sidxSent=!1};ISOFile.prototype.setSegmentOptions=function(e,t,r){var i=this.getTrackById(e);if(i){var s={};this.fragmentedTracks.push(s),s.id=e,s.user=t,(s.trak=i).nextSample=0,s.segmentStream=null,s.nb_samples=1e3,s.rapAlignement=!0,r&&(r.nbSamples&&(s.nb_samples=r.nbSamples),r.rapAlignement&&(s.rapAlignement=r.rapAlignement))}},ISOFile.prototype.unsetSegmentOptions=function(e){for(var t=-1,r=0;r<this.fragmentedTracks.length;r++){this.fragmentedTracks[r].id==e&&(t=r)}-1<t&&this.fragmentedTracks.splice(t,1)},ISOFile.prototype.setExtractionOptions=function(e,t,r){var i=this.getTrackById(e);if(i){var s={};this.extractedTracks.push(s),s.id=e,s.user=t,(s.trak=i).nextSample=0,s.nb_samples=1e3,s.samples=[],r&&r.nbSamples&&(s.nb_samples=r.nbSamples)}},ISOFile.prototype.unsetExtractionOptions=function(e){for(var t=-1,r=0;r<this.extractedTracks.length;r++){this.extractedTracks[r].id==e&&(t=r)}-1<t&&this.extractedTracks.splice(t,1)},ISOFile.prototype.parse=function(){var e,t;if(!this.restoreParsePosition||this.restoreParsePosition())for(;;){if(this.hasIncompleteMdat&&this.hasIncompleteMdat()){if(this.processIncompleteMdat())continue;return}if(this.saveParsePosition&&this.saveParsePosition(),(e=BoxParser.parseOneBox(this.stream,!1)).code===BoxParser.ERR_NOT_ENOUGH_DATA){if(this.processIncompleteBox){if(this.processIncompleteBox(e))continue;return}return}var r;switch(r="uuid"!==(t=e.box).type?t.type:t.uuid,this.boxes.push(t),r){case"mdat":this.mdats.push(t);break;case"moof":this.moofs.push(t);break;case"moov":this.moovStartFound=!0,0===this.mdats.length&&(this.isProgressive=!0);default:void 0!==this[r]&&Log.warn("ISOFile","Duplicate Box of type: "+r+", overriding previous occurrence"),this[r]=t}this.updateUsedBytes&&this.updateUsedBytes(t,e)}},ISOFile.prototype.checkBuffer=function(e){if(null==e)throw"Buffer must be defined and non empty";if(void 0===e.fileStart)throw"Buffer must have a fileStart property";return 0===e.byteLength?(Log.warn("ISOFile","Ignoring empty buffer (fileStart: "+e.fileStart+")"),this.stream.logBufferLevel(),!1):(Log.info("ISOFile","Processing buffer (fileStart: "+e.fileStart+")"),e.usedBytes=0,this.stream.insertBuffer(e),this.stream.logBufferLevel(),!!this.stream.initialized()||(Log.warn("ISOFile","Not ready to start parsing"),!1))},ISOFile.prototype.appendBuffer=function(e,t){var r;if(this.checkBuffer(e))return this.parse(),this.moovStartFound&&!this.moovStartSent&&(this.moovStartSent=!0,this.onMoovStart&&this.onMoovStart()),this.moov?(this.sampleListBuilt||(this.buildSampleLists(),this.sampleListBuilt=!0),this.updateSampleLists(),this.onReady&&!this.readySent&&(this.readySent=!0,this.onReady(this.getInfo())),this.processSamples(t),this.nextSeekPosition?(r=this.nextSeekPosition,this.nextSeekPosition=void 0):r=this.nextParsePosition,this.stream.getEndFilePositionAfter&&(r=this.stream.getEndFilePositionAfter(r))):r=this.nextParsePosition?this.nextParsePosition:0,this.sidx&&this.onSidx&&!this.sidxSent&&(this.onSidx(this.sidx),this.sidxSent=!0),this.meta&&(this.flattenItemInfo&&!this.itemListBuilt&&(this.flattenItemInfo(),this.itemListBuilt=!0),this.processItems&&this.processItems(this.onItem)),this.stream.cleanBuffers&&(Log.info("ISOFile","Done processing buffer (fileStart: "+e.fileStart+") - next buffer to fetch should have a fileStart position of "+r),this.stream.logBufferLevel(),this.stream.cleanBuffers(),this.stream.logBufferLevel(!0),Log.info("ISOFile","Sample data size in memory: "+this.getAllocatedSampleDataSize())),r},ISOFile.prototype.getInfo=function(){var e,t,r,i,s,a={},o=new Date("1904-01-01T00:00:00Z").getTime();if(this.moov)for(a.hasMoov=!0,a.duration=this.moov.mvhd.duration,a.timescale=this.moov.mvhd.timescale,a.isFragmented=null!=this.moov.mvex,a.isFragmented&&this.moov.mvex.mehd&&(a.fragment_duration=this.moov.mvex.mehd.fragment_duration),a.isProgressive=this.isProgressive,a.hasIOD=null!=this.moov.iods,a.brands=[],a.brands.push(this.ftyp.major_brand),a.brands=a.brands.concat(this.ftyp.compatible_brands),a.created=new Date(o+1e3*this.moov.mvhd.creation_time),a.modified=new Date(o+1e3*this.moov.mvhd.modification_time),a.tracks=[],a.audioTracks=[],a.videoTracks=[],a.subtitleTracks=[],a.metadataTracks=[],a.hintTracks=[],a.otherTracks=[],e=0;e<this.moov.traks.length;e++){if(s=(r=this.moov.traks[e]).mdia.minf.stbl.stsd.entries[0],i={},a.tracks.push(i),i.id=r.tkhd.track_id,i.name=r.mdia.hdlr.name,i.references=[],r.tref)for(t=0;t<r.tref.boxes.length;t++)ref={},i.references.push(ref),ref.type=r.tref.boxes[t].type,ref.track_ids=r.tref.boxes[t].track_ids;r.edts&&(i.edits=r.edts.elst.entries),i.created=new Date(o+1e3*r.tkhd.creation_time),i.modified=new Date(o+1e3*r.tkhd.modification_time),i.movie_duration=r.tkhd.duration,i.movie_timescale=a.timescale,i.layer=r.tkhd.layer,i.alternate_group=r.tkhd.alternate_group,i.volume=r.tkhd.volume,i.matrix=r.tkhd.matrix,i.track_width=r.tkhd.width/65536,i.track_height=r.tkhd.height/65536,i.timescale=r.mdia.mdhd.timescale,i.cts_shift=r.mdia.minf.stbl.cslg,i.duration=r.mdia.mdhd.duration,i.samples_duration=r.samples_duration,i.codec=s.getCodec(),i.kind=r.udta&&r.udta.kinds.length?r.udta.kinds[0]:{schemeURI:"",value:""},i.language=r.mdia.elng?r.mdia.elng.extended_language:r.mdia.mdhd.languageString,i.nb_samples=r.samples.length,i.size=r.samples_size,i.bitrate=8*i.size*i.timescale/i.samples_duration,s.isAudio()?(i.type="audio",a.audioTracks.push(i),i.audio={},i.audio.sample_rate=s.getSampleRate(),i.audio.channel_count=s.getChannelCount(),i.audio.sample_size=s.getSampleSize()):s.isVideo()?(i.type="video",a.videoTracks.push(i),i.video={},i.video.width=s.getWidth(),i.video.height=s.getHeight()):s.isSubtitle()?(i.type="subtitles",a.subtitleTracks.push(i)):s.isHint()?(i.type="metadata",a.hintTracks.push(i)):s.isMetadata()?(i.type="metadata",a.metadataTracks.push(i)):(i.type="metadata",a.otherTracks.push(i))}else a.hasMoov=!1;if(a.mime="",a.hasMoov&&a.tracks){for(a.videoTracks&&0<a.videoTracks.length?a.mime+='video/mp4; codecs="':a.audioTracks&&0<a.audioTracks.length?a.mime+='audio/mp4; codecs="':a.mime+='application/mp4; codecs="',e=0;e<a.tracks.length;e++)0!==e&&(a.mime+=","),a.mime+=a.tracks[e].codec;a.mime+='"; profiles="',a.mime+=this.ftyp.compatible_brands.join(),a.mime+='"'}return a},ISOFile.prototype.processSamples=function(e){var t,r;if(this.sampleProcessingStarted){if(this.isFragmentationInitialized&&null!==this.onSegment)for(t=0;t<this.fragmentedTracks.length;t++){var i=this.fragmentedTracks[t];for(r=i.trak;r.nextSample<r.samples.length&&this.sampleProcessingStarted;){Log.debug("ISOFile","Creating media fragment on track #"+i.id+" for sample "+r.nextSample);var s=this.createFragment(i.id,r.nextSample,i.segmentStream);if(!s)break;if(i.segmentStream=s,r.nextSample++,(r.nextSample%i.nb_samples==0||e&&r.nextSample>=r.samples.length)&&(Log.info("ISOFile","Sending fragmented data on track #"+i.id+" for samples ["+Math.max(0,r.nextSample-i.nb_samples)+","+(r.nextSample-1)+"]"),Log.info("ISOFile","Sample data size in memory: "+this.getAllocatedSampleDataSize()),this.onSegment&&this.onSegment(i.id,i.user,i.segmentStream.buffer,r.nextSample,e&&r.nextSample>=r.samples.length),i.segmentStream=null,i!==this.fragmentedTracks[t]))break}}if(null!==this.onSamples)for(t=0;t<this.extractedTracks.length;t++){var a=this.extractedTracks[t];for(r=a.trak;r.nextSample<r.samples.length&&this.sampleProcessingStarted;){Log.debug("ISOFile","Exporting on track #"+a.id+" sample #"+r.nextSample);var o=this.getSample(r,r.nextSample);if(!o)break;if(r.nextSample++,a.samples.push(o),(r.nextSample%a.nb_samples==0||r.nextSample>=r.samples.length)&&(Log.debug("ISOFile","Sending samples on track #"+a.id+" for sample "+r.nextSample),this.onSamples&&this.onSamples(a.id,a.user,a.samples),a.samples=[],a!==this.extractedTracks[t]))break}}}},ISOFile.prototype.getBox=function(e){var t=this.getBoxes(e,!0);return t.length?t[0]:null},ISOFile.prototype.getBoxes=function(e,t){var r=[];return ISOFile._sweep.call(this,e,r,t),r},ISOFile._sweep=function(e,t,r){for(var i in this.type&&this.type==e&&t.push(this),this.boxes){if(t.length&&r)return;ISOFile._sweep.call(this.boxes[i],e,t,r)}},ISOFile.prototype.getTrackSamplesInfo=function(e){var t=this.getTrackById(e);return t?t.samples:void 0},ISOFile.prototype.getTrackSample=function(e,t){var r=this.getTrackById(e);return this.getSample(r,t)},ISOFile.prototype.releaseUsedSamples=function(e,t){var r=0,i=this.getTrackById(e);i.lastValidSample||(i.lastValidSample=0);for(var s=i.lastValidSample;s<t;s++)r+=this.releaseSample(i,s);Log.info("ISOFile","Track #"+e+" released samples up to "+t+" (released size: "+r+", remaining: "+this.samplesDataSize+")"),i.lastValidSample=t},ISOFile.prototype.start=function(){this.sampleProcessingStarted=!0,this.processSamples(!1)},ISOFile.prototype.stop=function(){this.sampleProcessingStarted=!1},ISOFile.prototype.flush=function(){Log.info("ISOFile","Flushing remaining samples"),this.updateSampleLists(),this.processSamples(!0),this.stream.cleanBuffers(),this.stream.logBufferLevel(!0)},ISOFile.prototype.seekTrack=function(e,t,r){var i,s,a,o,n=0,h=0;if(0===r.samples.length)return Log.info("ISOFile","No sample in track, cannot seek! Using time "+Log.getDurationString(0,1)+" and offset: 0"),{offset:0,time:0};for(i=0;i<r.samples.length;i++){if(s=r.samples[i],0===i)h=0,o=s.timescale;else if(s.cts>e*s.timescale){h=i-1;break}t&&s.is_sync&&(n=i)}for(t&&(h=n),e=r.samples[h].cts,r.nextSample=h;r.samples[h].alreadyRead===r.samples[h].size&&r.samples[h+1];)h++;return a=r.samples[h].offset+r.samples[h].alreadyRead,Log.info("ISOFile","Seeking to "+(t?"RAP":"")+" sample #"+r.nextSample+" on track "+r.tkhd.track_id+", time "+Log.getDurationString(e,o)+" and offset: "+a),{offset:a,time:e/o}},ISOFile.prototype.seek=function(e,t){var r,i,s,a=this.moov,o={offset:1/0,time:1/0};if(this.moov){for(s=0;s<a.traks.length;s++)r=a.traks[s],(i=this.seekTrack(e,t,r)).offset<o.offset&&(o.offset=i.offset),i.time<o.time&&(o.time=i.time);return Log.info("ISOFile","Seeking at time "+Log.getDurationString(o.time,1)+" needs a buffer with a fileStart position of "+o.offset),o.offset===1/0?o={offset:this.nextParsePosition,time:0}:o.offset=this.stream.getEndFilePositionAfter(o.offset),Log.info("ISOFile","Adjusted seek position (after checking data already in buffer): "+o.offset),o}throw"Cannot seek: moov not received!"},ISOFile.prototype.equal=function(e){for(var t=0;t<this.boxes.length&&t<e.boxes.length;){var r=this.boxes[t],i=e.boxes[t];if(!BoxParser.boxEqual(r,i))return!1;t++}return!0},"undefined"!=typeof exports&&(exports.ISOFile=ISOFile),BoxParser.Box.prototype.printHeader=function(e){this.size+=8,this.size>MAX_SIZE&&(this.size+=8),"uuid"===this.type&&(this.size+=16),e.log(e.indent+"size:"+this.size),e.log(e.indent+"type:"+this.type)},BoxParser.FullBox.prototype.printHeader=function(e){this.size+=4,BoxParser.Box.prototype.printHeader.call(this,e),e.log(e.indent+"version:"+this.version),e.log(e.indent+"flags:"+this.flags)},BoxParser.Box.prototype.print=function(e){this.printHeader(e)},BoxParser.ContainerBox.prototype.print=function(e){this.printHeader(e);for(var t=0;t<this.boxes.length;t++)if(this.boxes[t]){var r=e.indent;e.indent+=" ",this.boxes[t].print(e),e.indent=r}},ISOFile.prototype.print=function(e){e.indent="";for(var t=0;t<this.boxes.length;t++)this.boxes[t]&&this.boxes[t].print(e)},BoxParser.mvhdBox.prototype.print=function(e){BoxParser.FullBox.prototype.printHeader.call(this,e),e.log(e.indent+"creation_time: "+this.creation_time),e.log(e.indent+"modification_time: "+this.modification_time),e.log(e.indent+"timescale: "+this.timescale),e.log(e.indent+"duration: "+this.duration),e.log(e.indent+"rate: "+this.rate),e.log(e.indent+"volume: "+(this.volume>>8)),e.log(e.indent+"matrix: "+this.matrix.join(", ")),e.log(e.indent+"next_track_id: "+this.next_track_id)},BoxParser.tkhdBox.prototype.print=function(e){BoxParser.FullBox.prototype.printHeader.call(this,e),e.log(e.indent+"creation_time: "+this.creation_time),e.log(e.indent+"modification_time: "+this.modification_time),e.log(e.indent+"track_id: "+this.track_id),e.log(e.indent+"duration: "+this.duration),e.log(e.indent+"volume: "+(this.volume>>8)),e.log(e.indent+"matrix: "+this.matrix.join(", ")),e.log(e.indent+"layer: "+this.layer),e.log(e.indent+"alternate_group: "+this.alternate_group),e.log(e.indent+"width: "+this.width),e.log(e.indent+"height: "+this.height)};var MP4Box={createFile:function(e,t){var r=void 0===e||e,i=new ISOFile(t);return i.discardMdatData=!r,i}};"undefined"!=typeof exports&&(exports.createFile=MP4Box.createFile);
  //# sourceMappingURL=mp4box.simple.min.js.map