Comparing version 2.4.3 to 2.5.0
@@ -1,1 +0,1 @@ | ||
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.muxjs=t()}}(function(){return function t(e,i,s){function a(r,o){if(!i[r]){if(!e[r]){var h="function"==typeof require&&require;if(!o&&h)return h(r,!0);if(n)return n(r,!0);var p=new Error("Cannot find module '"+r+"'");throw p.code="MODULE_NOT_FOUND",p}var d=i[r]={exports:{}};e[r][0].call(d.exports,function(t){var i=e[r][1][t];return a(i?i:t)},d,d.exports,t,e,i,s)}return i[r].exports}for(var n="function"==typeof require&&require,r=0;r<s.length;r++)a(s[r]);return a}({1:[function(t,e,i){"use strict";var s,a=t("../utils/stream.js"),n=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];s=function(){var t;s.prototype.init.call(this),this.push=function(e){var i,s,a,r,o,h,p=0,d=0;if("audio"===e.type)for(t?(r=t,t=new Uint8Array(r.byteLength+e.data.byteLength),t.set(r),t.set(e.data,r.byteLength)):t=e.data;p+5<t.length;)if(255===t[p]&&240===(246&t[p+1])){if(s=2*(1&~t[p+1]),i=(3&t[p+3])<<11|t[p+4]<<3|(224&t[p+5])>>5,o=1024*((3&t[p+6])+1),h=9e4*o/n[(60&t[p+2])>>>2],a=p+i,t.byteLength<a)return;if(this.trigger("data",{pts:e.pts+d*h,dts:e.dts+d*h,sampleCount:o,audioobjecttype:(t[p+2]>>>6&3)+1,channelcount:(1&t[p+2])<<2|(192&t[p+3])>>>6,samplerate:n[(60&t[p+2])>>>2],samplingfrequencyindex:(60&t[p+2])>>>2,samplesize:16,data:t.subarray(p+7+s,a)}),t.byteLength===a)return void(t=void 0);d++,t=t.subarray(a)}else p++},this.flush=function(){this.trigger("done")}},s.prototype=new a,e.exports=s},{"../utils/stream.js":12}],2:[function(t,e,i){"use strict";var s,a,n,r=t("../utils/stream.js"),o=t("../utils/exp-golomb.js");a=function(){var t,e,i=0;a.prototype.init.call(this),this.push=function(s){var a;for(e?(a=new Uint8Array(e.byteLength+s.data.byteLength),a.set(e),a.set(s.data,e.byteLength),e=a):e=s.data;i<e.byteLength-3;i++)if(1===e[i+2]){t=i+5;break}for(;t<e.byteLength;)switch(e[t]){case 0:if(0!==e[t-1]){t+=2;break}if(0!==e[t-2]){t++;break}i+3!==t-2&&this.trigger("data",e.subarray(i+3,t-2));do t++;while(1!==e[t]&&t<e.length);i=t-2,t+=3;break;case 1:if(0!==e[t-1]||0!==e[t-2]){t+=3;break}this.trigger("data",e.subarray(i+3,t-2)),i=t-2,t+=3;break;default:t+=3}e=e.subarray(i),t-=i,i=0},this.flush=function(){e&&e.byteLength>3&&this.trigger("data",e.subarray(i+3)),e=null,i=0,this.trigger("done")}},a.prototype=new r,n={100:!0,110:!0,122:!0,244:!0,44:!0,83:!0,86:!0,118:!0,128:!0,138:!0,139:!0,134:!0},s=function(){var t,e,i,r,h,p,d,l=new a;s.prototype.init.call(this),t=this,this.push=function(t){"video"===t.type&&(e=t.trackId,i=t.pts,r=t.dts,l.push(t))},l.on("data",function(s){var a={trackId:e,pts:i,dts:r,data:s};switch(31&s[0]){case 5:a.nalUnitType="slice_layer_without_partitioning_rbsp_idr";break;case 6:a.nalUnitType="sei_rbsp",a.escapedRBSP=h(s.subarray(1));break;case 7:a.nalUnitType="seq_parameter_set_rbsp",a.escapedRBSP=h(s.subarray(1)),a.config=p(a.escapedRBSP);break;case 8:a.nalUnitType="pic_parameter_set_rbsp";break;case 9:a.nalUnitType="access_unit_delimiter_rbsp"}t.trigger("data",a)}),l.on("done",function(){t.trigger("done")}),this.flush=function(){l.flush()},d=function(t,e){var i,s,a=8,n=8;for(i=0;t>i;i++)0!==n&&(s=e.readExpGolomb(),n=(a+s+256)%256),a=0===n?a:n},h=function(t){for(var e,i,s=t.byteLength,a=[],n=1;s-2>n;)0===t[n]&&0===t[n+1]&&3===t[n+2]?(a.push(n+2),n+=2):n++;if(0===a.length)return t;e=s-a.length,i=new Uint8Array(e);var r=0;for(n=0;e>n;r++,n++)r===a[0]&&(r++,a.shift()),i[n]=t[r];return i},p=function(t){var e,i,s,a,r,h,p,l,u,c,f,y,g,m,b=0,v=0,w=0,T=0,_=1;if(e=new o(t),i=e.readUnsignedByte(),a=e.readUnsignedByte(),s=e.readUnsignedByte(),e.skipUnsignedExpGolomb(),n[i]&&(r=e.readUnsignedExpGolomb(),3===r&&e.skipBits(1),e.skipUnsignedExpGolomb(),e.skipUnsignedExpGolomb(),e.skipBits(1),e.readBoolean()))for(f=3!==r?8:12,m=0;f>m;m++)e.readBoolean()&&(6>m?d(16,e):d(64,e));if(e.skipUnsignedExpGolomb(),h=e.readUnsignedExpGolomb(),0===h)e.readUnsignedExpGolomb();else if(1===h)for(e.skipBits(1),e.skipExpGolomb(),e.skipExpGolomb(),p=e.readUnsignedExpGolomb(),m=0;p>m;m++)e.skipExpGolomb();if(e.skipUnsignedExpGolomb(),e.skipBits(1),l=e.readUnsignedExpGolomb(),u=e.readUnsignedExpGolomb(),c=e.readBits(1),0===c&&e.skipBits(1),e.skipBits(1),e.readBoolean()&&(b=e.readUnsignedExpGolomb(),v=e.readUnsignedExpGolomb(),w=e.readUnsignedExpGolomb(),T=e.readUnsignedExpGolomb()),e.readBoolean()&&e.readBoolean()){switch(g=e.readUnsignedByte()){case 1:y=[1,1];break;case 2:y=[12,11];break;case 3:y=[10,11];break;case 4:y=[16,11];break;case 5:y=[40,33];break;case 6:y=[24,11];break;case 7:y=[20,11];break;case 8:y=[32,11];break;case 9:y=[80,33];break;case 10:y=[18,11];break;case 11:y=[15,11];break;case 12:y=[64,33];break;case 13:y=[160,99];break;case 14:y=[4,3];break;case 15:y=[3,2];break;case 16:y=[2,1];break;case 255:y=[e.readUnsignedByte()<<8|e.readUnsignedByte(),e.readUnsignedByte()<<8|e.readUnsignedByte()]}y&&(_=y[0]/y[1])}return{profileIdc:i,levelIdc:s,profileCompatibility:a,width:Math.ceil((16*(l+1)-2*b-2*v)*_),height:(2-c)*(u+1)*16-2*w-2*T}}},s.prototype=new r,e.exports={H264Stream:s,NalByteStream:a}},{"../utils/exp-golomb.js":11,"../utils/stream.js":12}],3:[function(t,e,i){"use strict";var s;s=function(t,e){var i,a=0,n=16384,r=function(t,e){var i,s=t.position+e;s<t.bytes.byteLength||(i=new Uint8Array(2*s),i.set(t.bytes.subarray(0,t.position),0),t.bytes=i,t.view=new DataView(t.bytes.buffer))},o=s.widthBytes||new Uint8Array("width".length),h=s.heightBytes||new Uint8Array("height".length),p=s.videocodecidBytes||new Uint8Array("videocodecid".length);if(!s.widthBytes){for(i=0;i<"width".length;i++)o[i]="width".charCodeAt(i);for(i=0;i<"height".length;i++)h[i]="height".charCodeAt(i);for(i=0;i<"videocodecid".length;i++)p[i]="videocodecid".charCodeAt(i);s.widthBytes=o,s.heightBytes=h,s.videocodecidBytes=p}switch(this.keyFrame=!1,t){case s.VIDEO_TAG:this.length=16,n*=6;break;case s.AUDIO_TAG:this.length=13,this.keyFrame=!0;break;case s.METADATA_TAG:this.length=29,this.keyFrame=!0;break;default:throw new Error("Unknown FLV tag type")}this.bytes=new Uint8Array(n),this.view=new DataView(this.bytes.buffer),this.bytes[0]=t,this.position=this.length,this.keyFrame=e,this.pts=0,this.dts=0,this.writeBytes=function(t,e,i){var s,a=e||0;i=i||t.byteLength,s=a+i,r(this,i),this.bytes.set(t.subarray(a,s),this.position),this.position+=i,this.length=Math.max(this.length,this.position)},this.writeByte=function(t){r(this,1),this.bytes[this.position]=t,this.position++,this.length=Math.max(this.length,this.position)},this.writeShort=function(t){r(this,2),this.view.setUint16(this.position,t),this.position+=2,this.length=Math.max(this.length,this.position)},this.negIndex=function(t){return this.bytes[this.length-t]},this.nalUnitSize=function(){return 0===a?0:this.length-(a+4)},this.startNalUnit=function(){if(a>0)throw new Error("Attempted to create new NAL wihout closing the old one");a=this.length,this.length+=4,this.position=this.length},this.endNalUnit=function(t){var e,i;this.length===a+4?this.length-=4:a>0&&(e=a+4,i=this.length-e,this.position=a,this.view.setUint32(this.position,i),this.position=this.length,t&&t.push(this.bytes.subarray(e,e+i))),a=0},this.writeMetaDataDouble=function(t,e){var i;if(r(this,2+t.length+9),this.view.setUint16(this.position,t.length),this.position+=2,"width"===t)this.bytes.set(o,this.position),this.position+=5;else if("height"===t)this.bytes.set(h,this.position),this.position+=6;else if("videocodecid"===t)this.bytes.set(p,this.position),this.position+=12;else for(i=0;i<t.length;i++)this.bytes[this.position]=t.charCodeAt(i),this.position++;this.position++,this.view.setFloat64(this.position,e),this.position+=8,this.length=Math.max(this.length,this.position),++a},this.writeMetaDataBoolean=function(t,e){var i;for(r(this,2),this.view.setUint16(this.position,t.length),this.position+=2,i=0;i<t.length;i++)r(this,1),this.bytes[this.position]=t.charCodeAt(i),this.position++;r(this,2),this.view.setUint8(this.position,1),this.position++,this.view.setUint8(this.position,e?1:0),this.position++,this.length=Math.max(this.length,this.position),++a},this.finalize=function(){var t,i;switch(this.bytes[0]){case s.VIDEO_TAG:this.bytes[11]=7|(this.keyFrame||e?16:32),this.bytes[12]=e?0:1,t=this.pts-this.dts,this.bytes[13]=(16711680&t)>>>16,this.bytes[14]=(65280&t)>>>8,this.bytes[15]=(255&t)>>>0;break;case s.AUDIO_TAG:this.bytes[11]=175,this.bytes[12]=e?0:1;break;case s.METADATA_TAG:this.position=11,this.view.setUint8(this.position,2),this.position++,this.view.setUint16(this.position,10),this.position+=2,this.bytes.set([111,110,77,101,116,97,68,97,116,97],this.position),this.position+=10,this.bytes[this.position]=8,this.position++,this.view.setUint32(this.position,a),this.position=this.length,this.bytes.set([0,0,9],this.position),this.position+=3,this.length=this.position}return i=this.length-11,this.bytes[1]=(16711680&i)>>>16,this.bytes[2]=(65280&i)>>>8,this.bytes[3]=(255&i)>>>0,this.bytes[4]=(16711680&this.dts)>>>16,this.bytes[5]=(65280&this.dts)>>>8,this.bytes[6]=(255&this.dts)>>>0,this.bytes[7]=(4278190080&this.dts)>>>24,this.bytes[8]=0,this.bytes[9]=0,this.bytes[10]=0,r(this,4),this.view.setUint32(this.length,this.length),this.length+=4,this.position+=4,this.bytes=this.bytes.subarray(0,this.length),this.frameTime=s.frameTime(this.bytes),this}},s.AUDIO_TAG=8,s.VIDEO_TAG=9,s.METADATA_TAG=18,s.isAudioFrame=function(t){return s.AUDIO_TAG===t[0]},s.isVideoFrame=function(t){return s.VIDEO_TAG===t[0]},s.isMetaData=function(t){return s.METADATA_TAG===t[0]},s.isKeyFrame=function(t){return s.isVideoFrame(t)?23===t[11]:s.isAudioFrame(t)?!0:!!s.isMetaData(t)},s.frameTime=function(t){var e=t[4]<<16;return e|=t[5]<<8,e|=t[6]<<0,e|=t[7]<<24},e.exports=s},{}],4:[function(t,e,i){e.exports={tag:t("./flv-tag"),Transmuxer:t("./transmuxer")}},{"./flv-tag":3,"./transmuxer":5}],5:[function(t,e,i){"use strict";var s,a,n,r,o,h,p,d=t("../utils/stream.js"),l=t("./flv-tag.js"),u=t("../m2ts/m2ts.js"),c=t("../codecs/adts.js"),f=t("../codecs/h264").H264Stream;o=function(t,e){"number"==typeof e.pts&&(void 0===t.timelineStartInfo.pts?t.timelineStartInfo.pts=e.pts:t.timelineStartInfo.pts=Math.min(t.timelineStartInfo.pts,e.pts)),"number"==typeof e.dts&&(void 0===t.timelineStartInfo.dts?t.timelineStartInfo.dts=e.dts:t.timelineStartInfo.dts=Math.min(t.timelineStartInfo.dts,e.dts))},h=function(t,e){var i=new l(l.METADATA_TAG);return i.dts=e,i.pts=e,i.writeMetaDataDouble("videocodecid",7),i.writeMetaDataDouble("width",t.width),i.writeMetaDataDouble("height",t.height),i},p=function(t,e){var i,s=new l(l.VIDEO_TAG,!0);for(s.dts=e,s.pts=e,s.writeByte(1),s.writeByte(t.profileIdc),s.writeByte(t.profileCompatibility),s.writeByte(t.levelIdc),s.writeByte(255),s.writeByte(225),s.writeShort(t.sps[0].length),s.writeBytes(t.sps[0]),s.writeByte(t.pps.length),i=0;i<t.pps.length;++i)s.writeShort(t.pps[i].length),s.writeBytes(t.pps[i]);return s},n=function(t){var e,i=[];n.prototype.init.call(this),this.push=function(e){o(t,e),t&&void 0===t.channelcount&&(t.audioobjecttype=e.audioobjecttype,t.channelcount=e.channelcount,t.samplerate=e.samplerate,t.samplingfrequencyindex=e.samplingfrequencyindex,t.samplesize=e.samplesize,t.extraData=t.audioobjecttype<<11|t.samplingfrequencyindex<<7|t.channelcount<<3),e.pts=Math.round(e.pts/90),e.dts=Math.round(e.dts/90),i.push(e)},this.flush=function(){var s,a,n,r=[];if(0===i.length)return void this.trigger("done");for(n=-(1/0);i.length;)s=i.shift(),(t.extraData!==e||s.pts-n>=1e3)&&(a=new l(l.METADATA_TAG),a.pts=s.pts,a.dts=s.dts,a.writeMetaDataDouble("audiocodecid",10),a.writeMetaDataBoolean("stereo",2===t.channelcount),a.writeMetaDataDouble("audiosamplerate",t.samplerate),a.writeMetaDataDouble("audiosamplesize",16),r.push(a),e=t.extraData,a=new l(l.AUDIO_TAG,!0),a.pts=s.pts,a.dts=s.dts,a.view.setUint16(a.position,t.extraData),a.position+=2,a.length=Math.max(a.length,a.position),r.push(a),n=s.pts),a=new l(l.AUDIO_TAG),a.pts=s.pts,a.dts=s.dts,a.writeBytes(s.data),r.push(a);e=null,this.trigger("data",{track:t,tags:r}),this.trigger("done")}},n.prototype=new d,a=function(t){var e,i,s=[];a.prototype.init.call(this),this.finishFrame=function(i,s){s&&(e&&t&&t.newMetadata&&(s.keyFrame||0===i.length)&&(i.push(h(e,s.pts)),i.push(p(t,s.pts)),t.newMetadata=!1),s.endNalUnit(),i.push(s))},this.push=function(e){o(t,e),e.pts=Math.round(e.pts/90),e.dts=Math.round(e.dts/90),s.push(e)},this.flush=function(){for(var a,n=[];s.length&&"access_unit_delimiter_rbsp"!==s[0].nalUnitType;)s.shift();if(0===s.length)return void this.trigger("done");for(;s.length;)a=s.shift(),"seq_parameter_set_rbsp"===a.nalUnitType?(t.newMetadata=!0,e=a.config,t.width=e.width,t.height=e.height,t.sps=[a.data],t.profileIdc=e.profileIdc,t.levelIdc=e.levelIdc,t.profileCompatibility=e.profileCompatibility,i.endNalUnit()):"pic_parameter_set_rbsp"===a.nalUnitType?(t.newMetadata=!0,t.pps=[a.data],i.endNalUnit()):"access_unit_delimiter_rbsp"===a.nalUnitType?(i&&this.finishFrame(n,i),i=new l(l.VIDEO_TAG),i.pts=a.pts,i.dts=a.dts):("slice_layer_without_partitioning_rbsp_idr"===a.nalUnitType&&(i.keyFrame=!0),i.endNalUnit()),i.startNalUnit(),i.writeBytes(a.data);i&&this.finishFrame(n,i),this.trigger("data",{track:t,tags:n}),this.trigger("done")}},a.prototype=new d,r=function(t){this.numberOfTracks=0,this.metadataStream=t.metadataStream,this.videoTags=[],this.audioTags=[],this.videoTrack=null,this.audioTrack=null,this.pendingCaptions=[],this.pendingMetadata=[],this.pendingTracks=0,r.prototype.init.call(this),this.push=function(t){return t.text?this.pendingCaptions.push(t):t.frames?this.pendingMetadata.push(t):("video"===t.track.type&&(this.videoTrack=t.track,this.videoTags=t.tags,this.pendingTracks++),void("audio"===t.track.type&&(this.audioTrack=t.track,this.audioTags=t.tags,this.pendingTracks++)))}},r.prototype=new d,r.prototype.flush=function(){var t,e,i,s,a={tags:{},captions:[],metadata:[]};if(!(this.pendingTracks<this.numberOfTracks)){for(this.videoTrack?s=this.videoTrack.timelineStartInfo.pts:this.audioTrack&&(s=this.audioTrack.timelineStartInfo.pts),a.tags.videoTags=this.videoTags,a.tags.audioTags=this.audioTags,i=0;i<this.pendingCaptions.length;i++)e=this.pendingCaptions[i],e.startTime=e.startPts-s,e.startTime/=9e4,e.endTime=e.endPts-s,e.endTime/=9e4,a.captions.push(e);for(i=0;i<this.pendingMetadata.length;i++)t=this.pendingMetadata[i],t.cueTime=t.pts-s,t.cueTime/=9e4,a.metadata.push(t);a.metadata.dispatchType=this.metadataStream.dispatchType,this.videoTrack=null,this.audioTrack=null,this.videoTags=[],this.audioTags=[],this.pendingCaptions.length=0,this.pendingMetadata.length=0,this.pendingTracks=0,this.trigger("data",a),this.trigger("done")}},s=function(t){var e,i,o,h,p,d,y,g,m,b,v,w,T=this;s.prototype.init.call(this),t=t||{},this.metadataStream=new u.MetadataStream,t.metadataStream=this.metadataStream,e=new u.TransportPacketStream,i=new u.TransportParseStream,o=new u.ElementaryStream,h=new u.TimestampRolloverStream("video"),p=new u.TimestampRolloverStream("audio"),d=new u.TimestampRolloverStream("timed-metadata"),y=new c,g=new f,w=new r(t),e.pipe(i).pipe(o),o.pipe(h).pipe(g),o.pipe(p).pipe(y),o.pipe(d).pipe(this.metadataStream).pipe(w),v=new u.CaptionStream,g.pipe(v).pipe(w),o.on("data",function(t){var e,i,s;if("metadata"===t.type){for(e=t.tracks.length;e--;)"video"===t.tracks[e].type?i=t.tracks[e]:"audio"===t.tracks[e].type&&(s=t.tracks[e]);i&&!m&&(w.numberOfTracks++,m=new a(i),g.pipe(m).pipe(w)),s&&!b&&(w.numberOfTracks++,b=new n(s),y.pipe(b).pipe(w))}}),this.push=function(t){e.push(t)},this.flush=function(){e.flush()},w.on("data",function(t){T.trigger("data",t)}),w.on("done",function(){T.trigger("done")}),this.getFlvHeader=function(t,e,i){var s,a,n,r=new Uint8Array(9),o=new DataView(r.buffer);return t=t||0,e=void 0===e?!0:e,i=void 0===i?!0:i,o.setUint8(0,70),o.setUint8(1,76),o.setUint8(2,86),o.setUint8(3,1),o.setUint8(4,(e?4:0)|(i?1:0)),o.setUint32(5,r.byteLength),0>=t?(a=new Uint8Array(r.byteLength+4),a.set(r),a.set([0,0,0,0],r.byteLength),a):(s=new l(l.METADATA_TAG),s.pts=s.dts=0,s.writeMetaDataDouble("duration",t),n=s.finalize().length,a=new Uint8Array(r.byteLength+n),a.set(r),a.set(o.byteLength,n),a)}},s.prototype=new d,e.exports=s},{"../codecs/adts.js":1,"../codecs/h264":2,"../m2ts/m2ts.js":7,"../utils/stream.js":12,"./flv-tag.js":3}],6:[function(t,e,i){"use strict";var s=4,a=128,n=t("../utils/stream"),r=function(t){for(var e=0,i={payloadType:-1,payloadSize:0},n=0,r=0;e<t.byteLength&&t[e]!==a;){for(;255===t[e];)n+=255,e++;for(n+=t[e++];255===t[e];)r+=255,e++;if(r+=t[e++],!i.payload&&n===s){i.payloadType=n,i.payloadSize=r,i.payload=t.subarray(e,e+r);break}e+=r,n=0,r=0}return i},o=function(t){return 181!==t.payload[0]?null:49!==(t.payload[1]<<8|t.payload[2])?null:"GA94"!==String.fromCharCode(t.payload[3],t.payload[4],t.payload[5],t.payload[6])?null:3!==t.payload[7]?null:t.payload.subarray(8,t.payload.length-1)},h=function(t,e){var i,s,a,n,r=[];if(!(64&e[0]))return r;for(s=31&e[0],i=0;s>i;i++)a=3*i,n={type:3&e[a+2],pts:t},4&e[a+2]&&(n.ccData=e[a+3]<<8|e[a+4],r.push(n));return r},p=function(){p.prototype.init.call(this),this.captionPackets_=[],this.field1_=new A,this.field1_.on("data",this.trigger.bind(this,"data")),this.field1_.on("done",this.trigger.bind(this,"done"))};p.prototype=new n,p.prototype.push=function(t){var e,i;"sei_rbsp"===t.nalUnitType&&(e=r(t.escapedRBSP),e.payloadType===s&&(i=o(e),i&&(this.captionPackets_=this.captionPackets_.concat(h(t.pts,i)))))},p.prototype.flush=function(){return this.captionPackets_.length?(this.captionPackets_.sort(function(t,e){return t.pts-e.pts}),this.captionPackets_.forEach(this.field1_.push,this.field1_),this.captionPackets_.length=0,void this.field1_.flush()):void this.field1_.flush()};var d={42:225,92:233,94:237,95:243,96:250,123:231,124:247,125:209,126:241,127:9608},l=function(t){return null===t?"":(t=d[t]||t,String.fromCharCode(t))},u=0,c=5152,f=5167,y=5157,g=5158,m=5159,b=5165,v=5153,w=5164,T=5166,_=14,k=function(){for(var t=[],e=_+1;e--;)t.push("");return t},A=function(){A.prototype.init.call(this),this.mode_="popOn",this.topRow_=0,this.startPts_=0,this.displayed_=k(),this.nonDisplayed_=k(),this.lastControlCode_=null,this.push=function(t){if(0===t.type){var e,i,s,a;if(e=32639&t.ccData,e===this.lastControlCode_)return void(this.lastControlCode_=null);switch(4096===(61440&e)?this.lastControlCode_=e:this.lastControlCode_=null,e){case u:break;case c:this.mode_="popOn";break;case f:this.flushDisplayed(t.pts),i=this.displayed_,this.displayed_=this.nonDisplayed_,this.nonDisplayed_=i,this.startPts_=t.pts;break;case y:this.topRow_=_-1,this.mode_="rollUp";break;case g:this.topRow_=_-2,this.mode_="rollUp";break;case m:this.topRow_=_-3,this.mode_="rollUp";break;case b:this.flushDisplayed(t.pts),this.shiftRowsUp_(),this.startPts_=t.pts;break;case v:"popOn"===this.mode_?this.nonDisplayed_[_]=this.nonDisplayed_[_].slice(0,-1):this.displayed_[_]=this.displayed_[_].slice(0,-1);break;case w:this.flushDisplayed(t.pts),this.displayed_=k();break;case T:this.nonDisplayed_=k();break;default:if(s=e>>>8,a=255&e,s>=16&&23>=s&&a>=64&&127>=a&&(16!==s||96>a)&&(s=32,a=null),(17===s||25===s)&&a>=48&&63>=a&&(s=9834,a=""),16===(240&s))return;this[this.mode_](t.pts,s,a)}}}};A.prototype=new n,A.prototype.flushDisplayed=function(t){var e=this.displayed_.map(function(t){return t.trim()}).filter(function(t){return t.length}).join("\n");e.length&&this.trigger("data",{startPts:this.startPts_,endPts:t,text:e})},A.prototype.popOn=function(t,e,i){var s=this.nonDisplayed_[_];s+=l(e),s+=l(i),this.nonDisplayed_[_]=s},A.prototype.rollUp=function(t,e,i){var s=this.displayed_[_];""===s&&(this.flushDisplayed(t),this.startPts_=t),s+=l(e),s+=l(i),this.displayed_[_]=s},A.prototype.shiftRowsUp_=function(){var t;for(t=0;t<this.topRow_;t++)this.displayed_[t]="";for(t=this.topRow_;_>t;t++)this.displayed_[t]=this.displayed_[t+1];this.displayed_[_]=""},e.exports={CaptionStream:p,Cea608Stream:A}},{"../utils/stream":12}],7:[function(t,e,i){"use strict";var s,a,n,r=t("../utils/stream.js"),o=t("./caption-stream"),h=t("./stream-types"),p=t("./timestamp-rollover-stream"),d=t("./stream-types.js"),l=188,u=71;s=function(){var t=new Uint8Array(l),e=0;s.prototype.init.call(this),this.push=function(i){var s,a=0,n=l;for(e?(s=new Uint8Array(i.byteLength+e),s.set(t.subarray(0,e)),s.set(i,e),e=0):s=i;n<s.byteLength;)s[a]!==u||s[n]!==u?(a++,n++):(this.trigger("data",s.subarray(a,n)),a+=l,n+=l);a<s.byteLength&&(t.set(s.subarray(a),0),e=s.byteLength-a)},this.flush=function(){e===l&&t[0]===u&&(this.trigger("data",t),e=0),this.trigger("done")}},s.prototype=new r,a=function(){var t,e,i,s;a.prototype.init.call(this),s=this,this.packetsWaitingForPmt=[],this.programMapTable=void 0,t=function(t,s){var a=0;s.payloadUnitStartIndicator&&(a+=t[a]+1),"pat"===s.type?e(t.subarray(a),s):i(t.subarray(a),s)},e=function(t,e){e.section_number=t[7],e.last_section_number=t[8],s.pmtPid=(31&t[10])<<8|t[11],e.pmtPid=s.pmtPid},i=function(t,e){var i,a,n,r;if(1&t[5]){for(s.programMapTable={},i=(15&t[1])<<8|t[2],a=3+i-4,n=(15&t[10])<<8|t[11],r=12+n;a>r;)s.programMapTable[(31&t[r+1])<<8|t[r+2]]=t[r],r+=((15&t[r+3])<<8|t[r+4])+5;for(e.programMapTable=s.programMapTable;s.packetsWaitingForPmt.length;)s.processPes_.apply(s,s.packetsWaitingForPmt.shift())}},this.push=function(e){var i={},s=4;i.payloadUnitStartIndicator=!!(64&e[1]),i.pid=31&e[1],i.pid<<=8,i.pid|=e[2],(48&e[3])>>>4>1&&(s+=e[s]+1),0===i.pid?(i.type="pat",t(e.subarray(s),i),this.trigger("data",i)):i.pid===this.pmtPid?(i.type="pmt",t(e.subarray(s),i),this.trigger("data",i)):void 0===this.programMapTable?this.packetsWaitingForPmt.push([e,s,i]):this.processPes_(e,s,i)},this.processPes_=function(t,e,i){i.streamType=this.programMapTable[i.pid],i.type="pes",i.data=t.subarray(e),this.trigger("data",i)}},a.prototype=new r,a.STREAM_TYPES={h264:27,adts:15},n=function(){var t=this,e={data:[],size:0},i={data:[],size:0},s={data:[],size:0},a=function(t,e){var i;e.dataAlignmentIndicator=0!==(4&t[6]),i=t[7],192&i&&(e.pts=(14&t[9])<<27|(255&t[10])<<20|(254&t[11])<<12|(255&t[12])<<5|(254&t[13])>>>3,e.pts*=4,e.pts+=(6&t[13])>>>1,e.dts=e.pts,64&i&&(e.dts=(14&t[14])<<27|(255&t[15])<<20|(254&t[16])<<12|(255&t[17])<<5|(254&t[18])>>>3,e.dts*=4,e.dts+=(6&t[18])>>>1)),e.data=t.subarray(9+t[8])},r=function(e,i){var s,n=new Uint8Array(e.size),r={type:i},o=0;if(e.data.length){for(r.trackId=e.data[0].pid;e.data.length;)s=e.data.shift(),n.set(s.data,o),o+=s.data.byteLength;a(n,r),e.size=0,t.trigger("data",r)}};n.prototype.init.call(this),this.push=function(a){({pat:function(){},pes:function(){var t,n;switch(a.streamType){case h.H264_STREAM_TYPE:case d.H264_STREAM_TYPE:t=e,n="video";break;case h.ADTS_STREAM_TYPE:t=i,n="audio";break;case h.METADATA_STREAM_TYPE:t=s,n="timed-metadata";break;default:return}a.payloadUnitStartIndicator&&r(t,n),t.data.push(a),t.size+=a.data.byteLength},pmt:function(){var e,i,s={type:"metadata",tracks:[]},n=a.programMapTable;for(e in n)n.hasOwnProperty(e)&&(i={timelineStartInfo:{baseMediaDecodeTime:0}},i.id=+e,n[e]===d.H264_STREAM_TYPE?(i.codec="avc",i.type="video"):n[e]===d.ADTS_STREAM_TYPE&&(i.codec="adts",i.type="audio"),s.tracks.push(i));t.trigger("data",s)}})[a.type]()},this.flush=function(){r(e,"video"),r(i,"audio"),r(s,"timed-metadata"),this.trigger("done")}},n.prototype=new r;var c={PAT_PID:0,MP2T_PACKET_LENGTH:l,TransportPacketStream:s,TransportParseStream:a,ElementaryStream:n,TimestampRolloverStream:p,CaptionStream:o.CaptionStream,Cea608Stream:o.Cea608Stream,MetadataStream:t("./metadata-stream")};for(var f in h)h.hasOwnProperty(f)&&(c[f]=h[f]);e.exports=c},{"../utils/stream.js":12,"./caption-stream":6,"./metadata-stream":8,"./stream-types":9,"./stream-types.js":9,"./timestamp-rollover-stream":10}],8:[function(t,e,i){"use strict";var s,a=t("../utils/stream"),n=t("./stream-types"),r=function(t,e,i){var s,a="";for(s=e;i>s;s++)a+="%"+("00"+t[s].toString(16)).slice(-2);return a},o=function(t,e,i){return decodeURIComponent(r(t,e,i))},h=function(t,e,i){return unescape(r(t,e,i))},p=function(t){return t[0]<<21|t[1]<<14|t[2]<<7|t[3]},d={TXXX:function(t){var e;if(3===t.data[0]){for(e=1;e<t.data.length;e++)if(0===t.data[e]){t.description=o(t.data,1,e),t.value=o(t.data,e+1,t.data.length-1);break}t.data=t.value}},WXXX:function(t){var e;if(3===t.data[0])for(e=1;e<t.data.length;e++)if(0===t.data[e]){t.description=o(t.data,1,e),t.url=o(t.data,e+1,t.data.length);break}},PRIV:function(t){var e;for(e=0;e<t.data.length;e++)if(0===t.data[e]){t.owner=h(t.data,0,e);break}t.privateData=t.data.subarray(e+1),t.data=t.privateData}};s=function(t){var e,i={debug:!(!t||!t.debug),descriptor:t&&t.descriptor},a=0,r=[],o=0;if(s.prototype.init.call(this),this.dispatchType=n.METADATA_STREAM_TYPE.toString(16),i.descriptor)for(e=0;e<i.descriptor.length;e++)this.dispatchType+=("00"+i.descriptor[e].toString(16)).slice(-2);this.push=function(t){var e,s,n,h,l,u;if("timed-metadata"===t.type){if(t.dataAlignmentIndicator&&(o=0,r.length=0),0===r.length&&(t.data.length<10||t.data[0]!=="I".charCodeAt(0)||t.data[1]!=="D".charCodeAt(0)||t.data[2]!=="3".charCodeAt(0)))return void(i.debug&&console.log("Skipping unrecognized metadata packet"));if(r.push(t),o+=t.data.byteLength,1===r.length&&(a=p(t.data.subarray(6,10)),a+=10),!(a>o)){for(e={data:new Uint8Array(a),frames:[],pts:r[0].pts,dts:r[0].dts},l=0;a>l;)e.data.set(r[0].data.subarray(0,a-l),l),l+=r[0].data.byteLength,o-=r[0].data.byteLength,r.shift();s=10,64&e.data[5]&&(s+=4,s+=p(e.data.subarray(10,14)),a-=p(e.data.subarray(16,20)));do{if(n=p(e.data.subarray(s+4,s+8)),1>n)return console.log("Malformed ID3 frame encountered. Skipping metadata parsing.");if(u=String.fromCharCode(e.data[s],e.data[s+1],e.data[s+2],e.data[s+3]),h={id:u,data:e.data.subarray(s+10,s+n+10)},h.key=h.id,d[h.id]&&(d[h.id](h),"com.apple.streaming.transportStreamTimestamp"===h.owner)){var c=h.data,f=(1&c[3])<<30|c[4]<<22|c[5]<<14|c[6]<<6|c[7]>>>2;f*=4,f+=3&c[7],h.timeStamp=f,this.trigger("timestamp",h)}e.frames.push(h),s+=10,s+=n}while(a>s);this.trigger("data",e)}}}},s.prototype=new a,e.exports=s},{"../utils/stream":12,"./stream-types":9}],9:[function(t,e,i){"use strict";e.exports={H264_STREAM_TYPE:27,ADTS_STREAM_TYPE:15,METADATA_STREAM_TYPE:21}},{}],10:[function(t,e,i){"use strict";var s=t("../utils/stream"),a=8589934592,n=4294967296,r=function(t){var e,i;r.prototype.init.call(this),this.type_=t;var s=function(t,e){var i=1;for(t>e&&(i=-1);Math.abs(e-t)>n;)t+=i*a;return t};this.push=function(t){t.type===this.type_&&(void 0===i&&(i=t.dts),t.dts=s(t.dts,i),t.pts=s(t.pts,i),e=t.dts,this.trigger("data",t))},this.flush=function(){i=e,this.trigger("done")}};r.prototype=new s,e.exports=r},{"../utils/stream":12}],11:[function(t,e,i){"use strict";var s;s=function(t){var e=t.byteLength,i=0,s=0;this.length=function(){return 8*e},this.bitsAvailable=function(){return 8*e+s},this.loadWord=function(){var a=t.byteLength-e,n=new Uint8Array(4),r=Math.min(4,e);if(0===r)throw new Error("no bytes available");n.set(t.subarray(a,a+r)),i=new DataView(n.buffer).getUint32(0),s=8*r,e-=r},this.skipBits=function(t){var a;s>t?(i<<=t,s-=t):(t-=s,a=Math.floor(t/8),t-=8*a,e-=a,this.loadWord(),i<<=t,s-=t)},this.readBits=function(t){var a=Math.min(s,t),n=i>>>32-a;return s-=a,s>0?i<<=a:e>0&&this.loadWord(),a=t-a,a>0?n<<a|this.readBits(a):n},this.skipLeadingZeros=function(){var t;for(t=0;s>t;++t)if(0!==(i&2147483648>>>t))return i<<=t,s-=t,t;return this.loadWord(),t+this.skipLeadingZeros()},this.skipUnsignedExpGolomb=function(){this.skipBits(1+this.skipLeadingZeros())},this.skipExpGolomb=function(){this.skipBits(1+this.skipLeadingZeros())},this.readUnsignedExpGolomb=function(){var t=this.skipLeadingZeros();return this.readBits(t+1)-1},this.readExpGolomb=function(){var t=this.readUnsignedExpGolomb();return 1&t?1+t>>>1:-1*(t>>>1)},this.readBoolean=function(){return 1===this.readBits(1)},this.readUnsignedByte=function(){return this.readBits(8)},this.loadWord()},e.exports=s},{}],12:[function(t,e,i){"use strict";var s=function(){this.init=function(){var t={};this.on=function(e,i){t[e]||(t[e]=[]),t[e].push(i)},this.off=function(e,i){var s;return t[e]?(s=t[e].indexOf(i),t[e].splice(s,1),s>-1):!1},this.trigger=function(e){var i,s,a,n;if(i=t[e])if(2===arguments.length)for(a=i.length,s=0;a>s;++s)i[s].call(this,arguments[1]);else{for(n=[],s=arguments.length,s=1;s<arguments.length;++s)n.push(arguments[s]);for(a=i.length,s=0;a>s;++s)i[s].apply(this,n)}},this.dispose=function(){t={}}}};s.prototype.pipe=function(t){return this.on("data",function(e){t.push(e)}),this.on("done",function(e){t.flush(e)}),t},s.prototype.push=function(t){this.trigger("data",t)},s.prototype.flush=function(t){this.trigger("done",t)},e.exports=s},{}]},{},[4])(4)}); | ||
!function t(i,e,s){function a(r,o){if(!e[r]){if(!i[r]){var h="function"==typeof require&&require;if(!o&&h)return h(r,!0);if(n)return n(r,!0);var p=new Error("Cannot find module '"+r+"'");throw p.code="MODULE_NOT_FOUND",p}var d=e[r]={exports:{}};i[r][0].call(d.exports,function(t){var e=i[r][1][t];return a(e?e:t)},d,d.exports,t,i,e,s)}return e[r].exports}for(var n="function"==typeof require&&require,r=0;r<s.length;r++)a(s[r]);return a}({1:[function(t,i,e){"use strict";var s,a=t(12),n=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];s=function(){var t;s.prototype.init.call(this),this.push=function(i){var e,s,a,r,o,h,p=0,d=0;if("audio"===i.type)for(t?(r=t,t=new Uint8Array(r.byteLength+i.data.byteLength),t.set(r),t.set(i.data,r.byteLength)):t=i.data;p+5<t.length;)if(255===t[p]&&240===(246&t[p+1])){if(s=2*(1&~t[p+1]),e=(3&t[p+3])<<11|t[p+4]<<3|(224&t[p+5])>>5,o=1024*((3&t[p+6])+1),h=9e4*o/n[(60&t[p+2])>>>2],a=p+e,t.byteLength<a)return;if(this.trigger("data",{pts:i.pts+d*h,dts:i.dts+d*h,sampleCount:o,audioobjecttype:(t[p+2]>>>6&3)+1,channelcount:(1&t[p+2])<<2|(192&t[p+3])>>>6,samplerate:n[(60&t[p+2])>>>2],samplingfrequencyindex:(60&t[p+2])>>>2,samplesize:16,data:t.subarray(p+7+s,a)}),t.byteLength===a)return void(t=void 0);d++,t=t.subarray(a)}else p++},this.flush=function(){this.trigger("done")}},s.prototype=new a,i.exports=s},{}],2:[function(t,i,e){"use strict";var s,a,n,r=t(12),o=t(11);a=function(){var t,i,e=0;a.prototype.init.call(this),this.push=function(s){var a;for(i?(a=new Uint8Array(i.byteLength+s.data.byteLength),a.set(i),a.set(s.data,i.byteLength),i=a):i=s.data;e<i.byteLength-3;e++)if(1===i[e+2]){t=e+5;break}for(;t<i.byteLength;)switch(i[t]){case 0:if(0!==i[t-1]){t+=2;break}if(0!==i[t-2]){t++;break}e+3!==t-2&&this.trigger("data",i.subarray(e+3,t-2));do t++;while(1!==i[t]&&t<i.length);e=t-2,t+=3;break;case 1:if(0!==i[t-1]||0!==i[t-2]){t+=3;break}this.trigger("data",i.subarray(e+3,t-2)),e=t-2,t+=3;break;default:t+=3}i=i.subarray(e),t-=e,e=0},this.flush=function(){i&&i.byteLength>3&&this.trigger("data",i.subarray(e+3)),i=null,e=0,this.trigger("done")}},a.prototype=new r,n={100:!0,110:!0,122:!0,244:!0,44:!0,83:!0,86:!0,118:!0,128:!0,138:!0,139:!0,134:!0},s=function(){var t,i,e,r,h,p,d,l=new a;s.prototype.init.call(this),t=this,this.push=function(t){"video"===t.type&&(i=t.trackId,e=t.pts,r=t.dts,l.push(t))},l.on("data",function(s){var a={trackId:i,pts:e,dts:r,data:s};switch(31&s[0]){case 5:a.nalUnitType="slice_layer_without_partitioning_rbsp_idr";break;case 6:a.nalUnitType="sei_rbsp",a.escapedRBSP=h(s.subarray(1));break;case 7:a.nalUnitType="seq_parameter_set_rbsp",a.escapedRBSP=h(s.subarray(1)),a.config=p(a.escapedRBSP);break;case 8:a.nalUnitType="pic_parameter_set_rbsp";break;case 9:a.nalUnitType="access_unit_delimiter_rbsp"}t.trigger("data",a)}),l.on("done",function(){t.trigger("done")}),this.flush=function(){l.flush()},d=function(t,i){var e,s,a=8,n=8;for(e=0;e<t;e++)0!==n&&(s=i.readExpGolomb(),n=(a+s+256)%256),a=0===n?a:n},h=function(t){for(var i,e,s=t.byteLength,a=[],n=1;n<s-2;)0===t[n]&&0===t[n+1]&&3===t[n+2]?(a.push(n+2),n+=2):n++;if(0===a.length)return t;i=s-a.length,e=new Uint8Array(i);var r=0;for(n=0;n<i;r++,n++)r===a[0]&&(r++,a.shift()),e[n]=t[r];return e},p=function(t){var i,e,s,a,r,h,p,l,u,c,f,g,y,b,m=0,v=0,w=0,T=0,_=1;if(i=new o(t),e=i.readUnsignedByte(),a=i.readUnsignedByte(),s=i.readUnsignedByte(),i.skipUnsignedExpGolomb(),n[e]&&(r=i.readUnsignedExpGolomb(),3===r&&i.skipBits(1),i.skipUnsignedExpGolomb(),i.skipUnsignedExpGolomb(),i.skipBits(1),i.readBoolean()))for(f=3!==r?8:12,b=0;b<f;b++)i.readBoolean()&&(b<6?d(16,i):d(64,i));if(i.skipUnsignedExpGolomb(),h=i.readUnsignedExpGolomb(),0===h)i.readUnsignedExpGolomb();else if(1===h)for(i.skipBits(1),i.skipExpGolomb(),i.skipExpGolomb(),p=i.readUnsignedExpGolomb(),b=0;b<p;b++)i.skipExpGolomb();if(i.skipUnsignedExpGolomb(),i.skipBits(1),l=i.readUnsignedExpGolomb(),u=i.readUnsignedExpGolomb(),c=i.readBits(1),0===c&&i.skipBits(1),i.skipBits(1),i.readBoolean()&&(m=i.readUnsignedExpGolomb(),v=i.readUnsignedExpGolomb(),w=i.readUnsignedExpGolomb(),T=i.readUnsignedExpGolomb()),i.readBoolean()&&i.readBoolean()){switch(y=i.readUnsignedByte()){case 1:g=[1,1];break;case 2:g=[12,11];break;case 3:g=[10,11];break;case 4:g=[16,11];break;case 5:g=[40,33];break;case 6:g=[24,11];break;case 7:g=[20,11];break;case 8:g=[32,11];break;case 9:g=[80,33];break;case 10:g=[18,11];break;case 11:g=[15,11];break;case 12:g=[64,33];break;case 13:g=[160,99];break;case 14:g=[4,3];break;case 15:g=[3,2];break;case 16:g=[2,1];break;case 255:g=[i.readUnsignedByte()<<8|i.readUnsignedByte(),i.readUnsignedByte()<<8|i.readUnsignedByte()]}g&&(_=g[0]/g[1])}return{profileIdc:e,levelIdc:s,profileCompatibility:a,width:Math.ceil((16*(l+1)-2*m-2*v)*_),height:(2-c)*(u+1)*16-2*w-2*T}}},s.prototype=new r,i.exports={H264Stream:s,NalByteStream:a}},{}],3:[function(t,i,e){"use strict";var s;s=function(t,i){var e,a=0,n=16384,r=function(t,i){var e,s=t.position+i;s<t.bytes.byteLength||(e=new Uint8Array(2*s),e.set(t.bytes.subarray(0,t.position),0),t.bytes=e,t.view=new DataView(t.bytes.buffer))},o=s.widthBytes||new Uint8Array("width".length),h=s.heightBytes||new Uint8Array("height".length),p=s.videocodecidBytes||new Uint8Array("videocodecid".length);if(!s.widthBytes){for(e=0;e<"width".length;e++)o[e]="width".charCodeAt(e);for(e=0;e<"height".length;e++)h[e]="height".charCodeAt(e);for(e=0;e<"videocodecid".length;e++)p[e]="videocodecid".charCodeAt(e);s.widthBytes=o,s.heightBytes=h,s.videocodecidBytes=p}switch(this.keyFrame=!1,t){case s.VIDEO_TAG:this.length=16,n*=6;break;case s.AUDIO_TAG:this.length=13,this.keyFrame=!0;break;case s.METADATA_TAG:this.length=29,this.keyFrame=!0;break;default:throw new Error("Unknown FLV tag type")}this.bytes=new Uint8Array(n),this.view=new DataView(this.bytes.buffer),this.bytes[0]=t,this.position=this.length,this.keyFrame=i,this.pts=0,this.dts=0,this.writeBytes=function(t,i,e){var s,a=i||0;e=e||t.byteLength,s=a+e,r(this,e),this.bytes.set(t.subarray(a,s),this.position),this.position+=e,this.length=Math.max(this.length,this.position)},this.writeByte=function(t){r(this,1),this.bytes[this.position]=t,this.position++,this.length=Math.max(this.length,this.position)},this.writeShort=function(t){r(this,2),this.view.setUint16(this.position,t),this.position+=2,this.length=Math.max(this.length,this.position)},this.negIndex=function(t){return this.bytes[this.length-t]},this.nalUnitSize=function(){return 0===a?0:this.length-(a+4)},this.startNalUnit=function(){if(a>0)throw new Error("Attempted to create new NAL wihout closing the old one");a=this.length,this.length+=4,this.position=this.length},this.endNalUnit=function(t){var i,e;this.length===a+4?this.length-=4:a>0&&(i=a+4,e=this.length-i,this.position=a,this.view.setUint32(this.position,e),this.position=this.length,t&&t.push(this.bytes.subarray(i,i+e))),a=0},this.writeMetaDataDouble=function(t,i){var e;if(r(this,2+t.length+9),this.view.setUint16(this.position,t.length),this.position+=2,"width"===t)this.bytes.set(o,this.position),this.position+=5;else if("height"===t)this.bytes.set(h,this.position),this.position+=6;else if("videocodecid"===t)this.bytes.set(p,this.position),this.position+=12;else for(e=0;e<t.length;e++)this.bytes[this.position]=t.charCodeAt(e),this.position++;this.position++,this.view.setFloat64(this.position,i),this.position+=8,this.length=Math.max(this.length,this.position),++a},this.writeMetaDataBoolean=function(t,i){var e;for(r(this,2),this.view.setUint16(this.position,t.length),this.position+=2,e=0;e<t.length;e++)r(this,1),this.bytes[this.position]=t.charCodeAt(e),this.position++;r(this,2),this.view.setUint8(this.position,1),this.position++,this.view.setUint8(this.position,i?1:0),this.position++,this.length=Math.max(this.length,this.position),++a},this.finalize=function(){var t,e;switch(this.bytes[0]){case s.VIDEO_TAG:this.bytes[11]=7|(this.keyFrame||i?16:32),this.bytes[12]=i?0:1,t=this.pts-this.dts,this.bytes[13]=(16711680&t)>>>16,this.bytes[14]=(65280&t)>>>8,this.bytes[15]=(255&t)>>>0;break;case s.AUDIO_TAG:this.bytes[11]=175,this.bytes[12]=i?0:1;break;case s.METADATA_TAG:this.position=11,this.view.setUint8(this.position,2),this.position++,this.view.setUint16(this.position,10),this.position+=2,this.bytes.set([111,110,77,101,116,97,68,97,116,97],this.position),this.position+=10,this.bytes[this.position]=8,this.position++,this.view.setUint32(this.position,a),this.position=this.length,this.bytes.set([0,0,9],this.position),this.position+=3,this.length=this.position}return e=this.length-11,this.bytes[1]=(16711680&e)>>>16,this.bytes[2]=(65280&e)>>>8,this.bytes[3]=(255&e)>>>0,this.bytes[4]=(16711680&this.dts)>>>16,this.bytes[5]=(65280&this.dts)>>>8,this.bytes[6]=(255&this.dts)>>>0,this.bytes[7]=(4278190080&this.dts)>>>24,this.bytes[8]=0,this.bytes[9]=0,this.bytes[10]=0,r(this,4),this.view.setUint32(this.length,this.length),this.length+=4,this.position+=4,this.bytes=this.bytes.subarray(0,this.length),this.frameTime=s.frameTime(this.bytes),this}},s.AUDIO_TAG=8,s.VIDEO_TAG=9,s.METADATA_TAG=18,s.isAudioFrame=function(t){return s.AUDIO_TAG===t[0]},s.isVideoFrame=function(t){return s.VIDEO_TAG===t[0]},s.isMetaData=function(t){return s.METADATA_TAG===t[0]},s.isKeyFrame=function(t){return s.isVideoFrame(t)?23===t[11]:!!s.isAudioFrame(t)||!!s.isMetaData(t)},s.frameTime=function(t){var i=t[4]<<16;return i|=t[5]<<8,i|=t[6]<<0,i|=t[7]<<24},i.exports=s},{}],4:[function(t,i,e){i.exports={tag:t(3),Transmuxer:t(5)}},{}],5:[function(t,i,e){"use strict";var s,a,n,r,o,h,p,d=t(12),l=t(3),u=t(7),c=t(1),f=t(2).H264Stream;o=function(t,i){"number"==typeof i.pts&&(void 0===t.timelineStartInfo.pts?t.timelineStartInfo.pts=i.pts:t.timelineStartInfo.pts=Math.min(t.timelineStartInfo.pts,i.pts)),"number"==typeof i.dts&&(void 0===t.timelineStartInfo.dts?t.timelineStartInfo.dts=i.dts:t.timelineStartInfo.dts=Math.min(t.timelineStartInfo.dts,i.dts))},h=function(t,i){var e=new l(l.METADATA_TAG);return e.dts=i,e.pts=i,e.writeMetaDataDouble("videocodecid",7),e.writeMetaDataDouble("width",t.width),e.writeMetaDataDouble("height",t.height),e},p=function(t,i){var e,s=new l(l.VIDEO_TAG,!0);for(s.dts=i,s.pts=i,s.writeByte(1),s.writeByte(t.profileIdc),s.writeByte(t.profileCompatibility),s.writeByte(t.levelIdc),s.writeByte(255),s.writeByte(225),s.writeShort(t.sps[0].length),s.writeBytes(t.sps[0]),s.writeByte(t.pps.length),e=0;e<t.pps.length;++e)s.writeShort(t.pps[e].length),s.writeBytes(t.pps[e]);return s},n=function(t){var i,e=[];n.prototype.init.call(this),this.push=function(i){o(t,i),t&&void 0===t.channelcount&&(t.audioobjecttype=i.audioobjecttype,t.channelcount=i.channelcount,t.samplerate=i.samplerate,t.samplingfrequencyindex=i.samplingfrequencyindex,t.samplesize=i.samplesize,t.extraData=t.audioobjecttype<<11|t.samplingfrequencyindex<<7|t.channelcount<<3),i.pts=Math.round(i.pts/90),i.dts=Math.round(i.dts/90),e.push(i)},this.flush=function(){var s,a,n,r=[];if(0===e.length)return void this.trigger("done");for(n=-(1/0);e.length;)s=e.shift(),(t.extraData!==i||s.pts-n>=1e3)&&(a=new l(l.METADATA_TAG),a.pts=s.pts,a.dts=s.dts,a.writeMetaDataDouble("audiocodecid",10),a.writeMetaDataBoolean("stereo",2===t.channelcount),a.writeMetaDataDouble("audiosamplerate",t.samplerate),a.writeMetaDataDouble("audiosamplesize",16),r.push(a),i=t.extraData,a=new l(l.AUDIO_TAG,!0),a.pts=s.pts,a.dts=s.dts,a.view.setUint16(a.position,t.extraData),a.position+=2,a.length=Math.max(a.length,a.position),r.push(a),n=s.pts),a=new l(l.AUDIO_TAG),a.pts=s.pts,a.dts=s.dts,a.writeBytes(s.data),r.push(a);i=null,this.trigger("data",{track:t,tags:r}),this.trigger("done")}},n.prototype=new d,a=function(t){var i,e,s=[];a.prototype.init.call(this),this.finishFrame=function(e,s){s&&(i&&t&&t.newMetadata&&(s.keyFrame||0===e.length)&&(e.push(h(i,s.pts)),e.push(p(t,s.pts)),t.newMetadata=!1),s.endNalUnit(),e.push(s))},this.push=function(i){o(t,i),i.pts=Math.round(i.pts/90),i.dts=Math.round(i.dts/90),s.push(i)},this.flush=function(){for(var a,n=[];s.length&&"access_unit_delimiter_rbsp"!==s[0].nalUnitType;)s.shift();if(0===s.length)return void this.trigger("done");for(;s.length;)a=s.shift(),"seq_parameter_set_rbsp"===a.nalUnitType?(t.newMetadata=!0,i=a.config,t.width=i.width,t.height=i.height,t.sps=[a.data],t.profileIdc=i.profileIdc,t.levelIdc=i.levelIdc,t.profileCompatibility=i.profileCompatibility,e.endNalUnit()):"pic_parameter_set_rbsp"===a.nalUnitType?(t.newMetadata=!0,t.pps=[a.data],e.endNalUnit()):"access_unit_delimiter_rbsp"===a.nalUnitType?(e&&this.finishFrame(n,e),e=new l(l.VIDEO_TAG),e.pts=a.pts,e.dts=a.dts):("slice_layer_without_partitioning_rbsp_idr"===a.nalUnitType&&(e.keyFrame=!0),e.endNalUnit()),e.startNalUnit(),e.writeBytes(a.data);e&&this.finishFrame(n,e),this.trigger("data",{track:t,tags:n}),this.trigger("done")}},a.prototype=new d,r=function(t){this.numberOfTracks=0,this.metadataStream=t.metadataStream,this.videoTags=[],this.audioTags=[],this.videoTrack=null,this.audioTrack=null,this.pendingCaptions=[],this.pendingMetadata=[],this.pendingTracks=0,r.prototype.init.call(this),this.push=function(t){return t.text?this.pendingCaptions.push(t):t.frames?this.pendingMetadata.push(t):("video"===t.track.type&&(this.videoTrack=t.track,this.videoTags=t.tags,this.pendingTracks++),void("audio"===t.track.type&&(this.audioTrack=t.track,this.audioTags=t.tags,this.pendingTracks++)))}},r.prototype=new d,r.prototype.flush=function(){var t,i,e,s,a={tags:{},captions:[],metadata:[]};if(!(this.pendingTracks<this.numberOfTracks)){for(this.videoTrack?s=this.videoTrack.timelineStartInfo.pts:this.audioTrack&&(s=this.audioTrack.timelineStartInfo.pts),a.tags.videoTags=this.videoTags,a.tags.audioTags=this.audioTags,e=0;e<this.pendingCaptions.length;e++)i=this.pendingCaptions[e],i.startTime=i.startPts-s,i.startTime/=9e4,i.endTime=i.endPts-s,i.endTime/=9e4,a.captions.push(i);for(e=0;e<this.pendingMetadata.length;e++)t=this.pendingMetadata[e],t.cueTime=t.pts-s,t.cueTime/=9e4,a.metadata.push(t);a.metadata.dispatchType=this.metadataStream.dispatchType,this.videoTrack=null,this.audioTrack=null,this.videoTags=[],this.audioTags=[],this.pendingCaptions.length=0,this.pendingMetadata.length=0,this.pendingTracks=0,this.trigger("data",a),this.trigger("done")}},s=function(t){var i,e,o,h,p,d,g,y,b,m,v,w,T=this;s.prototype.init.call(this),t=t||{},this.metadataStream=new u.MetadataStream,t.metadataStream=this.metadataStream,i=new u.TransportPacketStream,e=new u.TransportParseStream,o=new u.ElementaryStream,h=new u.TimestampRolloverStream("video"),p=new u.TimestampRolloverStream("audio"),d=new u.TimestampRolloverStream("timed-metadata"),g=new c,y=new f,w=new r(t),i.pipe(e).pipe(o),o.pipe(h).pipe(y),o.pipe(p).pipe(g),o.pipe(d).pipe(this.metadataStream).pipe(w),v=new u.CaptionStream,y.pipe(v).pipe(w),o.on("data",function(t){var i,e,s;if("metadata"===t.type){for(i=t.tracks.length;i--;)"video"===t.tracks[i].type?e=t.tracks[i]:"audio"===t.tracks[i].type&&(s=t.tracks[i]);e&&!b&&(w.numberOfTracks++,b=new a(e),y.pipe(b).pipe(w)),s&&!m&&(w.numberOfTracks++,m=new n(s),g.pipe(m).pipe(w))}}),this.push=function(t){i.push(t)},this.flush=function(){i.flush()},w.on("data",function(t){T.trigger("data",t)}),w.on("done",function(){T.trigger("done")}),this.getFlvHeader=function(t,i,e){var s,a,n,r=new Uint8Array(9),o=new DataView(r.buffer);return t=t||0,i=void 0===i||i,e=void 0===e||e,o.setUint8(0,70),o.setUint8(1,76),o.setUint8(2,86),o.setUint8(3,1),o.setUint8(4,(i?4:0)|(e?1:0)),o.setUint32(5,r.byteLength),t<=0?(a=new Uint8Array(r.byteLength+4),a.set(r),a.set([0,0,0,0],r.byteLength),a):(s=new l(l.METADATA_TAG),s.pts=s.dts=0,s.writeMetaDataDouble("duration",t),n=s.finalize().length,a=new Uint8Array(r.byteLength+n),a.set(r),a.set(o.byteLength,n),a)}},s.prototype=new d,i.exports=s},{}],6:[function(t,i,e){"use strict";var s=4,a=128,n=t(12),r=function(t){for(var i=0,e={payloadType:-1,payloadSize:0},n=0,r=0;i<t.byteLength&&t[i]!==a;){for(;255===t[i];)n+=255,i++;for(n+=t[i++];255===t[i];)r+=255,i++;if(r+=t[i++],!e.payload&&n===s){e.payloadType=n,e.payloadSize=r,e.payload=t.subarray(i,i+r);break}i+=r,n=0,r=0}return e},o=function(t){return 181!==t.payload[0]?null:49!==(t.payload[1]<<8|t.payload[2])?null:"GA94"!==String.fromCharCode(t.payload[3],t.payload[4],t.payload[5],t.payload[6])?null:3!==t.payload[7]?null:t.payload.subarray(8,t.payload.length-1)},h=function(t,i){var e,s,a,n,r=[];if(!(64&i[0]))return r;for(s=31&i[0],e=0;e<s;e++)a=3*e,n={type:3&i[a+2],pts:t},4&i[a+2]&&(n.ccData=i[a+3]<<8|i[a+4],r.push(n));return r},p=function(){p.prototype.init.call(this),this.captionPackets_=[],this.field1_=new A,this.field1_.on("data",this.trigger.bind(this,"data")),this.field1_.on("done",this.trigger.bind(this,"done"))};p.prototype=new n,p.prototype.push=function(t){var i,e;"sei_rbsp"===t.nalUnitType&&(i=r(t.escapedRBSP),i.payloadType===s&&(e=o(i),e&&(this.captionPackets_=this.captionPackets_.concat(h(t.pts,e)))))},p.prototype.flush=function(){return this.captionPackets_.length?(this.captionPackets_.forEach(function(t,i){t.presortIndex=i}),this.captionPackets_.sort(function(t,i){return t.pts===i.pts?t.presortIndex-i.presortIndex:t.pts-i.pts}),this.captionPackets_.forEach(this.field1_.push,this.field1_),this.captionPackets_.length=0,void this.field1_.flush()):void this.field1_.flush()};var d={42:225,92:233,94:237,95:243,96:250,123:231,124:247,125:209,126:241,127:9608},l=function(t){return null===t?"":(t=d[t]||t,String.fromCharCode(t))},u=0,c=5152,f=5167,g=5157,y=5158,b=5159,m=5165,v=5153,w=5164,T=5166,_=14,k=function(){for(var t=[],i=_+1;i--;)t.push("");return t},A=function(){A.prototype.init.call(this),this.mode_="popOn",this.topRow_=0,this.startPts_=0,this.displayed_=k(),this.nonDisplayed_=k(),this.lastControlCode_=null,this.push=function(t){if(0===t.type){var i,e,s,a;if(i=32639&t.ccData,i===this.lastControlCode_)return void(this.lastControlCode_=null);switch(4096===(61440&i)?this.lastControlCode_=i:this.lastControlCode_=null,i){case u:break;case c:this.mode_="popOn";break;case f:this.flushDisplayed(t.pts),e=this.displayed_,this.displayed_=this.nonDisplayed_,this.nonDisplayed_=e,this.startPts_=t.pts;break;case g:this.topRow_=_-1,this.mode_="rollUp";break;case y:this.topRow_=_-2,this.mode_="rollUp";break;case b:this.topRow_=_-3,this.mode_="rollUp";break;case m:this.flushDisplayed(t.pts),this.shiftRowsUp_(),this.startPts_=t.pts;break;case v:"popOn"===this.mode_?this.nonDisplayed_[_]=this.nonDisplayed_[_].slice(0,-1):this.displayed_[_]=this.displayed_[_].slice(0,-1);break;case w:this.flushDisplayed(t.pts),this.displayed_=k();break;case T:this.nonDisplayed_=k();break;default:if(s=i>>>8,a=255&i,s>=16&&s<=23&&a>=64&&a<=127&&(16!==s||a<96)&&(s=32,a=null),(17===s||25===s)&&a>=48&&a<=63&&(s=9834,a=""),16===(240&s))return;this[this.mode_](t.pts,s,a)}}}};A.prototype=new n,A.prototype.flushDisplayed=function(t){var i=this.displayed_.map(function(t){return t.trim()}).filter(function(t){return t.length}).join("\n");i.length&&this.trigger("data",{startPts:this.startPts_,endPts:t,text:i})},A.prototype.popOn=function(t,i,e){var s=this.nonDisplayed_[_];s+=l(i),s+=l(e),this.nonDisplayed_[_]=s},A.prototype.rollUp=function(t,i,e){var s=this.displayed_[_];""===s&&(this.flushDisplayed(t),this.startPts_=t),s+=l(i),s+=l(e),this.displayed_[_]=s},A.prototype.shiftRowsUp_=function(){var t;for(t=0;t<this.topRow_;t++)this.displayed_[t]="";for(t=this.topRow_;t<_;t++)this.displayed_[t]=this.displayed_[t+1];this.displayed_[_]=""},i.exports={CaptionStream:p,Cea608Stream:A}},{}],7:[function(t,i,e){"use strict";var s,a,n,r=t(12),o=t(6),h=t(9),p=t(10).TimestampRolloverStream,d=t(9),l=188,u=71;s=function(){var t=new Uint8Array(l),i=0;s.prototype.init.call(this),this.push=function(e){var s,a=0,n=l;for(i?(s=new Uint8Array(e.byteLength+i),s.set(t.subarray(0,i)),s.set(e,i),i=0):s=e;n<s.byteLength;)s[a]!==u||s[n]!==u?(a++,n++):(this.trigger("data",s.subarray(a,n)),a+=l,n+=l);a<s.byteLength&&(t.set(s.subarray(a),0),i=s.byteLength-a)},this.flush=function(){i===l&&t[0]===u&&(this.trigger("data",t),i=0),this.trigger("done")}},s.prototype=new r,a=function(){var t,i,e,s;a.prototype.init.call(this),s=this,this.packetsWaitingForPmt=[],this.programMapTable=void 0,t=function(t,s){var a=0;s.payloadUnitStartIndicator&&(a+=t[a]+1),"pat"===s.type?i(t.subarray(a),s):e(t.subarray(a),s)},i=function(t,i){i.section_number=t[7],i.last_section_number=t[8],s.pmtPid=(31&t[10])<<8|t[11],i.pmtPid=s.pmtPid},e=function(t,i){var e,a,n,r;if(1&t[5]){for(s.programMapTable={},e=(15&t[1])<<8|t[2],a=3+e-4,n=(15&t[10])<<8|t[11],r=12+n;r<a;)s.programMapTable[(31&t[r+1])<<8|t[r+2]]=t[r],r+=((15&t[r+3])<<8|t[r+4])+5;for(i.programMapTable=s.programMapTable;s.packetsWaitingForPmt.length;)s.processPes_.apply(s,s.packetsWaitingForPmt.shift())}},this.push=function(i){var e={},s=4;e.payloadUnitStartIndicator=!!(64&i[1]),e.pid=31&i[1],e.pid<<=8,e.pid|=i[2],(48&i[3])>>>4>1&&(s+=i[s]+1),0===e.pid?(e.type="pat",t(i.subarray(s),e),this.trigger("data",e)):e.pid===this.pmtPid?(e.type="pmt",t(i.subarray(s),e),this.trigger("data",e)):void 0===this.programMapTable?this.packetsWaitingForPmt.push([i,s,e]):this.processPes_(i,s,e)},this.processPes_=function(t,i,e){e.streamType=this.programMapTable[e.pid],e.type="pes",e.data=t.subarray(i),this.trigger("data",e)}},a.prototype=new r,a.STREAM_TYPES={h264:27,adts:15},n=function(){var t=this,i={data:[],size:0},e={data:[],size:0},s={data:[],size:0},a=function(t,i){var e;i.dataAlignmentIndicator=0!==(4&t[6]),e=t[7],192&e&&(i.pts=(14&t[9])<<27|(255&t[10])<<20|(254&t[11])<<12|(255&t[12])<<5|(254&t[13])>>>3,i.pts*=4,i.pts+=(6&t[13])>>>1,i.dts=i.pts,64&e&&(i.dts=(14&t[14])<<27|(255&t[15])<<20|(254&t[16])<<12|(255&t[17])<<5|(254&t[18])>>>3,i.dts*=4,i.dts+=(6&t[18])>>>1)),i.data=t.subarray(9+t[8])},r=function(i,e){var s,n=new Uint8Array(i.size),r={type:e},o=0;if(i.data.length){for(r.trackId=i.data[0].pid;i.data.length;)s=i.data.shift(),n.set(s.data,o),o+=s.data.byteLength;a(n,r),i.size=0,t.trigger("data",r)}};n.prototype.init.call(this),this.push=function(a){({pat:function(){},pes:function(){var t,n;switch(a.streamType){case h.H264_STREAM_TYPE:case d.H264_STREAM_TYPE:t=i,n="video";break;case h.ADTS_STREAM_TYPE:t=e,n="audio";break;case h.METADATA_STREAM_TYPE:t=s,n="timed-metadata";break;default:return}a.payloadUnitStartIndicator&&r(t,n),t.data.push(a),t.size+=a.data.byteLength},pmt:function(){var i,e,s={type:"metadata",tracks:[]},n=a.programMapTable;for(i in n)n.hasOwnProperty(i)&&(e={timelineStartInfo:{baseMediaDecodeTime:0}},e.id=+i,n[i]===d.H264_STREAM_TYPE?(e.codec="avc",e.type="video"):n[i]===d.ADTS_STREAM_TYPE&&(e.codec="adts",e.type="audio"),s.tracks.push(e));t.trigger("data",s)}})[a.type]()},this.flush=function(){r(i,"video"),r(e,"audio"),r(s,"timed-metadata"),this.trigger("done")}},n.prototype=new r;var c={PAT_PID:0,MP2T_PACKET_LENGTH:l,TransportPacketStream:s,TransportParseStream:a,ElementaryStream:n,TimestampRolloverStream:p,CaptionStream:o.CaptionStream,Cea608Stream:o.Cea608Stream,MetadataStream:t(8)};for(var f in h)h.hasOwnProperty(f)&&(c[f]=h[f]);i.exports=c},{}],8:[function(t,i,e){"use strict";var s,a=t(12),n=t(9),r=function(t,i,e){var s,a="";for(s=i;s<e;s++)a+="%"+("00"+t[s].toString(16)).slice(-2);return a},o=function(t,i,e){return decodeURIComponent(r(t,i,e))},h=function(t,i,e){return unescape(r(t,i,e))},p=function(t){return t[0]<<21|t[1]<<14|t[2]<<7|t[3]},d={TXXX:function(t){var i;if(3===t.data[0]){for(i=1;i<t.data.length;i++)if(0===t.data[i]){t.description=o(t.data,1,i),t.value=o(t.data,i+1,t.data.length-1);break}t.data=t.value}},WXXX:function(t){var i;if(3===t.data[0])for(i=1;i<t.data.length;i++)if(0===t.data[i]){t.description=o(t.data,1,i),t.url=o(t.data,i+1,t.data.length);break}},PRIV:function(t){var i;for(i=0;i<t.data.length;i++)if(0===t.data[i]){t.owner=h(t.data,0,i);break}t.privateData=t.data.subarray(i+1),t.data=t.privateData}};s=function(t){var i,e={debug:!(!t||!t.debug),descriptor:t&&t.descriptor},a=0,r=[],o=0;if(s.prototype.init.call(this),this.dispatchType=n.METADATA_STREAM_TYPE.toString(16),e.descriptor)for(i=0;i<e.descriptor.length;i++)this.dispatchType+=("00"+e.descriptor[i].toString(16)).slice(-2);this.push=function(t){var i,s,n,h,l,u;if("timed-metadata"===t.type){if(t.dataAlignmentIndicator&&(o=0,r.length=0),0===r.length&&(t.data.length<10||t.data[0]!=="I".charCodeAt(0)||t.data[1]!=="D".charCodeAt(0)||t.data[2]!=="3".charCodeAt(0)))return void(e.debug&&console.log("Skipping unrecognized metadata packet"));if(r.push(t),o+=t.data.byteLength,1===r.length&&(a=p(t.data.subarray(6,10)),a+=10),!(o<a)){for(i={data:new Uint8Array(a),frames:[],pts:r[0].pts,dts:r[0].dts},l=0;l<a;)i.data.set(r[0].data.subarray(0,a-l),l),l+=r[0].data.byteLength,o-=r[0].data.byteLength,r.shift();s=10,64&i.data[5]&&(s+=4,s+=p(i.data.subarray(10,14)),a-=p(i.data.subarray(16,20)));do{if(n=p(i.data.subarray(s+4,s+8)),n<1)return console.log("Malformed ID3 frame encountered. Skipping metadata parsing.");if(u=String.fromCharCode(i.data[s],i.data[s+1],i.data[s+2],i.data[s+3]),h={id:u,data:i.data.subarray(s+10,s+n+10)},h.key=h.id,d[h.id]&&(d[h.id](h),"com.apple.streaming.transportStreamTimestamp"===h.owner)){var c=h.data,f=(1&c[3])<<30|c[4]<<22|c[5]<<14|c[6]<<6|c[7]>>>2;f*=4,f+=3&c[7],h.timeStamp=f,void 0===i.pts&&void 0===i.dts&&(i.pts=h.timeStamp,i.dts=h.timeStamp),this.trigger("timestamp",h)}i.frames.push(h),s+=10,s+=n}while(s<a);this.trigger("data",i)}}}},s.prototype=new a,i.exports=s},{}],9:[function(t,i,e){"use strict";i.exports={H264_STREAM_TYPE:27,ADTS_STREAM_TYPE:15,METADATA_STREAM_TYPE:21}},{}],10:[function(t,i,e){"use strict";var s=t(12),a=8589934592,n=4294967296,r=function(t,i){var e=1;for(t>i&&(e=-1);Math.abs(i-t)>n;)t+=e*a;return t},o=function(t){var i,e;o.prototype.init.call(this),this.type_=t,this.push=function(t){t.type===this.type_&&(void 0===e&&(e=t.dts),t.dts=r(t.dts,e),t.pts=r(t.pts,e),i=t.dts,this.trigger("data",t))},this.flush=function(){e=i,this.trigger("done")}};o.prototype=new s,i.exports={TimestampRolloverStream:o,handleRollover:r}},{}],11:[function(t,i,e){"use strict";var s;s=function(t){var i=t.byteLength,e=0,s=0;this.length=function(){return 8*i},this.bitsAvailable=function(){return 8*i+s},this.loadWord=function(){var a=t.byteLength-i,n=new Uint8Array(4),r=Math.min(4,i);if(0===r)throw new Error("no bytes available");n.set(t.subarray(a,a+r)),e=new DataView(n.buffer).getUint32(0),s=8*r,i-=r},this.skipBits=function(t){var a;s>t?(e<<=t,s-=t):(t-=s,a=Math.floor(t/8),t-=8*a,i-=a,this.loadWord(),e<<=t,s-=t)},this.readBits=function(t){var a=Math.min(s,t),n=e>>>32-a;return s-=a,s>0?e<<=a:i>0&&this.loadWord(),a=t-a,a>0?n<<a|this.readBits(a):n},this.skipLeadingZeros=function(){var t;for(t=0;t<s;++t)if(0!==(e&2147483648>>>t))return e<<=t,s-=t,t;return this.loadWord(),t+this.skipLeadingZeros()},this.skipUnsignedExpGolomb=function(){this.skipBits(1+this.skipLeadingZeros())},this.skipExpGolomb=function(){this.skipBits(1+this.skipLeadingZeros())},this.readUnsignedExpGolomb=function(){var t=this.skipLeadingZeros();return this.readBits(t+1)-1},this.readExpGolomb=function(){var t=this.readUnsignedExpGolomb();return 1&t?1+t>>>1:-1*(t>>>1)},this.readBoolean=function(){return 1===this.readBits(1)},this.readUnsignedByte=function(){return this.readBits(8)},this.loadWord()},i.exports=s},{}],12:[function(t,i,e){"use strict";var s=function(){this.init=function(){var t={};this.on=function(i,e){t[i]||(t[i]=[]),t[i].push(e)},this.off=function(i,e){var s;return!!t[i]&&(s=t[i].indexOf(e),t[i].splice(s,1),s>-1)},this.trigger=function(i){var e,s,a,n;if(e=t[i])if(2===arguments.length)for(a=e.length,s=0;s<a;++s)e[s].call(this,arguments[1]);else{for(n=[],s=arguments.length,s=1;s<arguments.length;++s)n.push(arguments[s]);for(a=e.length,s=0;s<a;++s)e[s].apply(this,n)}},this.dispose=function(){t={}}}};s.prototype.pipe=function(t){return this.on("data",function(i){t.push(i)}),this.on("done",function(i){t.flush(i)}),t},s.prototype.push=function(t){this.trigger("data",t)},s.prototype.flush=function(t){this.trigger("done",t)},i.exports=s},{}]},{},[4]); |
@@ -1,2 +0,2 @@ | ||
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.muxjs=t()}}(function(){return function t(e,a,i){function n(s,o){if(!a[s]){if(!e[s]){var d="function"==typeof require&&require;if(!o&&d)return d(s,!0);if(r)return r(s,!0);var p=new Error("Cannot find module '"+s+"'");throw p.code="MODULE_NOT_FOUND",p}var h=a[s]={exports:{}};e[s][0].call(h.exports,function(t){var a=e[s][1][t];return n(a?a:t)},h,h.exports,t,e,a,i)}return a[s].exports}for(var r="function"==typeof require&&require,s=0;s<i.length;s++)n(i[s]);return n}({1:[function(t,e,a){"use strict";var i,n=t("../utils/stream.js");i=function(){var t=new Uint8Array,e=0;i.prototype.init.call(this),this.setTimestamp=function(t){e=t},this.parseId3TagSize=function(t,e){var a=t[e+6]<<21|t[e+7]<<14|t[e+8]<<7|t[e+9],i=t[e+5],n=(16&i)>>4;return n?a+20:a+10},this.parseAdtsSize=function(t,e){var a=(224&t[e+5])>>5,i=t[e+4]<<3,n=6144&t[e+3];return n|i|a},this.push=function(a){var i,n,r,s,o=0,d=0;for(t.length?(s=t.length,t=new Uint8Array(a.byteLength+s),t.set(t.subarray(0,s)),t.set(a,s)):t=a;t.length-d>=3;)if(t[d]!=="I".charCodeAt(0)||t[d+1]!=="D".charCodeAt(0)||t[d+2]!=="3".charCodeAt(0))if(t[d]&!0&&240===(240&t[d+1])){if(t.length-d<7)break;if(o=this.parseAdtsSize(t,d),o>t.length)break;r={type:"audio",data:t.subarray(d,d+o),pts:e,dts:e},this.trigger("data",r),d+=o}else d++;else{if(t.length-d<10)break;if(o=this.parseId3TagSize(t,d),o>t.length)break;n={type:"timed-metadata",data:t.subarray(d,d+o)},this.trigger("data",n),d+=o}i=t.length-d,t=i>0?t.subarray(d):new Uint8Array}},i.prototype=new n,e.exports=i},{"../utils/stream.js":13}],2:[function(t,e,a){"use strict";var i,n=t("../utils/stream.js"),r=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];i=function(){var t;i.prototype.init.call(this),this.push=function(e){var a,i,n,s,o,d,p=0,h=0;if("audio"===e.type)for(t?(s=t,t=new Uint8Array(s.byteLength+e.data.byteLength),t.set(s),t.set(e.data,s.byteLength)):t=e.data;p+5<t.length;)if(255===t[p]&&240===(246&t[p+1])){if(i=2*(1&~t[p+1]),a=(3&t[p+3])<<11|t[p+4]<<3|(224&t[p+5])>>5,o=1024*((3&t[p+6])+1),d=9e4*o/r[(60&t[p+2])>>>2],n=p+a,t.byteLength<n)return;if(this.trigger("data",{pts:e.pts+h*d,dts:e.dts+h*d,sampleCount:o,audioobjecttype:(t[p+2]>>>6&3)+1,channelcount:(1&t[p+2])<<2|(192&t[p+3])>>>6,samplerate:r[(60&t[p+2])>>>2],samplingfrequencyindex:(60&t[p+2])>>>2,samplesize:16,data:t.subarray(p+7+i,n)}),t.byteLength===n)return void(t=void 0);h++,t=t.subarray(n)}else p++},this.flush=function(){this.trigger("done")}},i.prototype=new n,e.exports=i},{"../utils/stream.js":13}],3:[function(t,e,a){"use strict";var i,n,r,s=t("../utils/stream.js"),o=t("../utils/exp-golomb.js");n=function(){var t,e,a=0;n.prototype.init.call(this),this.push=function(i){var n;for(e?(n=new Uint8Array(e.byteLength+i.data.byteLength),n.set(e),n.set(i.data,e.byteLength),e=n):e=i.data;a<e.byteLength-3;a++)if(1===e[a+2]){t=a+5;break}for(;t<e.byteLength;)switch(e[t]){case 0:if(0!==e[t-1]){t+=2;break}if(0!==e[t-2]){t++;break}a+3!==t-2&&this.trigger("data",e.subarray(a+3,t-2));do t++;while(1!==e[t]&&t<e.length);a=t-2,t+=3;break;case 1:if(0!==e[t-1]||0!==e[t-2]){t+=3;break}this.trigger("data",e.subarray(a+3,t-2)),a=t-2,t+=3;break;default:t+=3}e=e.subarray(a),t-=a,a=0},this.flush=function(){e&&e.byteLength>3&&this.trigger("data",e.subarray(a+3)),e=null,a=0,this.trigger("done")}},n.prototype=new s,r={100:!0,110:!0,122:!0,244:!0,44:!0,83:!0,86:!0,118:!0,128:!0,138:!0,139:!0,134:!0},i=function(){var t,e,a,s,d,p,h,u=new n;i.prototype.init.call(this),t=this,this.push=function(t){"video"===t.type&&(e=t.trackId,a=t.pts,s=t.dts,u.push(t))},u.on("data",function(i){var n={trackId:e,pts:a,dts:s,data:i};switch(31&i[0]){case 5:n.nalUnitType="slice_layer_without_partitioning_rbsp_idr";break;case 6:n.nalUnitType="sei_rbsp",n.escapedRBSP=d(i.subarray(1));break;case 7:n.nalUnitType="seq_parameter_set_rbsp",n.escapedRBSP=d(i.subarray(1)),n.config=p(n.escapedRBSP);break;case 8:n.nalUnitType="pic_parameter_set_rbsp";break;case 9:n.nalUnitType="access_unit_delimiter_rbsp"}t.trigger("data",n)}),u.on("done",function(){t.trigger("done")}),this.flush=function(){u.flush()},h=function(t,e){var a,i,n=8,r=8;for(a=0;t>a;a++)0!==r&&(i=e.readExpGolomb(),r=(n+i+256)%256),n=0===r?n:r},d=function(t){for(var e,a,i=t.byteLength,n=[],r=1;i-2>r;)0===t[r]&&0===t[r+1]&&3===t[r+2]?(n.push(r+2),r+=2):r++;if(0===n.length)return t;e=i-n.length,a=new Uint8Array(e);var s=0;for(r=0;e>r;s++,r++)s===n[0]&&(s++,n.shift()),a[r]=t[s];return a},p=function(t){var e,a,i,n,s,d,p,u,m,c,l,f,g,y,b=0,S=0,v=0,T=0,_=1;if(e=new o(t),a=e.readUnsignedByte(),n=e.readUnsignedByte(),i=e.readUnsignedByte(),e.skipUnsignedExpGolomb(),r[a]&&(s=e.readUnsignedExpGolomb(),3===s&&e.skipBits(1),e.skipUnsignedExpGolomb(),e.skipUnsignedExpGolomb(),e.skipBits(1),e.readBoolean()))for(l=3!==s?8:12,y=0;l>y;y++)e.readBoolean()&&(6>y?h(16,e):h(64,e));if(e.skipUnsignedExpGolomb(),d=e.readUnsignedExpGolomb(),0===d)e.readUnsignedExpGolomb();else if(1===d)for(e.skipBits(1),e.skipExpGolomb(),e.skipExpGolomb(),p=e.readUnsignedExpGolomb(),y=0;p>y;y++)e.skipExpGolomb();if(e.skipUnsignedExpGolomb(),e.skipBits(1),u=e.readUnsignedExpGolomb(),m=e.readUnsignedExpGolomb(),c=e.readBits(1),0===c&&e.skipBits(1),e.skipBits(1),e.readBoolean()&&(b=e.readUnsignedExpGolomb(),S=e.readUnsignedExpGolomb(),v=e.readUnsignedExpGolomb(),T=e.readUnsignedExpGolomb()),e.readBoolean()&&e.readBoolean()){switch(g=e.readUnsignedByte()){case 1:f=[1,1];break;case 2:f=[12,11];break;case 3:f=[10,11];break;case 4:f=[16,11];break;case 5:f=[40,33];break;case 6:f=[24,11];break;case 7:f=[20,11];break;case 8:f=[32,11];break;case 9:f=[80,33];break;case 10:f=[18,11];break;case 11:f=[15,11];break;case 12:f=[64,33];break;case 13:f=[160,99];break;case 14:f=[4,3];break;case 15:f=[3,2];break;case 16:f=[2,1];break;case 255:f=[e.readUnsignedByte()<<8|e.readUnsignedByte(),e.readUnsignedByte()<<8|e.readUnsignedByte()]}f&&(_=f[0]/f[1])}return{profileIdc:a,levelIdc:i,profileCompatibility:n,width:Math.ceil((16*(u+1)-2*b-2*S)*_),height:(2-c)*(m+1)*16-2*v-2*T}}},i.prototype=new s,e.exports={H264Stream:i,NalByteStream:n}},{"../utils/exp-golomb.js":12,"../utils/stream.js":13}],4:[function(t,e,a){"use strict";var i=4,n=128,r=t("../utils/stream"),s=function(t){for(var e=0,a={payloadType:-1,payloadSize:0},r=0,s=0;e<t.byteLength&&t[e]!==n;){for(;255===t[e];)r+=255,e++;for(r+=t[e++];255===t[e];)s+=255,e++;if(s+=t[e++],!a.payload&&r===i){a.payloadType=r,a.payloadSize=s,a.payload=t.subarray(e,e+s);break}e+=s,r=0,s=0}return a},o=function(t){return 181!==t.payload[0]?null:49!==(t.payload[1]<<8|t.payload[2])?null:"GA94"!==String.fromCharCode(t.payload[3],t.payload[4],t.payload[5],t.payload[6])?null:3!==t.payload[7]?null:t.payload.subarray(8,t.payload.length-1)},d=function(t,e){var a,i,n,r,s=[];if(!(64&e[0]))return s;for(i=31&e[0],a=0;i>a;a++)n=3*a,r={type:3&e[n+2],pts:t},4&e[n+2]&&(r.ccData=e[n+3]<<8|e[n+4],s.push(r));return s},p=function(){p.prototype.init.call(this),this.captionPackets_=[],this.field1_=new w,this.field1_.on("data",this.trigger.bind(this,"data")),this.field1_.on("done",this.trigger.bind(this,"done"))};p.prototype=new r,p.prototype.push=function(t){var e,a;"sei_rbsp"===t.nalUnitType&&(e=s(t.escapedRBSP),e.payloadType===i&&(a=o(e),a&&(this.captionPackets_=this.captionPackets_.concat(d(t.pts,a)))))},p.prototype.flush=function(){return this.captionPackets_.length?(this.captionPackets_.sort(function(t,e){return t.pts-e.pts}),this.captionPackets_.forEach(this.field1_.push,this.field1_),this.captionPackets_.length=0,void this.field1_.flush()):void this.field1_.flush()};var h={42:225,92:233,94:237,95:243,96:250,123:231,124:247,125:209,126:241,127:9608},u=function(t){return null===t?"":(t=h[t]||t,String.fromCharCode(t))},m=0,c=5152,l=5167,f=5157,g=5158,y=5159,b=5165,S=5153,v=5164,T=5166,_=14,k=function(){for(var t=[],e=_+1;e--;)t.push("");return t},w=function(){w.prototype.init.call(this),this.mode_="popOn",this.topRow_=0,this.startPts_=0,this.displayed_=k(),this.nonDisplayed_=k(),this.lastControlCode_=null,this.push=function(t){if(0===t.type){var e,a,i,n;if(e=32639&t.ccData,e===this.lastControlCode_)return void(this.lastControlCode_=null);switch(4096===(61440&e)?this.lastControlCode_=e:this.lastControlCode_=null,e){case m:break;case c:this.mode_="popOn";break;case l:this.flushDisplayed(t.pts),a=this.displayed_,this.displayed_=this.nonDisplayed_,this.nonDisplayed_=a,this.startPts_=t.pts;break;case f:this.topRow_=_-1,this.mode_="rollUp";break;case g:this.topRow_=_-2,this.mode_="rollUp";break;case y:this.topRow_=_-3,this.mode_="rollUp";break;case b:this.flushDisplayed(t.pts),this.shiftRowsUp_(),this.startPts_=t.pts;break;case S:"popOn"===this.mode_?this.nonDisplayed_[_]=this.nonDisplayed_[_].slice(0,-1):this.displayed_[_]=this.displayed_[_].slice(0,-1);break;case v:this.flushDisplayed(t.pts),this.displayed_=k();break;case T:this.nonDisplayed_=k();break;default:if(i=e>>>8,n=255&e,i>=16&&23>=i&&n>=64&&127>=n&&(16!==i||96>n)&&(i=32,n=null),(17===i||25===i)&&n>=48&&63>=n&&(i=9834,n=""),16===(240&i))return;this[this.mode_](t.pts,i,n)}}}};w.prototype=new r,w.prototype.flushDisplayed=function(t){var e=this.displayed_.map(function(t){return t.trim()}).filter(function(t){return t.length}).join("\n");e.length&&this.trigger("data",{startPts:this.startPts_,endPts:t,text:e})},w.prototype.popOn=function(t,e,a){var i=this.nonDisplayed_[_];i+=u(e),i+=u(a),this.nonDisplayed_[_]=i},w.prototype.rollUp=function(t,e,a){var i=this.displayed_[_];""===i&&(this.flushDisplayed(t),this.startPts_=t),i+=u(e),i+=u(a),this.displayed_[_]=i},w.prototype.shiftRowsUp_=function(){var t;for(t=0;t<this.topRow_;t++)this.displayed_[t]="";for(t=this.topRow_;_>t;t++)this.displayed_[t]=this.displayed_[t+1];this.displayed_[_]=""},e.exports={CaptionStream:p,Cea608Stream:w}},{"../utils/stream":13}],5:[function(t,e,a){"use strict";var i,n,r,s=t("../utils/stream.js"),o=t("./caption-stream"),d=t("./stream-types"),p=t("./timestamp-rollover-stream"),h=t("./stream-types.js"),u=188,m=71;i=function(){var t=new Uint8Array(u),e=0;i.prototype.init.call(this),this.push=function(a){var i,n=0,r=u;for(e?(i=new Uint8Array(a.byteLength+e),i.set(t.subarray(0,e)),i.set(a,e),e=0):i=a;r<i.byteLength;)i[n]!==m||i[r]!==m?(n++,r++):(this.trigger("data",i.subarray(n,r)),n+=u,r+=u);n<i.byteLength&&(t.set(i.subarray(n),0),e=i.byteLength-n)},this.flush=function(){e===u&&t[0]===m&&(this.trigger("data",t),e=0),this.trigger("done")}},i.prototype=new s,n=function(){var t,e,a,i;n.prototype.init.call(this),i=this,this.packetsWaitingForPmt=[],this.programMapTable=void 0,t=function(t,i){var n=0;i.payloadUnitStartIndicator&&(n+=t[n]+1),"pat"===i.type?e(t.subarray(n),i):a(t.subarray(n),i)},e=function(t,e){e.section_number=t[7],e.last_section_number=t[8],i.pmtPid=(31&t[10])<<8|t[11],e.pmtPid=i.pmtPid},a=function(t,e){var a,n,r,s;if(1&t[5]){for(i.programMapTable={},a=(15&t[1])<<8|t[2],n=3+a-4,r=(15&t[10])<<8|t[11],s=12+r;n>s;)i.programMapTable[(31&t[s+1])<<8|t[s+2]]=t[s],s+=((15&t[s+3])<<8|t[s+4])+5;for(e.programMapTable=i.programMapTable;i.packetsWaitingForPmt.length;)i.processPes_.apply(i,i.packetsWaitingForPmt.shift())}},this.push=function(e){var a={},i=4;a.payloadUnitStartIndicator=!!(64&e[1]),a.pid=31&e[1],a.pid<<=8,a.pid|=e[2],(48&e[3])>>>4>1&&(i+=e[i]+1),0===a.pid?(a.type="pat",t(e.subarray(i),a),this.trigger("data",a)):a.pid===this.pmtPid?(a.type="pmt",t(e.subarray(i),a),this.trigger("data",a)):void 0===this.programMapTable?this.packetsWaitingForPmt.push([e,i,a]):this.processPes_(e,i,a)},this.processPes_=function(t,e,a){a.streamType=this.programMapTable[a.pid],a.type="pes",a.data=t.subarray(e),this.trigger("data",a)}},n.prototype=new s,n.STREAM_TYPES={h264:27,adts:15},r=function(){var t=this,e={data:[],size:0},a={data:[],size:0},i={data:[],size:0},n=function(t,e){var a;e.dataAlignmentIndicator=0!==(4&t[6]),a=t[7],192&a&&(e.pts=(14&t[9])<<27|(255&t[10])<<20|(254&t[11])<<12|(255&t[12])<<5|(254&t[13])>>>3,e.pts*=4,e.pts+=(6&t[13])>>>1,e.dts=e.pts,64&a&&(e.dts=(14&t[14])<<27|(255&t[15])<<20|(254&t[16])<<12|(255&t[17])<<5|(254&t[18])>>>3,e.dts*=4,e.dts+=(6&t[18])>>>1)),e.data=t.subarray(9+t[8])},s=function(e,a){var i,r=new Uint8Array(e.size),s={type:a},o=0;if(e.data.length){for(s.trackId=e.data[0].pid;e.data.length;)i=e.data.shift(),r.set(i.data,o),o+=i.data.byteLength;n(r,s),e.size=0,t.trigger("data",s)}};r.prototype.init.call(this),this.push=function(n){({pat:function(){},pes:function(){var t,r;switch(n.streamType){case d.H264_STREAM_TYPE:case h.H264_STREAM_TYPE:t=e,r="video";break;case d.ADTS_STREAM_TYPE:t=a,r="audio";break;case d.METADATA_STREAM_TYPE:t=i,r="timed-metadata";break;default:return}n.payloadUnitStartIndicator&&s(t,r),t.data.push(n),t.size+=n.data.byteLength},pmt:function(){var e,a,i={type:"metadata",tracks:[]},r=n.programMapTable;for(e in r)r.hasOwnProperty(e)&&(a={timelineStartInfo:{baseMediaDecodeTime:0}},a.id=+e,r[e]===h.H264_STREAM_TYPE?(a.codec="avc",a.type="video"):r[e]===h.ADTS_STREAM_TYPE&&(a.codec="adts",a.type="audio"),i.tracks.push(a));t.trigger("data",i)}})[n.type]()},this.flush=function(){s(e,"video"),s(a,"audio"),s(i,"timed-metadata"),this.trigger("done")}},r.prototype=new s;var c={PAT_PID:0,MP2T_PACKET_LENGTH:u,TransportPacketStream:i,TransportParseStream:n,ElementaryStream:r,TimestampRolloverStream:p,CaptionStream:o.CaptionStream,Cea608Stream:o.Cea608Stream,MetadataStream:t("./metadata-stream")};for(var l in d)d.hasOwnProperty(l)&&(c[l]=d[l]);e.exports=c},{"../utils/stream.js":13,"./caption-stream":4,"./metadata-stream":6,"./stream-types":7,"./stream-types.js":7,"./timestamp-rollover-stream":8}],6:[function(t,e,a){"use strict";var i,n=t("../utils/stream"),r=t("./stream-types"),s=function(t,e,a){var i,n="";for(i=e;a>i;i++)n+="%"+("00"+t[i].toString(16)).slice(-2);return n},o=function(t,e,a){return decodeURIComponent(s(t,e,a))},d=function(t,e,a){return unescape(s(t,e,a))},p=function(t){return t[0]<<21|t[1]<<14|t[2]<<7|t[3]},h={TXXX:function(t){var e;if(3===t.data[0]){for(e=1;e<t.data.length;e++)if(0===t.data[e]){t.description=o(t.data,1,e),t.value=o(t.data,e+1,t.data.length-1);break}t.data=t.value}},WXXX:function(t){var e;if(3===t.data[0])for(e=1;e<t.data.length;e++)if(0===t.data[e]){t.description=o(t.data,1,e),t.url=o(t.data,e+1,t.data.length);break}},PRIV:function(t){var e;for(e=0;e<t.data.length;e++)if(0===t.data[e]){t.owner=d(t.data,0,e);break}t.privateData=t.data.subarray(e+1),t.data=t.privateData}};i=function(t){var e,a={debug:!(!t||!t.debug),descriptor:t&&t.descriptor},n=0,s=[],o=0;if(i.prototype.init.call(this),this.dispatchType=r.METADATA_STREAM_TYPE.toString(16),a.descriptor)for(e=0;e<a.descriptor.length;e++)this.dispatchType+=("00"+a.descriptor[e].toString(16)).slice(-2);this.push=function(t){var e,i,r,d,u,m;if("timed-metadata"===t.type){if(t.dataAlignmentIndicator&&(o=0,s.length=0),0===s.length&&(t.data.length<10||t.data[0]!=="I".charCodeAt(0)||t.data[1]!=="D".charCodeAt(0)||t.data[2]!=="3".charCodeAt(0)))return void(a.debug&&console.log("Skipping unrecognized metadata packet"));if(s.push(t),o+=t.data.byteLength,1===s.length&&(n=p(t.data.subarray(6,10)),n+=10),!(n>o)){for(e={data:new Uint8Array(n),frames:[],pts:s[0].pts,dts:s[0].dts},u=0;n>u;)e.data.set(s[0].data.subarray(0,n-u),u),u+=s[0].data.byteLength,o-=s[0].data.byteLength,s.shift();i=10,64&e.data[5]&&(i+=4,i+=p(e.data.subarray(10,14)),n-=p(e.data.subarray(16,20)));do{if(r=p(e.data.subarray(i+4,i+8)),1>r)return console.log("Malformed ID3 frame encountered. Skipping metadata parsing.");if(m=String.fromCharCode(e.data[i],e.data[i+1],e.data[i+2],e.data[i+3]),d={id:m,data:e.data.subarray(i+10,i+r+10)},d.key=d.id,h[d.id]&&(h[d.id](d),"com.apple.streaming.transportStreamTimestamp"===d.owner)){var c=d.data,l=(1&c[3])<<30|c[4]<<22|c[5]<<14|c[6]<<6|c[7]>>>2;l*=4,l+=3&c[7],d.timeStamp=l,this.trigger("timestamp",d)}e.frames.push(d),i+=10,i+=r}while(n>i);this.trigger("data",e)}}}},i.prototype=new n,e.exports=i},{"../utils/stream":13,"./stream-types":7}],7:[function(t,e,a){"use strict";e.exports={H264_STREAM_TYPE:27,ADTS_STREAM_TYPE:15,METADATA_STREAM_TYPE:21}},{}],8:[function(t,e,a){"use strict";var i=t("../utils/stream"),n=8589934592,r=4294967296,s=function(t){var e,a;s.prototype.init.call(this),this.type_=t;var i=function(t,e){var a=1;for(t>e&&(a=-1);Math.abs(e-t)>r;)t+=a*n;return t};this.push=function(t){t.type===this.type_&&(void 0===a&&(a=t.dts),t.dts=i(t.dts,a),t.pts=i(t.pts,a),e=t.dts,this.trigger("data",t))},this.flush=function(){a=e,this.trigger("done")}};s.prototype=new i,e.exports=s},{"../utils/stream":13}],9:[function(t,e,a){e.exports={generator:t("./mp4-generator"),Transmuxer:t("./transmuxer").Transmuxer,AudioSegmentStream:t("./transmuxer").AudioSegmentStream,VideoSegmentStream:t("./transmuxer").VideoSegmentStream}},{"./mp4-generator":10,"./transmuxer":11}],10:[function(t,e,a){"use strict";var i,n,r,s,o,d,p,h,u,m,c,l,f,g,y,b,S,v,T,_,k,w,A,x,U,D,P,L,C,M,E,I,B,R,O,z;!function(){var t;if(A={avc1:[],avcC:[],btrt:[],dinf:[],dref:[],esds:[],ftyp:[],hdlr:[],mdat:[],mdhd:[],mdia:[],mfhd:[],minf:[],moof:[],moov:[],mp4a:[],mvex:[],mvhd:[],sdtp:[],smhd:[],stbl:[],stco:[],stsc:[],stsd:[],stsz:[],stts:[],styp:[],tfdt:[],tfhd:[],traf:[],trak:[],trun:[],trex:[],tkhd:[],vmhd:[]},"undefined"!=typeof Uint8Array){for(t in A)A.hasOwnProperty(t)&&(A[t]=[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]);x=new Uint8Array(["i".charCodeAt(0),"s".charCodeAt(0),"o".charCodeAt(0),"m".charCodeAt(0)]),D=new Uint8Array(["a".charCodeAt(0),"v".charCodeAt(0),"c".charCodeAt(0),"1".charCodeAt(0)]),U=new Uint8Array([0,0,0,1]),P=new Uint8Array([0,0,0,0,0,0,0,0,118,105,100,101,0,0,0,0,0,0,0,0,0,0,0,0,86,105,100,101,111,72,97,110,100,108,101,114,0]),L=new Uint8Array([0,0,0,0,0,0,0,0,115,111,117,110,0,0,0,0,0,0,0,0,0,0,0,0,83,111,117,110,100,72,97,110,100,108,101,114,0]),C={video:P,audio:L},I=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1]),E=new Uint8Array([0,0,0,0,0,0,0,0]),B=new Uint8Array([0,0,0,0,0,0,0,0]),R=B,O=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]),z=B,M=new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0])}}(),i=function(t){var e,a,i,n=[],r=0;for(e=1;e<arguments.length;e++)n.push(arguments[e]);for(e=n.length;e--;)r+=n[e].byteLength;for(a=new Uint8Array(r+8),i=new DataView(a.buffer,a.byteOffset,a.byteLength),i.setUint32(0,a.byteLength),a.set(t,4),e=0,r=8;e<n.length;e++)a.set(n[e],r),r+=n[e].byteLength;return a},n=function(){return i(A.dinf,i(A.dref,I))},r=function(t){return i(A.esds,new Uint8Array([0,0,0,0,3,25,0,0,0,4,17,64,21,0,6,0,0,0,218,192,0,0,218,192,5,2,t.audioobjecttype<<3|t.samplingfrequencyindex>>>1,t.samplingfrequencyindex<<7|t.channelcount<<3,6,1,2]))},s=function(){return i(A.ftyp,x,U,x,D)},b=function(t){return i(A.hdlr,C[t])},o=function(t){return i(A.mdat,t)},y=function(t){var e=new Uint8Array([0,0,0,0,0,0,0,2,0,0,0,3,0,1,95,144,t.duration>>>24&255,t.duration>>>16&255,t.duration>>>8&255,255&t.duration,85,196,0,0]);return t.samplerate&&(e[12]=t.samplerate>>>24&255,e[13]=t.samplerate>>>16&255,e[14]=t.samplerate>>>8&255,e[15]=255&t.samplerate),i(A.mdhd,e)},g=function(t){return i(A.mdia,y(t),b(t.type),p(t))},d=function(t){return i(A.mfhd,new Uint8Array([0,0,0,0,(4278190080&t)>>24,(16711680&t)>>16,(65280&t)>>8,255&t]))},p=function(t){return i(A.minf,"video"===t.type?i(A.vmhd,M):i(A.smhd,E),n(),v(t))},h=function(t,e){for(var a=[],n=e.length;n--;)a[n]=_(e[n]);return i.apply(null,[A.moof,d(t)].concat(a))},u=function(t){for(var e=t.length,a=[];e--;)a[e]=l(t[e]);return i.apply(null,[A.moov,c(4294967295)].concat(a).concat(m(t)))},m=function(t){for(var e=t.length,a=[];e--;)a[e]=k(t[e]);return i.apply(null,[A.mvex].concat(a))},c=function(t){var e=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,2,0,1,95,144,(4278190080&t)>>24,(16711680&t)>>16,(65280&t)>>8,255&t,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255]);return i(A.mvhd,e)},S=function(t){var e,a,n=t.samples||[],r=new Uint8Array(4+n.length);for(a=0;a<n.length;a++)e=n[a].flags,r[a+4]=e.dependsOn<<4|e.isDependedOn<<2|e.hasRedundancy;return i(A.sdtp,r)},v=function(t){return i(A.stbl,T(t),i(A.stts,z),i(A.stsc,R),i(A.stsz,O),i(A.stco,B))},function(){var t,e;T=function(a){return i(A.stsd,new Uint8Array([0,0,0,0,0,0,0,1]),"video"===a.type?t(a):e(a))},t=function(t){var e,a=t.sps||[],n=t.pps||[],r=[],s=[];for(e=0;e<a.length;e++)r.push((65280&a[e].byteLength)>>>8),r.push(255&a[e].byteLength),r=r.concat(Array.prototype.slice.call(a[e]));for(e=0;e<n.length;e++)s.push((65280&n[e].byteLength)>>>8),s.push(255&n[e].byteLength),s=s.concat(Array.prototype.slice.call(n[e]));return i(A.avc1,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,(65280&t.width)>>8,255&t.width,(65280&t.height)>>8,255&t.height,0,72,0,0,0,72,0,0,0,0,0,0,0,1,19,118,105,100,101,111,106,115,45,99,111,110,116,114,105,98,45,104,108,115,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),i(A.avcC,new Uint8Array([1,t.profileIdc,t.profileCompatibility,t.levelIdc,255].concat([a.length]).concat(r).concat([n.length]).concat(s))),i(A.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])))},e=function(t){return i(A.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,(65280&t.channelcount)>>8,255&t.channelcount,(65280&t.samplesize)>>8,255&t.samplesize,0,0,0,0,(65280&t.samplerate)>>8,255&t.samplerate,0,0]),r(t))}}(),f=function(t){var e=new Uint8Array([0,0,0,7,0,0,0,0,0,0,0,0,(4278190080&t.id)>>24,(16711680&t.id)>>16,(65280&t.id)>>8,255&t.id,0,0,0,0,(4278190080&t.duration)>>24,(16711680&t.duration)>>16,(65280&t.duration)>>8,255&t.duration,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,(65280&t.width)>>8,255&t.width,0,0,(65280&t.height)>>8,255&t.height,0,0]);return i(A.tkhd,e)},_=function(t){var e,a,n,r,s;return e=i(A.tfhd,new Uint8Array([0,0,0,58,(4278190080&t.id)>>24,(16711680&t.id)>>16,(65280&t.id)>>8,255&t.id,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0])),a=i(A.tfdt,new Uint8Array([0,0,0,0,t.baseMediaDecodeTime>>>24&255,t.baseMediaDecodeTime>>>16&255,t.baseMediaDecodeTime>>>8&255,255&t.baseMediaDecodeTime])),s=88,"audio"===t.type?(n=w(t,s),i(A.traf,e,a,n)):(r=S(t),n=w(t,r.length+s),i(A.traf,e,a,n,r))},l=function(t){return t.duration=t.duration||4294967295,i(A.trak,f(t),g(t))},k=function(t){var e=new Uint8Array([0,0,0,0,(4278190080&t.id)>>24,(16711680&t.id)>>16,(65280&t.id)>>8,255&t.id,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]);return"video"!==t.type&&(e[e.length-1]=0),i(A.trex,e)},function(){var t,e,a;a=function(t,e){var a=0,i=0,n=0,r=0;return t.length&&(void 0!==t[0].duration&&(a=1),void 0!==t[0].size&&(i=2),void 0!==t[0].flags&&(n=4),void 0!==t[0].compositionTimeOffset&&(r=8)),[0,0,a|i|n|r,1,(4278190080&t.length)>>>24,(16711680&t.length)>>>16,(65280&t.length)>>>8,255&t.length,(4278190080&e)>>>24,(16711680&e)>>>16,(65280&e)>>>8,255&e]},e=function(t,e){var n,r,s,o;for(r=t.samples||[],e+=20+16*r.length,n=a(r,e),o=0;o<r.length;o++)s=r[o],n=n.concat([(4278190080&s.duration)>>>24,(16711680&s.duration)>>>16,(65280&s.duration)>>>8,255&s.duration,(4278190080&s.size)>>>24,(16711680&s.size)>>>16,(65280&s.size)>>>8,255&s.size,s.flags.isLeading<<2|s.flags.dependsOn,s.flags.isDependedOn<<6|s.flags.hasRedundancy<<4|s.flags.paddingValue<<1|s.flags.isNonSyncSample,61440&s.flags.degradationPriority,15&s.flags.degradationPriority,(4278190080&s.compositionTimeOffset)>>>24,(16711680&s.compositionTimeOffset)>>>16,(65280&s.compositionTimeOffset)>>>8,255&s.compositionTimeOffset]);return i(A.trun,new Uint8Array(n))},t=function(t,e){var n,r,s,o;for(r=t.samples||[],e+=20+8*r.length,n=a(r,e),o=0;o<r.length;o++)s=r[o],n=n.concat([(4278190080&s.duration)>>>24,(16711680&s.duration)>>>16,(65280&s.duration)>>>8,255&s.duration,(4278190080&s.size)>>>24,(16711680&s.size)>>>16,(65280&s.size)>>>8,255&s.size]);return i(A.trun,new Uint8Array(n))},w=function(a,i){return"audio"===a.type?t(a,i):e(a,i)}}(),e.exports={ftyp:s,mdat:o,moof:h,moov:u,initSegment:function(t){var e,a=s(),i=u(t);return e=new Uint8Array(a.byteLength+i.byteLength),e.set(a),e.set(i,a.byteLength),e}}},{}],11:[function(t,e,a){"use strict";var i,n,r,s,o,d,p,h,u,m,c,l=t("../utils/stream.js"),f=t("./mp4-generator.js"),g=t("../m2ts/m2ts.js"),y=t("../codecs/adts.js"),b=t("../codecs/h264").H264Stream,S=t("../aac"),v=["audioobjecttype","channelcount","samplerate","samplingfrequencyindex","samplesize"],T=["width","height","profileIdc","levelIdc","profileCompatibility"];o=function(){return{size:0,flags:{isLeading:0,dependsOn:1,isDependedOn:0,hasRedundancy:0,degradationPriority:0}}},d=function(t){return t[0]==="I".charCodeAt(0)&&t[1]==="D".charCodeAt(0)&&t[2]==="3".charCodeAt(0)},m=function(t,e){var a;if(t.length!==e.length)return!1;for(a=0;a<t.length;a++)if(t[a]!==e[a])return!1;return!0},c=function(t){var e,a,i=0;for(e=0;e<t.length;e++)a=t[e],i+=a.data.byteLength;return i},n=function(t){var e=[],a=0,i=0;n.prototype.init.call(this),this.push=function(a){p(t,a),t&&v.forEach(function(e){t[e]=a[e]}),e.push(a)},this.setEarliestDts=function(e){i=e-t.timelineStartInfo.baseMediaDecodeTime},this.flush=function(){var i,n,r,s;return 0===e.length?void this.trigger("done","AudioSegmentStream"):(i=this.trimAdtsFramesByEarliestDts_(e),t.samples=this.generateSampleTable_(i),r=f.mdat(this.concatenateFrameData_(i)),e=[],u(t),n=f.moof(a,[t]),s=new Uint8Array(n.byteLength+r.byteLength),a++,s.set(n),s.set(r,n.byteLength),h(t),this.trigger("data",{track:t,boxes:s}),void this.trigger("done","AudioSegmentStream"))},this.trimAdtsFramesByEarliestDts_=function(e){return t.minSegmentDts>=i?e:(t.minSegmentDts=1/0,e.filter(function(e){return e.dts>=i?(t.minSegmentDts=Math.min(t.minSegmentDts,e.dts),t.minSegmentPts=t.minSegmentDts,!0):!1}))},this.generateSampleTable_=function(t){var e,a,i=[];for(e=0;e<t.length;e++)a=t[e],i.push({size:a.data.byteLength,duration:1024});return i},this.concatenateFrameData_=function(t){var e,a,i=0,n=new Uint8Array(c(t));for(e=0;e<t.length;e++)a=t[e],n.set(a.data,i),i+=a.data.byteLength;return n}},n.prototype=new l,i=function(t){var e,a,n=0,r=[];i.prototype.init.call(this),delete t.minPTS,this.gopCache_=[],this.push=function(i){p(t,i),"seq_parameter_set_rbsp"!==i.nalUnitType||e||(e=i.config,t.sps=[i.data],T.forEach(function(a){t[a]=e[a]},this)),"pic_parameter_set_rbsp"!==i.nalUnitType||a||(a=i.data,t.pps=[i.data]),r.push(i)},this.flush=function(){for(var e,a,i,s,o,d;r.length&&"access_unit_delimiter_rbsp"!==r[0].nalUnitType;)r.shift();return 0===r.length?(this.resetStream_(),void this.trigger("done","VideoSegmentStream")):(e=this.groupNalsIntoFrames_(r),i=this.groupFramesIntoGops_(e),i[0][0].keyFrame||(a=this.getGopForFusion_(r[0],t),a?(i.unshift(a),i.byteLength+=a.byteLength,i.nalCount+=a.nalCount,i.pts=a.pts,i.dts=a.dts,i.duration+=a.duration):i=this.extendFirstKeyFrame_(i)),p(t,i),t.samples=this.generateSampleTable_(i),o=f.mdat(this.concatenateNalData_(i)),this.gopCache_.unshift({gop:i.pop(),pps:t.pps,sps:t.sps}),this.gopCache_.length=Math.min(6,this.gopCache_.length),r=[],u(t),this.trigger("timelineStartInfo",t.timelineStartInfo),s=f.moof(n,[t]),d=new Uint8Array(s.byteLength+o.byteLength),n++,d.set(s),d.set(o,s.byteLength),this.trigger("data",{track:t,boxes:d}),this.resetStream_(),void this.trigger("done","VideoSegmentStream"))},this.resetStream_=function(){h(t),e=void 0,a=void 0},this.getGopForFusion_=function(e){var a,i,n,r,s,o=45e3,d=1e4,p=1/0;for(s=0;s<this.gopCache_.length;s++)r=this.gopCache_[s],n=r.gop,t.pps&&m(t.pps[0],r.pps[0])&&t.sps&&m(t.sps[0],r.sps[0])&&(n.dts<t.timelineStartInfo.dts||(a=e.dts-n.dts-n.duration,a>=-d&&o>=a&&(!i||p>a)&&(i=r,p=a)));return i?i.gop:null},this.extendFirstKeyFrame_=function(t){var e;return t[0][0].keyFrame||(e=t.shift(),t.byteLength-=e.byteLength,t.nalCount-=e.nalCount,t[0][0].dts=e.dts,t[0][0].pts=e.pts,t[0][0].duration+=e.duration),t},this.groupNalsIntoFrames_=function(t){var e,a,i=[],n=[];for(i.byteLength=0,e=0;e<t.length;e++)a=t[e],"access_unit_delimiter_rbsp"===a.nalUnitType?(i.length&&(i.duration=a.dts-i.dts,n.push(i)),i=[a],i.byteLength=a.data.byteLength,i.pts=a.pts,i.dts=a.dts):("slice_layer_without_partitioning_rbsp_idr"===a.nalUnitType&&(i.keyFrame=!0),i.duration=a.dts-i.dts,i.byteLength+=a.data.byteLength,i.push(a));return n.length&&(!i.duration||i.duration<=0)&&(i.duration=n[n.length-1].duration),n.push(i),n},this.groupFramesIntoGops_=function(t){var e,a,i=[],n=[];for(i.byteLength=0,i.nalCount=0,i.duration=0,i.pts=t[0].pts,i.dts=t[0].dts,n.byteLength=0,n.nalCount=0,n.duration=0,n.pts=t[0].pts,n.dts=t[0].dts,e=0;e<t.length;e++)a=t[e],a.keyFrame?(i.length&&(n.push(i),n.byteLength+=i.byteLength,n.nalCount+=i.nalCount,n.duration+=i.duration),i=[a],i.nalCount=a.length,i.byteLength=a.byteLength,i.pts=a.pts,i.dts=a.dts,i.duration=a.duration):(i.duration+=a.duration,i.nalCount+=a.length,i.byteLength+=a.byteLength,i.push(a));return n.length&&i.duration<=0&&(i.duration=n[n.length-1].duration),n.byteLength+=i.byteLength,n.nalCount+=i.nalCount,n.duration+=i.duration,n.push(i),n},this.generateSampleTable_=function(t,e){var a,i,n,r,s,d=e||0,p=[];for(a=0;a<t.length;a++)for(r=t[a],i=0;i<r.length;i++)s=r[i],n=o(),n.dataOffset=d,n.compositionTimeOffset=s.pts-s.dts,n.duration=s.duration,n.size=4*s.length,n.size+=s.byteLength,s.keyFrame&&(n.flags.dependsOn=2),d+=n.size,p.push(n);return p},this.concatenateNalData_=function(t){var e,a,i,n,r,s,o=0,d=t.byteLength,p=t.nalCount,h=d+4*p,u=new Uint8Array(h),m=new DataView(u.buffer);for(e=0;e<t.length;e++)for(n=t[e],a=0;a<n.length;a++)for(r=n[a],i=0;i<r.length;i++)s=r[i],m.setUint32(o,s.data.byteLength),o+=4,u.set(s.data,o),o+=s.data.byteLength;return u}},i.prototype=new l,p=function(t,e){"number"==typeof e.pts&&(void 0===t.timelineStartInfo.pts&&(t.timelineStartInfo.pts=e.pts),void 0===t.minSegmentPts?t.minSegmentPts=e.pts:t.minSegmentPts=Math.min(t.minSegmentPts,e.pts),void 0===t.maxSegmentPts?t.maxSegmentPts=e.pts:t.maxSegmentPts=Math.max(t.maxSegmentPts,e.pts)),"number"==typeof e.dts&&(void 0===t.timelineStartInfo.dts&&(t.timelineStartInfo.dts=e.dts),void 0===t.minSegmentDts?t.minSegmentDts=e.dts:t.minSegmentDts=Math.min(t.minSegmentDts,e.dts),void 0===t.maxSegmentDts?t.maxSegmentDts=e.dts:t.maxSegmentDts=Math.max(t.maxSegmentDts,e.dts))},h=function(t){delete t.minSegmentDts,delete t.maxSegmentDts,delete t.minSegmentPts,delete t.maxSegmentPts},u=function(t){var e,a=9e4,i=t.minSegmentDts-t.timelineStartInfo.dts,n=t.minSegmentPts-t.minSegmentDts;t.baseMediaDecodeTime=t.timelineStartInfo.baseMediaDecodeTime,t.baseMediaDecodeTime+=i,t.baseMediaDecodeTime-=n,t.baseMediaDecodeTime=Math.max(0,t.baseMediaDecodeTime),"audio"===t.type&&(e=t.samplerate/a,t.baseMediaDecodeTime*=e,t.baseMediaDecodeTime=Math.floor(t.baseMediaDecodeTime))},s=function(t,e){this.numberOfTracks=0,this.metadataStream=e,"undefined"!=typeof t.remux?this.remuxTracks=!!t.remux:this.remuxTracks=!0,this.pendingTracks=[],this.videoTrack=null,this.pendingBoxes=[],this.pendingCaptions=[],this.pendingMetadata=[],this.pendingBytes=0,this.emittedTracks=0,s.prototype.init.call(this),this.push=function(t){return t.text?this.pendingCaptions.push(t):t.frames?this.pendingMetadata.push(t):(this.pendingTracks.push(t.track),this.pendingBoxes.push(t.boxes),this.pendingBytes+=t.boxes.byteLength,"video"===t.track.type&&(this.videoTrack=t.track),void("audio"===t.track.type&&(this.audioTrack=t.track)))}},s.prototype=new l,s.prototype.flush=function(t){var e,a,i,n,r=0,s={captions:[],metadata:[],info:{}},o=0;if(this.pendingTracks.length<this.numberOfTracks){if("VideoSegmentStream"!==t&&"AudioSegmentStream"!==t)return;if(this.remuxTracks)return;if(0===this.pendingTracks.length)return this.emittedTracks++,void(this.emittedTracks>=this.numberOfTracks&&(this.trigger("done"),this.emittedTracks=0))}for(this.videoTrack?(o=this.videoTrack.timelineStartInfo.pts,T.forEach(function(t){s.info[t]=this.videoTrack[t]},this)):this.audioTrack&&(o=this.audioTrack.timelineStartInfo.pts, | ||
v.forEach(function(t){s.info[t]=this.audioTrack[t]},this)),1===this.pendingTracks.length?s.type=this.pendingTracks[0].type:s.type="combined",this.emittedTracks+=this.pendingTracks.length,i=f.initSegment(this.pendingTracks),s.data=new Uint8Array(i.byteLength+this.pendingBytes),s.data.set(i),r+=i.byteLength,n=0;n<this.pendingBoxes.length;n++)s.data.set(this.pendingBoxes[n],r),r+=this.pendingBoxes[n].byteLength;for(n=0;n<this.pendingCaptions.length;n++)e=this.pendingCaptions[n],e.startTime=e.startPts-o,e.startTime/=9e4,e.endTime=e.endPts-o,e.endTime/=9e4,s.captions.push(e);for(n=0;n<this.pendingMetadata.length;n++)a=this.pendingMetadata[n],a.cueTime=a.pts-o,a.cueTime/=9e4,s.metadata.push(a);s.metadata.dispatchType=this.metadataStream.dispatchType,this.pendingTracks.length=0,this.videoTrack=null,this.pendingBoxes.length=0,this.pendingCaptions.length=0,this.pendingBytes=0,this.pendingMetadata.length=0,this.trigger("data",s),this.emittedTracks>=this.numberOfTracks&&(this.trigger("done"),this.emittedTracks=0)},r=function(t){var e,a,o=this,p=!0;r.prototype.init.call(this),t=t||{},this.baseMediaDecodeTime=t.baseMediaDecodeTime||0,this.transmuxPipeline_={},this.setupAacPipeline=function(){var e={};this.transmuxPipeline_=e,e.type="aac",e.metadataStream=new g.MetadataStream,e.aacStream=new S,e.audioTimestampRolloverStream=new g.TimestampRolloverStream("audio"),e.timedMetadataTimestampRolloverStream=new g.TimestampRolloverStream("timed-metadata"),e.adtsStream=new y,e.coalesceStream=new s(t,e.metadataStream),e.headOfPipeline=e.aacStream,e.aacStream.pipe(e.audioTimestampRolloverStream).pipe(e.adtsStream),e.aacStream.pipe(e.timedMetadataTimestampRolloverStream).pipe(e.metadataStream).pipe(e.coalesceStream),e.metadataStream.on("timestamp",function(t){e.aacStream.setTimestamp(t.timeStamp)}),e.aacStream.on("data",function(t){"timed-metadata"!==t.type||e.audioSegmentStream||(a=a||{timelineStartInfo:{baseMediaDecodeTime:o.baseMediaDecodeTime},codec:"adts",type:"audio"},e.coalesceStream.numberOfTracks++,e.audioSegmentStream=new n(a),e.adtsStream.pipe(e.audioSegmentStream).pipe(e.coalesceStream))}),e.coalesceStream.on("data",this.trigger.bind(this,"data")),e.coalesceStream.on("done",this.trigger.bind(this,"done"))},this.setupTsPipeline=function(){var r={};this.transmuxPipeline_=r,r.type="ts",r.metadataStream=new g.MetadataStream,r.packetStream=new g.TransportPacketStream,r.parseStream=new g.TransportParseStream,r.elementaryStream=new g.ElementaryStream,r.videoTimestampRolloverStream=new g.TimestampRolloverStream("video"),r.audioTimestampRolloverStream=new g.TimestampRolloverStream("audio"),r.timedMetadataTimestampRolloverStream=new g.TimestampRolloverStream("timed-metadata"),r.adtsStream=new y,r.h264Stream=new b,r.captionStream=new g.CaptionStream,r.coalesceStream=new s(t,r.metadataStream),r.headOfPipeline=r.packetStream,r.packetStream.pipe(r.parseStream).pipe(r.elementaryStream),r.elementaryStream.pipe(r.videoTimestampRolloverStream).pipe(r.h264Stream),r.elementaryStream.pipe(r.audioTimestampRolloverStream).pipe(r.adtsStream),r.elementaryStream.pipe(r.timedMetadataTimestampRolloverStream).pipe(r.metadataStream).pipe(r.coalesceStream),r.h264Stream.pipe(r.captionStream).pipe(r.coalesceStream),r.elementaryStream.on("data",function(t){var s;if("metadata"===t.type){for(s=t.tracks.length;s--;)e||"video"!==t.tracks[s].type?a||"audio"!==t.tracks[s].type||(a=t.tracks[s],a.timelineStartInfo.baseMediaDecodeTime=o.baseMediaDecodeTime):(e=t.tracks[s],e.timelineStartInfo.baseMediaDecodeTime=o.baseMediaDecodeTime);e&&!r.videoSegmentStream&&(r.coalesceStream.numberOfTracks++,r.videoSegmentStream=new i(e),r.videoSegmentStream.on("timelineStartInfo",function(t){a&&(a.timelineStartInfo=t,r.audioSegmentStream.setEarliestDts(t.dts))}),r.h264Stream.pipe(r.videoSegmentStream).pipe(r.coalesceStream)),a&&!r.audioSegmentStream&&(r.coalesceStream.numberOfTracks++,r.audioSegmentStream=new n(a),r.adtsStream.pipe(r.audioSegmentStream).pipe(r.coalesceStream))}}),r.coalesceStream.on("data",this.trigger.bind(this,"data")),r.coalesceStream.on("done",this.trigger.bind(this,"done"))},this.setBaseMediaDecodeTime=function(t){var i=this.transmuxPipeline_;this.baseMediaDecodeTime=t,a&&(a.timelineStartInfo.dts=void 0,a.timelineStartInfo.pts=void 0,h(a),a.timelineStartInfo.baseMediaDecodeTime=t),e&&(i.videoSegmentStream&&(i.videoSegmentStream.gopCache_=[]),e.timelineStartInfo.dts=void 0,e.timelineStartInfo.pts=void 0,h(e),e.timelineStartInfo.baseMediaDecodeTime=t)},this.push=function(t){if(p){var e=d(t);e&&"aac"!==this.transmuxPipeline_.type?this.setupAacPipeline():e||"ts"===this.transmuxPipeline_.type||this.setupTsPipeline(),p=!1}this.transmuxPipeline_.headOfPipeline.push(t)},this.flush=function(){p=!0,this.transmuxPipeline_.headOfPipeline.flush()}},r.prototype=new l,e.exports={Transmuxer:r,VideoSegmentStream:i,AudioSegmentStream:n,AUDIO_PROPERTIES:v,VIDEO_PROPERTIES:T}},{"../aac":1,"../codecs/adts.js":2,"../codecs/h264":3,"../m2ts/m2ts.js":5,"../utils/stream.js":13,"./mp4-generator.js":10}],12:[function(t,e,a){"use strict";var i;i=function(t){var e=t.byteLength,a=0,i=0;this.length=function(){return 8*e},this.bitsAvailable=function(){return 8*e+i},this.loadWord=function(){var n=t.byteLength-e,r=new Uint8Array(4),s=Math.min(4,e);if(0===s)throw new Error("no bytes available");r.set(t.subarray(n,n+s)),a=new DataView(r.buffer).getUint32(0),i=8*s,e-=s},this.skipBits=function(t){var n;i>t?(a<<=t,i-=t):(t-=i,n=Math.floor(t/8),t-=8*n,e-=n,this.loadWord(),a<<=t,i-=t)},this.readBits=function(t){var n=Math.min(i,t),r=a>>>32-n;return i-=n,i>0?a<<=n:e>0&&this.loadWord(),n=t-n,n>0?r<<n|this.readBits(n):r},this.skipLeadingZeros=function(){var t;for(t=0;i>t;++t)if(0!==(a&2147483648>>>t))return a<<=t,i-=t,t;return this.loadWord(),t+this.skipLeadingZeros()},this.skipUnsignedExpGolomb=function(){this.skipBits(1+this.skipLeadingZeros())},this.skipExpGolomb=function(){this.skipBits(1+this.skipLeadingZeros())},this.readUnsignedExpGolomb=function(){var t=this.skipLeadingZeros();return this.readBits(t+1)-1},this.readExpGolomb=function(){var t=this.readUnsignedExpGolomb();return 1&t?1+t>>>1:-1*(t>>>1)},this.readBoolean=function(){return 1===this.readBits(1)},this.readUnsignedByte=function(){return this.readBits(8)},this.loadWord()},e.exports=i},{}],13:[function(t,e,a){"use strict";var i=function(){this.init=function(){var t={};this.on=function(e,a){t[e]||(t[e]=[]),t[e].push(a)},this.off=function(e,a){var i;return t[e]?(i=t[e].indexOf(a),t[e].splice(i,1),i>-1):!1},this.trigger=function(e){var a,i,n,r;if(a=t[e])if(2===arguments.length)for(n=a.length,i=0;n>i;++i)a[i].call(this,arguments[1]);else{for(r=[],i=arguments.length,i=1;i<arguments.length;++i)r.push(arguments[i]);for(n=a.length,i=0;n>i;++i)a[i].apply(this,r)}},this.dispose=function(){t={}}}};i.prototype.pipe=function(t){return this.on("data",function(e){t.push(e)}),this.on("done",function(e){t.flush(e)}),t},i.prototype.push=function(t){this.trigger("data",t)},i.prototype.flush=function(t){this.trigger("done",t)},e.exports=i},{}]},{},[9])(9)}); | ||
!function t(e,a,i){function n(s,o){if(!a[s]){if(!e[s]){var d="function"==typeof require&&require;if(!o&&d)return d(s,!0);if(r)return r(s,!0);var p=new Error("Cannot find module '"+s+"'");throw p.code="MODULE_NOT_FOUND",p}var h=a[s]={exports:{}};e[s][0].call(h.exports,function(t){var a=e[s][1][t];return n(a?a:t)},h,h.exports,t,e,a,i)}return a[s].exports}for(var r="function"==typeof require&&require,s=0;s<i.length;s++)n(i[s]);return n}({1:[function(t,e,a){"use strict";var i,n=t(13);i=function(){var t=new Uint8Array,e=0;i.prototype.init.call(this),this.setTimestamp=function(t){e=t},this.parseId3TagSize=function(t,e){var a=t[e+6]<<21|t[e+7]<<14|t[e+8]<<7|t[e+9],i=t[e+5],n=(16&i)>>4;return n?a+20:a+10},this.parseAdtsSize=function(t,e){var a=(224&t[e+5])>>5,i=t[e+4]<<3,n=6144&t[e+3];return n|i|a},this.push=function(a){var i,n,r,s,o=0,d=0;for(t.length?(s=t.length,t=new Uint8Array(a.byteLength+s),t.set(t.subarray(0,s)),t.set(a,s)):t=a;t.length-d>=3;)if(t[d]!=="I".charCodeAt(0)||t[d+1]!=="D".charCodeAt(0)||t[d+2]!=="3".charCodeAt(0))if(t[d]&!0&&240===(240&t[d+1])){if(t.length-d<7)break;if(o=this.parseAdtsSize(t,d),o>t.length)break;r={type:"audio",data:t.subarray(d,d+o),pts:e,dts:e},this.trigger("data",r),d+=o}else d++;else{if(t.length-d<10)break;if(o=this.parseId3TagSize(t,d),o>t.length)break;n={type:"timed-metadata",data:t.subarray(d,d+o)},this.trigger("data",n),d+=o}i=t.length-d,t=i>0?t.subarray(d):new Uint8Array}},i.prototype=new n,e.exports=i},{}],2:[function(t,e,a){"use strict";var i,n=t(13),r=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];i=function(){var t;i.prototype.init.call(this),this.push=function(e){var a,i,n,s,o,d,p=0,h=0;if("audio"===e.type)for(t?(s=t,t=new Uint8Array(s.byteLength+e.data.byteLength),t.set(s),t.set(e.data,s.byteLength)):t=e.data;p+5<t.length;)if(255===t[p]&&240===(246&t[p+1])){if(i=2*(1&~t[p+1]),a=(3&t[p+3])<<11|t[p+4]<<3|(224&t[p+5])>>5,o=1024*((3&t[p+6])+1),d=9e4*o/r[(60&t[p+2])>>>2],n=p+a,t.byteLength<n)return;if(this.trigger("data",{pts:e.pts+h*d,dts:e.dts+h*d,sampleCount:o,audioobjecttype:(t[p+2]>>>6&3)+1,channelcount:(1&t[p+2])<<2|(192&t[p+3])>>>6,samplerate:r[(60&t[p+2])>>>2],samplingfrequencyindex:(60&t[p+2])>>>2,samplesize:16,data:t.subarray(p+7+i,n)}),t.byteLength===n)return void(t=void 0);h++,t=t.subarray(n)}else p++},this.flush=function(){this.trigger("done")}},i.prototype=new n,e.exports=i},{}],3:[function(t,e,a){"use strict";var i,n,r,s=t(13),o=t(12);n=function(){var t,e,a=0;n.prototype.init.call(this),this.push=function(i){var n;for(e?(n=new Uint8Array(e.byteLength+i.data.byteLength),n.set(e),n.set(i.data,e.byteLength),e=n):e=i.data;a<e.byteLength-3;a++)if(1===e[a+2]){t=a+5;break}for(;t<e.byteLength;)switch(e[t]){case 0:if(0!==e[t-1]){t+=2;break}if(0!==e[t-2]){t++;break}a+3!==t-2&&this.trigger("data",e.subarray(a+3,t-2));do t++;while(1!==e[t]&&t<e.length);a=t-2,t+=3;break;case 1:if(0!==e[t-1]||0!==e[t-2]){t+=3;break}this.trigger("data",e.subarray(a+3,t-2)),a=t-2,t+=3;break;default:t+=3}e=e.subarray(a),t-=a,a=0},this.flush=function(){e&&e.byteLength>3&&this.trigger("data",e.subarray(a+3)),e=null,a=0,this.trigger("done")}},n.prototype=new s,r={100:!0,110:!0,122:!0,244:!0,44:!0,83:!0,86:!0,118:!0,128:!0,138:!0,139:!0,134:!0},i=function(){var t,e,a,s,d,p,h,u=new n;i.prototype.init.call(this),t=this,this.push=function(t){"video"===t.type&&(e=t.trackId,a=t.pts,s=t.dts,u.push(t))},u.on("data",function(i){var n={trackId:e,pts:a,dts:s,data:i};switch(31&i[0]){case 5:n.nalUnitType="slice_layer_without_partitioning_rbsp_idr";break;case 6:n.nalUnitType="sei_rbsp",n.escapedRBSP=d(i.subarray(1));break;case 7:n.nalUnitType="seq_parameter_set_rbsp",n.escapedRBSP=d(i.subarray(1)),n.config=p(n.escapedRBSP);break;case 8:n.nalUnitType="pic_parameter_set_rbsp";break;case 9:n.nalUnitType="access_unit_delimiter_rbsp"}t.trigger("data",n)}),u.on("done",function(){t.trigger("done")}),this.flush=function(){u.flush()},h=function(t,e){var a,i,n=8,r=8;for(a=0;a<t;a++)0!==r&&(i=e.readExpGolomb(),r=(n+i+256)%256),n=0===r?n:r},d=function(t){for(var e,a,i=t.byteLength,n=[],r=1;r<i-2;)0===t[r]&&0===t[r+1]&&3===t[r+2]?(n.push(r+2),r+=2):r++;if(0===n.length)return t;e=i-n.length,a=new Uint8Array(e);var s=0;for(r=0;r<e;s++,r++)s===n[0]&&(s++,n.shift()),a[r]=t[s];return a},p=function(t){var e,a,i,n,s,d,p,u,c,l,m,f,g,y,b=0,S=0,v=0,T=0,_=1;if(e=new o(t),a=e.readUnsignedByte(),n=e.readUnsignedByte(),i=e.readUnsignedByte(),e.skipUnsignedExpGolomb(),r[a]&&(s=e.readUnsignedExpGolomb(),3===s&&e.skipBits(1),e.skipUnsignedExpGolomb(),e.skipUnsignedExpGolomb(),e.skipBits(1),e.readBoolean()))for(m=3!==s?8:12,y=0;y<m;y++)e.readBoolean()&&(y<6?h(16,e):h(64,e));if(e.skipUnsignedExpGolomb(),d=e.readUnsignedExpGolomb(),0===d)e.readUnsignedExpGolomb();else if(1===d)for(e.skipBits(1),e.skipExpGolomb(),e.skipExpGolomb(),p=e.readUnsignedExpGolomb(),y=0;y<p;y++)e.skipExpGolomb();if(e.skipUnsignedExpGolomb(),e.skipBits(1),u=e.readUnsignedExpGolomb(),c=e.readUnsignedExpGolomb(),l=e.readBits(1),0===l&&e.skipBits(1),e.skipBits(1),e.readBoolean()&&(b=e.readUnsignedExpGolomb(),S=e.readUnsignedExpGolomb(),v=e.readUnsignedExpGolomb(),T=e.readUnsignedExpGolomb()),e.readBoolean()&&e.readBoolean()){switch(g=e.readUnsignedByte()){case 1:f=[1,1];break;case 2:f=[12,11];break;case 3:f=[10,11];break;case 4:f=[16,11];break;case 5:f=[40,33];break;case 6:f=[24,11];break;case 7:f=[20,11];break;case 8:f=[32,11];break;case 9:f=[80,33];break;case 10:f=[18,11];break;case 11:f=[15,11];break;case 12:f=[64,33];break;case 13:f=[160,99];break;case 14:f=[4,3];break;case 15:f=[3,2];break;case 16:f=[2,1];break;case 255:f=[e.readUnsignedByte()<<8|e.readUnsignedByte(),e.readUnsignedByte()<<8|e.readUnsignedByte()]}f&&(_=f[0]/f[1])}return{profileIdc:a,levelIdc:i,profileCompatibility:n,width:Math.ceil((16*(u+1)-2*b-2*S)*_),height:(2-l)*(c+1)*16-2*v-2*T}}},i.prototype=new s,e.exports={H264Stream:i,NalByteStream:n}},{}],4:[function(t,e,a){"use strict";var i=4,n=128,r=t(13),s=function(t){for(var e=0,a={payloadType:-1,payloadSize:0},r=0,s=0;e<t.byteLength&&t[e]!==n;){for(;255===t[e];)r+=255,e++;for(r+=t[e++];255===t[e];)s+=255,e++;if(s+=t[e++],!a.payload&&r===i){a.payloadType=r,a.payloadSize=s,a.payload=t.subarray(e,e+s);break}e+=s,r=0,s=0}return a},o=function(t){return 181!==t.payload[0]?null:49!==(t.payload[1]<<8|t.payload[2])?null:"GA94"!==String.fromCharCode(t.payload[3],t.payload[4],t.payload[5],t.payload[6])?null:3!==t.payload[7]?null:t.payload.subarray(8,t.payload.length-1)},d=function(t,e){var a,i,n,r,s=[];if(!(64&e[0]))return s;for(i=31&e[0],a=0;a<i;a++)n=3*a,r={type:3&e[n+2],pts:t},4&e[n+2]&&(r.ccData=e[n+3]<<8|e[n+4],s.push(r));return s},p=function(){p.prototype.init.call(this),this.captionPackets_=[],this.field1_=new w,this.field1_.on("data",this.trigger.bind(this,"data")),this.field1_.on("done",this.trigger.bind(this,"done"))};p.prototype=new r,p.prototype.push=function(t){var e,a;"sei_rbsp"===t.nalUnitType&&(e=s(t.escapedRBSP),e.payloadType===i&&(a=o(e),a&&(this.captionPackets_=this.captionPackets_.concat(d(t.pts,a)))))},p.prototype.flush=function(){return this.captionPackets_.length?(this.captionPackets_.forEach(function(t,e){t.presortIndex=e}),this.captionPackets_.sort(function(t,e){return t.pts===e.pts?t.presortIndex-e.presortIndex:t.pts-e.pts}),this.captionPackets_.forEach(this.field1_.push,this.field1_),this.captionPackets_.length=0,void this.field1_.flush()):void this.field1_.flush()};var h={42:225,92:233,94:237,95:243,96:250,123:231,124:247,125:209,126:241,127:9608},u=function(t){return null===t?"":(t=h[t]||t,String.fromCharCode(t))},c=0,l=5152,m=5167,f=5157,g=5158,y=5159,b=5165,S=5153,v=5164,T=5166,_=14,k=function(){for(var t=[],e=_+1;e--;)t.push("");return t},w=function(){w.prototype.init.call(this),this.mode_="popOn",this.topRow_=0,this.startPts_=0,this.displayed_=k(),this.nonDisplayed_=k(),this.lastControlCode_=null,this.push=function(t){if(0===t.type){var e,a,i,n;if(e=32639&t.ccData,e===this.lastControlCode_)return void(this.lastControlCode_=null);switch(4096===(61440&e)?this.lastControlCode_=e:this.lastControlCode_=null,e){case c:break;case l:this.mode_="popOn";break;case m:this.flushDisplayed(t.pts),a=this.displayed_,this.displayed_=this.nonDisplayed_,this.nonDisplayed_=a,this.startPts_=t.pts;break;case f:this.topRow_=_-1,this.mode_="rollUp";break;case g:this.topRow_=_-2,this.mode_="rollUp";break;case y:this.topRow_=_-3,this.mode_="rollUp";break;case b:this.flushDisplayed(t.pts),this.shiftRowsUp_(),this.startPts_=t.pts;break;case S:"popOn"===this.mode_?this.nonDisplayed_[_]=this.nonDisplayed_[_].slice(0,-1):this.displayed_[_]=this.displayed_[_].slice(0,-1);break;case v:this.flushDisplayed(t.pts),this.displayed_=k();break;case T:this.nonDisplayed_=k();break;default:if(i=e>>>8,n=255&e,i>=16&&i<=23&&n>=64&&n<=127&&(16!==i||n<96)&&(i=32,n=null),(17===i||25===i)&&n>=48&&n<=63&&(i=9834,n=""),16===(240&i))return;this[this.mode_](t.pts,i,n)}}}};w.prototype=new r,w.prototype.flushDisplayed=function(t){var e=this.displayed_.map(function(t){return t.trim()}).filter(function(t){return t.length}).join("\n");e.length&&this.trigger("data",{startPts:this.startPts_,endPts:t,text:e})},w.prototype.popOn=function(t,e,a){var i=this.nonDisplayed_[_];i+=u(e),i+=u(a),this.nonDisplayed_[_]=i},w.prototype.rollUp=function(t,e,a){var i=this.displayed_[_];""===i&&(this.flushDisplayed(t),this.startPts_=t),i+=u(e),i+=u(a),this.displayed_[_]=i},w.prototype.shiftRowsUp_=function(){var t;for(t=0;t<this.topRow_;t++)this.displayed_[t]="";for(t=this.topRow_;t<_;t++)this.displayed_[t]=this.displayed_[t+1];this.displayed_[_]=""},e.exports={CaptionStream:p,Cea608Stream:w}},{}],5:[function(t,e,a){"use strict";var i,n,r,s=t(13),o=t(4),d=t(7),p=t(8).TimestampRolloverStream,h=t(7),u=188,c=71;i=function(){var t=new Uint8Array(u),e=0;i.prototype.init.call(this),this.push=function(a){var i,n=0,r=u;for(e?(i=new Uint8Array(a.byteLength+e),i.set(t.subarray(0,e)),i.set(a,e),e=0):i=a;r<i.byteLength;)i[n]!==c||i[r]!==c?(n++,r++):(this.trigger("data",i.subarray(n,r)),n+=u,r+=u);n<i.byteLength&&(t.set(i.subarray(n),0),e=i.byteLength-n)},this.flush=function(){e===u&&t[0]===c&&(this.trigger("data",t),e=0),this.trigger("done")}},i.prototype=new s,n=function(){var t,e,a,i;n.prototype.init.call(this),i=this,this.packetsWaitingForPmt=[],this.programMapTable=void 0,t=function(t,i){var n=0;i.payloadUnitStartIndicator&&(n+=t[n]+1),"pat"===i.type?e(t.subarray(n),i):a(t.subarray(n),i)},e=function(t,e){e.section_number=t[7],e.last_section_number=t[8],i.pmtPid=(31&t[10])<<8|t[11],e.pmtPid=i.pmtPid},a=function(t,e){var a,n,r,s;if(1&t[5]){for(i.programMapTable={},a=(15&t[1])<<8|t[2],n=3+a-4,r=(15&t[10])<<8|t[11],s=12+r;s<n;)i.programMapTable[(31&t[s+1])<<8|t[s+2]]=t[s],s+=((15&t[s+3])<<8|t[s+4])+5;for(e.programMapTable=i.programMapTable;i.packetsWaitingForPmt.length;)i.processPes_.apply(i,i.packetsWaitingForPmt.shift())}},this.push=function(e){var a={},i=4;a.payloadUnitStartIndicator=!!(64&e[1]),a.pid=31&e[1],a.pid<<=8,a.pid|=e[2],(48&e[3])>>>4>1&&(i+=e[i]+1),0===a.pid?(a.type="pat",t(e.subarray(i),a),this.trigger("data",a)):a.pid===this.pmtPid?(a.type="pmt",t(e.subarray(i),a),this.trigger("data",a)):void 0===this.programMapTable?this.packetsWaitingForPmt.push([e,i,a]):this.processPes_(e,i,a)},this.processPes_=function(t,e,a){a.streamType=this.programMapTable[a.pid],a.type="pes",a.data=t.subarray(e),this.trigger("data",a)}},n.prototype=new s,n.STREAM_TYPES={h264:27,adts:15},r=function(){var t=this,e={data:[],size:0},a={data:[],size:0},i={data:[],size:0},n=function(t,e){var a;e.dataAlignmentIndicator=0!==(4&t[6]),a=t[7],192&a&&(e.pts=(14&t[9])<<27|(255&t[10])<<20|(254&t[11])<<12|(255&t[12])<<5|(254&t[13])>>>3,e.pts*=4,e.pts+=(6&t[13])>>>1,e.dts=e.pts,64&a&&(e.dts=(14&t[14])<<27|(255&t[15])<<20|(254&t[16])<<12|(255&t[17])<<5|(254&t[18])>>>3,e.dts*=4,e.dts+=(6&t[18])>>>1)),e.data=t.subarray(9+t[8])},s=function(e,a){var i,r=new Uint8Array(e.size),s={type:a},o=0;if(e.data.length){for(s.trackId=e.data[0].pid;e.data.length;)i=e.data.shift(),r.set(i.data,o),o+=i.data.byteLength;n(r,s),e.size=0,t.trigger("data",s)}};r.prototype.init.call(this),this.push=function(n){({pat:function(){},pes:function(){var t,r;switch(n.streamType){case d.H264_STREAM_TYPE:case h.H264_STREAM_TYPE:t=e,r="video";break;case d.ADTS_STREAM_TYPE:t=a,r="audio";break;case d.METADATA_STREAM_TYPE:t=i,r="timed-metadata";break;default:return}n.payloadUnitStartIndicator&&s(t,r),t.data.push(n),t.size+=n.data.byteLength},pmt:function(){var e,a,i={type:"metadata",tracks:[]},r=n.programMapTable;for(e in r)r.hasOwnProperty(e)&&(a={timelineStartInfo:{baseMediaDecodeTime:0}},a.id=+e,r[e]===h.H264_STREAM_TYPE?(a.codec="avc",a.type="video"):r[e]===h.ADTS_STREAM_TYPE&&(a.codec="adts",a.type="audio"),i.tracks.push(a));t.trigger("data",i)}})[n.type]()},this.flush=function(){s(e,"video"),s(a,"audio"),s(i,"timed-metadata"),this.trigger("done")}},r.prototype=new s;var l={PAT_PID:0,MP2T_PACKET_LENGTH:u,TransportPacketStream:i,TransportParseStream:n,ElementaryStream:r,TimestampRolloverStream:p,CaptionStream:o.CaptionStream,Cea608Stream:o.Cea608Stream,MetadataStream:t(6)};for(var m in d)d.hasOwnProperty(m)&&(l[m]=d[m]);e.exports=l},{}],6:[function(t,e,a){"use strict";var i,n=t(13),r=t(7),s=function(t,e,a){var i,n="";for(i=e;i<a;i++)n+="%"+("00"+t[i].toString(16)).slice(-2);return n},o=function(t,e,a){return decodeURIComponent(s(t,e,a))},d=function(t,e,a){return unescape(s(t,e,a))},p=function(t){return t[0]<<21|t[1]<<14|t[2]<<7|t[3]},h={TXXX:function(t){var e;if(3===t.data[0]){for(e=1;e<t.data.length;e++)if(0===t.data[e]){t.description=o(t.data,1,e),t.value=o(t.data,e+1,t.data.length-1);break}t.data=t.value}},WXXX:function(t){var e;if(3===t.data[0])for(e=1;e<t.data.length;e++)if(0===t.data[e]){t.description=o(t.data,1,e),t.url=o(t.data,e+1,t.data.length);break}},PRIV:function(t){var e;for(e=0;e<t.data.length;e++)if(0===t.data[e]){t.owner=d(t.data,0,e);break}t.privateData=t.data.subarray(e+1),t.data=t.privateData}};i=function(t){var e,a={debug:!(!t||!t.debug),descriptor:t&&t.descriptor},n=0,s=[],o=0;if(i.prototype.init.call(this),this.dispatchType=r.METADATA_STREAM_TYPE.toString(16),a.descriptor)for(e=0;e<a.descriptor.length;e++)this.dispatchType+=("00"+a.descriptor[e].toString(16)).slice(-2);this.push=function(t){var e,i,r,d,u,c;if("timed-metadata"===t.type){if(t.dataAlignmentIndicator&&(o=0,s.length=0),0===s.length&&(t.data.length<10||t.data[0]!=="I".charCodeAt(0)||t.data[1]!=="D".charCodeAt(0)||t.data[2]!=="3".charCodeAt(0)))return void(a.debug&&console.log("Skipping unrecognized metadata packet"));if(s.push(t),o+=t.data.byteLength,1===s.length&&(n=p(t.data.subarray(6,10)),n+=10),!(o<n)){for(e={data:new Uint8Array(n),frames:[],pts:s[0].pts,dts:s[0].dts},u=0;u<n;)e.data.set(s[0].data.subarray(0,n-u),u),u+=s[0].data.byteLength,o-=s[0].data.byteLength,s.shift();i=10,64&e.data[5]&&(i+=4,i+=p(e.data.subarray(10,14)),n-=p(e.data.subarray(16,20)));do{if(r=p(e.data.subarray(i+4,i+8)),r<1)return console.log("Malformed ID3 frame encountered. Skipping metadata parsing.");if(c=String.fromCharCode(e.data[i],e.data[i+1],e.data[i+2],e.data[i+3]),d={id:c,data:e.data.subarray(i+10,i+r+10)},d.key=d.id,h[d.id]&&(h[d.id](d),"com.apple.streaming.transportStreamTimestamp"===d.owner)){var l=d.data,m=(1&l[3])<<30|l[4]<<22|l[5]<<14|l[6]<<6|l[7]>>>2;m*=4,m+=3&l[7],d.timeStamp=m,void 0===e.pts&&void 0===e.dts&&(e.pts=d.timeStamp,e.dts=d.timeStamp),this.trigger("timestamp",d)}e.frames.push(d),i+=10,i+=r}while(i<n);this.trigger("data",e)}}}},i.prototype=new n,e.exports=i},{}],7:[function(t,e,a){"use strict";e.exports={H264_STREAM_TYPE:27,ADTS_STREAM_TYPE:15,METADATA_STREAM_TYPE:21}},{}],8:[function(t,e,a){"use strict";var i=t(13),n=8589934592,r=4294967296,s=function(t,e){var a=1;for(t>e&&(a=-1);Math.abs(e-t)>r;)t+=a*n;return t},o=function(t){var e,a;o.prototype.init.call(this),this.type_=t,this.push=function(t){t.type===this.type_&&(void 0===a&&(a=t.dts),t.dts=s(t.dts,a),t.pts=s(t.pts,a),e=t.dts,this.trigger("data",t))},this.flush=function(){a=e,this.trigger("done")}};o.prototype=new i,e.exports={TimestampRolloverStream:o,handleRollover:s}},{}],9:[function(t,e,a){e.exports={generator:t(10),Transmuxer:t(11).Transmuxer,AudioSegmentStream:t(11).AudioSegmentStream,VideoSegmentStream:t(11).VideoSegmentStream}},{}],10:[function(t,e,a){"use strict";var i,n,r,s,o,d,p,h,u,c,l,m,f,g,y,b,S,v,T,_,k,w,A,U,x,P,D,L,C,M,E,I,R,B,O,z,G=Math.pow(2,32)-1;!function(){var t;if(A={avc1:[],avcC:[],btrt:[],dinf:[],dref:[],esds:[],ftyp:[],hdlr:[],mdat:[],mdhd:[],mdia:[],mfhd:[],minf:[],moof:[],moov:[],mp4a:[],mvex:[],mvhd:[],sdtp:[],smhd:[],stbl:[],stco:[],stsc:[],stsd:[],stsz:[],stts:[],styp:[],tfdt:[],tfhd:[],traf:[],trak:[],trun:[],trex:[],tkhd:[],vmhd:[]},"undefined"!=typeof Uint8Array){for(t in A)A.hasOwnProperty(t)&&(A[t]=[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]);U=new Uint8Array(["i".charCodeAt(0),"s".charCodeAt(0),"o".charCodeAt(0),"m".charCodeAt(0)]),P=new Uint8Array(["a".charCodeAt(0),"v".charCodeAt(0),"c".charCodeAt(0),"1".charCodeAt(0)]),x=new Uint8Array([0,0,0,1]),D=new Uint8Array([0,0,0,0,0,0,0,0,118,105,100,101,0,0,0,0,0,0,0,0,0,0,0,0,86,105,100,101,111,72,97,110,100,108,101,114,0]),L=new Uint8Array([0,0,0,0,0,0,0,0,115,111,117,110,0,0,0,0,0,0,0,0,0,0,0,0,83,111,117,110,100,72,97,110,100,108,101,114,0]),C={video:D,audio:L},I=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1]),E=new Uint8Array([0,0,0,0,0,0,0,0]),R=new Uint8Array([0,0,0,0,0,0,0,0]),B=R,O=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]),z=R,M=new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0])}}(),i=function(t){var e,a,i,n=[],r=0;for(e=1;e<arguments.length;e++)n.push(arguments[e]);for(e=n.length;e--;)r+=n[e].byteLength;for(a=new Uint8Array(r+8),i=new DataView(a.buffer,a.byteOffset,a.byteLength),i.setUint32(0,a.byteLength),a.set(t,4),e=0,r=8;e<n.length;e++)a.set(n[e],r),r+=n[e].byteLength;return a},n=function(){return i(A.dinf,i(A.dref,I))},r=function(t){return i(A.esds,new Uint8Array([0,0,0,0,3,25,0,0,0,4,17,64,21,0,6,0,0,0,218,192,0,0,218,192,5,2,t.audioobjecttype<<3|t.samplingfrequencyindex>>>1,t.samplingfrequencyindex<<7|t.channelcount<<3,6,1,2]))},s=function(){return i(A.ftyp,U,x,U,P)},b=function(t){return i(A.hdlr,C[t])},o=function(t){return i(A.mdat,t)},y=function(t){var e=new Uint8Array([0,0,0,0,0,0,0,2,0,0,0,3,0,1,95,144,t.duration>>>24&255,t.duration>>>16&255,t.duration>>>8&255,255&t.duration,85,196,0,0]);return t.samplerate&&(e[12]=t.samplerate>>>24&255,e[13]=t.samplerate>>>16&255,e[14]=t.samplerate>>>8&255,e[15]=255&t.samplerate),i(A.mdhd,e)},g=function(t){return i(A.mdia,y(t),b(t.type),p(t))},d=function(t){return i(A.mfhd,new Uint8Array([0,0,0,0,(4278190080&t)>>24,(16711680&t)>>16,(65280&t)>>8,255&t]))},p=function(t){return i(A.minf,"video"===t.type?i(A.vmhd,M):i(A.smhd,E),n(),v(t))},h=function(t,e){for(var a=[],n=e.length;n--;)a[n]=_(e[n]);return i.apply(null,[A.moof,d(t)].concat(a))},u=function(t){for(var e=t.length,a=[];e--;)a[e]=m(t[e]);return i.apply(null,[A.moov,l(4294967295)].concat(a).concat(c(t)))},c=function(t){for(var e=t.length,a=[];e--;)a[e]=k(t[e]);return i.apply(null,[A.mvex].concat(a))},l=function(t){var e=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,2,0,1,95,144,(4278190080&t)>>24,(16711680&t)>>16,(65280&t)>>8,255&t,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255]);return i(A.mvhd,e)},S=function(t){var e,a,n=t.samples||[],r=new Uint8Array(4+n.length);for(a=0;a<n.length;a++)e=n[a].flags,r[a+4]=e.dependsOn<<4|e.isDependedOn<<2|e.hasRedundancy;return i(A.sdtp,r)},v=function(t){return i(A.stbl,T(t),i(A.stts,z),i(A.stsc,B),i(A.stsz,O),i(A.stco,R))},function(){var t,e;T=function(a){return i(A.stsd,new Uint8Array([0,0,0,0,0,0,0,1]),"video"===a.type?t(a):e(a))},t=function(t){var e,a=t.sps||[],n=t.pps||[],r=[],s=[];for(e=0;e<a.length;e++)r.push((65280&a[e].byteLength)>>>8),r.push(255&a[e].byteLength),r=r.concat(Array.prototype.slice.call(a[e]));for(e=0;e<n.length;e++)s.push((65280&n[e].byteLength)>>>8),s.push(255&n[e].byteLength),s=s.concat(Array.prototype.slice.call(n[e]));return i(A.avc1,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,(65280&t.width)>>8,255&t.width,(65280&t.height)>>8,255&t.height,0,72,0,0,0,72,0,0,0,0,0,0,0,1,19,118,105,100,101,111,106,115,45,99,111,110,116,114,105,98,45,104,108,115,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),i(A.avcC,new Uint8Array([1,t.profileIdc,t.profileCompatibility,t.levelIdc,255].concat([a.length]).concat(r).concat([n.length]).concat(s))),i(A.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])))},e=function(t){return i(A.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,(65280&t.channelcount)>>8,255&t.channelcount,(65280&t.samplesize)>>8,255&t.samplesize,0,0,0,0,(65280&t.samplerate)>>8,255&t.samplerate,0,0]),r(t))}}(),f=function(t){var e=new Uint8Array([0,0,0,7,0,0,0,0,0,0,0,0,(4278190080&t.id)>>24,(16711680&t.id)>>16,(65280&t.id)>>8,255&t.id,0,0,0,0,(4278190080&t.duration)>>24,(16711680&t.duration)>>16,(65280&t.duration)>>8,255&t.duration,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,(65280&t.width)>>8,255&t.width,0,0,(65280&t.height)>>8,255&t.height,0,0]);return i(A.tkhd,e)},_=function(t){var e,a,n,r,s,o,d;return e=i(A.tfhd,new Uint8Array([0,0,0,58,(4278190080&t.id)>>24,(16711680&t.id)>>16,(65280&t.id)>>8,255&t.id,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0])),o=Math.floor(t.baseMediaDecodeTime/(G+1)),d=Math.floor(t.baseMediaDecodeTime%(G+1)),a=i(A.tfdt,new Uint8Array([1,0,0,0,o>>>24&255,o>>>16&255,o>>>8&255,255&o,d>>>24&255,d>>>16&255,d>>>8&255,255&d])),s=92,"audio"===t.type?(n=w(t,s),i(A.traf,e,a,n)):(r=S(t),n=w(t,r.length+s),i(A.traf,e,a,n,r))},m=function(t){return t.duration=t.duration||4294967295,i(A.trak,f(t),g(t))},k=function(t){var e=new Uint8Array([0,0,0,0,(4278190080&t.id)>>24,(16711680&t.id)>>16,(65280&t.id)>>8,255&t.id,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]);return"video"!==t.type&&(e[e.length-1]=0),i(A.trex,e)},function(){var t,e,a;a=function(t,e){var a=0,i=0,n=0,r=0;return t.length&&(void 0!==t[0].duration&&(a=1),void 0!==t[0].size&&(i=2),void 0!==t[0].flags&&(n=4),void 0!==t[0].compositionTimeOffset&&(r=8)),[0,0,a|i|n|r,1,(4278190080&t.length)>>>24,(16711680&t.length)>>>16,(65280&t.length)>>>8,255&t.length,(4278190080&e)>>>24,(16711680&e)>>>16,(65280&e)>>>8,255&e]},e=function(t,e){var n,r,s,o;for(r=t.samples||[],e+=20+16*r.length,n=a(r,e),o=0;o<r.length;o++)s=r[o],n=n.concat([(4278190080&s.duration)>>>24,(16711680&s.duration)>>>16,(65280&s.duration)>>>8,255&s.duration,(4278190080&s.size)>>>24,(16711680&s.size)>>>16,(65280&s.size)>>>8,255&s.size,s.flags.isLeading<<2|s.flags.dependsOn,s.flags.isDependedOn<<6|s.flags.hasRedundancy<<4|s.flags.paddingValue<<1|s.flags.isNonSyncSample,61440&s.flags.degradationPriority,15&s.flags.degradationPriority,(4278190080&s.compositionTimeOffset)>>>24,(16711680&s.compositionTimeOffset)>>>16,(65280&s.compositionTimeOffset)>>>8,255&s.compositionTimeOffset]);return i(A.trun,new Uint8Array(n))},t=function(t,e){var n,r,s,o;for(r=t.samples||[],e+=20+8*r.length,n=a(r,e),o=0;o<r.length;o++)s=r[o],n=n.concat([(4278190080&s.duration)>>>24,(16711680&s.duration)>>>16,(65280&s.duration)>>>8,255&s.duration,(4278190080&s.size)>>>24,(16711680&s.size)>>>16,(65280&s.size)>>>8,255&s.size]);return i(A.trun,new Uint8Array(n))},w=function(a,i){return"audio"===a.type?t(a,i):e(a,i)}}(),e.exports={ftyp:s,mdat:o,moof:h,moov:u,initSegment:function(t){var e,a=s(),i=u(t);return e=new Uint8Array(a.byteLength+i.byteLength),e.set(a),e.set(i,a.byteLength),e}}},{}],11:[function(t,e,a){"use strict";var i,n,r,s,o,d,p,h,u,c,l,m=t(13),f=t(10),g=t(5),y=t(2),b=t(3).H264Stream,S=t(1),v=["audioobjecttype","channelcount","samplerate","samplingfrequencyindex","samplesize"],T=["width","height","profileIdc","levelIdc","profileCompatibility"];o=function(){return{size:0,flags:{isLeading:0,dependsOn:1,isDependedOn:0,hasRedundancy:0,degradationPriority:0}}},d=function(t){return t[0]==="I".charCodeAt(0)&&t[1]==="D".charCodeAt(0)&&t[2]==="3".charCodeAt(0)},c=function(t,e){var a;if(t.length!==e.length)return!1;for(a=0;a<t.length;a++)if(t[a]!==e[a])return!1;return!0},l=function(t){var e,a,i=0;for(e=0;e<t.length;e++)a=t[e],i+=a.data.byteLength;return i},n=function(t){var e=[],a=0,i=0;n.prototype.init.call(this),this.push=function(a){p(t,a),t&&v.forEach(function(e){t[e]=a[e]}),e.push(a)},this.setEarliestDts=function(e){i=e-t.timelineStartInfo.baseMediaDecodeTime},this.flush=function(){var i,n,r,s;return 0===e.length?void this.trigger("done","AudioSegmentStream"):(i=this.trimAdtsFramesByEarliestDts_(e),t.samples=this.generateSampleTable_(i),r=f.mdat(this.concatenateFrameData_(i)),e=[],u(t),n=f.moof(a,[t]),s=new Uint8Array(n.byteLength+r.byteLength),a++,s.set(n),s.set(r,n.byteLength),h(t),this.trigger("data",{track:t,boxes:s}),void this.trigger("done","AudioSegmentStream"))},this.trimAdtsFramesByEarliestDts_=function(e){return t.minSegmentDts>=i?e:(t.minSegmentDts=1/0,e.filter(function(e){return e.dts>=i&&(t.minSegmentDts=Math.min(t.minSegmentDts,e.dts),t.minSegmentPts=t.minSegmentDts,!0)}))},this.generateSampleTable_=function(t){var e,a,i=[];for(e=0;e<t.length;e++)a=t[e],i.push({size:a.data.byteLength,duration:1024});return i},this.concatenateFrameData_=function(t){var e,a,i=0,n=new Uint8Array(l(t));for(e=0;e<t.length;e++)a=t[e],n.set(a.data,i),i+=a.data.byteLength;return n}},n.prototype=new m,i=function(t){var e,a,n=0,r=[];i.prototype.init.call(this),delete t.minPTS,this.gopCache_=[],this.push=function(i){p(t,i),"seq_parameter_set_rbsp"!==i.nalUnitType||e||(e=i.config,t.sps=[i.data],T.forEach(function(a){t[a]=e[a]},this)),"pic_parameter_set_rbsp"!==i.nalUnitType||a||(a=i.data,t.pps=[i.data]),r.push(i)},this.flush=function(){for(var e,a,i,s,o,d;r.length&&"access_unit_delimiter_rbsp"!==r[0].nalUnitType;)r.shift();return 0===r.length?(this.resetStream_(),void this.trigger("done","VideoSegmentStream")):(e=this.groupNalsIntoFrames_(r),i=this.groupFramesIntoGops_(e),i[0][0].keyFrame||(a=this.getGopForFusion_(r[0],t),a?(i.unshift(a),i.byteLength+=a.byteLength,i.nalCount+=a.nalCount,i.pts=a.pts,i.dts=a.dts,i.duration+=a.duration):i=this.extendFirstKeyFrame_(i)),p(t,i),t.samples=this.generateSampleTable_(i),o=f.mdat(this.concatenateNalData_(i)),this.gopCache_.unshift({gop:i.pop(),pps:t.pps,sps:t.sps}),this.gopCache_.length=Math.min(6,this.gopCache_.length),r=[],u(t),this.trigger("timelineStartInfo",t.timelineStartInfo),s=f.moof(n,[t]),d=new Uint8Array(s.byteLength+o.byteLength),n++,d.set(s),d.set(o,s.byteLength),this.trigger("data",{track:t,boxes:d}),this.resetStream_(),void this.trigger("done","VideoSegmentStream"))},this.resetStream_=function(){h(t),e=void 0,a=void 0},this.getGopForFusion_=function(e){var a,i,n,r,s,o=45e3,d=1e4,p=1/0;for(s=0;s<this.gopCache_.length;s++)r=this.gopCache_[s],n=r.gop,t.pps&&c(t.pps[0],r.pps[0])&&t.sps&&c(t.sps[0],r.sps[0])&&(n.dts<t.timelineStartInfo.dts||(a=e.dts-n.dts-n.duration,a>=-d&&a<=o&&(!i||p>a)&&(i=r,p=a)));return i?i.gop:null},this.extendFirstKeyFrame_=function(t){var e;return t[0][0].keyFrame||(e=t.shift(),t.byteLength-=e.byteLength,t.nalCount-=e.nalCount,t[0][0].dts=e.dts,t[0][0].pts=e.pts,t[0][0].duration+=e.duration),t},this.groupNalsIntoFrames_=function(t){var e,a,i=[],n=[];for(i.byteLength=0,e=0;e<t.length;e++)a=t[e],"access_unit_delimiter_rbsp"===a.nalUnitType?(i.length&&(i.duration=a.dts-i.dts,n.push(i)),i=[a],i.byteLength=a.data.byteLength,i.pts=a.pts,i.dts=a.dts):("slice_layer_without_partitioning_rbsp_idr"===a.nalUnitType&&(i.keyFrame=!0),i.duration=a.dts-i.dts,i.byteLength+=a.data.byteLength,i.push(a));return n.length&&(!i.duration||i.duration<=0)&&(i.duration=n[n.length-1].duration),n.push(i),n},this.groupFramesIntoGops_=function(t){var e,a,i=[],n=[];for(i.byteLength=0,i.nalCount=0,i.duration=0,i.pts=t[0].pts,i.dts=t[0].dts,n.byteLength=0,n.nalCount=0,n.duration=0,n.pts=t[0].pts,n.dts=t[0].dts,e=0;e<t.length;e++)a=t[e],a.keyFrame?(i.length&&(n.push(i),n.byteLength+=i.byteLength,n.nalCount+=i.nalCount,n.duration+=i.duration),i=[a],i.nalCount=a.length,i.byteLength=a.byteLength,i.pts=a.pts,i.dts=a.dts,i.duration=a.duration):(i.duration+=a.duration,i.nalCount+=a.length,i.byteLength+=a.byteLength,i.push(a));return n.length&&i.duration<=0&&(i.duration=n[n.length-1].duration),n.byteLength+=i.byteLength,n.nalCount+=i.nalCount,n.duration+=i.duration,n.push(i),n},this.generateSampleTable_=function(t,e){var a,i,n,r,s,d=e||0,p=[];for(a=0;a<t.length;a++)for(r=t[a],i=0;i<r.length;i++)s=r[i],n=o(),n.dataOffset=d,n.compositionTimeOffset=s.pts-s.dts,n.duration=s.duration,n.size=4*s.length,n.size+=s.byteLength,s.keyFrame&&(n.flags.dependsOn=2),d+=n.size,p.push(n);return p},this.concatenateNalData_=function(t){var e,a,i,n,r,s,o=0,d=t.byteLength,p=t.nalCount,h=d+4*p,u=new Uint8Array(h),c=new DataView(u.buffer);for(e=0;e<t.length;e++)for(n=t[e],a=0;a<n.length;a++)for(r=n[a],i=0;i<r.length;i++)s=r[i],c.setUint32(o,s.data.byteLength),o+=4,u.set(s.data,o),o+=s.data.byteLength;return u}},i.prototype=new m,p=function(t,e){"number"==typeof e.pts&&(void 0===t.timelineStartInfo.pts&&(t.timelineStartInfo.pts=e.pts),void 0===t.minSegmentPts?t.minSegmentPts=e.pts:t.minSegmentPts=Math.min(t.minSegmentPts,e.pts),void 0===t.maxSegmentPts?t.maxSegmentPts=e.pts:t.maxSegmentPts=Math.max(t.maxSegmentPts,e.pts)),"number"==typeof e.dts&&(void 0===t.timelineStartInfo.dts&&(t.timelineStartInfo.dts=e.dts),void 0===t.minSegmentDts?t.minSegmentDts=e.dts:t.minSegmentDts=Math.min(t.minSegmentDts,e.dts),void 0===t.maxSegmentDts?t.maxSegmentDts=e.dts:t.maxSegmentDts=Math.max(t.maxSegmentDts,e.dts))},h=function(t){delete t.minSegmentDts,delete t.maxSegmentDts,delete t.minSegmentPts,delete t.maxSegmentPts},u=function(t){var e,a=9e4,i=t.minSegmentDts-t.timelineStartInfo.dts,n=t.minSegmentPts-t.minSegmentDts;t.baseMediaDecodeTime=t.timelineStartInfo.baseMediaDecodeTime,t.baseMediaDecodeTime+=i,t.baseMediaDecodeTime-=n,t.baseMediaDecodeTime=Math.max(0,t.baseMediaDecodeTime),"audio"===t.type&&(e=t.samplerate/a,t.baseMediaDecodeTime*=e,t.baseMediaDecodeTime=Math.floor(t.baseMediaDecodeTime))},s=function(t,e){this.numberOfTracks=0,this.metadataStream=e,"undefined"!=typeof t.remux?this.remuxTracks=!!t.remux:this.remuxTracks=!0,this.pendingTracks=[],this.videoTrack=null,this.pendingBoxes=[],this.pendingCaptions=[],this.pendingMetadata=[],this.pendingBytes=0,this.emittedTracks=0,s.prototype.init.call(this),this.push=function(t){return t.text?this.pendingCaptions.push(t):t.frames?this.pendingMetadata.push(t):(this.pendingTracks.push(t.track),this.pendingBoxes.push(t.boxes),this.pendingBytes+=t.boxes.byteLength,"video"===t.track.type&&(this.videoTrack=t.track),void("audio"===t.track.type&&(this.audioTrack=t.track)))}},s.prototype=new m,s.prototype.flush=function(t){var e,a,i,n,r=0,s={captions:[],metadata:[],info:{}},o=0;if(this.pendingTracks.length<this.numberOfTracks){if("VideoSegmentStream"!==t&&"AudioSegmentStream"!==t)return;if(this.remuxTracks)return;if(0===this.pendingTracks.length)return this.emittedTracks++,void(this.emittedTracks>=this.numberOfTracks&&(this.trigger("done"),this.emittedTracks=0))}for(this.videoTrack?(o=this.videoTrack.timelineStartInfo.pts,T.forEach(function(t){s.info[t]=this.videoTrack[t]},this)):this.audioTrack&&(o=this.audioTrack.timelineStartInfo.pts,v.forEach(function(t){s.info[t]=this.audioTrack[t]},this)),1===this.pendingTracks.length?s.type=this.pendingTracks[0].type:s.type="combined",this.emittedTracks+=this.pendingTracks.length,i=f.initSegment(this.pendingTracks),s.data=new Uint8Array(i.byteLength+this.pendingBytes),s.data.set(i),r+=i.byteLength,n=0;n<this.pendingBoxes.length;n++)s.data.set(this.pendingBoxes[n],r),r+=this.pendingBoxes[n].byteLength;for(n=0;n<this.pendingCaptions.length;n++)e=this.pendingCaptions[n],e.startTime=e.startPts-o,e.startTime/=9e4,e.endTime=e.endPts-o,e.endTime/=9e4,s.captions.push(e);for(n=0;n<this.pendingMetadata.length;n++)a=this.pendingMetadata[n],a.cueTime=a.pts-o,a.cueTime/=9e4,s.metadata.push(a);s.metadata.dispatchType=this.metadataStream.dispatchType, | ||
this.pendingTracks.length=0,this.videoTrack=null,this.pendingBoxes.length=0,this.pendingCaptions.length=0,this.pendingBytes=0,this.pendingMetadata.length=0,this.trigger("data",s),this.emittedTracks>=this.numberOfTracks&&(this.trigger("done"),this.emittedTracks=0)},r=function(t){var e,a,o=this,p=!0;r.prototype.init.call(this),t=t||{},this.baseMediaDecodeTime=t.baseMediaDecodeTime||0,this.transmuxPipeline_={},this.setupAacPipeline=function(){var e={};this.transmuxPipeline_=e,e.type="aac",e.metadataStream=new g.MetadataStream,e.aacStream=new S,e.audioTimestampRolloverStream=new g.TimestampRolloverStream("audio"),e.timedMetadataTimestampRolloverStream=new g.TimestampRolloverStream("timed-metadata"),e.adtsStream=new y,e.coalesceStream=new s(t,e.metadataStream),e.headOfPipeline=e.aacStream,e.aacStream.pipe(e.audioTimestampRolloverStream).pipe(e.adtsStream),e.aacStream.pipe(e.timedMetadataTimestampRolloverStream).pipe(e.metadataStream).pipe(e.coalesceStream),e.metadataStream.on("timestamp",function(t){e.aacStream.setTimestamp(t.timeStamp)}),e.aacStream.on("data",function(t){"timed-metadata"!==t.type||e.audioSegmentStream||(a=a||{timelineStartInfo:{baseMediaDecodeTime:o.baseMediaDecodeTime},codec:"adts",type:"audio"},e.coalesceStream.numberOfTracks++,e.audioSegmentStream=new n(a),e.adtsStream.pipe(e.audioSegmentStream).pipe(e.coalesceStream))}),e.coalesceStream.on("data",this.trigger.bind(this,"data")),e.coalesceStream.on("done",this.trigger.bind(this,"done"))},this.setupTsPipeline=function(){var r={};this.transmuxPipeline_=r,r.type="ts",r.metadataStream=new g.MetadataStream,r.packetStream=new g.TransportPacketStream,r.parseStream=new g.TransportParseStream,r.elementaryStream=new g.ElementaryStream,r.videoTimestampRolloverStream=new g.TimestampRolloverStream("video"),r.audioTimestampRolloverStream=new g.TimestampRolloverStream("audio"),r.timedMetadataTimestampRolloverStream=new g.TimestampRolloverStream("timed-metadata"),r.adtsStream=new y,r.h264Stream=new b,r.captionStream=new g.CaptionStream,r.coalesceStream=new s(t,r.metadataStream),r.headOfPipeline=r.packetStream,r.packetStream.pipe(r.parseStream).pipe(r.elementaryStream),r.elementaryStream.pipe(r.videoTimestampRolloverStream).pipe(r.h264Stream),r.elementaryStream.pipe(r.audioTimestampRolloverStream).pipe(r.adtsStream),r.elementaryStream.pipe(r.timedMetadataTimestampRolloverStream).pipe(r.metadataStream).pipe(r.coalesceStream),r.h264Stream.pipe(r.captionStream).pipe(r.coalesceStream),r.elementaryStream.on("data",function(t){var s;if("metadata"===t.type){for(s=t.tracks.length;s--;)e||"video"!==t.tracks[s].type?a||"audio"!==t.tracks[s].type||(a=t.tracks[s],a.timelineStartInfo.baseMediaDecodeTime=o.baseMediaDecodeTime):(e=t.tracks[s],e.timelineStartInfo.baseMediaDecodeTime=o.baseMediaDecodeTime);e&&!r.videoSegmentStream&&(r.coalesceStream.numberOfTracks++,r.videoSegmentStream=new i(e),r.videoSegmentStream.on("timelineStartInfo",function(t){a&&(a.timelineStartInfo=t,r.audioSegmentStream.setEarliestDts(t.dts))}),r.h264Stream.pipe(r.videoSegmentStream).pipe(r.coalesceStream)),a&&!r.audioSegmentStream&&(r.coalesceStream.numberOfTracks++,r.audioSegmentStream=new n(a),r.adtsStream.pipe(r.audioSegmentStream).pipe(r.coalesceStream))}}),r.coalesceStream.on("data",this.trigger.bind(this,"data")),r.coalesceStream.on("done",this.trigger.bind(this,"done"))},this.setBaseMediaDecodeTime=function(t){var i=this.transmuxPipeline_;this.baseMediaDecodeTime=t,a&&(a.timelineStartInfo.dts=void 0,a.timelineStartInfo.pts=void 0,h(a),a.timelineStartInfo.baseMediaDecodeTime=t),e&&(i.videoSegmentStream&&(i.videoSegmentStream.gopCache_=[]),e.timelineStartInfo.dts=void 0,e.timelineStartInfo.pts=void 0,h(e),e.timelineStartInfo.baseMediaDecodeTime=t)},this.push=function(t){if(p){var e=d(t);e&&"aac"!==this.transmuxPipeline_.type?this.setupAacPipeline():e||"ts"===this.transmuxPipeline_.type||this.setupTsPipeline(),p=!1}this.transmuxPipeline_.headOfPipeline.push(t)},this.flush=function(){p=!0,this.transmuxPipeline_.headOfPipeline.flush()}},r.prototype=new m,e.exports={Transmuxer:r,VideoSegmentStream:i,AudioSegmentStream:n,AUDIO_PROPERTIES:v,VIDEO_PROPERTIES:T}},{}],12:[function(t,e,a){"use strict";var i;i=function(t){var e=t.byteLength,a=0,i=0;this.length=function(){return 8*e},this.bitsAvailable=function(){return 8*e+i},this.loadWord=function(){var n=t.byteLength-e,r=new Uint8Array(4),s=Math.min(4,e);if(0===s)throw new Error("no bytes available");r.set(t.subarray(n,n+s)),a=new DataView(r.buffer).getUint32(0),i=8*s,e-=s},this.skipBits=function(t){var n;i>t?(a<<=t,i-=t):(t-=i,n=Math.floor(t/8),t-=8*n,e-=n,this.loadWord(),a<<=t,i-=t)},this.readBits=function(t){var n=Math.min(i,t),r=a>>>32-n;return i-=n,i>0?a<<=n:e>0&&this.loadWord(),n=t-n,n>0?r<<n|this.readBits(n):r},this.skipLeadingZeros=function(){var t;for(t=0;t<i;++t)if(0!==(a&2147483648>>>t))return a<<=t,i-=t,t;return this.loadWord(),t+this.skipLeadingZeros()},this.skipUnsignedExpGolomb=function(){this.skipBits(1+this.skipLeadingZeros())},this.skipExpGolomb=function(){this.skipBits(1+this.skipLeadingZeros())},this.readUnsignedExpGolomb=function(){var t=this.skipLeadingZeros();return this.readBits(t+1)-1},this.readExpGolomb=function(){var t=this.readUnsignedExpGolomb();return 1&t?1+t>>>1:-1*(t>>>1)},this.readBoolean=function(){return 1===this.readBits(1)},this.readUnsignedByte=function(){return this.readBits(8)},this.loadWord()},e.exports=i},{}],13:[function(t,e,a){"use strict";var i=function(){this.init=function(){var t={};this.on=function(e,a){t[e]||(t[e]=[]),t[e].push(a)},this.off=function(e,a){var i;return!!t[e]&&(i=t[e].indexOf(a),t[e].splice(i,1),i>-1)},this.trigger=function(e){var a,i,n,r;if(a=t[e])if(2===arguments.length)for(n=a.length,i=0;i<n;++i)a[i].call(this,arguments[1]);else{for(r=[],i=arguments.length,i=1;i<arguments.length;++i)r.push(arguments[i]);for(n=a.length,i=0;i<n;++i)a[i].apply(this,r)}},this.dispose=function(){t={}}}};i.prototype.pipe=function(t){return this.on("data",function(e){t.push(e)}),this.on("done",function(e){t.flush(e)}),t},i.prototype.push=function(t){this.trigger("data",t)},i.prototype.flush=function(t){this.trigger("done",t)},e.exports=i},{}]},{},[9]); |
@@ -13,4 +13,5 @@ 'use strict'; | ||
muxjs.flv.tools = require('./tools/flv-inspector'); | ||
muxjs.mp2t.tools = require('./tools/ts-inspector'); | ||
module.exports = muxjs; |
@@ -15,3 +15,3 @@ /** | ||
StreamTypes = require('./stream-types'), | ||
TimestampRolloverStream = require('./timestamp-rollover-stream'); | ||
TimestampRolloverStream = require('./timestamp-rollover-stream').TimestampRolloverStream; | ||
@@ -18,0 +18,0 @@ var m2tsStreamTypes = require('./stream-types.js'); |
@@ -20,2 +20,25 @@ /** | ||
var handleRollover = function(value, reference) { | ||
var direction = 1; | ||
if (value > reference) { | ||
// If the current timestamp value is greater than our reference timestamp and we detect a | ||
// timestamp rollover, this means the roll over is happening in the opposite direction. | ||
// Example scenario: Enter a long stream/video just after a rollover occurred. The reference | ||
// point will be set to a small number, e.g. 1. The user then seeks backwards over the | ||
// rollover point. In loading this segment, the timestamp values will be very large, | ||
// e.g. 2^33 - 1. Since this comes before the data we loaded previously, we want to adjust | ||
// the time stamp to be `value - 2^33`. | ||
direction = -1; | ||
} | ||
// Note: A seek forwards or back that is greater than the RO_THRESH (2^32, ~13 hours) will | ||
// cause an incorrect adjustment. | ||
while (Math.abs(reference - value) > RO_THRESH) { | ||
value += (direction * MAX_TS); | ||
} | ||
return value; | ||
}; | ||
var TimestampRolloverStream = function(type) { | ||
@@ -28,25 +51,2 @@ var lastDTS, referenceDTS; | ||
var handleRollover = function(value, reference) { | ||
var direction = 1; | ||
if (value > reference) { | ||
// If the current timestamp value is greater than our reference timestamp and we detect a | ||
// timestamp rollover, this means the roll over is happening in the opposite direction. | ||
// Example scenario: Enter a long stream/video just after a rollover occurred. The reference | ||
// point will be set to a small number, e.g. 1. The user then seeks backwards over the | ||
// rollover point. In loading this segment, the timestamp values will be very large, | ||
// e.g. 2^33 - 1. Since this comes before the data we loaded previously, we want to adjust | ||
// the time stamp to be `value - 2^33`. | ||
direction = -1; | ||
} | ||
// Note: A seek forwards or back that is greater than the RO_THRESH (2^32, ~13 hours) will | ||
// cause an incorrect adjustment. | ||
while (Math.abs(reference - value) > RO_THRESH) { | ||
value += (direction * MAX_TS); | ||
} | ||
return value; | ||
}; | ||
this.push = function(data) { | ||
@@ -78,2 +78,5 @@ if (data.type !== this.type_) { | ||
module.exports = TimestampRolloverStream; | ||
module.exports = { | ||
TimestampRolloverStream: TimestampRolloverStream, | ||
handleRollover: handleRollover | ||
}; |
@@ -12,2 +12,4 @@ /** | ||
var UINT32_MAX = Math.pow(2, 32) - 1; | ||
var box, dinf, esds, ftyp, mdat, mfhd, minf, moof, moov, mvex, mvhd, | ||
@@ -540,4 +542,5 @@ trak, tkhd, mdia, mdhd, hdlr, sdtp, stbl, stsd, traf, trex, | ||
traf = function(track) { | ||
var trackFragmentHeader, trackFragmentDecodeTime, | ||
trackFragmentRun, sampleDependencyTable, dataOffset; | ||
var trackFragmentHeader, trackFragmentDecodeTime, trackFragmentRun, | ||
sampleDependencyTable, dataOffset, | ||
upperWordBaseMediaDecodeTime, lowerWordBaseMediaDecodeTime; | ||
@@ -557,10 +560,17 @@ trackFragmentHeader = box(types.tfhd, new Uint8Array([ | ||
upperWordBaseMediaDecodeTime = Math.floor(track.baseMediaDecodeTime / (UINT32_MAX + 1)); | ||
lowerWordBaseMediaDecodeTime = Math.floor(track.baseMediaDecodeTime % (UINT32_MAX + 1)); | ||
trackFragmentDecodeTime = box(types.tfdt, new Uint8Array([ | ||
0x00, // version 0 | ||
0x01, // version 1 | ||
0x00, 0x00, 0x00, // flags | ||
// baseMediaDecodeTime | ||
(track.baseMediaDecodeTime >>> 24) & 0xFF, | ||
(track.baseMediaDecodeTime >>> 16) & 0xFF, | ||
(track.baseMediaDecodeTime >>> 8) & 0xFF, | ||
track.baseMediaDecodeTime & 0xFF | ||
(upperWordBaseMediaDecodeTime >>> 24) & 0xFF, | ||
(upperWordBaseMediaDecodeTime >>> 16) & 0xFF, | ||
(upperWordBaseMediaDecodeTime >>> 8) & 0xFF, | ||
upperWordBaseMediaDecodeTime & 0xFF, | ||
(lowerWordBaseMediaDecodeTime >>> 24) & 0xFF, | ||
(lowerWordBaseMediaDecodeTime >>> 16) & 0xFF, | ||
(lowerWordBaseMediaDecodeTime >>> 8) & 0xFF, | ||
lowerWordBaseMediaDecodeTime & 0xFF | ||
])); | ||
@@ -572,3 +582,3 @@ | ||
dataOffset = (32 + // tfhd | ||
16 + // tfdt | ||
20 + // tfdt | ||
8 + // traf header | ||
@@ -575,0 +585,0 @@ 16 + // mfhd |
{ | ||
"name": "mux.js", | ||
"version": "2.4.3", | ||
"version": "2.5.0", | ||
"description": "A collection of lightweight utilities for inspecting and manipulating video container formats.", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
789504
34
19421
4
12
1