mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
8 lines
269 KiB
JavaScript
8 lines
269 KiB
JavaScript
|
|
/*!
|
|
* artplayer-proxy-webav.js v1.0.0
|
|
* Github: https://github.com/zhw2590582/ArtPlayer
|
|
* (c) 2017-2025 Harvey Zack
|
|
* Released under the MIT License.
|
|
*/
|
|
!function(t,e,r,s,n){var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},o="function"==typeof a[s]&&a[s],h=o.cache||{},l="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function u(e,r){if(!h[e]){if(!t[e]){var n="function"==typeof a[s]&&a[s];if(!r&&n)return n(e,!0);if(o)return o(e,!0);if(l&&"string"==typeof e)return l(e);var d=Error("Cannot find module '"+e+"'");throw d.code="MODULE_NOT_FOUND",d}p.resolve=function(r){var s=t[e][1][r];return null!=s?s:r},p.cache={};var f=h[e]=new u.Module(e);t[e][0].call(f.exports,p,f,f.exports,this)}return h[e].exports;function p(t){var e=p.resolve(t);return!1===e?{}:u(e)}}u.isParcelRequire=!0,u.Module=function(t){this.id=t,this.bundle=u,this.exports={}},u.modules=t,u.cache=h,u.parent=o,u.register=function(e,r){t[e]=[function(t,e){e.exports=r},{}]},Object.defineProperty(u,"root",{get:function(){return a[s]}}),a[s]=u;for(var d=0;d<e.length;d++)u(e[d]);if(r){var f=u(r);"object"==typeof exports&&"undefined"!=typeof module?module.exports=f:"function"==typeof define&&define.amd&&define(function(){return f})}}({jc2x7:[function(t,e,r){var s=t("@parcel/transformer-js/src/esmodule-helpers.js");s.defineInteropFlag(r),s.export(r,"default",()=>a);var n=t("@webav/av-cliper");function a(t={}){return e=>{let r,s;let{option:a,constructor:o}=e,{createElement:h,def:l}=o.utils,u=h("canvas"),d=u.getContext("2d"),f=null,p=null,c=null,m=null,g=0,y={playing:!1,duration:0,videoWidth:0,videoHeight:0,currentTime:0,playbackRate:1,paused:!0,ended:!1,readyState:0,buffered:0,muted:a.muted,volume:a.volume,autoplay:a.autoplay};function _(){c&&(clearInterval(c),c=null),p&&(p.stop(),p=null)}function b(){if(s){let t=y.muted?0:y.volume;s.gain.setValueAtTime(t,r.currentTime)}}async function w(){r||(s=(r=new AudioContext).createGain()).connect(r.destination);let t=1e6*y.currentTime,n=0,a=!0,o=performance.now();async function h(){if(!y.playing)return;let h=performance.now(),l=h-o;o=h,null!==m?(t=1e6*m,m=null,a=!0):t+=1e3*l*y.playbackRate,y.currentTime=t/1e6;let{state:u,video:c,audio:g}=await f.tick(Math.round(t));if(e.emit("video:timeupdate",{type:"timeupdate"}),"done"===u){_(),y.ended=!0,y.playing=!1,y.paused=!0,e.emit("video:ended",{type:"ended"});return}if(c&&"success"===u&&(d.clearRect(0,0,y.videoWidth,y.videoHeight),d.drawImage(c,0,0,y.videoWidth,y.videoHeight),c.close()),a)a=!1;else if(g?.[0]?.length){let t=r.createBuffer(2,g[0].length,48e3);t.copyToChannel(g[0],0),t.copyToChannel(g[1],1),(p=r.createBufferSource()).buffer=t,p.connect(s),p.playbackRate.setValueAtTime(y.playbackRate,r.currentTime),n=Math.max(r.currentTime,n),p.start(n),n+=t.duration/y.playbackRate}}_(),b(),y.playing=!0,y.paused=!1,c=setInterval(h,1e3/60)}async function v(t){let{video:e}=await f.tick(1e6*t);e&&(d.clearRect(0,0,u.width,u.height),d.drawImage(e,0,0,u.width,u.height),e.close())}function S(){let t=e.template?.$player;if(!t||a.autoSize)return;let r=u.videoWidth/u.videoHeight,s=t.clientWidth,n=t.clientHeight,o=0,h=0;s/n>r?o=(s-n*r)/2:h=(n-s/r)/2,Object.assign(u.style,{padding:`${h}px ${o}px`})}async function E(){if(!await (0,n.Combinator).isSupported())throw e.notice.show="WebAV is not supported",Error("WebAV is not supported");_(),Object.assign(y,{playing:!1,duration:0,videoWidth:0,videoHeight:0,currentTime:0,playbackRate:1,paused:!0,ended:!1,readyState:0,buffered:0,muted:a.muted,volume:a.volume,autoplay:a.autoplay}),f&&(f.destroy(),e.emit("video:abort",{type:"abort"}),e.emit("video:emptied",{type:"emptied"}));try{await Promise.resolve(),y.readyState=1,e.emit("video:loadstart",{type:"loadstart"});let r=await fetch(a.url);if(!r.body)throw Error("No response body");f=new n.MP4Clip(r.body,t)}catch(t){throw y.readyState=0,e.emit("video:error",t),t}let r=await f.ready;Object.assign(y,{readyState:4,duration:Math.round(r.duration/1e6),videoWidth:r.width,videoHeight:r.height}),u.width=y.videoWidth,u.height=y.videoHeight,await v(.1),S(),e.emit("video:loadedmetadata",{type:"loadedmetadata"}),e.emit("video:durationchange",{type:"durationchange"}),e.emit("video:loadeddata",{type:"loadeddata"}),e.emit("video:canplay",{type:"canplay"}),e.emit("video:canplaythrough",{type:"canplaythrough"})}return l(u,"duration",{get:()=>y.duration}),l(u,"videoWidth",{get:()=>y.videoWidth}),l(u,"videoHeight",{get:()=>y.videoHeight}),l(u,"volume",{get:()=>y.volume,set:t=>{y.volume=Math.max(0,Math.min(1,t)),b(),e.emit("video:volumechange",{type:"volumechange"})}}),l(u,"currentTime",{get:()=>y.currentTime,set:t=>{if(y.readyState<4)return;let r=Math.max(0,Math.min(t,y.duration)),s=performance.now();s-g>16&&(g=s,m=r,y.currentTime=r,y.playing||v(r),e.emit("video:timeupdate",{type:"timeupdate"}))}}),l(u,"autoplay",{get:()=>y.autoplay,set:t=>{y.autoplay=t,t&&y.readyState>=4&&u.play()}}),l(u,"src",{get:()=>a.url,set:t=>{a.url=t,E().then(()=>{a.autoplay&&u.play()})}}),l(u,"playbackRate",{get:()=>y.playbackRate,set:t=>{y.playbackRate=Math.max(.25,Math.min(2,t)),p&&p.playbackRate.setValueAtTime(y.playbackRate,r.currentTime),e.emit("video:ratechange",{type:"ratechange"})}}),l(u,"playing",{get:()=>y.playing}),l(u,"paused",{get:()=>y.paused}),l(u,"ended",{get:()=>y.ended}),l(u,"readyState",{get:()=>y.readyState}),l(u,"muted",{get:()=>y.muted,set:t=>{y.muted=t,b(),e.emit("video:volumechange",{type:"volumechange"})}}),l(u,"buffered",{get:()=>({start:()=>0,end:()=>y.buffered,length:1})}),l(u,"play",{value:async()=>!(y.readyState<4)&&(await w(),e.emit("video:play",{type:"play"}),e.emit("video:playing",{type:"playing"}),!0)}),l(u,"pause",{value:()=>{_(),y.playing=!1,y.paused=!0,e.emit("video:pause",{type:"pause"})}}),e.on("destroy",()=>{_(),f&&f.destroy()}),e.on("resize",S),u}}"undefined"!=typeof window&&(window.artplayerProxyWebAV=a)},{"@webav/av-cliper":"b01Rz","@parcel/transformer-js/src/esmodule-helpers.js":"9pCYc"}],b01Rz:[function(t,e,r){var s,n,a,o,h,l,u,d,f,p,c,m,g,y,_,b,w,v,S,E,U,x,T,A,C,I,B,k,F,R,P,z,L,D,M,O,N,G,Y,W,V,H,X,j,Z,$,K,q,Q,J,tt,te,ti,tr,ts,tn,ta,to,th,tl,tu,td,tf,tp,tc,tm,tg,ty,t_,tb,tw,tv,tS,tE,tU,tx,tT,tA,tC,tI,tB,tk,tF,tR,tP,tz,tL,tD,tM,tO,tN,tG,tY,tW,tV,tH,tX,tj,tZ,t$,tK,tq,tQ,tJ,t0,t1,t2,t3,t6,t8,t4,t5,t9,t7,et,ee,ei,er,es,en,ea,eo,eh,el,eu,ed=t("@parcel/transformer-js/src/esmodule-helpers.js");ed.defineInteropFlag(r),ed.export(r,"AudioClip",()=>iX),ed.export(r,"Combinator",()=>rB),ed.export(r,"DEFAULT_AUDIO_CONF",()=>iC),ed.export(r,"EmbedSubtitlesClip",()=>iQ),ed.export(r,"EventTool",()=>i0),ed.export(r,"ImgClip",()=>iV),ed.export(r,"Log",()=>e5),ed.export(r,"MP4Clip",()=>iz),ed.export(r,"MediaStreamClip",()=>iK),ed.export(r,"OffscreenSprite",()=>rT),ed.export(r,"Rect",()=>rE),ed.export(r,"VisibleSprite",()=>rA),ed.export(r,"adjustAudioDataVolume",()=>iy),ed.export(r,"audioResample",()=>iw),ed.export(r,"autoReadStream",()=>iE),ed.export(r,"concatAudioClip",()=>ij),ed.export(r,"concatFloat32Array",()=>ip),ed.export(r,"concatPCMFragments",()=>ic),ed.export(r,"createChromakey",()=>rv),ed.export(r,"createEl",()=>eE),ed.export(r,"createHLSLoader",()=>rm),ed.export(r,"decodeImg",()=>i_),ed.export(r,"extractPCM4AudioBuffer",()=>ig),ed.export(r,"extractPCM4AudioData",()=>im),ed.export(r,"fastConcatMP4",()=>rt),ed.export(r,"file2stream",()=>i9),ed.export(r,"fixFMP4Duration",()=>ri),ed.export(r,"mixinMP4AndAudio",()=>rr),ed.export(r,"mixinPCM",()=>ib),ed.export(r,"recodemux",()=>i4),ed.export(r,"renderTxt2Img",()=>eU),ed.export(r,"renderTxt2ImgBitmap",()=>ex),ed.export(r,"ringSliceFloat32Array",()=>iS),ed.export(r,"workerTimer",()=>is);var ef=arguments[3],ep=t("718a311db185ef08").Buffer,ec=Object.defineProperty,em=t=>{throw TypeError(t)},eg=(t,e,r)=>e in t?ec(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ey=(t,e,r)=>eg(t,"symbol"!=typeof e?e+"":e,r),e_=(t,e,r)=>e.has(t)||em("Cannot "+r),eb=(t,e,r)=>(e_(t,e,"read from private field"),r?r.call(t):e.get(t)),ew=(t,e,r)=>e.has(t)?em("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),ev=(t,e,r,s)=>(e_(t,e,"write to private field"),s?s.call(t,r):e.set(t,r),r),eS=(t,e,r)=>(e_(t,e,"access private method"),r);function eE(t){return document.createElement(t)}function eU(t,e){let r=eE("pre");r.style.cssText=`margin: 0; ${e}; visibility: hidden; position: fixed;`,r.textContent=t,document.body.appendChild(r);let{width:s,height:n}=r.getBoundingClientRect();r.remove(),r.style.visibility="visible";let a=new Image;a.width=s,a.height=n;let o=`<svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${n}"><foreignObject width="100%" height="100%"><div xmlns="http://www.w3.org/1999/xhtml">${r.outerHTML}</div></foreignObject></svg>`.replace(/\t/g,"").replace(/#/g,"%23");return a.src=`data:image/svg+xml;charset=utf-8,${o}`,a}async function ex(t,e){let r=eU(t,e);await new Promise(t=>{r.onload=t});let s=new OffscreenCanvas(r.width,r.height),n=s.getContext("2d");return null==n||n.drawImage(r,0,0,r.width,r.height),await createImageBitmap(s)}var eT=t=>{throw TypeError(t)},eA=(t,e,r)=>e.has(t)||eT("Cannot "+r),eC=(t,e,r)=>(eA(t,e,"read from private field"),r?r.call(t):e.get(t)),eI=(t,e,r)=>e.has(t)?eT("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),eB=(t,e,r,s)=>(eA(t,e,"write to private field"),e.set(t,r),r);let ek="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2Z1bmN0aW9uIHUobil7aWYobj09PSIvIilyZXR1cm57cGFyZW50Om51bGwsbmFtZToiIn07Y29uc3QgZT1uLnNwbGl0KCIvIikuZmlsdGVyKGk9PmkubGVuZ3RoPjApO2lmKGUubGVuZ3RoPT09MCl0aHJvdyBFcnJvcigiSW52YWxpZCBwYXRoIik7Y29uc3QgYT1lW2UubGVuZ3RoLTFdLHI9Ii8iK2Uuc2xpY2UoMCwtMSkuam9pbigiLyIpO3JldHVybntuYW1lOmEscGFyZW50OnJ9fWFzeW5jIGZ1bmN0aW9uIHcobixlKXtjb25zdHtwYXJlbnQ6YSxuYW1lOnJ9PXUobik7aWYoYT09bnVsbClyZXR1cm4gYXdhaXQgbmF2aWdhdG9yLnN0b3JhZ2UuZ2V0RGlyZWN0b3J5KCk7Y29uc3QgaT1hLnNwbGl0KCIvIikuZmlsdGVyKHQ9PnQubGVuZ3RoPjApO3RyeXtsZXQgdD1hd2FpdCBuYXZpZ2F0b3Iuc3RvcmFnZS5nZXREaXJlY3RvcnkoKTtmb3IoY29uc3QgcyBvZiBpKXQ9YXdhaXQgdC5nZXREaXJlY3RvcnlIYW5kbGUocyx7Y3JlYXRlOmUuY3JlYXRlfSk7aWYoZS5pc0ZpbGUpcmV0dXJuIGF3YWl0IHQuZ2V0RmlsZUhhbmRsZShyLHtjcmVhdGU6ZS5jcmVhdGV9KX1jYXRjaCh0KXtpZih0Lm5hbWU9PT0iTm90Rm91bmRFcnJvciIpcmV0dXJuIG51bGw7dGhyb3cgdH19Y29uc3QgZj17fTtzZWxmLm9ubWVzc2FnZT1hc3luYyBuPT57dmFyIGk7Y29uc3R7ZXZ0VHlwZTplLGFyZ3M6YX09bi5kYXRhO2xldCByPWZbYS5maWxlSWRdO3RyeXtsZXQgdDtjb25zdCBzPVtdO2lmKGU9PT0icmVnaXN0ZXIiKXtjb25zdCBsPWF3YWl0IHcoYS5maWxlUGF0aCx7Y3JlYXRlOiEwLGlzRmlsZTohMH0pO2lmKGw9PW51bGwpdGhyb3cgRXJyb3IoYG5vdCBmb3VuZCBmaWxlOiAke2EuZmlsZUlkfWApO3I9YXdhaXQgbC5jcmVhdGVTeW5jQWNjZXNzSGFuZGxlKHttb2RlOmEubW9kZX0pLGZbYS5maWxlSWRdPXJ9ZWxzZSBpZihlPT09ImNsb3NlIilhd2FpdCByLmNsb3NlKCksZGVsZXRlIGZbYS5maWxlSWRdO2Vsc2UgaWYoZT09PSJ0cnVuY2F0ZSIpYXdhaXQgci50cnVuY2F0ZShhLm5ld1NpemUpO2Vsc2UgaWYoZT09PSJ3cml0ZSIpe2NvbnN0e2RhdGE6bCxvcHRzOm99PW4uZGF0YS5hcmdzO3Q9YXdhaXQgci53cml0ZShsLG8pfWVsc2UgaWYoZT09PSJyZWFkIil7Y29uc3R7b2Zmc2V0Omwsc2l6ZTpvfT1uLmRhdGEuYXJncyxnPW5ldyBVaW50OEFycmF5KG8pLGQ9YXdhaXQgci5yZWFkKGcse2F0Omx9KSxjPWcuYnVmZmVyO3Q9ZD09PW8/YzooKGk9Yy50cmFuc2Zlcik9PW51bGw/dm9pZCAwOmkuY2FsbChjLGQpKT8/Yy5zbGljZSgwLGQpLHMucHVzaCh0KX1lbHNlIGU9PT0iZ2V0U2l6ZSI/dD1hd2FpdCByLmdldFNpemUoKTplPT09ImZsdXNoIiYmYXdhaXQgci5mbHVzaCgpO3NlbGYucG9zdE1lc3NhZ2Uoe2V2dFR5cGU6ImNhbGxiYWNrIixjYklkOm4uZGF0YS5jYklkLHJldHVyblZhbDp0fSxzKX1jYXRjaCh0KXtjb25zdCBzPXQ7c2VsZi5wb3N0TWVzc2FnZSh7ZXZ0VHlwZToidGhyb3dFcnJvciIsY2JJZDpuLmRhdGEuY2JJZCxlcnJNc2c6cy5uYW1lKyI6ICIrcy5tZXNzYWdlK2AKYCtKU09OLnN0cmluZ2lmeShuLmRhdGEpfSl9fX0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPW9wZnMtd29ya2VyLUY0UldscWNfLmpzLm1hcAo=",eF="u">typeof self&&self.Blob&&new Blob([Uint8Array.from(atob(ek),t=>t.charCodeAt(0))],{type:"text/javascript;charset=utf-8"});function eR(t){let e;try{if(!(e=eF&&(self.URL||self.webkitURL).createObjectURL(eF)))throw"";let r=new Worker(e,{name:null==t?void 0:t.name});return r.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),r}catch{return new Worker("data:text/javascript;base64,"+ek,{name:null==t?void 0:t.name})}finally{e&&(self.URL||self.webkitURL).revokeObjectURL(e)}}async function eP(t,e,r){let s=function(){if(ez.length<3){let t=function(){let t=new eR,e=0,r={};return t.onmessage=({data:t})=>{var e,s;"callback"===t.evtType?null==(e=r[t.cbId])||e.resolve(t.returnVal):"throwError"===t.evtType&&(null==(s=r[t.cbId])||s.reject(Error(t.errMsg))),delete r[t.cbId]},async function(s,n,a=[]){e+=1;let o=new Promise((t,s)=>{r[e]={resolve:t,reject:s}});return t.postMessage({cbId:e,evtType:s,args:n},a),o}}();return ez.push(t),t}{let t=ez[eL];return eL=(eL+1)%ez.length,t}}();return await s("register",{fileId:t,filePath:e,mode:r}),{read:async(e,r)=>await s("read",{fileId:t,offset:e,size:r}),write:async(e,r)=>await s("write",{fileId:t,data:e,opts:r},[ArrayBuffer.isView(e)?e.buffer:e]),close:async()=>await s("close",{fileId:t}),truncate:async e=>await s("truncate",{fileId:t,newSize:e}),getSize:async()=>await s("getSize",{fileId:t}),flush:async()=>await s("flush",{fileId:t})}}let ez=[],eL=0;function eD(t){if("/"===t)return{parent:null,name:""};let e=t.split("/").filter(t=>t.length>0);if(0===e.length)throw Error("Invalid path");return{name:e[e.length-1],parent:"/"+e.slice(0,-1).join("/")}}async function eM(t,e){let{parent:r,name:s}=eD(t);if(null==r)return await navigator.storage.getDirectory();let n=r.split("/").filter(t=>t.length>0);try{let t=await navigator.storage.getDirectory();for(let r of n)t=await t.getDirectoryHandle(r,{create:e.create});return e.isFile?await t.getFileHandle(s,{create:e.create}):await t.getDirectoryHandle(s,{create:e.create})}catch(t){if("NotFoundError"===t.name)return null;throw t}}async function eO(t){let{parent:e,name:r}=eD(t);if(null==e){let t=await navigator.storage.getDirectory();for await(let e of t.keys())await t.removeEntry(e,{recursive:!0});return}let s=await eM(e,{create:!1,isFile:!1});null!=s&&await s.removeEntry(r,{recursive:!0})}function eN(t,e){return`${t}/${e}`.replace("//","/")}function eG(t){return new eY(t)}class eY{constructor(t){eI(this,g),eI(this,y),eI(this,_),eB(this,g,t);let{parent:e,name:r}=eD(t);eB(this,y,r),eB(this,_,e)}get kind(){return"dir"}get name(){return eC(this,y)}get path(){return eC(this,g)}get parent(){return null==eC(this,_)?null:eG(eC(this,_))}async create(){return await eM(eC(this,g),{create:!0,isFile:!1}),eG(eC(this,g))}async exists(){return await eM(eC(this,g),{create:!1,isFile:!1}) instanceof FileSystemDirectoryHandle}async remove(){for(let t of(await this.children()))try{await t.remove()}catch(t){console.warn(t)}try{await eO(eC(this,g))}catch(t){console.warn(t)}}async children(){let t=await eM(eC(this,g),{create:!1,isFile:!1});if(null==t)return[];let e=[];for await(let r of t.values())e.push(("file"===r.kind?eV:eG)(eN(eC(this,g),r.name)));return e}async copyTo(t){if(!await this.exists())throw Error(`dir ${this.path} not exists`);let e=await t.exists()?eG(eN(t.path,this.name)):t;return await e.create(),await Promise.all((await this.children()).map(t=>t.copyTo(e))),e}async moveTo(t){let e=await this.copyTo(t);return await this.remove(),e}}g=/* @__PURE__ */new WeakMap,y=/* @__PURE__ */new WeakMap,_=/* @__PURE__ */new WeakMap;let eW=/* @__PURE__ */new Map;function eV(t,e="rw"){if("rw"===e){let r=eW.get(t)??new e$(t,e);return eW.set(t,r),r}return new e$(t,e)}async function eH(t,e,r={overwrite:!0}){if(e instanceof e$){await eH(t,await e.stream(),r);return}let s=await (t instanceof e$?t:eV(t,"rw")).createWriter();try{if(r.overwrite&&await s.truncate(0),e instanceof ReadableStream){let t=e.getReader();for(;;){let{done:e,value:r}=await t.read();if(e)break;await s.write(r)}}else await s.write(e)}catch(t){throw t}finally{await s.close()}}let eX=0,ej=()=>++eX,eZ=class t{constructor(t,e){eI(this,b),eI(this,w),eI(this,v),eI(this,S),eI(this,E),eI(this,U,0),eI(this,x,/* @__PURE__ */(()=>{let t=null;return()=>(eB(this,U,eC(this,U)+1),t??(t=new Promise(async(e,r)=>{try{let r=await eP(eC(this,E),eC(this,b),eC(this,S));e([r,async()=>{eB(this,U,eC(this,U)-1),eC(this,U)>0||(t=null,await r.close())}])}catch(t){r(t)}})))})()),eI(this,T,!1),eB(this,E,ej()),eB(this,b,t),eB(this,S,{r:"read-only",rw:"readwrite","rw-unsafe":"readwrite-unsafe"}[e]);let{parent:r,name:s}=eD(t);eB(this,v,s),eB(this,w,r)}get kind(){return"file"}get path(){return eC(this,b)}get name(){return eC(this,v)}get parent(){return null==eC(this,w)?null:eG(eC(this,w))}async createWriter(){if("read-only"===eC(this,S))throw Error("file is read-only");if(eC(this,T))throw Error("Other writer have not been closed");eB(this,T,!0);let t=new TextEncoder,[e,r]=await eC(this,x).call(this),s=await e.getSize(),n=!1;return{write:async(r,a={})=>{if(n)throw Error("Writer is closed");let o="string"==typeof r?t.encode(r):r,h=a.at??s;return s=h+o.byteLength,await e.write(o,{at:h})},truncate:async t=>{if(n)throw Error("Writer is closed");await e.truncate(t),s>t&&(s=t)},flush:async()=>{if(n)throw Error("Writer is closed");await e.flush()},close:async()=>{if(n)throw Error("Writer is closed");n=!0,eB(this,T,!1),await r()}}}async createReader(){let[t,e]=await eC(this,x).call(this),r=!1,s=0;return{read:async(e,n={})=>{if(r)throw Error("Reader is closed");let a=n.at??s,o=await t.read(a,e);return s=a+o.byteLength,o},getSize:async()=>{if(r)throw Error("Reader is closed");return await t.getSize()},close:async()=>{r||(r=!0,await e())}}}async text(){return new TextDecoder().decode(await this.arrayBuffer())}async arrayBuffer(){let t=await eM(eC(this,b),{create:!1,isFile:!0});return null==t?new ArrayBuffer(0):(await t.getFile()).arrayBuffer()}async stream(){let t=await this.getOriginFile();return null==t?new ReadableStream({pull:t=>{t.close()}}):t.stream()}async getOriginFile(){var t;return null==(t=await eM(eC(this,b),{create:!1,isFile:!0}))?void 0:t.getFile()}async getSize(){let t=await eM(eC(this,b),{create:!1,isFile:!0});return null==t?0:(await t.getFile()).size}async exists(){return await eM(eC(this,b),{create:!1,isFile:!0}) instanceof FileSystemFileHandle}async remove(){if(eC(this,U))throw Error("exists unclosed reader/writer");await eO(eC(this,b))}async copyTo(e){if(!await this.exists())throw Error(`file ${this.path} not exists`);if(e instanceof t)return eV(e.path)===this?this:(await eH(e.path,this),eV(e.path));if(e instanceof eY)return await this.copyTo(eV(eN(e.path,this.name)));throw Error("Illegal target type")}async moveTo(t){let e=await this.copyTo(t);return await this.remove(),e}};b=/* @__PURE__ */new WeakMap,w=/* @__PURE__ */new WeakMap,v=/* @__PURE__ */new WeakMap,S=/* @__PURE__ */new WeakMap,E=/* @__PURE__ */new WeakMap,U=/* @__PURE__ */new WeakMap,x=/* @__PURE__ */new WeakMap,T=/* @__PURE__ */new WeakMap;let e$=eZ,eK="/.opfs-tools-temp-dir";async function eq(t){try{if("file"===t.kind){if(!await t.exists())return!0;let e=await t.createWriter();await e.truncate(0),await e.close(),await t.remove()}else await t.remove();return!0}catch(t){return console.warn(t),!1}}let eQ=[],eJ=!1;async function e0(){if(null==globalThis.localStorage)return;let t="OPFS_TOOLS_EXPIRES_TMP_FILES";eJ||(eJ=!0,globalThis.addEventListener("unload",()=>{0!==eQ.length&&localStorage.setItem(t,`${localStorage.getItem(t)??""},${eQ.join(",")}`)}));let e=localStorage.getItem(t)??"";for(let t of e.split(","))0!==t.length&&await eq(eV(`${eK}/${t}`))&&(e=e.replace(t,""));localStorage.setItem(t,e.replace(/,{2,}/g,","))}function e1(){let t=`${Math.random().toString().slice(2)}-${Date.now()}`;return eQ.push(t),eV(`${eK}/${t}`)}!async function(){var t;!0===globalThis.__opfs_tools_tmpfile_init__||(globalThis.__opfs_tools_tmpfile_init__=!0,null==globalThis.FileSystemDirectoryHandle||null==globalThis.FileSystemFileHandle||(null==(t=globalThis.navigator)?void 0:t.storage.getDirectory)==null||(setInterval(async()=>{for(let t of(await eG(eK).children())){let e=/^\d+-(\d+)$/.exec(t.name);(null==e||Date.now()-Number(e[1])>2592e5)&&await eq(t)}},6e4),await e0()))}();let e2=1,e3=e1(),e6=null,e8=["debug","info","warn","error"].reduce((t,e,r)=>Object.assign(t,{[e]:(...t)=>{e2<=r&&(console[e](...t),null==e6||e6.write(`[${e}][${function(){let t=/* @__PURE__ */new Date;return`${t.getHours()}:${t.getMinutes()}:${t.getSeconds()}.${t.getMilliseconds()}`}()}] ${t.map(t=>t instanceof Error?String(t):"object"==typeof t?JSON.stringify(t,(t,e)=>e instanceof Error?String(e):e):String(t)).join(" ")} `))}}),{}),e4=/* @__PURE__ */new Map,e5={setLogLevel:t=>{e2=e4.get(t)??1},...e8,create:t=>Object.fromEntries(Object.entries(e8).map(([e,r])=>[e,(...e)=>r(t,...e)])),dump:async()=>(await e7,await (null==e6?void 0:e6.flush()),await e3.text())};async function e9(){try{e6=await e3.createWriter(),e5.info(navigator.userAgent),e5.info("date: "+/* @__PURE__ */new Date().toLocaleDateString())}catch(t){if(!(t instanceof Error))throw t;if(t.message.includes("createSyncAccessHandle is not a function"))console.warn(t);else throw t}}e4.set(e5.debug,0),e4.set(e5.info,1),e4.set(e5.warn,2),e4.set(e5.error,3);let e7=null==globalThis.navigator?null:e9(),it=()=>{let t;self.onmessage=e=>{"start"===e.data.event&&(self.clearInterval(t),t=self.setInterval(()=>{self.postMessage({})},16.6)),"stop"===e.data.event&&self.clearInterval(t)}},ie=/* @__PURE__ */new Map,ii=1,ir=null;null!=globalThis.Worker&&((ir=(()=>{let t=new Blob([`(${it.toString()})()`]);return new Worker(URL.createObjectURL(t))})()).onmessage=()=>{for(let[t,e]of(ii+=1,ie))if(ii%t==0)for(let t of e)t()});let is=(t,e)=>{let r=Math.round(e/16.6),s=ie.get(r)??/* @__PURE__ */new Set;return s.add(t),ie.set(r,s),1===ie.size&&1===s.size&&(null==ir||ir.postMessage({event:"start"})),()=>{s.delete(t),0===s.size&&ie.delete(r),0===ie.size&&(ii=0,null==ir||ir.postMessage({event:"stop"}))}};class ia{constructor(t,e,r){var s;this.length_=t,this.scaleFactor_=(t-1)/e,this.interpolate=this.cubic,"point"===r.method?this.interpolate=this.point:"linear"===r.method?this.interpolate=this.linear:"sinc"===r.method&&(this.interpolate=this.sinc),this.tangentFactor_=1-Math.max(0,Math.min(1,r.tension||0)),this.sincFilterSize_=r.sincFilterSize||1,this.kernel_=(s=r.sincWindow||io,function(t){return(0===t?1:Math.sin(Math.PI*t)/(Math.PI*t))*s(t)})}point(t,e){return this.getClippedInput_(Math.round(this.scaleFactor_*t),e)}linear(t,e){let r=Math.floor(t=this.scaleFactor_*t);return(1-(t-=r))*this.getClippedInput_(r,e)+t*this.getClippedInput_(r+1,e)}cubic(t,e){let r=Math.floor(t=this.scaleFactor_*t),s=[this.getTangent_(r,e),this.getTangent_(r+1,e)],n=[this.getClippedInput_(r,e),this.getClippedInput_(r+1,e)],a=(t-=r)*t,o=t*a;return(2*o-3*a+1)*n[0]+(o-2*a+t)*s[0]+(-2*o+3*a)*n[1]+(o-a)*s[1]}sinc(t,e){let r=Math.floor(t=this.scaleFactor_*t),s=r-this.sincFilterSize_+1,n=r+this.sincFilterSize_,a=0;for(let r=s;r<=n;r++)a+=this.kernel_(t-r)*this.getClippedInput_(r,e);return a}getTangent_(t,e){return this.tangentFactor_*(this.getClippedInput_(t+1,e)-this.getClippedInput_(t-1,e))/2}getClippedInput_(t,e){return 0<=t&&t<this.length_?e[t]:0}}function io(t){return Math.exp(-t/2*t/2)}let ih={point:!1,linear:!1,cubic:!0,sinc:!0},il={IIR:16,FIR:71},iu={IIR:class{constructor(t,e,r){let s=[];for(let n=0;n<t;n++)s.push(this.getCoeffs_({Fs:e,Fc:r,Q:.5/Math.sin(Math.PI/(2*t)*(n+.5))}));this.stages=[];for(let t=0;t<s.length;t++)this.stages[t]={b0:s[t].b[0],b1:s[t].b[1],b2:s[t].b[2],a1:s[t].a[0],a2:s[t].a[1],k:s[t].k,z:[0,0]}}filter(t){let e=t;for(let t=0,r=this.stages.length;t<r;t++)e=this.runStage_(t,e);return e}getCoeffs_(t){let e={};e.z=[0,0],e.a=[],e.b=[];let r=this.preCalc_(t,e);return e.k=1,e.b.push((1-r.cw)/(2*r.a0)),e.b.push(2*e.b[0]),e.b.push(e.b[0]),e}preCalc_(t,e){let r={},s=2*Math.PI*t.Fc/t.Fs;return r.alpha=Math.sin(s)/(2*t.Q),r.cw=Math.cos(s),r.a0=1+r.alpha,e.a0=r.a0,e.a.push(-2*r.cw/r.a0),e.k=1,e.a.push((1-r.alpha)/r.a0),r}runStage_(t,e){let r=e*this.stages[t].k-this.stages[t].a1*this.stages[t].z[0]-this.stages[t].a2*this.stages[t].z[1],s=this.stages[t].b0*r+this.stages[t].b1*this.stages[t].z[0]+this.stages[t].b2*this.stages[t].z[1];return this.stages[t].z[1]=this.stages[t].z[0],this.stages[t].z[0]=r,s}reset(){for(let t=0;t<this.stages.length;t++)this.stages[t].z=[0,0]}},FIR:class{constructor(t,e,r){let s=2*Math.PI*r/e,n=0;this.filters=[];for(let e=0;e<=t;e++)e-t/2==0?this.filters[e]=s:(this.filters[e]=Math.sin(s*(e-t/2))/(e-t/2),this.filters[e]*=.54-.46*Math.cos(2*Math.PI*e/t)),n+=this.filters[e];for(let e=0;e<=t;e++)this.filters[e]/=n;this.z=this.initZ_()}filter(t){this.z.buf[this.z.pointer]=t;let e=0;for(let t=0,r=this.z.buf.length;t<r;t++)e+=this.filters[t]*this.z.buf[(this.z.pointer+t)%this.z.buf.length];return this.z.pointer=(this.z.pointer+1)%this.z.buf.length,e}reset(){this.z=this.initZ_()}initZ_(){let t=[];for(let e=0;e<this.filters.length-1;e++)t.push(0);return{buf:t,pointer:0}}}};function id(t,e,r){for(let s=0,n=e.length;s<n;s++)e[s]=r.interpolate(s,t)}function ip(t){let e=new Float32Array(t.map(t=>t.length).reduce((t,e)=>t+e)),r=0;for(let s of t)e.set(s,r),r+=s.length;return e}function ic(t){let e=[];for(let r=0;r<t.length;r+=1)for(let s=0;s<t[r].length;s+=1)null==e[s]&&(e[s]=[]),e[s].push(t[r][s]);return e.map(ip)}function im(t){if("f32-planar"===t.format){let e=[];for(let r=0;r<t.numberOfChannels;r+=1){let s=new ArrayBuffer(t.allocationSize({planeIndex:r}));t.copyTo(s,{planeIndex:r}),e.push(new Float32Array(s))}return e}if("s16"===t.format){let e=new ArrayBuffer(t.allocationSize({planeIndex:0}));return t.copyTo(e,{planeIndex:0}),function(t,e){let r=t.length/e,s=Array.from({length:e},()=>new Float32Array(r));for(let n=0;n<r;n++)for(let r=0;r<e;r++){let a=t[n*e+r];s[r][n]=a/32768}return s}(new Int16Array(e),t.numberOfChannels)}throw Error("Unsupported audio data format")}function ig(t){return Array(t.numberOfChannels).fill(0).map((e,r)=>t.getChannelData(r))}function iy(t,e){let r=new Float32Array(ip(im(t))).map(t=>t*e),s=new AudioData({sampleRate:t.sampleRate,numberOfChannels:t.numberOfChannels,timestamp:t.timestamp,format:t.format,numberOfFrames:t.numberOfFrames,data:r});return t.close(),s}async function i_(t,e){var r;let s=new ImageDecoder({type:e,data:t});await Promise.all([s.completed,s.tracks.ready]);let n=(null==(r=s.tracks.selectedTrack)?void 0:r.frameCount)??1,a=[];for(let t=0;t<n;t+=1)a.push((await s.decode({frameIndex:t})).image);return a}function ib(t){var e,r;let s=Math.max(...t.map(t=>{var e;return(null==(e=t[0])?void 0:e.length)??0})),n=new Float32Array(2*s);for(let a=0;a<s;a++){let o=0,h=0;for(let s=0;s<t.length;s++){let n=(null==(e=t[s][0])?void 0:e[a])??0,l=(null==(r=t[s][1])?void 0:r[a])??n;o+=n,h+=l}n[a]=o,n[a+s]=h}return n}async function iw(t,e,r){let s=t.length,n=Array(r.chanCount).fill(0).map(()=>new Float32Array(0));if(0===s)return n;let a=Math.max(...t.map(t=>t.length));if(0===a)return n;if(null==globalThis.OfflineAudioContext)return t.map(t=>new Float32Array(function(t,e,r,s={}){let n=(r-e)/e+1,a=new Float64Array(t.length*n);s.method=s.method||"cubic";let o=new ia(t.length,a.length,{method:s.method,tension:s.tension||0,sincFilterSize:s.sincFilterSize||6,sincWindow:s.sincWindow||void 0});if(void 0===s.LPF&&(s.LPF=ih[s.method]),s.LPF){s.LPFType=s.LPFType||"IIR";let n=iu[s.LPFType];r>e?function(t,e,r,s){for(let n=0,a=e.length;n<a;n++)e[n]=s.filter(r.interpolate(n,t));s.reset();for(let t=e.length-1;t>=0;t--)e[t]=s.filter(e[t])}(t,a,o,new n(s.LPFOrder||il[s.LPFType],r,e/2)):function(t,e,r,s){for(let e=0,r=t.length;e<r;e++)t[e]=s.filter(t[e]);s.reset();for(let e=t.length-1;e>=0;e--)t[e]=s.filter(t[e]);id(t,e,r)}(t,a,o,new n(s.LPFOrder||il[s.LPFType],e,r/2))}else id(t,a,o);return a}(t,e,r.rate,{method:"sinc",LPF:!1})));let o=new globalThis.OfflineAudioContext(r.chanCount,a*r.rate/e,r.rate),h=o.createBufferSource(),l=o.createBuffer(s,a,e);return t.forEach((t,e)=>l.copyToChannel(t,e)),h.buffer=l,h.connect(o.destination),h.start(),ig(await o.startRendering())}function iv(t){return new Promise(e=>{let r=is(()=>{r(),e()},t)})}function iS(t,e,r){let s=r-e,n=new Float32Array(s),a=0;for(;a<s;)n[a]=t[(e+a)%t.length],a+=1;return n}function iE(t,e){let r=!1;return(async function(){let s=t.getReader();for(;!r;){let{value:t,done:r}=await s.read();if(r){e.onDone();return}await e.onChunk(t)}s.releaseLock(),await t.cancel()})().catch(e5.error),()=>{r=!0}}var iU="u">typeof globalThis?globalThis:"u">typeof window?window:"u">typeof ef?ef:"u">typeof self?self:{};function ix(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var iT={};(s=/* @__PURE__ */new Date,n=4,a={setLogLevel:function(t){t==this.debug?n=1:t==this.info?n=2:t==this.warn?n=3:(this.error,n=4)},debug:function(t,e){void 0===console.debug&&(console.debug=console.log),1>=n&&console.debug("["+a.getDurationString(/* @__PURE__ */new Date-s,1e3)+"]","["+t+"]",e)},log:function(t,e){this.debug(t.msg)},info:function(t,e){2>=n&&console.info("["+a.getDurationString(/* @__PURE__ */new Date-s,1e3)+"]","["+t+"]",e)},warn:function(t,e){3>=n&&console.warn("["+a.getDurationString(/* @__PURE__ */new Date-s,1e3)+"]","["+t+"]",e)},error:function(t,e){4>=n&&console.error("["+a.getDurationString(/* @__PURE__ */new Date-s,1e3)+"]","["+t+"]",e)}}).getDurationString=function(t,e){function r(t,e){for(var r=(""+t).split(".");r[0].length<e;)r[0]="0"+r[0];return r.join(".")}t<0?(s=!0,t=-t):s=!1;var s,n=t/(e||1),a=Math.floor(n/3600),o=Math.floor((n-=3600*a)/60),h=1e3*(n-=60*o);return h-=1e3*(n=Math.floor(n)),h=Math.floor(h),(s?"-":"")+a+":"+r(o,2)+":"+r(n,2)+"."+r(h,3)},a.printRanges=function(t){var e=t.length;if(!(e>0))return"(empty)";for(var r="",s=0;s<e;s++)s>0&&(r+=","),r+="["+a.getDurationString(t.start(s))+","+a.getDurationString(t.end(s))+"]";return r},iT.Log=a,(o=function(t){if(t instanceof ArrayBuffer)this.buffer=t,this.dataview=new DataView(t);else throw"Needs an array buffer";this.position=0}).prototype.getPosition=function(){return this.position},o.prototype.getEndPosition=function(){return this.buffer.byteLength},o.prototype.getLength=function(){return this.buffer.byteLength},o.prototype.seek=function(t){var e=Math.max(0,Math.min(this.buffer.byteLength,t));return this.position=isNaN(e)||!isFinite(e)?0:e,!0},o.prototype.isEos=function(){return this.getPosition()>=this.getEndPosition()},o.prototype.readAnyInt=function(t,e){var r=0;if(this.position+t<=this.buffer.byteLength){switch(t){case 1:r=e?this.dataview.getInt8(this.position):this.dataview.getUint8(this.position);break;case 2:r=e?this.dataview.getInt16(this.position):this.dataview.getUint16(this.position);break;case 3:if(e)throw"No method for reading signed 24 bits values";r=this.dataview.getUint8(this.position)<<16|this.dataview.getUint8(this.position+1)<<8|this.dataview.getUint8(this.position+2);break;case 4:r=e?this.dataview.getInt32(this.position):this.dataview.getUint32(this.position);break;case 8:if(e)throw"No method for reading signed 64 bits values";r=this.dataview.getUint32(this.position)<<32|this.dataview.getUint32(this.position+4);break;default:throw"readInt method not implemented for size: "+t}return this.position+=t,r}throw"Not enough bytes in buffer"},o.prototype.readUint8=function(){return this.readAnyInt(1,!1)},o.prototype.readUint16=function(){return this.readAnyInt(2,!1)},o.prototype.readUint24=function(){return this.readAnyInt(3,!1)},o.prototype.readUint32=function(){return this.readAnyInt(4,!1)},o.prototype.readUint64=function(){return this.readAnyInt(8,!1)},o.prototype.readString=function(t){if(this.position+t<=this.buffer.byteLength){for(var e="",r=0;r<t;r++)e+=String.fromCharCode(this.readUint8());return e}throw"Not enough bytes in buffer"},o.prototype.readCString=function(){for(var t=[];;){var e=this.readUint8();if(0!==e)t.push(e);else break}return String.fromCharCode.apply(null,t)},o.prototype.readInt8=function(){return this.readAnyInt(1,!0)},o.prototype.readInt16=function(){return this.readAnyInt(2,!0)},o.prototype.readInt32=function(){return this.readAnyInt(4,!0)},o.prototype.readInt64=function(){return this.readAnyInt(8,!1)},o.prototype.readUint8Array=function(t){for(var e=new Uint8Array(t),r=0;r<t;r++)e[r]=this.readUint8();return e},o.prototype.readInt16Array=function(t){for(var e=new Int16Array(t),r=0;r<t;r++)e[r]=this.readInt16();return e},o.prototype.readUint16Array=function(t){for(var e=new Int16Array(t),r=0;r<t;r++)e[r]=this.readUint16();return e},o.prototype.readUint32Array=function(t){for(var e=new Uint32Array(t),r=0;r<t;r++)e[r]=this.readUint32();return e},o.prototype.readInt32Array=function(t){for(var e=new Int32Array(t),r=0;r<t;r++)e[r]=this.readInt32();return e},iT.MP4BoxStream=o,(h=function(t,e,r){this._byteOffset=e||0,t instanceof ArrayBuffer?this.buffer=t:"object"==typeof t?(this.dataView=t,e&&(this._byteOffset+=e)):this.buffer=new ArrayBuffer(t||0),this.position=0,this.endianness=r??h.LITTLE_ENDIAN}).prototype={},h.prototype.getPosition=function(){return this.position},h.prototype._realloc=function(t){if(this._dynamicSize){var e=this._byteOffset+this.position+t,r=this._buffer.byteLength;if(e<=r){e>this._byteLength&&(this._byteLength=e);return}for(r<1&&(r=1);e>r;)r*=2;var s=new ArrayBuffer(r),n=new Uint8Array(this._buffer);new Uint8Array(s,0,n.length).set(n),this.buffer=s,this._byteLength=e}},h.prototype._trimAlloc=function(){if(this._byteLength!=this._buffer.byteLength){var t=new ArrayBuffer(this._byteLength),e=new Uint8Array(t),r=new Uint8Array(this._buffer,0,e.length);e.set(r),this.buffer=t}},h.BIG_ENDIAN=!1,h.LITTLE_ENDIAN=!0,h.prototype._byteLength=0,Object.defineProperty(h.prototype,"byteLength",{get:function(){return this._byteLength-this._byteOffset}}),Object.defineProperty(h.prototype,"buffer",{get:function(){return this._trimAlloc(),this._buffer},set:function(t){this._buffer=t,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._buffer.byteLength}}),Object.defineProperty(h.prototype,"byteOffset",{get:function(){return this._byteOffset},set:function(t){this._byteOffset=t,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._buffer.byteLength}}),Object.defineProperty(h.prototype,"dataView",{get:function(){return this._dataView},set:function(t){this._byteOffset=t.byteOffset,this._buffer=t.buffer,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._byteOffset+t.byteLength}}),h.prototype.seek=function(t){var e=Math.max(0,Math.min(this.byteLength,t));this.position=isNaN(e)||!isFinite(e)?0:e},h.prototype.isEof=function(){return this.position>=this._byteLength},h.prototype.mapUint8Array=function(t){this._realloc(1*t);var e=new Uint8Array(this._buffer,this.byteOffset+this.position,t);return this.position+=1*t,e},h.prototype.readInt32Array=function(t,e){var r=new Int32Array(t=t??this.byteLength-this.position/4);return h.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),h.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},h.prototype.readInt16Array=function(t,e){var r=new Int16Array(t=t??this.byteLength-this.position/2);return h.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),h.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},h.prototype.readInt8Array=function(t){var e=new Int8Array(t=t??this.byteLength-this.position);return h.memcpy(e.buffer,0,this.buffer,this.byteOffset+this.position,t*e.BYTES_PER_ELEMENT),this.position+=e.byteLength,e},h.prototype.readUint32Array=function(t,e){var r=new Uint32Array(t=t??this.byteLength-this.position/4);return h.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),h.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},h.prototype.readUint16Array=function(t,e){var r=new Uint16Array(t=t??this.byteLength-this.position/2);return h.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),h.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},h.prototype.readUint8Array=function(t){var e=new Uint8Array(t=t??this.byteLength-this.position);return h.memcpy(e.buffer,0,this.buffer,this.byteOffset+this.position,t*e.BYTES_PER_ELEMENT),this.position+=e.byteLength,e},h.prototype.readFloat64Array=function(t,e){var r=new Float64Array(t=t??this.byteLength-this.position/8);return h.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),h.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},h.prototype.readFloat32Array=function(t,e){var r=new Float32Array(t=t??this.byteLength-this.position/4);return h.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),h.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},h.prototype.readInt32=function(t){var e=this._dataView.getInt32(this.position,t??this.endianness);return this.position+=4,e},h.prototype.readInt16=function(t){var e=this._dataView.getInt16(this.position,t??this.endianness);return this.position+=2,e},h.prototype.readInt8=function(){var t=this._dataView.getInt8(this.position);return this.position+=1,t},h.prototype.readUint32=function(t){var e=this._dataView.getUint32(this.position,t??this.endianness);return this.position+=4,e},h.prototype.readUint16=function(t){var e=this._dataView.getUint16(this.position,t??this.endianness);return this.position+=2,e},h.prototype.readUint8=function(){var t=this._dataView.getUint8(this.position);return this.position+=1,t},h.prototype.readFloat32=function(t){var e=this._dataView.getFloat32(this.position,t??this.endianness);return this.position+=4,e},h.prototype.readFloat64=function(t){var e=this._dataView.getFloat64(this.position,t??this.endianness);return this.position+=8,e},h.endianness=new Int8Array(new Int16Array([1]).buffer)[0]>0,h.memcpy=function(t,e,r,s,n){var a=new Uint8Array(t,e,n),o=new Uint8Array(r,s,n);a.set(o)},h.arrayToNative=function(t,e){return e==this.endianness?t:this.flipArrayEndianness(t)},h.nativeToEndian=function(t,e){return this.endianness==e?t:this.flipArrayEndianness(t)},h.flipArrayEndianness=function(t){for(var e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),r=0;r<t.byteLength;r+=t.BYTES_PER_ELEMENT)for(var s=r+t.BYTES_PER_ELEMENT-1,n=r;s>n;s--,n++){var a=e[n];e[n]=e[s],e[s]=a}return t},h.prototype.failurePosition=0,String.fromCharCodeUint8=function(t){for(var e=[],r=0;r<t.length;r++)e[r]=t[r];return String.fromCharCode.apply(null,e)},h.prototype.readString=function(t,e){return null==e||"ASCII"==e?String.fromCharCodeUint8.apply(null,[this.mapUint8Array(t??this.byteLength-this.position)]):new TextDecoder(e).decode(this.mapUint8Array(t))},h.prototype.readCString=function(t){var e=this.byteLength-this.position,r=new Uint8Array(this._buffer,this._byteOffset+this.position),s=e;null!=t&&(s=Math.min(t,e));for(var n=0;n<s&&0!==r[n];n++);var a=String.fromCharCodeUint8.apply(null,[this.mapUint8Array(n)]);return null!=t?this.position+=s-n:n!=e&&(this.position+=1),a},h.prototype.readInt64=function(){return 4294967296*this.readInt32()+this.readUint32()},h.prototype.readUint64=function(){return 4294967296*this.readUint32()+this.readUint32()},h.prototype.readInt64=function(){return 4294967296*this.readUint32()+this.readUint32()},h.prototype.readUint24=function(){return(this.readUint8()<<16)+(this.readUint8()<<8)+this.readUint8()},iT.DataStream=h,h.prototype.save=function(t){var e=new Blob([this.buffer]);if(window.URL&&URL.createObjectURL){var r=window.URL.createObjectURL(e),s=document.createElement("a");document.body.appendChild(s),s.setAttribute("href",r),s.setAttribute("download",t),s.setAttribute("target","_self"),s.click(),window.URL.revokeObjectURL(r)}else throw"DataStream.save: Can't create object URL."},h.prototype._dynamicSize=!0,Object.defineProperty(h.prototype,"dynamicSize",{get:function(){return this._dynamicSize},set:function(t){t||this._trimAlloc(),this._dynamicSize=t}}),h.prototype.shift=function(t){var e=new ArrayBuffer(this._byteLength-t),r=new Uint8Array(e),s=new Uint8Array(this._buffer,t,r.length);r.set(s),this.buffer=e,this.position-=t},h.prototype.writeInt32Array=function(t,e){if(this._realloc(4*t.length),t instanceof Int32Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)h.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapInt32Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeInt32(t[r],e)},h.prototype.writeInt16Array=function(t,e){if(this._realloc(2*t.length),t instanceof Int16Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)h.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapInt16Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeInt16(t[r],e)},h.prototype.writeInt8Array=function(t){if(this._realloc(1*t.length),t instanceof Int8Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)h.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapInt8Array(t.length);else for(var e=0;e<t.length;e++)this.writeInt8(t[e])},h.prototype.writeUint32Array=function(t,e){if(this._realloc(4*t.length),t instanceof Uint32Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)h.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapUint32Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeUint32(t[r],e)},h.prototype.writeUint16Array=function(t,e){if(this._realloc(2*t.length),t instanceof Uint16Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)h.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapUint16Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeUint16(t[r],e)},h.prototype.writeUint8Array=function(t){if(this._realloc(1*t.length),t instanceof Uint8Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)h.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapUint8Array(t.length);else for(var e=0;e<t.length;e++)this.writeUint8(t[e])},h.prototype.writeFloat64Array=function(t,e){if(this._realloc(8*t.length),t instanceof Float64Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)h.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapFloat64Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeFloat64(t[r],e)},h.prototype.writeFloat32Array=function(t,e){if(this._realloc(4*t.length),t instanceof Float32Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)h.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapFloat32Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeFloat32(t[r],e)},h.prototype.writeInt32=function(t,e){this._realloc(4),this._dataView.setInt32(this.position,t,e??this.endianness),this.position+=4},h.prototype.writeInt16=function(t,e){this._realloc(2),this._dataView.setInt16(this.position,t,e??this.endianness),this.position+=2},h.prototype.writeInt8=function(t){this._realloc(1),this._dataView.setInt8(this.position,t),this.position+=1},h.prototype.writeUint32=function(t,e){this._realloc(4),this._dataView.setUint32(this.position,t,e??this.endianness),this.position+=4},h.prototype.writeUint16=function(t,e){this._realloc(2),this._dataView.setUint16(this.position,t,e??this.endianness),this.position+=2},h.prototype.writeUint8=function(t){this._realloc(1),this._dataView.setUint8(this.position,t),this.position+=1},h.prototype.writeFloat32=function(t,e){this._realloc(4),this._dataView.setFloat32(this.position,t,e??this.endianness),this.position+=4},h.prototype.writeFloat64=function(t,e){this._realloc(8),this._dataView.setFloat64(this.position,t,e??this.endianness),this.position+=8},h.prototype.writeUCS2String=function(t,e,r){null==r&&(r=t.length);for(var s=0;s<t.length&&s<r;s++)this.writeUint16(t.charCodeAt(s),e);for(;s<r;s++)this.writeUint16(0)},h.prototype.writeString=function(t,e,r){var s=0;if(null==e||"ASCII"==e){if(null!=r){var n=Math.min(t.length,r);for(s=0;s<n;s++)this.writeUint8(t.charCodeAt(s));for(;s<r;s++)this.writeUint8(0)}else for(s=0;s<t.length;s++)this.writeUint8(t.charCodeAt(s))}else this.writeUint8Array(new TextEncoder(e).encode(t.substring(0,r)))},h.prototype.writeCString=function(t,e){var r=0;if(null!=e){var s=Math.min(t.length,e);for(r=0;r<s;r++)this.writeUint8(t.charCodeAt(r));for(;r<e;r++)this.writeUint8(0)}else{for(r=0;r<t.length;r++)this.writeUint8(t.charCodeAt(r));this.writeUint8(0)}},h.prototype.writeStruct=function(t,e){for(var r=0;r<t.length;r+=2){var s=t[r+1];this.writeType(s,e[t[r]],e)}},h.prototype.writeType=function(t,e,r){if("function"==typeof t)return t(this,e);if("object"==typeof t&&!(t instanceof Array))return t.set(this,e,r);var s,n=null,a="ASCII",o=this.position;switch("string"==typeof t&&/:/.test(t)&&(t=(s=t.split(":"))[0],n=parseInt(s[1])),"string"==typeof t&&/,/.test(t)&&(t=(s=t.split(","))[0],a=parseInt(s[1])),t){case"uint8":this.writeUint8(e);break;case"int8":this.writeInt8(e);break;case"uint16":this.writeUint16(e,this.endianness);break;case"int16":this.writeInt16(e,this.endianness);break;case"uint32":this.writeUint32(e,this.endianness);break;case"int32":this.writeInt32(e,this.endianness);break;case"float32":this.writeFloat32(e,this.endianness);break;case"float64":this.writeFloat64(e,this.endianness);break;case"uint16be":this.writeUint16(e,h.BIG_ENDIAN);break;case"int16be":this.writeInt16(e,h.BIG_ENDIAN);break;case"uint32be":this.writeUint32(e,h.BIG_ENDIAN);break;case"int32be":this.writeInt32(e,h.BIG_ENDIAN);break;case"float32be":this.writeFloat32(e,h.BIG_ENDIAN);break;case"float64be":this.writeFloat64(e,h.BIG_ENDIAN);break;case"uint16le":this.writeUint16(e,h.LITTLE_ENDIAN);break;case"int16le":this.writeInt16(e,h.LITTLE_ENDIAN);break;case"uint32le":this.writeUint32(e,h.LITTLE_ENDIAN);break;case"int32le":this.writeInt32(e,h.LITTLE_ENDIAN);break;case"float32le":this.writeFloat32(e,h.LITTLE_ENDIAN);break;case"float64le":this.writeFloat64(e,h.LITTLE_ENDIAN);break;case"cstring":this.writeCString(e,n);break;case"string":this.writeString(e,a,n);break;case"u16string":this.writeUCS2String(e,this.endianness,n);break;case"u16stringle":this.writeUCS2String(e,h.LITTLE_ENDIAN,n);break;case"u16stringbe":this.writeUCS2String(e,h.BIG_ENDIAN,n);break;default:if(3==t.length){for(var l=t[1],u=0;u<e.length;u++)this.writeType(l,e[u]);break}this.writeStruct(t,e)}null!=n&&(this.position=o,this._realloc(n),this.position=o+n)},h.prototype.writeUint64=function(t){var e=Math.floor(t/4294967296);this.writeUint32(e),this.writeUint32(4294967295&t)},h.prototype.writeUint24=function(t){this.writeUint8((16711680&t)>>16),this.writeUint8((65280&t)>>8),this.writeUint8(255&t)},h.prototype.adjustUint32=function(t,e){var r=this.position;this.seek(t),this.writeUint32(e),this.seek(r)},h.prototype.mapInt32Array=function(t,e){this._realloc(4*t);var r=new Int32Array(this._buffer,this.byteOffset+this.position,t);return h.arrayToNative(r,e??this.endianness),this.position+=4*t,r},h.prototype.mapInt16Array=function(t,e){this._realloc(2*t);var r=new Int16Array(this._buffer,this.byteOffset+this.position,t);return h.arrayToNative(r,e??this.endianness),this.position+=2*t,r},h.prototype.mapInt8Array=function(t){this._realloc(1*t);var e=new Int8Array(this._buffer,this.byteOffset+this.position,t);return this.position+=1*t,e},h.prototype.mapUint32Array=function(t,e){this._realloc(4*t);var r=new Uint32Array(this._buffer,this.byteOffset+this.position,t);return h.arrayToNative(r,e??this.endianness),this.position+=4*t,r},h.prototype.mapUint16Array=function(t,e){this._realloc(2*t);var r=new Uint16Array(this._buffer,this.byteOffset+this.position,t);return h.arrayToNative(r,e??this.endianness),this.position+=2*t,r},h.prototype.mapFloat64Array=function(t,e){this._realloc(8*t);var r=new Float64Array(this._buffer,this.byteOffset+this.position,t);return h.arrayToNative(r,e??this.endianness),this.position+=8*t,r},h.prototype.mapFloat32Array=function(t,e){this._realloc(4*t);var r=new Float32Array(this._buffer,this.byteOffset+this.position,t);return h.arrayToNative(r,e??this.endianness),this.position+=4*t,r},(l=function(t){this.buffers=[],this.bufferIndex=-1,t&&(this.insertBuffer(t),this.bufferIndex=0)}).prototype=new h(new ArrayBuffer,0,h.BIG_ENDIAN),l.prototype.initialized=function(){var t;return this.bufferIndex>-1||(this.buffers.length>0?0===(t=this.buffers[0]).fileStart?(this.buffer=t,this.bufferIndex=0,a.debug("MultiBufferStream","Stream ready for parsing"),!0):(a.warn("MultiBufferStream","The first buffer should have a fileStart of 0"),this.logBufferLevel(),!1):(a.warn("MultiBufferStream","No buffer to start parsing from"),this.logBufferLevel(),!1))},ArrayBuffer.concat=function(t,e){a.debug("ArrayBuffer","Trying to create a new buffer of size: "+(t.byteLength+e.byteLength));var r=new Uint8Array(t.byteLength+e.byteLength);return r.set(new Uint8Array(t),0),r.set(new Uint8Array(e),t.byteLength),r.buffer},l.prototype.reduceBuffer=function(t,e,r){var s;return(s=new Uint8Array(r)).set(new Uint8Array(t,e,r)),s.buffer.fileStart=t.fileStart+e,s.buffer.usedBytes=0,s.buffer},l.prototype.insertBuffer=function(t){for(var e=!0,r=0;r<this.buffers.length;r++){var s=this.buffers[r];if(t.fileStart<=s.fileStart){if(t.fileStart===s.fileStart){if(t.byteLength>s.byteLength){this.buffers.splice(r,1),r--;continue}a.warn("MultiBufferStream","Buffer (fileStart: "+t.fileStart+" - Length: "+t.byteLength+") already appended, ignoring")}else t.fileStart+t.byteLength<=s.fileStart||(t=this.reduceBuffer(t,0,s.fileStart-t.fileStart)),a.debug("MultiBufferStream","Appending new buffer (fileStart: "+t.fileStart+" - Length: "+t.byteLength+")"),this.buffers.splice(r,0,t),0===r&&(this.buffer=t);e=!1;break}if(t.fileStart<s.fileStart+s.byteLength){var n=s.fileStart+s.byteLength-t.fileStart,o=t.byteLength-n;if(o>0)t=this.reduceBuffer(t,n,o);else{e=!1;break}}}e&&(a.debug("MultiBufferStream","Appending new buffer (fileStart: "+t.fileStart+" - Length: "+t.byteLength+")"),this.buffers.push(t),0===r&&(this.buffer=t))},l.prototype.logBufferLevel=function(t){var e,r,s,n,o,h=[],l="";for(s=0,n=0,e=0;e<this.buffers.length;e++)r=this.buffers[e],0===e?(h.push(o={}),o.start=r.fileStart,o.end=r.fileStart+r.byteLength,l+="["+o.start+"-"):o.end===r.fileStart?o.end=r.fileStart+r.byteLength:((o={}).start=r.fileStart,l+=h[h.length-1].end-1+"], ["+o.start+"-",o.end=r.fileStart+r.byteLength,h.push(o)),s+=r.usedBytes,n+=r.byteLength;h.length>0&&(l+=o.end-1+"]"),(t?a.info:a.debug)("MultiBufferStream",0===this.buffers.length?"No more buffer in memory":""+this.buffers.length+" stored buffer(s) ("+s+"/"+n+" bytes), continuous ranges: "+l)},l.prototype.cleanBuffers=function(){var t,e;for(t=0;t<this.buffers.length;t++)(e=this.buffers[t]).usedBytes===e.byteLength&&(a.debug("MultiBufferStream","Removing buffer #"+t),this.buffers.splice(t,1),t--)},l.prototype.mergeNextBuffer=function(){if(!(this.bufferIndex+1<this.buffers.length)||(t=this.buffers[this.bufferIndex+1]).fileStart!==this.buffer.fileStart+this.buffer.byteLength)return!1;var t,e=this.buffer.byteLength,r=this.buffer.usedBytes,s=this.buffer.fileStart;return this.buffers[this.bufferIndex]=ArrayBuffer.concat(this.buffer,t),this.buffer=this.buffers[this.bufferIndex],this.buffers.splice(this.bufferIndex+1,1),this.buffer.usedBytes=r,this.buffer.fileStart=s,a.debug("ISOFile","Concatenating buffer for box parsing (length: "+e+"->"+this.buffer.byteLength+")"),!0},l.prototype.findPosition=function(t,e,r){var s,n=null,o=-1;for(s=!0===t?0:this.bufferIndex;s<this.buffers.length&&(n=this.buffers[s]).fileStart<=e;)o=s,r&&(n.fileStart+n.byteLength<=e?n.usedBytes=n.byteLength:n.usedBytes=e-n.fileStart,this.logBufferLevel()),s++;return -1!==o&&(n=this.buffers[o]).fileStart+n.byteLength>=e?(a.debug("MultiBufferStream","Found position in existing buffer #"+o),o):-1},l.prototype.findEndContiguousBuf=function(t){var e,r,s,n=void 0!==t?t:this.bufferIndex;if(r=this.buffers[n],this.buffers.length>n+1)for(e=n+1;e<this.buffers.length&&(s=this.buffers[e]).fileStart===r.fileStart+r.byteLength;e++)r=s;return r.fileStart+r.byteLength},l.prototype.getEndFilePositionAfter=function(t){var e=this.findPosition(!0,t,!1);return -1!==e?this.findEndContiguousBuf(e):t},l.prototype.addUsedBytes=function(t){this.buffer.usedBytes+=t,this.logBufferLevel()},l.prototype.setAllUsedBytes=function(){this.buffer.usedBytes=this.buffer.byteLength,this.logBufferLevel()},l.prototype.seek=function(t,e,r){var s;return -1!==(s=this.findPosition(e,t,r))?(this.buffer=this.buffers[s],this.bufferIndex=s,this.position=t-this.buffer.fileStart,a.debug("MultiBufferStream","Repositioning parser at buffer position: "+this.position),!0):(a.debug("MultiBufferStream","Position "+t+" not found in buffered data"),!1)},l.prototype.getPosition=function(){if(-1===this.bufferIndex||null===this.buffers[this.bufferIndex])throw"Error accessing position in the MultiBufferStream";return this.buffers[this.bufferIndex].fileStart+this.position},l.prototype.getLength=function(){return this.byteLength},l.prototype.getEndPosition=function(){if(-1===this.bufferIndex||null===this.buffers[this.bufferIndex])throw"Error accessing position in the MultiBufferStream";return this.buffers[this.bufferIndex].fileStart+this.byteLength},iT.MultiBufferStream=l,u=function(){var t=[];t[3]="ES_Descriptor",t[4]="DecoderConfigDescriptor",t[5]="DecoderSpecificInfo",t[6]="SLConfigDescriptor",this.getDescriptorName=function(e){return t[e]};var e=this,r={};return this.parseOneDescriptor=function(e){var s,n,o,h=0;for(s=e.readUint8(),o=e.readUint8();128&o;)h=(127&o)<<7,o=e.readUint8();return h+=127&o,a.debug("MPEG4DescriptorParser","Found "+(t[s]||"Descriptor "+s)+", size "+h+" at position "+e.getPosition()),(n=t[s]?new r[t[s]](h):new r.Descriptor(h)).parse(e),n},r.Descriptor=function(t,e){this.tag=t,this.size=e,this.descs=[]},r.Descriptor.prototype.parse=function(t){this.data=t.readUint8Array(this.size)},r.Descriptor.prototype.findDescriptor=function(t){for(var e=0;e<this.descs.length;e++)if(this.descs[e].tag==t)return this.descs[e];return null},r.Descriptor.prototype.parseRemainingDescriptors=function(t){for(var r=t.position;t.position<r+this.size;){var s=e.parseOneDescriptor(t);this.descs.push(s)}},r.ES_Descriptor=function(t){r.Descriptor.call(this,3,t)},r.ES_Descriptor.prototype=new r.Descriptor,r.ES_Descriptor.prototype.parse=function(t){if(this.ES_ID=t.readUint16(),this.flags=t.readUint8(),this.size-=3,128&this.flags?(this.dependsOn_ES_ID=t.readUint16(),this.size-=2):this.dependsOn_ES_ID=0,64&this.flags){var e=t.readUint8();this.URL=t.readString(e),this.size-=e+1}else this.URL="";32&this.flags?(this.OCR_ES_ID=t.readUint16(),this.size-=2):this.OCR_ES_ID=0,this.parseRemainingDescriptors(t)},r.ES_Descriptor.prototype.getOTI=function(t){var e=this.findDescriptor(4);return e?e.oti:0},r.ES_Descriptor.prototype.getAudioConfig=function(t){var e=this.findDescriptor(4);if(!e)return null;var r=e.findDescriptor(5);if(!r||!r.data)return null;var s=(248&r.data[0])>>3;return 31===s&&r.data.length>=2&&(s=32+((7&r.data[0])<<3)+((224&r.data[1])>>5)),s},r.DecoderConfigDescriptor=function(t){r.Descriptor.call(this,4,t)},r.DecoderConfigDescriptor.prototype=new r.Descriptor,r.DecoderConfigDescriptor.prototype.parse=function(t){this.oti=t.readUint8(),this.streamType=t.readUint8(),this.bufferSize=t.readUint24(),this.maxBitrate=t.readUint32(),this.avgBitrate=t.readUint32(),this.size-=13,this.parseRemainingDescriptors(t)},r.DecoderSpecificInfo=function(t){r.Descriptor.call(this,5,t)},r.DecoderSpecificInfo.prototype=new r.Descriptor,r.SLConfigDescriptor=function(t){r.Descriptor.call(this,6,t)},r.SLConfigDescriptor.prototype=new r.Descriptor,this},iT.MPEG4DescriptorParser=u,(d={ERR_INVALID_DATA:-1,ERR_NOT_ENOUGH_DATA:0,OK:1,BASIC_BOXES:["mdat","idat","free","skip","meco","strk"],FULL_BOXES:["hmhd","nmhd","iods","xml ","bxml","ipro","mere"],CONTAINER_BOXES:[["moov",["trak","pssh"]],["trak"],["edts"],["mdia"],["minf"],["dinf"],["stbl",["sgpd","sbgp"]],["mvex",["trex"]],["moof",["traf"]],["traf",["trun","sgpd","sbgp"]],["vttc"],["tref"],["iref"],["mfra",["tfra"]],["meco"],["hnti"],["hinf"],["strk"],["strd"],["sinf"],["rinf"],["schi"],["trgr"],["udta",["kind"]],["iprp",["ipma"]],["ipco"],["grpl"],["j2kH"],["etyp",["tyco"]]],boxCodes:[],fullBoxCodes:[],containerBoxCodes:[],sampleEntryCodes:{},sampleGroupEntryCodes:[],trackGroupTypes:[],UUIDBoxes:{},UUIDs:[],initialize:function(){d.FullBox.prototype=new d.Box,d.ContainerBox.prototype=new d.Box,d.SampleEntry.prototype=new d.Box,d.TrackGroupTypeBox.prototype=new d.FullBox,d.BASIC_BOXES.forEach(function(t){d.createBoxCtor(t)}),d.FULL_BOXES.forEach(function(t){d.createFullBoxCtor(t)}),d.CONTAINER_BOXES.forEach(function(t){d.createContainerBoxCtor(t[0],null,t[1])})},Box:function(t,e,r){this.type=t,this.size=e,this.uuid=r},FullBox:function(t,e,r){d.Box.call(this,t,e,r),this.flags=0,this.version=0},ContainerBox:function(t,e,r){d.Box.call(this,t,e,r),this.boxes=[]},SampleEntry:function(t,e,r,s){d.ContainerBox.call(this,t,e),this.hdr_size=r,this.start=s},SampleGroupEntry:function(t){this.grouping_type=t},TrackGroupTypeBox:function(t,e){d.FullBox.call(this,t,e)},createBoxCtor:function(t,e){d.boxCodes.push(t),d[t+"Box"]=function(e){d.Box.call(this,t,e)},d[t+"Box"].prototype=new d.Box,e&&(d[t+"Box"].prototype.parse=e)},createFullBoxCtor:function(t,e){d[t+"Box"]=function(e){d.FullBox.call(this,t,e)},d[t+"Box"].prototype=new d.FullBox,d[t+"Box"].prototype.parse=function(t){this.parseFullHeader(t),e&&e.call(this,t)}},addSubBoxArrays:function(t){if(t){this.subBoxNames=t;for(var e=t.length,r=0;r<e;r++)this[t[r]+"s"]=[]}},createContainerBoxCtor:function(t,e,r){d[t+"Box"]=function(e){d.ContainerBox.call(this,t,e),d.addSubBoxArrays.call(this,r)},d[t+"Box"].prototype=new d.ContainerBox,e&&(d[t+"Box"].prototype.parse=e)},createMediaSampleEntryCtor:function(t,e,r){d.sampleEntryCodes[t]=[],d[t+"SampleEntry"]=function(t,e){d.SampleEntry.call(this,t,e),d.addSubBoxArrays.call(this,r)},d[t+"SampleEntry"].prototype=new d.SampleEntry,e&&(d[t+"SampleEntry"].prototype.parse=e)},createSampleEntryCtor:function(t,e,r,s){d.sampleEntryCodes[t].push(e),d[e+"SampleEntry"]=function(r){d[t+"SampleEntry"].call(this,e,r),d.addSubBoxArrays.call(this,s)},d[e+"SampleEntry"].prototype=new d[t+"SampleEntry"],r&&(d[e+"SampleEntry"].prototype.parse=r)},createEncryptedSampleEntryCtor:function(t,e,r){d.createSampleEntryCtor.call(this,t,e,r,["sinf"])},createSampleGroupCtor:function(t,e){d[t+"SampleGroupEntry"]=function(e){d.SampleGroupEntry.call(this,t,e)},d[t+"SampleGroupEntry"].prototype=new d.SampleGroupEntry,e&&(d[t+"SampleGroupEntry"].prototype.parse=e)},createTrackGroupCtor:function(t,e){d[t+"TrackGroupTypeBox"]=function(e){d.TrackGroupTypeBox.call(this,t,e)},d[t+"TrackGroupTypeBox"].prototype=new d.TrackGroupTypeBox,e&&(d[t+"TrackGroupTypeBox"].prototype.parse=e)},createUUIDBox:function(t,e,r,s){d.UUIDs.push(t),d.UUIDBoxes[t]=function(s){e?d.FullBox.call(this,"uuid",s,t):r?d.ContainerBox.call(this,"uuid",s,t):d.Box.call(this,"uuid",s,t)},d.UUIDBoxes[t].prototype=e?new d.FullBox:r?new d.ContainerBox:new d.Box,s&&(e?d.UUIDBoxes[t].prototype.parse=function(t){this.parseFullHeader(t),s&&s.call(this,t)}:d.UUIDBoxes[t].prototype.parse=s)}}).initialize(),d.TKHD_FLAG_ENABLED=1,d.TKHD_FLAG_IN_MOVIE=2,d.TKHD_FLAG_IN_PREVIEW=4,d.TFHD_FLAG_BASE_DATA_OFFSET=1,d.TFHD_FLAG_SAMPLE_DESC=2,d.TFHD_FLAG_SAMPLE_DUR=8,d.TFHD_FLAG_SAMPLE_SIZE=16,d.TFHD_FLAG_SAMPLE_FLAGS=32,d.TFHD_FLAG_DUR_EMPTY=65536,d.TFHD_FLAG_DEFAULT_BASE_IS_MOOF=131072,d.TRUN_FLAGS_DATA_OFFSET=1,d.TRUN_FLAGS_FIRST_FLAG=4,d.TRUN_FLAGS_DURATION=256,d.TRUN_FLAGS_SIZE=512,d.TRUN_FLAGS_FLAGS=1024,d.TRUN_FLAGS_CTS_OFFSET=2048,d.Box.prototype.add=function(t){return this.addBox(new d[t+"Box"])},d.Box.prototype.addBox=function(t){return this.boxes.push(t),this[t.type+"s"]?this[t.type+"s"].push(t):this[t.type]=t,t},d.Box.prototype.set=function(t,e){return this[t]=e,this},d.Box.prototype.addEntry=function(t,e){var r=e||"entries";return this[r]||(this[r]=[]),this[r].push(t),this},iT.BoxParser=d,d.parseUUID=function(t){return d.parseHex16(t)},d.parseHex16=function(t){for(var e="",r=0;r<16;r++){var s=t.readUint8().toString(16);e+=1===s.length?"0"+s:s}return e},d.parseOneBox=function(t,e,r){var s,n,o,h=t.getPosition(),l=0;if(t.getEndPosition()-h<8)return a.debug("BoxParser","Not enough data in stream to parse the type and size of the box"),{code:d.ERR_NOT_ENOUGH_DATA};if(r&&r<8)return a.debug("BoxParser","Not enough bytes left in the parent box to parse a new box"),{code:d.ERR_NOT_ENOUGH_DATA};var u=t.readUint32(),f=t.readString(4),p=f;if(a.debug("BoxParser","Found box of type '"+f+"' and size "+u+" at position "+h),l=8,"uuid"==f){if(t.getEndPosition()-t.getPosition()<16||r-l<16)return t.seek(h),a.debug("BoxParser","Not enough bytes left in the parent box to parse a UUID box"),{code:d.ERR_NOT_ENOUGH_DATA};o=d.parseUUID(t),l+=16,p=o}if(1==u){if(t.getEndPosition()-t.getPosition()<8||r&&r-l<8)return t.seek(h),a.warn("BoxParser",'Not enough data in stream to parse the extended size of the "'+f+'" box'),{code:d.ERR_NOT_ENOUGH_DATA};u=t.readUint64(),l+=8}else if(0===u){if(r)u=r;else if("mdat"!==f)return a.error("BoxParser","Unlimited box size not supported for type: '"+f+"'"),s=new d.Box(f,u),{code:d.OK,box:s,size:s.size}}return 0!==u&&u<l?(a.error("BoxParser","Box of type "+f+" has an invalid size "+u+" (too small to be a box)"),{code:d.ERR_NOT_ENOUGH_DATA,type:f,size:u,hdr_size:l,start:h}):0!==u&&r&&u>r?(a.error("BoxParser","Box of type '"+f+"' has a size "+u+" greater than its container size "+r),{code:d.ERR_NOT_ENOUGH_DATA,type:f,size:u,hdr_size:l,start:h}):0!==u&&h+u>t.getEndPosition()?(t.seek(h),a.info("BoxParser","Not enough data in stream to parse the entire '"+f+"' box"),{code:d.ERR_NOT_ENOUGH_DATA,type:f,size:u,hdr_size:l,start:h}):e?{code:d.OK,type:f,size:u,hdr_size:l,start:h}:(d[f+"Box"]?s=new d[f+"Box"](u):"uuid"!==f?(a.warn("BoxParser","Unknown box type: '"+f+"'"),(s=new d.Box(f,u)).has_unparsed_data=!0):d.UUIDBoxes[o]?s=new d.UUIDBoxes[o](u):(a.warn("BoxParser","Unknown uuid type: '"+o+"'"),(s=new d.Box(f,u)).uuid=o,s.has_unparsed_data=!0),s.hdr_size=l,s.start=h,s.write===d.Box.prototype.write&&"mdat"!==s.type&&(a.info("BoxParser","'"+p+"' box writing not yet implemented, keeping unparsed data in memory for later write"),s.parseDataAndRewind(t)),s.parse(t),(n=t.getPosition()-(s.start+s.size))<0?(a.warn("BoxParser","Parsing of box '"+p+"' did not read the entire indicated box data size (missing "+-n+" bytes), seeking forward"),t.seek(s.start+s.size)):n>0&&(a.error("BoxParser","Parsing of box '"+p+"' read "+n+" more bytes than the indicated box data size, seeking backwards"),0!==s.size&&t.seek(s.start+s.size)),{code:d.OK,box:s,size:s.size})},d.Box.prototype.parse=function(t){"mdat"!=this.type?this.data=t.readUint8Array(this.size-this.hdr_size):0===this.size?t.seek(t.getEndPosition()):t.seek(this.start+this.size)},d.Box.prototype.parseDataAndRewind=function(t){this.data=t.readUint8Array(this.size-this.hdr_size),t.position-=this.size-this.hdr_size},d.FullBox.prototype.parseDataAndRewind=function(t){this.parseFullHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size),this.hdr_size-=4,t.position-=this.size-this.hdr_size},d.FullBox.prototype.parseFullHeader=function(t){this.version=t.readUint8(),this.flags=t.readUint24(),this.hdr_size+=4},d.FullBox.prototype.parse=function(t){this.parseFullHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size)},d.ContainerBox.prototype.parse=function(t){for(var e,r;t.getPosition()<this.start+this.size;)if((e=d.parseOneBox(t,!1,this.size-(t.getPosition()-this.start))).code!==d.OK)return;else if(r=e.box,this.boxes.push(r),this.subBoxNames&&-1!=this.subBoxNames.indexOf(r.type))this[this.subBoxNames[this.subBoxNames.indexOf(r.type)]+"s"].push(r);else{var s="uuid"!==r.type?r.type:r.uuid;this[s]?a.warn("Box of type "+s+" already stored in field of this type"):this[s]=r}},d.Box.prototype.parseLanguage=function(t){this.language=t.readUint16();var e=[];e[0]=this.language>>10&31,e[1]=this.language>>5&31,e[2]=31&this.language,this.languageString=String.fromCharCode(e[0]+96,e[1]+96,e[2]+96)},d.SAMPLE_ENTRY_TYPE_VISUAL="Visual",d.SAMPLE_ENTRY_TYPE_AUDIO="Audio",d.SAMPLE_ENTRY_TYPE_HINT="Hint",d.SAMPLE_ENTRY_TYPE_METADATA="Metadata",d.SAMPLE_ENTRY_TYPE_SUBTITLE="Subtitle",d.SAMPLE_ENTRY_TYPE_SYSTEM="System",d.SAMPLE_ENTRY_TYPE_TEXT="Text",d.SampleEntry.prototype.parseHeader=function(t){t.readUint8Array(6),this.data_reference_index=t.readUint16(),this.hdr_size+=8},d.SampleEntry.prototype.parse=function(t){this.parseHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size)},d.SampleEntry.prototype.parseDataAndRewind=function(t){this.parseHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size),this.hdr_size-=8,t.position-=this.size-this.hdr_size},d.SampleEntry.prototype.parseFooter=function(t){d.ContainerBox.prototype.parse.call(this,t)},d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_HINT),d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_METADATA),d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SUBTITLE),d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SYSTEM),d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_TEXT),d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,function(t){var e;this.parseHeader(t),t.readUint16(),t.readUint16(),t.readUint32Array(3),this.width=t.readUint16(),this.height=t.readUint16(),this.horizresolution=t.readUint32(),this.vertresolution=t.readUint32(),t.readUint32(),this.frame_count=t.readUint16(),e=Math.min(31,t.readUint8()),this.compressorname=t.readString(e),e<31&&t.readString(31-e),this.depth=t.readUint16(),t.readUint16(),this.parseFooter(t)}),d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,function(t){this.parseHeader(t),t.readUint32Array(2),this.channel_count=t.readUint16(),this.samplesize=t.readUint16(),t.readUint16(),t.readUint16(),this.samplerate=t.readUint32()/65536,this.parseFooter(t)}),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"avc1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"avc2"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"avc3"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"avc4"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"av01"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"dav1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"hvc1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"hev1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"hvt1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"lhe1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"dvh1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"dvhe"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"vvc1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"vvi1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"vvs1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"vvcN"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"vp08"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"vp09"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"avs3"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"j2ki"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"mjp2"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"mjpg"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"uncv"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"mp4a"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"ac-3"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"ac-4"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"ec-3"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"Opus"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"mha1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"mha2"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"mhm1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"mhm2"),d.createEncryptedSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"encv"),d.createEncryptedSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"enca"),d.createEncryptedSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SUBTITLE,"encu"),d.createEncryptedSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SYSTEM,"encs"),d.createEncryptedSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_TEXT,"enct"),d.createEncryptedSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_METADATA,"encm"),d.createBoxCtor("a1lx",function(t){var e=((1&(1&t.readUint8()))+1)*16;this.layer_size=[];for(var r=0;r<3;r++)16==e?this.layer_size[r]=t.readUint16():this.layer_size[r]=t.readUint32()}),d.createBoxCtor("a1op",function(t){this.op_index=t.readUint8()}),d.createFullBoxCtor("auxC",function(t){this.aux_type=t.readCString();var e=this.size-this.hdr_size-(this.aux_type.length+1);this.aux_subtype=t.readUint8Array(e)}),d.createBoxCtor("av1C",function(t){var e=t.readUint8();if(this.version=127&e,1!==this.version){a.error("av1C version "+this.version+" not supported");return}if(e=t.readUint8(),this.seq_profile=e>>5&7,this.seq_level_idx_0=31&e,e=t.readUint8(),this.seq_tier_0=e>>7&1,this.high_bitdepth=e>>6&1,this.twelve_bit=e>>5&1,this.monochrome=e>>4&1,this.chroma_subsampling_x=e>>3&1,this.chroma_subsampling_y=e>>2&1,this.chroma_sample_position=3&e,e=t.readUint8(),this.reserved_1=e>>5&7,0!==this.reserved_1){a.error("av1C reserved_1 parsing problem");return}if(this.initial_presentation_delay_present=e>>4&1,1===this.initial_presentation_delay_present)this.initial_presentation_delay_minus_one=15&e;else if(this.reserved_2=15&e,0!==this.reserved_2){a.error("av1C reserved_2 parsing problem");return}var r=this.size-this.hdr_size-4;this.configOBUs=t.readUint8Array(r)}),d.createBoxCtor("avcC",function(t){var e,r;for(this.configurationVersion=t.readUint8(),this.AVCProfileIndication=t.readUint8(),this.profile_compatibility=t.readUint8(),this.AVCLevelIndication=t.readUint8(),this.lengthSizeMinusOne=3&t.readUint8(),this.nb_SPS_nalus=31&t.readUint8(),r=this.size-this.hdr_size-6,this.SPS=[],e=0;e<this.nb_SPS_nalus;e++)this.SPS[e]={},this.SPS[e].length=t.readUint16(),this.SPS[e].nalu=t.readUint8Array(this.SPS[e].length),r-=2+this.SPS[e].length;for(this.nb_PPS_nalus=t.readUint8(),r--,this.PPS=[],e=0;e<this.nb_PPS_nalus;e++)this.PPS[e]={},this.PPS[e].length=t.readUint16(),this.PPS[e].nalu=t.readUint8Array(this.PPS[e].length),r-=2+this.PPS[e].length;r>0&&(this.ext=t.readUint8Array(r))}),d.createBoxCtor("btrt",function(t){this.bufferSizeDB=t.readUint32(),this.maxBitrate=t.readUint32(),this.avgBitrate=t.readUint32()}),d.createFullBoxCtor("ccst",function(t){var e=t.readUint8();this.all_ref_pics_intra=(128&e)==128,this.intra_pred_used=(64&e)==64,this.max_ref_per_pic=(63&e)>>2,t.readUint24()}),d.createBoxCtor("cdef",function(t){var e;for(this.channel_count=t.readUint16(),this.channel_indexes=[],this.channel_types=[],this.channel_associations=[],e=0;e<this.channel_count;e++)this.channel_indexes.push(t.readUint16()),this.channel_types.push(t.readUint16()),this.channel_associations.push(t.readUint16())}),d.createBoxCtor("clap",function(t){this.cleanApertureWidthN=t.readUint32(),this.cleanApertureWidthD=t.readUint32(),this.cleanApertureHeightN=t.readUint32(),this.cleanApertureHeightD=t.readUint32(),this.horizOffN=t.readUint32(),this.horizOffD=t.readUint32(),this.vertOffN=t.readUint32(),this.vertOffD=t.readUint32()}),d.createBoxCtor("clli",function(t){this.max_content_light_level=t.readUint16(),this.max_pic_average_light_level=t.readUint16()}),d.createFullBoxCtor("cmex",function(t){1&this.flags&&(this.pos_x=t.readInt32()),2&this.flags&&(this.pos_y=t.readInt32()),4&this.flags&&(this.pos_z=t.readInt32()),8&this.flags&&(0==this.version?16&this.flags?(this.quat_x=t.readInt32(),this.quat_y=t.readInt32(),this.quat_z=t.readInt32()):(this.quat_x=t.readInt16(),this.quat_y=t.readInt16(),this.quat_z=t.readInt16()):this.version),32&this.flags&&(this.id=t.readUint32())}),d.createFullBoxCtor("cmin",function(t){this.focal_length_x=t.readInt32(),this.principal_point_x=t.readInt32(),this.principal_point_y=t.readInt32(),1&this.flags&&(this.focal_length_y=t.readInt32(),this.skew_factor=t.readInt32())}),d.createBoxCtor("cmpd",function(t){for(this.component_count=t.readUint16(),this.component_types=[],this.component_type_urls=[],i=0;i<this.component_count;i++){var e=t.readUint16();this.component_types.push(e),e>=32768&&this.component_type_urls.push(t.readCString())}}),d.createFullBoxCtor("co64",function(t){var e,r;if(e=t.readUint32(),this.chunk_offsets=[],0===this.version)for(r=0;r<e;r++)this.chunk_offsets.push(t.readUint64())}),d.createFullBoxCtor("CoLL",function(t){this.maxCLL=t.readUint16(),this.maxFALL=t.readUint16()}),d.createBoxCtor("colr",function(t){if(this.colour_type=t.readString(4),"nclx"===this.colour_type){this.colour_primaries=t.readUint16(),this.transfer_characteristics=t.readUint16(),this.matrix_coefficients=t.readUint16();var e=t.readUint8();this.full_range_flag=e>>7}else"rICC"===this.colour_type?this.ICC_profile=t.readUint8Array(this.size-4):"prof"===this.colour_type&&(this.ICC_profile=t.readUint8Array(this.size-4))}),d.createFullBoxCtor("cprt",function(t){this.parseLanguage(t),this.notice=t.readCString()}),d.createFullBoxCtor("cslg",function(t){0===this.version&&(this.compositionToDTSShift=t.readInt32(),this.leastDecodeToDisplayDelta=t.readInt32(),this.greatestDecodeToDisplayDelta=t.readInt32(),this.compositionStartTime=t.readInt32(),this.compositionEndTime=t.readInt32())}),d.createFullBoxCtor("ctts",function(t){var e,r;if(e=t.readUint32(),this.sample_counts=[],this.sample_offsets=[],0===this.version)for(r=0;r<e;r++){this.sample_counts.push(t.readUint32());var s=t.readInt32();s<0&&a.warn("BoxParser","ctts box uses negative values without using version 1"),this.sample_offsets.push(s)}else if(1==this.version)for(r=0;r<e;r++)this.sample_counts.push(t.readUint32()),this.sample_offsets.push(t.readInt32())}),d.createBoxCtor("dac3",function(t){var e=t.readUint8(),r=t.readUint8(),s=t.readUint8();this.fscod=e>>6,this.bsid=e>>1&31,this.bsmod=(1&e)<<2|r>>6&3,this.acmod=r>>3&7,this.lfeon=r>>2&1,this.bit_rate_code=3&r|s>>5&7}),d.createBoxCtor("dec3",function(t){var e=t.readUint16();this.data_rate=e>>3,this.num_ind_sub=7&e,this.ind_subs=[];for(var r=0;r<this.num_ind_sub+1;r++){var s={};this.ind_subs.push(s);var n=t.readUint8(),a=t.readUint8(),o=t.readUint8();s.fscod=n>>6,s.bsid=n>>1&31,s.bsmod=(1&n)<<4|a>>4&15,s.acmod=a>>1&7,s.lfeon=1&a,s.num_dep_sub=o>>1&15,s.num_dep_sub>0&&(s.chan_loc=(1&o)<<8|t.readUint8())}}),d.createFullBoxCtor("dfLa",function(t){var e=[],r=["STREAMINFO","PADDING","APPLICATION","SEEKTABLE","VORBIS_COMMENT","CUESHEET","PICTURE","RESERVED"];for(this.parseFullHeader(t);;){var s=t.readUint8(),n=Math.min(127&s,r.length-1);if(n?t.readUint8Array(t.readUint24()):(t.readUint8Array(13),this.samplerate=t.readUint32()>>12,t.readUint8Array(20)),e.push(r[n]),128&s)break}this.numMetadataBlocks=e.length+" ("+e.join(", ")+")"}),d.createBoxCtor("dimm",function(t){this.bytessent=t.readUint64()}),d.createBoxCtor("dmax",function(t){this.time=t.readUint32()}),d.createBoxCtor("dmed",function(t){this.bytessent=t.readUint64()}),d.createBoxCtor("dOps",function(t){if(this.Version=t.readUint8(),this.OutputChannelCount=t.readUint8(),this.PreSkip=t.readUint16(),this.InputSampleRate=t.readUint32(),this.OutputGain=t.readInt16(),this.ChannelMappingFamily=t.readUint8(),0!==this.ChannelMappingFamily){this.StreamCount=t.readUint8(),this.CoupledCount=t.readUint8(),this.ChannelMapping=[];for(var e=0;e<this.OutputChannelCount;e++)this.ChannelMapping[e]=t.readUint8()}}),d.createFullBoxCtor("dref",function(t){var e,r;this.entries=[];for(var s=t.readUint32(),n=0;n<s;n++)if((e=d.parseOneBox(t,!1,this.size-(t.getPosition()-this.start))).code!==d.OK)return;else r=e.box,this.entries.push(r)}),d.createBoxCtor("drep",function(t){this.bytessent=t.readUint64()}),d.createFullBoxCtor("elng",function(t){this.extended_language=t.readString(this.size-this.hdr_size)}),d.createFullBoxCtor("elst",function(t){this.entries=[];for(var e=t.readUint32(),r=0;r<e;r++){var s={};this.entries.push(s),1===this.version?(s.segment_duration=t.readUint64(),s.media_time=t.readInt64()):(s.segment_duration=t.readUint32(),s.media_time=t.readInt32()),s.media_rate_integer=t.readInt16(),s.media_rate_fraction=t.readInt16()}}),d.createFullBoxCtor("emsg",function(t){1==this.version?(this.timescale=t.readUint32(),this.presentation_time=t.readUint64(),this.event_duration=t.readUint32(),this.id=t.readUint32(),this.scheme_id_uri=t.readCString(),this.value=t.readCString()):(this.scheme_id_uri=t.readCString(),this.value=t.readCString(),this.timescale=t.readUint32(),this.presentation_time_delta=t.readUint32(),this.event_duration=t.readUint32(),this.id=t.readUint32());var e=this.size-this.hdr_size-(16+(this.scheme_id_uri.length+1)+(this.value.length+1));1==this.version&&(e-=4),this.message_data=t.readUint8Array(e)}),d.createEntityToGroupCtor=function(t,e){d[t+"Box"]=function(e){d.FullBox.call(this,t,e)},d[t+"Box"].prototype=new d.FullBox,d[t+"Box"].prototype.parse=function(t){if(this.parseFullHeader(t),e)e.call(this,t);else for(this.group_id=t.readUint32(),this.num_entities_in_group=t.readUint32(),this.entity_ids=[],i=0;i<this.num_entities_in_group;i++){var r=t.readUint32();this.entity_ids.push(r)}}},d.createEntityToGroupCtor("aebr"),d.createEntityToGroupCtor("afbr"),d.createEntityToGroupCtor("albc"),d.createEntityToGroupCtor("altr"),d.createEntityToGroupCtor("brst"),d.createEntityToGroupCtor("dobr"),d.createEntityToGroupCtor("eqiv"),d.createEntityToGroupCtor("favc"),d.createEntityToGroupCtor("fobr"),d.createEntityToGroupCtor("iaug"),d.createEntityToGroupCtor("pano"),d.createEntityToGroupCtor("slid"),d.createEntityToGroupCtor("ster"),d.createEntityToGroupCtor("tsyn"),d.createEntityToGroupCtor("wbbr"),d.createEntityToGroupCtor("prgr"),d.createFullBoxCtor("esds",function(t){var e=t.readUint8Array(this.size-this.hdr_size);if(this.data=e,"u">typeof u){var r=new u;this.esd=r.parseOneDescriptor(new h(e.buffer,0,h.BIG_ENDIAN))}}),d.createBoxCtor("fiel",function(t){this.fieldCount=t.readUint8(),this.fieldOrdering=t.readUint8()}),d.createBoxCtor("frma",function(t){this.data_format=t.readString(4)}),d.createBoxCtor("ftyp",function(t){var e=this.size-this.hdr_size;this.major_brand=t.readString(4),this.minor_version=t.readUint32(),e-=8,this.compatible_brands=[];for(var r=0;e>=4;)this.compatible_brands[r]=t.readString(4),e-=4,r++}),d.createFullBoxCtor("hdlr",function(t){0===this.version&&(t.readUint32(),this.handler=t.readString(4),t.readUint32Array(3),this.name=t.readString(this.size-this.hdr_size-20),"\0"===this.name[this.name.length-1]&&(this.name=this.name.slice(0,-1)))}),d.createBoxCtor("hvcC",function(t){this.configurationVersion=t.readUint8(),n=t.readUint8(),this.general_profile_space=n>>6,this.general_tier_flag=(32&n)>>5,this.general_profile_idc=31&n,this.general_profile_compatibility=t.readUint32(),this.general_constraint_indicator=t.readUint8Array(6),this.general_level_idc=t.readUint8(),this.min_spatial_segmentation_idc=4095&t.readUint16(),this.parallelismType=3&t.readUint8(),this.chroma_format_idc=3&t.readUint8(),this.bit_depth_luma_minus8=7&t.readUint8(),this.bit_depth_chroma_minus8=7&t.readUint8(),this.avgFrameRate=t.readUint16(),n=t.readUint8(),this.constantFrameRate=n>>6,this.numTemporalLayers=(13&n)>>3,this.temporalIdNested=(4&n)>>2,this.lengthSizeMinusOne=3&n,this.nalu_arrays=[];var e,r,s,n,a=t.readUint8();for(e=0;e<a;e++){var o=[];this.nalu_arrays.push(o),n=t.readUint8(),o.completeness=(128&n)>>7,o.nalu_type=63&n;var h=t.readUint16();for(r=0;r<h;r++){var l={};o.push(l),s=t.readUint16(),l.data=t.readUint8Array(s)}}}),d.createFullBoxCtor("iinf",function(t){var e;0===this.version?this.entry_count=t.readUint16():this.entry_count=t.readUint32(),this.item_infos=[];for(var r=0;r<this.entry_count;r++)if((e=d.parseOneBox(t,!1,this.size-(t.getPosition()-this.start))).code!==d.OK)return;else"infe"!==e.box.type&&a.error("BoxParser","Expected 'infe' box, got "+e.box.type),this.item_infos[r]=e.box}),d.createFullBoxCtor("iloc",function(t){e=t.readUint8(),this.offset_size=e>>4&15,this.length_size=15&e,e=t.readUint8(),this.base_offset_size=e>>4&15,1===this.version||2===this.version?this.index_size=15&e:this.index_size=0,this.items=[];var e,r=0;if(this.version<2)r=t.readUint16();else if(2===this.version)r=t.readUint32();else throw"version of iloc box not supported";for(var s=0;s<r;s++){var n={};if(this.items.push(n),this.version<2)n.item_ID=t.readUint16();else if(2===this.version)n.item_ID=t.readUint16();else throw"version of iloc box not supported";switch(1===this.version||2===this.version?n.construction_method=15&t.readUint16():n.construction_method=0,n.data_reference_index=t.readUint16(),this.base_offset_size){case 0:n.base_offset=0;break;case 4:n.base_offset=t.readUint32();break;case 8:n.base_offset=t.readUint64();break;default:throw"Error reading base offset size"}var a=t.readUint16();n.extents=[];for(var o=0;o<a;o++){var h={};if(n.extents.push(h),1===this.version||2===this.version)switch(this.index_size){case 0:h.extent_index=0;break;case 4:h.extent_index=t.readUint32();break;case 8:h.extent_index=t.readUint64();break;default:throw"Error reading extent index"}switch(this.offset_size){case 0:h.extent_offset=0;break;case 4:h.extent_offset=t.readUint32();break;case 8:h.extent_offset=t.readUint64();break;default:throw"Error reading extent index"}switch(this.length_size){case 0:h.extent_length=0;break;case 4:h.extent_length=t.readUint32();break;case 8:h.extent_length=t.readUint64();break;default:throw"Error reading extent index"}}}}),d.createBoxCtor("imir",function(t){var e=t.readUint8();this.reserved=e>>7,this.axis=1&e}),d.createFullBoxCtor("infe",function(t){if((0===this.version||1===this.version)&&(this.item_ID=t.readUint16(),this.item_protection_index=t.readUint16(),this.item_name=t.readCString(),this.content_type=t.readCString(),this.content_encoding=t.readCString()),1===this.version){this.extension_type=t.readString(4),a.warn("BoxParser","Cannot parse extension type"),t.seek(this.start+this.size);return}this.version>=2&&(2===this.version?this.item_ID=t.readUint16():3===this.version&&(this.item_ID=t.readUint32()),this.item_protection_index=t.readUint16(),this.item_type=t.readString(4),this.item_name=t.readCString(),"mime"===this.item_type?(this.content_type=t.readCString(),this.content_encoding=t.readCString()):"uri "===this.item_type&&(this.item_uri_type=t.readCString()))}),d.createFullBoxCtor("ipma",function(t){var e,r;for(entry_count=t.readUint32(),this.associations=[],e=0;e<entry_count;e++){var s={};this.associations.push(s),this.version<1?s.id=t.readUint16():s.id=t.readUint32();var n=t.readUint8();for(s.props=[],r=0;r<n;r++){var a=t.readUint8(),o={};s.props.push(o),o.essential=(128&a)>>7==1,1&this.flags?o.property_index=(127&a)<<8|t.readUint8():o.property_index=127&a}}}),d.createFullBoxCtor("iref",function(t){var e,r;for(this.references=[];t.getPosition()<this.start+this.size;)if((e=d.parseOneBox(t,!0,this.size-(t.getPosition()-this.start))).code!==d.OK)return;else(r=0===this.version?new d.SingleItemTypeReferenceBox(e.type,e.size,e.hdr_size,e.start):new d.SingleItemTypeReferenceBoxLarge(e.type,e.size,e.hdr_size,e.start)).write===d.Box.prototype.write&&"mdat"!==r.type&&(a.warn("BoxParser",r.type+" box writing not yet implemented, keeping unparsed data in memory for later write"),r.parseDataAndRewind(t)),r.parse(t),this.references.push(r)}),d.createBoxCtor("irot",function(t){this.angle=3&t.readUint8()}),d.createFullBoxCtor("ispe",function(t){this.image_width=t.readUint32(),this.image_height=t.readUint32()}),d.createFullBoxCtor("kind",function(t){this.schemeURI=t.readCString(),this.value=t.readCString()}),d.createFullBoxCtor("leva",function(t){var e=t.readUint8();this.levels=[];for(var r=0;r<e;r++){var s={};this.levels[r]=s,s.track_ID=t.readUint32();var n=t.readUint8();switch(s.padding_flag=n>>7,s.assignment_type=127&n,s.assignment_type){case 0:s.grouping_type=t.readString(4);break;case 1:s.grouping_type=t.readString(4),s.grouping_type_parameter=t.readUint32();break;case 2:case 3:break;case 4:s.sub_track_id=t.readUint32();break;default:a.warn("BoxParser","Unknown leva assignement type")}}}),d.createBoxCtor("lsel",function(t){this.layer_id=t.readUint16()}),d.createBoxCtor("maxr",function(t){this.period=t.readUint32(),this.bytes=t.readUint32()}),d.createBoxCtor("mdcv",function(t){this.display_primaries=[],this.display_primaries[0]={},this.display_primaries[0].x=t.readUint16(),this.display_primaries[0].y=t.readUint16(),this.display_primaries[1]={},this.display_primaries[1].x=t.readUint16(),this.display_primaries[1].y=t.readUint16(),this.display_primaries[2]={},this.display_primaries[2].x=t.readUint16(),this.display_primaries[2].y=t.readUint16(),this.white_point={},this.white_point.x=t.readUint16(),this.white_point.y=t.readUint16(),this.max_display_mastering_luminance=t.readUint32(),this.min_display_mastering_luminance=t.readUint32()}),d.createFullBoxCtor("mdhd",function(t){1==this.version?(this.creation_time=t.readUint64(),this.modification_time=t.readUint64(),this.timescale=t.readUint32(),this.duration=t.readUint64()):(this.creation_time=t.readUint32(),this.modification_time=t.readUint32(),this.timescale=t.readUint32(),this.duration=t.readUint32()),this.parseLanguage(t),t.readUint16()}),d.createFullBoxCtor("mehd",function(t){1&this.flags&&(a.warn("BoxParser","mehd box incorrectly uses flags set to 1, converting version to 1"),this.version=1),1==this.version?this.fragment_duration=t.readUint64():this.fragment_duration=t.readUint32()}),d.createFullBoxCtor("meta",function(t){this.boxes=[],d.ContainerBox.prototype.parse.call(this,t)}),d.createFullBoxCtor("mfhd",function(t){this.sequence_number=t.readUint32()}),d.createFullBoxCtor("mfro",function(t){this._size=t.readUint32()}),d.createFullBoxCtor("mvhd",function(t){1==this.version?(this.creation_time=t.readUint64(),this.modification_time=t.readUint64(),this.timescale=t.readUint32(),this.duration=t.readUint64()):(this.creation_time=t.readUint32(),this.modification_time=t.readUint32(),this.timescale=t.readUint32(),this.duration=t.readUint32()),this.rate=t.readUint32(),this.volume=t.readUint16()>>8,t.readUint16(),t.readUint32Array(2),this.matrix=t.readUint32Array(9),t.readUint32Array(6),this.next_track_id=t.readUint32()}),d.createBoxCtor("npck",function(t){this.packetssent=t.readUint32()}),d.createBoxCtor("nump",function(t){this.packetssent=t.readUint64()}),d.createFullBoxCtor("padb",function(t){var e=t.readUint32();this.padbits=[];for(var r=0;r<Math.floor((e+1)/2);r++)this.padbits=t.readUint8()}),d.createBoxCtor("pasp",function(t){this.hSpacing=t.readUint32(),this.vSpacing=t.readUint32()}),d.createBoxCtor("payl",function(t){this.text=t.readString(this.size-this.hdr_size)}),d.createBoxCtor("payt",function(t){this.payloadID=t.readUint32();var e=t.readUint8();this.rtpmap_string=t.readString(e)}),d.createFullBoxCtor("pdin",function(t){var e=(this.size-this.hdr_size)/8;this.rate=[],this.initial_delay=[];for(var r=0;r<e;r++)this.rate[r]=t.readUint32(),this.initial_delay[r]=t.readUint32()}),d.createFullBoxCtor("pitm",function(t){0===this.version?this.item_id=t.readUint16():this.item_id=t.readUint32()}),d.createFullBoxCtor("pixi",function(t){var e;for(this.num_channels=t.readUint8(),this.bits_per_channels=[],e=0;e<this.num_channels;e++)this.bits_per_channels[e]=t.readUint8()}),d.createBoxCtor("pmax",function(t){this.bytes=t.readUint32()}),d.createFullBoxCtor("prdi",function(t){if(this.step_count=t.readUint16(),this.item_count=[],2&this.flags)for(var e=0;e<this.step_count;e++)this.item_count[e]=t.readUint16()}),d.createFullBoxCtor("prft",function(t){this.ref_track_id=t.readUint32(),this.ntp_timestamp=t.readUint64(),0===this.version?this.media_time=t.readUint32():this.media_time=t.readUint64()}),d.createFullBoxCtor("pssh",function(t){if(this.system_id=d.parseHex16(t),this.version>0){var e=t.readUint32();this.kid=[];for(var r=0;r<e;r++)this.kid[r]=d.parseHex16(t)}var s=t.readUint32();s>0&&(this.data=t.readUint8Array(s))}),d.createFullBoxCtor("clef",function(t){this.width=t.readUint32(),this.height=t.readUint32()}),d.createFullBoxCtor("enof",function(t){this.width=t.readUint32(),this.height=t.readUint32()}),d.createFullBoxCtor("prof",function(t){this.width=t.readUint32(),this.height=t.readUint32()}),d.createContainerBoxCtor("tapt",null,["clef","prof","enof"]),d.createBoxCtor("rtp ",function(t){this.descriptionformat=t.readString(4),this.sdptext=t.readString(this.size-this.hdr_size-4)}),d.createFullBoxCtor("saio",function(t){1&this.flags&&(this.aux_info_type=t.readUint32(),this.aux_info_type_parameter=t.readUint32());var e=t.readUint32();this.offset=[];for(var r=0;r<e;r++)0===this.version?this.offset[r]=t.readUint32():this.offset[r]=t.readUint64()}),d.createFullBoxCtor("saiz",function(t){1&this.flags&&(this.aux_info_type=t.readUint32(),this.aux_info_type_parameter=t.readUint32()),this.default_sample_info_size=t.readUint8();var e=t.readUint32();if(this.sample_info_size=[],0===this.default_sample_info_size)for(var r=0;r<e;r++)this.sample_info_size[r]=t.readUint8()}),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_METADATA,"mett",function(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.mime_format=t.readCString(),this.parseFooter(t)}),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_METADATA,"metx",function(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.namespace=t.readCString(),this.schema_location=t.readCString(),this.parseFooter(t)}),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SUBTITLE,"sbtt",function(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.mime_format=t.readCString(),this.parseFooter(t)}),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SUBTITLE,"stpp",function(t){this.parseHeader(t),this.namespace=t.readCString(),this.schema_location=t.readCString(),this.auxiliary_mime_types=t.readCString(),this.parseFooter(t)}),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SUBTITLE,"stxt",function(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.mime_format=t.readCString(),this.parseFooter(t)}),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SUBTITLE,"tx3g",function(t){this.parseHeader(t),this.displayFlags=t.readUint32(),this.horizontal_justification=t.readInt8(),this.vertical_justification=t.readInt8(),this.bg_color_rgba=t.readUint8Array(4),this.box_record=t.readInt16Array(4),this.style_record=t.readUint8Array(12),this.parseFooter(t)}),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_METADATA,"wvtt",function(t){this.parseHeader(t),this.parseFooter(t)}),d.createSampleGroupCtor("alst",function(t){var e,r=t.readUint16();for(this.first_output_sample=t.readUint16(),this.sample_offset=[],e=0;e<r;e++)this.sample_offset[e]=t.readUint32();var s=this.description_length-4-4*r;for(this.num_output_samples=[],this.num_total_samples=[],e=0;e<s/4;e++)this.num_output_samples[e]=t.readUint16(),this.num_total_samples[e]=t.readUint16()}),d.createSampleGroupCtor("avll",function(t){this.layerNumber=t.readUint8(),this.accurateStatisticsFlag=t.readUint8(),this.avgBitRate=t.readUint16(),this.avgFrameRate=t.readUint16()}),d.createSampleGroupCtor("avss",function(t){this.subSequenceIdentifier=t.readUint16(),this.layerNumber=t.readUint8();var e=t.readUint8();this.durationFlag=e>>7,this.avgRateFlag=e>>6&1,this.durationFlag&&(this.duration=t.readUint32()),this.avgRateFlag&&(this.accurateStatisticsFlag=t.readUint8(),this.avgBitRate=t.readUint16(),this.avgFrameRate=t.readUint16()),this.dependency=[];for(var r=t.readUint8(),s=0;s<r;s++){var n={};this.dependency.push(n),n.subSeqDirectionFlag=t.readUint8(),n.layerNumber=t.readUint8(),n.subSequenceIdentifier=t.readUint16()}}),d.createSampleGroupCtor("dtrt",function(t){a.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createSampleGroupCtor("mvif",function(t){a.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createSampleGroupCtor("prol",function(t){this.roll_distance=t.readInt16()}),d.createSampleGroupCtor("rap ",function(t){var e=t.readUint8();this.num_leading_samples_known=e>>7,this.num_leading_samples=127&e}),d.createSampleGroupCtor("rash",function(t){if(this.operation_point_count=t.readUint16(),this.description_length!==2+(1===this.operation_point_count?2:6*this.operation_point_count)+9)a.warn("BoxParser","Mismatch in "+this.grouping_type+" sample group length"),this.data=t.readUint8Array(this.description_length-2);else{if(1===this.operation_point_count)this.target_rate_share=t.readUint16();else{this.target_rate_share=[],this.available_bitrate=[];for(var e=0;e<this.operation_point_count;e++)this.available_bitrate[e]=t.readUint32(),this.target_rate_share[e]=t.readUint16()}this.maximum_bitrate=t.readUint32(),this.minimum_bitrate=t.readUint32(),this.discard_priority=t.readUint8()}}),d.createSampleGroupCtor("roll",function(t){this.roll_distance=t.readInt16()}),d.SampleGroupEntry.prototype.parse=function(t){a.warn("BoxParser","Unknown Sample Group type: "+this.grouping_type),this.data=t.readUint8Array(this.description_length)},d.createSampleGroupCtor("scif",function(t){a.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createSampleGroupCtor("scnm",function(t){a.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createSampleGroupCtor("seig",function(t){this.reserved=t.readUint8();var e=t.readUint8();this.crypt_byte_block=e>>4,this.skip_byte_block=15&e,this.isProtected=t.readUint8(),this.Per_Sample_IV_Size=t.readUint8(),this.KID=d.parseHex16(t),this.constant_IV_size=0,this.constant_IV=0,1===this.isProtected&&0===this.Per_Sample_IV_Size&&(this.constant_IV_size=t.readUint8(),this.constant_IV=t.readUint8Array(this.constant_IV_size))}),d.createSampleGroupCtor("stsa",function(t){a.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createSampleGroupCtor("sync",function(t){var e=t.readUint8();this.NAL_unit_type=63&e}),d.createSampleGroupCtor("tele",function(t){var e=t.readUint8();this.level_independently_decodable=e>>7}),d.createSampleGroupCtor("tsas",function(t){a.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createSampleGroupCtor("tscl",function(t){a.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createSampleGroupCtor("vipr",function(t){a.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createFullBoxCtor("sbgp",function(t){this.grouping_type=t.readString(4),1===this.version?this.grouping_type_parameter=t.readUint32():this.grouping_type_parameter=0,this.entries=[];for(var e=t.readUint32(),r=0;r<e;r++){var s={};this.entries.push(s),s.sample_count=t.readInt32(),s.group_description_index=t.readInt32()}}),d.createFullBoxCtor("schm",function(t){this.scheme_type=t.readString(4),this.scheme_version=t.readUint32(),1&this.flags&&(this.scheme_uri=t.readString(this.size-this.hdr_size-8))}),d.createBoxCtor("sdp ",function(t){this.sdptext=t.readString(this.size-this.hdr_size)}),d.createFullBoxCtor("sdtp",function(t){var e,r=this.size-this.hdr_size;this.is_leading=[],this.sample_depends_on=[],this.sample_is_depended_on=[],this.sample_has_redundancy=[];for(var s=0;s<r;s++)e=t.readUint8(),this.is_leading[s]=e>>6,this.sample_depends_on[s]=e>>4&3,this.sample_is_depended_on[s]=e>>2&3,this.sample_has_redundancy[s]=3&e}),d.createFullBoxCtor("senc"),d.createFullBoxCtor("sgpd",function(t){this.grouping_type=t.readString(4),a.debug("BoxParser","Found Sample Groups of type "+this.grouping_type),1===this.version?this.default_length=t.readUint32():this.default_length=0,this.version>=2&&(this.default_group_description_index=t.readUint32()),this.entries=[];for(var e,r=t.readUint32(),s=0;s<r;s++)e=d[this.grouping_type+"SampleGroupEntry"]?new d[this.grouping_type+"SampleGroupEntry"](this.grouping_type):new d.SampleGroupEntry(this.grouping_type),this.entries.push(e),1===this.version&&0===this.default_length?e.description_length=t.readUint32():e.description_length=this.default_length,e.write===d.SampleGroupEntry.prototype.write&&(a.info("BoxParser","SampleGroup for type "+this.grouping_type+" writing not yet implemented, keeping unparsed data in memory for later write"),e.data=t.readUint8Array(e.description_length),t.position-=e.description_length),e.parse(t)}),d.createFullBoxCtor("sidx",function(t){this.reference_ID=t.readUint32(),this.timescale=t.readUint32(),0===this.version?(this.earliest_presentation_time=t.readUint32(),this.first_offset=t.readUint32()):(this.earliest_presentation_time=t.readUint64(),this.first_offset=t.readUint64()),t.readUint16(),this.references=[];for(var e=t.readUint16(),r=0;r<e;r++){var s={};this.references.push(s);var n=t.readUint32();s.reference_type=n>>31&1,s.referenced_size=2147483647&n,s.subsegment_duration=t.readUint32(),n=t.readUint32(),s.starts_with_SAP=n>>31&1,s.SAP_type=n>>28&7,s.SAP_delta_time=268435455&n}}),d.SingleItemTypeReferenceBox=function(t,e,r,s){d.Box.call(this,t,e),this.hdr_size=r,this.start=s},d.SingleItemTypeReferenceBox.prototype=new d.Box,d.SingleItemTypeReferenceBox.prototype.parse=function(t){this.from_item_ID=t.readUint16();var e=t.readUint16();this.references=[];for(var r=0;r<e;r++)this.references[r]={},this.references[r].to_item_ID=t.readUint16()},d.SingleItemTypeReferenceBoxLarge=function(t,e,r,s){d.Box.call(this,t,e),this.hdr_size=r,this.start=s},d.SingleItemTypeReferenceBoxLarge.prototype=new d.Box,d.SingleItemTypeReferenceBoxLarge.prototype.parse=function(t){this.from_item_ID=t.readUint32();var e=t.readUint16();this.references=[];for(var r=0;r<e;r++)this.references[r]={},this.references[r].to_item_ID=t.readUint32()},d.createFullBoxCtor("SmDm",function(t){this.primaryRChromaticity_x=t.readUint16(),this.primaryRChromaticity_y=t.readUint16(),this.primaryGChromaticity_x=t.readUint16(),this.primaryGChromaticity_y=t.readUint16(),this.primaryBChromaticity_x=t.readUint16(),this.primaryBChromaticity_y=t.readUint16(),this.whitePointChromaticity_x=t.readUint16(),this.whitePointChromaticity_y=t.readUint16(),this.luminanceMax=t.readUint32(),this.luminanceMin=t.readUint32()}),d.createFullBoxCtor("smhd",function(t){this.balance=t.readUint16(),t.readUint16()}),d.createFullBoxCtor("ssix",function(t){this.subsegments=[];for(var e=t.readUint32(),r=0;r<e;r++){var s={};this.subsegments.push(s),s.ranges=[];for(var n=t.readUint32(),a=0;a<n;a++){var o={};s.ranges.push(o),o.level=t.readUint8(),o.range_size=t.readUint24()}}}),d.createFullBoxCtor("stco",function(t){var e;if(e=t.readUint32(),this.chunk_offsets=[],0===this.version)for(var r=0;r<e;r++)this.chunk_offsets.push(t.readUint32())}),d.createFullBoxCtor("stdp",function(t){var e=(this.size-this.hdr_size)/2;this.priority=[];for(var r=0;r<e;r++)this.priority[r]=t.readUint16()}),d.createFullBoxCtor("sthd"),d.createFullBoxCtor("stri",function(t){this.switch_group=t.readUint16(),this.alternate_group=t.readUint16(),this.sub_track_id=t.readUint32();var e=(this.size-this.hdr_size-8)/4;this.attribute_list=[];for(var r=0;r<e;r++)this.attribute_list[r]=t.readUint32()}),d.createFullBoxCtor("stsc",function(t){var e,r;if(e=t.readUint32(),this.first_chunk=[],this.samples_per_chunk=[],this.sample_description_index=[],0===this.version)for(r=0;r<e;r++)this.first_chunk.push(t.readUint32()),this.samples_per_chunk.push(t.readUint32()),this.sample_description_index.push(t.readUint32())}),d.createFullBoxCtor("stsd",function(t){var e,r,s,n;for(this.entries=[],s=t.readUint32(),e=1;e<=s;e++)if((r=d.parseOneBox(t,!0,this.size-(t.getPosition()-this.start))).code!==d.OK)return;else d[r.type+"SampleEntry"]?((n=new d[r.type+"SampleEntry"](r.size)).hdr_size=r.hdr_size,n.start=r.start):(a.warn("BoxParser","Unknown sample entry type: "+r.type),n=new d.SampleEntry(r.type,r.size,r.hdr_size,r.start)),n.write===d.SampleEntry.prototype.write&&(a.info("BoxParser","SampleEntry "+n.type+" box writing not yet implemented, keeping unparsed data in memory for later write"),n.parseDataAndRewind(t)),n.parse(t),this.entries.push(n)}),d.createFullBoxCtor("stsg",function(t){this.grouping_type=t.readUint32();var e=t.readUint16();this.group_description_index=[];for(var r=0;r<e;r++)this.group_description_index[r]=t.readUint32()}),d.createFullBoxCtor("stsh",function(t){var e,r;if(e=t.readUint32(),this.shadowed_sample_numbers=[],this.sync_sample_numbers=[],0===this.version)for(r=0;r<e;r++)this.shadowed_sample_numbers.push(t.readUint32()),this.sync_sample_numbers.push(t.readUint32())}),d.createFullBoxCtor("stss",function(t){var e,r;if(r=t.readUint32(),0===this.version)for(this.sample_numbers=[],e=0;e<r;e++)this.sample_numbers.push(t.readUint32())}),d.createFullBoxCtor("stsz",function(t){var e;if(this.sample_sizes=[],0===this.version)for(this.sample_size=t.readUint32(),this.sample_count=t.readUint32(),e=0;e<this.sample_count;e++)0===this.sample_size?this.sample_sizes.push(t.readUint32()):this.sample_sizes[e]=this.sample_size}),d.createFullBoxCtor("stts",function(t){var e,r,s;if(e=t.readUint32(),this.sample_counts=[],this.sample_deltas=[],0===this.version)for(r=0;r<e;r++)this.sample_counts.push(t.readUint32()),(s=t.readInt32())<0&&(a.warn("BoxParser","File uses negative stts sample delta, using value 1 instead, sync may be lost!"),s=1),this.sample_deltas.push(s)}),d.createFullBoxCtor("stvi",function(t){var e,r,s=t.readUint32();this.single_view_allowed=3&s,this.stereo_scheme=t.readUint32();var n=t.readUint32();for(this.stereo_indication_type=t.readString(n),this.boxes=[];t.getPosition()<this.start+this.size;)if((e=d.parseOneBox(t,!1,this.size-(t.getPosition()-this.start))).code!==d.OK)return;else r=e.box,this.boxes.push(r),this[r.type]=r}),d.createBoxCtor("styp",function(t){d.ftypBox.prototype.parse.call(this,t)}),d.createFullBoxCtor("stz2",function(t){var e,r;if(this.sample_sizes=[],0===this.version){if(this.reserved=t.readUint24(),this.field_size=t.readUint8(),r=t.readUint32(),4===this.field_size)for(e=0;e<r;e+=2){var s=t.readUint8();this.sample_sizes[e]=s>>4&15,this.sample_sizes[e+1]=15&s}else if(8===this.field_size)for(e=0;e<r;e++)this.sample_sizes[e]=t.readUint8();else if(16===this.field_size)for(e=0;e<r;e++)this.sample_sizes[e]=t.readUint16();else a.error("BoxParser","Error in length field in stz2 box")}}),d.createFullBoxCtor("subs",function(t){var e,r,s,n;for(s=t.readUint32(),this.entries=[],e=0;e<s;e++){var a={};if(this.entries[e]=a,a.sample_delta=t.readUint32(),a.subsamples=[],(n=t.readUint16())>0)for(r=0;r<n;r++){var o={};a.subsamples.push(o),1==this.version?o.size=t.readUint32():o.size=t.readUint16(),o.priority=t.readUint8(),o.discardable=t.readUint8(),o.codec_specific_parameters=t.readUint32()}}}),d.createFullBoxCtor("tenc",function(t){if(t.readUint8(),0===this.version)t.readUint8();else{var e=t.readUint8();this.default_crypt_byte_block=e>>4&15,this.default_skip_byte_block=15&e}this.default_isProtected=t.readUint8(),this.default_Per_Sample_IV_Size=t.readUint8(),this.default_KID=d.parseHex16(t),1===this.default_isProtected&&0===this.default_Per_Sample_IV_Size&&(this.default_constant_IV_size=t.readUint8(),this.default_constant_IV=t.readUint8Array(this.default_constant_IV_size))}),d.createFullBoxCtor("tfdt",function(t){1==this.version?this.baseMediaDecodeTime=t.readUint64():this.baseMediaDecodeTime=t.readUint32()}),d.createFullBoxCtor("tfhd",function(t){var e=0;this.track_id=t.readUint32(),this.size-this.hdr_size>e&&this.flags&d.TFHD_FLAG_BASE_DATA_OFFSET?(this.base_data_offset=t.readUint64(),e+=8):this.base_data_offset=0,this.size-this.hdr_size>e&&this.flags&d.TFHD_FLAG_SAMPLE_DESC?(this.default_sample_description_index=t.readUint32(),e+=4):this.default_sample_description_index=0,this.size-this.hdr_size>e&&this.flags&d.TFHD_FLAG_SAMPLE_DUR?(this.default_sample_duration=t.readUint32(),e+=4):this.default_sample_duration=0,this.size-this.hdr_size>e&&this.flags&d.TFHD_FLAG_SAMPLE_SIZE?(this.default_sample_size=t.readUint32(),e+=4):this.default_sample_size=0,this.size-this.hdr_size>e&&this.flags&d.TFHD_FLAG_SAMPLE_FLAGS?(this.default_sample_flags=t.readUint32(),e+=4):this.default_sample_flags=0}),d.createFullBoxCtor("tfra",function(t){this.track_ID=t.readUint32(),t.readUint24();var e=t.readUint8();this.length_size_of_traf_num=e>>4&3,this.length_size_of_trun_num=e>>2&3,this.length_size_of_sample_num=3&e,this.entries=[];for(var r=t.readUint32(),s=0;s<r;s++)1===this.version?(this.time=t.readUint64(),this.moof_offset=t.readUint64()):(this.time=t.readUint32(),this.moof_offset=t.readUint32()),this.traf_number=t["readUint"+8*(this.length_size_of_traf_num+1)](),this.trun_number=t["readUint"+8*(this.length_size_of_trun_num+1)](),this.sample_number=t["readUint"+8*(this.length_size_of_sample_num+1)]()}),d.createFullBoxCtor("tkhd",function(t){1==this.version?(this.creation_time=t.readUint64(),this.modification_time=t.readUint64(),this.track_id=t.readUint32(),t.readUint32(),this.duration=t.readUint64()):(this.creation_time=t.readUint32(),this.modification_time=t.readUint32(),this.track_id=t.readUint32(),t.readUint32(),this.duration=t.readUint32()),t.readUint32Array(2),this.layer=t.readInt16(),this.alternate_group=t.readInt16(),this.volume=t.readInt16()>>8,t.readUint16(),this.matrix=t.readInt32Array(9),this.width=t.readUint32(),this.height=t.readUint32()}),d.createBoxCtor("tmax",function(t){this.time=t.readUint32()}),d.createBoxCtor("tmin",function(t){this.time=t.readUint32()}),d.createBoxCtor("totl",function(t){this.bytessent=t.readUint32()}),d.createBoxCtor("tpay",function(t){this.bytessent=t.readUint32()}),d.createBoxCtor("tpyl",function(t){this.bytessent=t.readUint64()}),d.TrackGroupTypeBox.prototype.parse=function(t){this.parseFullHeader(t),this.track_group_id=t.readUint32()},d.createTrackGroupCtor("msrc"),d.TrackReferenceTypeBox=function(t,e,r,s){d.Box.call(this,t,e),this.hdr_size=r,this.start=s},d.TrackReferenceTypeBox.prototype=new d.Box,d.TrackReferenceTypeBox.prototype.parse=function(t){this.track_ids=t.readUint32Array((this.size-this.hdr_size)/4)},d.trefBox.prototype.parse=function(t){for(var e,r;t.getPosition()<this.start+this.size;)if((e=d.parseOneBox(t,!0,this.size-(t.getPosition()-this.start))).code!==d.OK)return;else(r=new d.TrackReferenceTypeBox(e.type,e.size,e.hdr_size,e.start)).write===d.Box.prototype.write&&"mdat"!==r.type&&(a.info("BoxParser","TrackReference "+r.type+" box writing not yet implemented, keeping unparsed data in memory for later write"),r.parseDataAndRewind(t)),r.parse(t),this.boxes.push(r)},d.createFullBoxCtor("trep",function(t){for(this.track_ID=t.readUint32(),this.boxes=[];t.getPosition()<this.start+this.size;)if((ret=d.parseOneBox(t,!1,this.size-(t.getPosition()-this.start))).code!==d.OK)return;else box=ret.box,this.boxes.push(box)}),d.createFullBoxCtor("trex",function(t){this.track_id=t.readUint32(),this.default_sample_description_index=t.readUint32(),this.default_sample_duration=t.readUint32(),this.default_sample_size=t.readUint32(),this.default_sample_flags=t.readUint32()}),d.createBoxCtor("trpy",function(t){this.bytessent=t.readUint64()}),d.createFullBoxCtor("trun",function(t){var e=0;if(this.sample_count=t.readUint32(),e+=4,this.size-this.hdr_size>e&&this.flags&d.TRUN_FLAGS_DATA_OFFSET?(this.data_offset=t.readInt32(),e+=4):this.data_offset=0,this.size-this.hdr_size>e&&this.flags&d.TRUN_FLAGS_FIRST_FLAG?(this.first_sample_flags=t.readUint32(),e+=4):this.first_sample_flags=0,this.sample_duration=[],this.sample_size=[],this.sample_flags=[],this.sample_composition_time_offset=[],this.size-this.hdr_size>e)for(var r=0;r<this.sample_count;r++)this.flags&d.TRUN_FLAGS_DURATION&&(this.sample_duration[r]=t.readUint32()),this.flags&d.TRUN_FLAGS_SIZE&&(this.sample_size[r]=t.readUint32()),this.flags&d.TRUN_FLAGS_FLAGS&&(this.sample_flags[r]=t.readUint32()),this.flags&d.TRUN_FLAGS_CTS_OFFSET&&(0===this.version?this.sample_composition_time_offset[r]=t.readUint32():this.sample_composition_time_offset[r]=t.readInt32())}),d.createFullBoxCtor("tsel",function(t){this.switch_group=t.readUint32();var e=(this.size-this.hdr_size-4)/4;this.attribute_list=[];for(var r=0;r<e;r++)this.attribute_list[r]=t.readUint32()}),d.createFullBoxCtor("txtC",function(t){this.config=t.readCString()}),d.createBoxCtor("tyco",function(t){var e=(this.size-this.hdr_size)/4;this.compatible_brands=[];for(var r=0;r<e;r++)this.compatible_brands[r]=t.readString(4)}),d.createFullBoxCtor("udes",function(t){this.lang=t.readCString(),this.name=t.readCString(),this.description=t.readCString(),this.tags=t.readCString()}),d.createFullBoxCtor("uncC",function(t){for(this.profile=t.readUint32(),this.component_count=t.readUint16(),this.component_index=[],this.component_bit_depth_minus_one=[],this.component_format=[],this.component_align_size=[],e=0;e<this.component_count;e++)this.component_index.push(t.readUint16()),this.component_bit_depth_minus_one.push(t.readUint8()),this.component_format.push(t.readUint8()),this.component_align_size.push(t.readUint8());this.sampling_type=t.readUint8(),this.interleave_type=t.readUint8(),this.block_size=t.readUint8();var e,r=t.readUint8();this.component_little_endian=r>>7&1,this.block_pad_lsb=r>>6&1,this.block_little_endian=r>>5&1,this.block_reversed=r>>4&1,this.pad_unknown=r>>3&1,this.pixel_size=t.readUint8(),this.row_align_size=t.readUint32(),this.tile_align_size=t.readUint32(),this.num_tile_cols_minus_one=t.readUint32(),this.num_tile_rows_minus_one=t.readUint32()}),d.createFullBoxCtor("url ",function(t){1!==this.flags&&(this.location=t.readCString())}),d.createFullBoxCtor("urn ",function(t){this.name=t.readCString(),this.size-this.hdr_size-this.name.length-1>0&&(this.location=t.readCString())}),d.createUUIDBox("a5d40b30e81411ddba2f0800200c9a66",!0,!1,function(t){this.LiveServerManifest=t.readString(this.size-this.hdr_size).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}),d.createUUIDBox("d08a4f1810f34a82b6c832d8aba183d3",!0,!1,function(t){this.system_id=d.parseHex16(t);var e=t.readUint32();e>0&&(this.data=t.readUint8Array(e))}),d.createUUIDBox("a2394f525a9b4f14a2446c427c648df4",!0,!1),d.createUUIDBox("8974dbce7be74c5184f97148f9882554",!0,!1,function(t){this.default_AlgorithmID=t.readUint24(),this.default_IV_size=t.readUint8(),this.default_KID=d.parseHex16(t)}),d.createUUIDBox("d4807ef2ca3946958e5426cb9e46a79f",!0,!1,function(t){this.fragment_count=t.readUint8(),this.entries=[];for(var e=0;e<this.fragment_count;e++){var r={},s=0,n=0;1===this.version?(s=t.readUint64(),n=t.readUint64()):(s=t.readUint32(),n=t.readUint32()),r.absolute_time=s,r.absolute_duration=n,this.entries.push(r)}}),d.createUUIDBox("6d1d9b0542d544e680e2141daff757b2",!0,!1,function(t){1===this.version?(this.absolute_time=t.readUint64(),this.duration=t.readUint64()):(this.absolute_time=t.readUint32(),this.duration=t.readUint32())}),d.createFullBoxCtor("vmhd",function(t){this.graphicsmode=t.readUint16(),this.opcolor=t.readUint16Array(3)}),d.createFullBoxCtor("vpcC",function(t){var e;1===this.version?(this.profile=t.readUint8(),this.level=t.readUint8(),e=t.readUint8(),this.bitDepth=e>>4,this.chromaSubsampling=e>>1&7,this.videoFullRangeFlag=1&e,this.colourPrimaries=t.readUint8(),this.transferCharacteristics=t.readUint8(),this.matrixCoefficients=t.readUint8()):(this.profile=t.readUint8(),this.level=t.readUint8(),e=t.readUint8(),this.bitDepth=e>>4&15,this.colorSpace=15&e,e=t.readUint8(),this.chromaSubsampling=e>>4&15,this.transferFunction=e>>1&7,this.videoFullRangeFlag=1&e),this.codecIntializationDataSize=t.readUint16(),this.codecIntializationData=t.readUint8Array(this.codecIntializationDataSize)}),d.createBoxCtor("vttC",function(t){this.text=t.readString(this.size-this.hdr_size)}),d.createFullBoxCtor("vvcC",function(t){var e,r,s={held_bits:void 0,num_held_bits:0,stream_read_1_bytes:function(t){this.held_bits=t.readUint8(),this.num_held_bits=8},stream_read_2_bytes:function(t){this.held_bits=t.readUint16(),this.num_held_bits=16},extract_bits:function(t){var e=this.held_bits>>this.num_held_bits-t&(1<<t)-1;return this.num_held_bits-=t,e}};if(s.stream_read_1_bytes(t),s.extract_bits(5),this.lengthSizeMinusOne=s.extract_bits(2),this.ptl_present_flag=s.extract_bits(1),this.ptl_present_flag){if(s.stream_read_2_bytes(t),this.ols_idx=s.extract_bits(9),this.num_sublayers=s.extract_bits(3),this.constant_frame_rate=s.extract_bits(2),this.chroma_format_idc=s.extract_bits(2),s.stream_read_1_bytes(t),this.bit_depth_minus8=s.extract_bits(3),s.extract_bits(5),s.stream_read_2_bytes(t),s.extract_bits(2),this.num_bytes_constraint_info=s.extract_bits(6),this.general_profile_idc=s.extract_bits(7),this.general_tier_flag=s.extract_bits(1),this.general_level_idc=t.readUint8(),s.stream_read_1_bytes(t),this.ptl_frame_only_constraint_flag=s.extract_bits(1),this.ptl_multilayer_enabled_flag=s.extract_bits(1),this.general_constraint_info=new Uint8Array(this.num_bytes_constraint_info),this.num_bytes_constraint_info){for(e=0;e<this.num_bytes_constraint_info-1;e++){var n=s.extract_bits(6);s.stream_read_1_bytes(t);var a=s.extract_bits(2);this.general_constraint_info[e]=n<<2|a}this.general_constraint_info[this.num_bytes_constraint_info-1]=s.extract_bits(6)}else s.extract_bits(6);if(this.num_sublayers>1){for(s.stream_read_1_bytes(t),this.ptl_sublayer_present_mask=0,r=this.num_sublayers-2;r>=0;--r){var o=s.extract_bits(1);this.ptl_sublayer_present_mask|=o<<r}for(r=this.num_sublayers;r<=8&&this.num_sublayers>1;++r)s.extract_bits(1);for(this.sublayer_level_idc=[],r=this.num_sublayers-2;r>=0;--r)this.ptl_sublayer_present_mask&1<<r&&(this.sublayer_level_idc[r]=t.readUint8())}if(this.ptl_num_sub_profiles=t.readUint8(),this.general_sub_profile_idc=[],this.ptl_num_sub_profiles)for(e=0;e<this.ptl_num_sub_profiles;e++)this.general_sub_profile_idc.push(t.readUint32());this.max_picture_width=t.readUint16(),this.max_picture_height=t.readUint16(),this.avg_frame_rate=t.readUint16()}this.nalu_arrays=[];var h=t.readUint8();for(e=0;e<h;e++){var l=[];this.nalu_arrays.push(l),s.stream_read_1_bytes(t),l.completeness=s.extract_bits(1),s.extract_bits(2),l.nalu_type=s.extract_bits(5);var u=1;for(13!=l.nalu_type&&12!=l.nalu_type&&(u=t.readUint16()),r=0;r<u;r++){var d=t.readUint16();l.push({data:t.readUint8Array(d),length:d})}}}),d.createFullBoxCtor("vvnC",function(t){var e=strm.readUint8();this.lengthSizeMinusOne=3&e}),d.SampleEntry.prototype.isVideo=function(){return!1},d.SampleEntry.prototype.isAudio=function(){return!1},d.SampleEntry.prototype.isSubtitle=function(){return!1},d.SampleEntry.prototype.isMetadata=function(){return!1},d.SampleEntry.prototype.isHint=function(){return!1},d.SampleEntry.prototype.getCodec=function(){return this.type.replace(".","")},d.SampleEntry.prototype.getWidth=function(){return""},d.SampleEntry.prototype.getHeight=function(){return""},d.SampleEntry.prototype.getChannelCount=function(){return""},d.SampleEntry.prototype.getSampleRate=function(){return""},d.SampleEntry.prototype.getSampleSize=function(){return""},d.VisualSampleEntry.prototype.isVideo=function(){return!0},d.VisualSampleEntry.prototype.getWidth=function(){return this.width},d.VisualSampleEntry.prototype.getHeight=function(){return this.height},d.AudioSampleEntry.prototype.isAudio=function(){return!0},d.AudioSampleEntry.prototype.getChannelCount=function(){return this.channel_count},d.AudioSampleEntry.prototype.getSampleRate=function(){return this.samplerate},d.AudioSampleEntry.prototype.getSampleSize=function(){return this.samplesize},d.SubtitleSampleEntry.prototype.isSubtitle=function(){return!0},d.MetadataSampleEntry.prototype.isMetadata=function(){return!0},d.decimalToHex=function(t,e){var r=Number(t).toString(16);for(e=typeof e>"u"||null===e?e=2:e;r.length<e;)r="0"+r;return r},d.avc1SampleEntry.prototype.getCodec=d.avc2SampleEntry.prototype.getCodec=d.avc3SampleEntry.prototype.getCodec=d.avc4SampleEntry.prototype.getCodec=function(){var t=d.SampleEntry.prototype.getCodec.call(this);return this.avcC?t+"."+d.decimalToHex(this.avcC.AVCProfileIndication)+d.decimalToHex(this.avcC.profile_compatibility)+d.decimalToHex(this.avcC.AVCLevelIndication):t},d.hev1SampleEntry.prototype.getCodec=d.hvc1SampleEntry.prototype.getCodec=function(){var t,e=d.SampleEntry.prototype.getCodec.call(this);if(this.hvcC){switch(e+=".",this.hvcC.general_profile_space){case 0:e+="";break;case 1:e+="A";break;case 2:e+="B";break;case 3:e+="C"}e+=this.hvcC.general_profile_idc+".";var r=this.hvcC.general_profile_compatibility,s=0;for(t=0;t<32&&(s|=1&r,31!=t);t++)s<<=1,r>>=1;e+=d.decimalToHex(s,0)+".",0===this.hvcC.general_tier_flag?e+="L":e+="H",e+=this.hvcC.general_level_idc;var n=!1,a="";for(t=5;t>=0;t--)(this.hvcC.general_constraint_indicator[t]||n)&&(a="."+d.decimalToHex(this.hvcC.general_constraint_indicator[t],0)+a,n=!0);e+=a}return e},d.vvc1SampleEntry.prototype.getCodec=d.vvi1SampleEntry.prototype.getCodec=function(){var t,e=d.SampleEntry.prototype.getCodec.call(this);if(this.vvcC){e+="."+this.vvcC.general_profile_idc,this.vvcC.general_tier_flag?e+=".H":e+=".L",e+=this.vvcC.general_level_idc;var r="";if(this.vvcC.general_constraint_info){var s,n,a=[];for(n=0|this.vvcC.ptl_frame_only_constraint<<7|this.vvcC.ptl_multilayer_enabled<<6,t=0;t<this.vvcC.general_constraint_info.length;++t)n|=this.vvcC.general_constraint_info[t]>>2&63,a.push(n),n&&(s=t),n=this.vvcC.general_constraint_info[t]>>2&3;if(void 0===s)r=".CA";else{r=".C";var o="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",h=0,l=0;for(t=0;t<=s;++t)for(h=h<<8|a[t],l+=8;l>=5;)r+=o[h>>l-5&31],l-=5,h&=(1<<l)-1;l&&(h<<=5-l,r+=o[31&h])}}e+=r}return e},d.mp4aSampleEntry.prototype.getCodec=function(){var t=d.SampleEntry.prototype.getCodec.call(this);if(!this.esds||!this.esds.esd)return t;var e=this.esds.esd.getOTI(),r=this.esds.esd.getAudioConfig();return t+"."+d.decimalToHex(e)+(r?"."+r:"")},d.stxtSampleEntry.prototype.getCodec=function(){var t=d.SampleEntry.prototype.getCodec.call(this);return this.mime_format?t+"."+this.mime_format:t},d.vp08SampleEntry.prototype.getCodec=d.vp09SampleEntry.prototype.getCodec=function(){var t=d.SampleEntry.prototype.getCodec.call(this),e=this.vpcC.level;0==e&&(e="00");var r=this.vpcC.bitDepth;return 8==r&&(r="08"),t+".0"+this.vpcC.profile+"."+e+"."+r},d.av01SampleEntry.prototype.getCodec=function(){var t,e=d.SampleEntry.prototype.getCodec.call(this),r=this.av1C.seq_level_idx_0;return r<10&&(r="0"+r),2===this.av1C.seq_profile&&1===this.av1C.high_bitdepth?t=1===this.av1C.twelve_bit?"12":"10":this.av1C.seq_profile<=2&&(t=1===this.av1C.high_bitdepth?"10":"08"),e+"."+this.av1C.seq_profile+"."+r+(this.av1C.seq_tier_0?"H":"M")+"."+t},d.Box.prototype.writeHeader=function(t,e){this.size+=8,this.size>4294967296&&(this.size+=8),"uuid"===this.type&&(this.size+=16),a.debug("BoxWriter","Writing box "+this.type+" of size: "+this.size+" at position "+t.getPosition()+(e||"")),this.size>4294967296?t.writeUint32(1):(this.sizePosition=t.getPosition(),t.writeUint32(this.size)),t.writeString(this.type,null,4),"uuid"===this.type&&t.writeUint8Array(this.uuid),this.size>4294967296&&t.writeUint64(this.size)},d.FullBox.prototype.writeHeader=function(t){this.size+=4,d.Box.prototype.writeHeader.call(this,t," v="+this.version+" f="+this.flags),t.writeUint8(this.version),t.writeUint24(this.flags)},d.Box.prototype.write=function(t){"mdat"===this.type?this.data&&(this.size=this.data.length,this.writeHeader(t),t.writeUint8Array(this.data)):(this.size=this.data?this.data.length:0,this.writeHeader(t),this.data&&t.writeUint8Array(this.data))},d.ContainerBox.prototype.write=function(t){this.size=0,this.writeHeader(t);for(var e=0;e<this.boxes.length;e++)this.boxes[e]&&(this.boxes[e].write(t),this.size+=this.boxes[e].size);a.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},d.TrackReferenceTypeBox.prototype.write=function(t){this.size=4*this.track_ids.length,this.writeHeader(t),t.writeUint32Array(this.track_ids)},d.avcCBox.prototype.write=function(t){var e;for(this.size=7,e=0;e<this.SPS.length;e++)this.size+=2+this.SPS[e].length;for(e=0;e<this.PPS.length;e++)this.size+=2+this.PPS[e].length;for(this.ext&&(this.size+=this.ext.length),this.writeHeader(t),t.writeUint8(this.configurationVersion),t.writeUint8(this.AVCProfileIndication),t.writeUint8(this.profile_compatibility),t.writeUint8(this.AVCLevelIndication),t.writeUint8(this.lengthSizeMinusOne+252),t.writeUint8(this.SPS.length+224),e=0;e<this.SPS.length;e++)t.writeUint16(this.SPS[e].length),t.writeUint8Array(this.SPS[e].nalu);for(t.writeUint8(this.PPS.length),e=0;e<this.PPS.length;e++)t.writeUint16(this.PPS[e].length),t.writeUint8Array(this.PPS[e].nalu);this.ext&&t.writeUint8Array(this.ext)},d.co64Box.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+8*this.chunk_offsets.length,this.writeHeader(t),t.writeUint32(this.chunk_offsets.length),e=0;e<this.chunk_offsets.length;e++)t.writeUint64(this.chunk_offsets[e])},d.cslgBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=20,this.writeHeader(t),t.writeInt32(this.compositionToDTSShift),t.writeInt32(this.leastDecodeToDisplayDelta),t.writeInt32(this.greatestDecodeToDisplayDelta),t.writeInt32(this.compositionStartTime),t.writeInt32(this.compositionEndTime)},d.cttsBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+8*this.sample_counts.length,this.writeHeader(t),t.writeUint32(this.sample_counts.length),e=0;e<this.sample_counts.length;e++)t.writeUint32(this.sample_counts[e]),1===this.version?t.writeInt32(this.sample_offsets[e]):t.writeUint32(this.sample_offsets[e])},d.drefBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4,this.writeHeader(t),t.writeUint32(this.entries.length);for(var e=0;e<this.entries.length;e++)this.entries[e].write(t),this.size+=this.entries[e].size;a.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},d.elngBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=this.extended_language.length,this.writeHeader(t),t.writeString(this.extended_language)},d.elstBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4+12*this.entries.length,this.writeHeader(t),t.writeUint32(this.entries.length);for(var e=0;e<this.entries.length;e++){var r=this.entries[e];t.writeUint32(r.segment_duration),t.writeInt32(r.media_time),t.writeInt16(r.media_rate_integer),t.writeInt16(r.media_rate_fraction)}},d.emsgBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=16+this.message_data.length+(this.scheme_id_uri.length+1)+(this.value.length+1),this.writeHeader(t),t.writeCString(this.scheme_id_uri),t.writeCString(this.value),t.writeUint32(this.timescale),t.writeUint32(this.presentation_time_delta),t.writeUint32(this.event_duration),t.writeUint32(this.id),t.writeUint8Array(this.message_data)},d.ftypBox.prototype.write=function(t){this.size=8+4*this.compatible_brands.length,this.writeHeader(t),t.writeString(this.major_brand,null,4),t.writeUint32(this.minor_version);for(var e=0;e<this.compatible_brands.length;e++)t.writeString(this.compatible_brands[e],null,4)},d.hdlrBox.prototype.write=function(t){this.size=20+this.name.length+1,this.version=0,this.flags=0,this.writeHeader(t),t.writeUint32(0),t.writeString(this.handler,null,4),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeCString(this.name)},d.hvcCBox.prototype.write=function(t){var e,r;for(this.size=23,e=0;e<this.nalu_arrays.length;e++)for(this.size+=3,r=0;r<this.nalu_arrays[e].length;r++)this.size+=2+this.nalu_arrays[e][r].data.length;for(this.writeHeader(t),t.writeUint8(this.configurationVersion),t.writeUint8(this.general_profile_space<<6+this.general_tier_flag<<5+this.general_profile_idc),t.writeUint32(this.general_profile_compatibility),t.writeUint8Array(this.general_constraint_indicator),t.writeUint8(this.general_level_idc),t.writeUint16(this.min_spatial_segmentation_idc+251658240),t.writeUint8(this.parallelismType+252),t.writeUint8(this.chroma_format_idc+252),t.writeUint8(this.bit_depth_luma_minus8+248),t.writeUint8(this.bit_depth_chroma_minus8+248),t.writeUint16(this.avgFrameRate),t.writeUint8((this.constantFrameRate<<6)+(this.numTemporalLayers<<3)+(this.temporalIdNested<<2)+this.lengthSizeMinusOne),t.writeUint8(this.nalu_arrays.length),e=0;e<this.nalu_arrays.length;e++)for(t.writeUint8((this.nalu_arrays[e].completeness<<7)+this.nalu_arrays[e].nalu_type),t.writeUint16(this.nalu_arrays[e].length),r=0;r<this.nalu_arrays[e].length;r++)t.writeUint16(this.nalu_arrays[e][r].data.length),t.writeUint8Array(this.nalu_arrays[e][r].data)},d.kindBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=this.schemeURI.length+1+(this.value.length+1),this.writeHeader(t),t.writeCString(this.schemeURI),t.writeCString(this.value)},d.mdhdBox.prototype.write=function(t){this.size=20,this.flags=0,this.version=0,this.writeHeader(t),t.writeUint32(this.creation_time),t.writeUint32(this.modification_time),t.writeUint32(this.timescale),t.writeUint32(this.duration),t.writeUint16(this.language),t.writeUint16(0)},d.mehdBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4,this.writeHeader(t),t.writeUint32(this.fragment_duration)},d.mfhdBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4,this.writeHeader(t),t.writeUint32(this.sequence_number)},d.mvhdBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=96,this.writeHeader(t),t.writeUint32(this.creation_time),t.writeUint32(this.modification_time),t.writeUint32(this.timescale),t.writeUint32(this.duration),t.writeUint32(this.rate),t.writeUint16(this.volume<<8),t.writeUint16(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32Array(this.matrix),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(this.next_track_id)},d.SampleEntry.prototype.writeHeader=function(t){this.size=8,d.Box.prototype.writeHeader.call(this,t),t.writeUint8(0),t.writeUint8(0),t.writeUint8(0),t.writeUint8(0),t.writeUint8(0),t.writeUint8(0),t.writeUint16(this.data_reference_index)},d.SampleEntry.prototype.writeFooter=function(t){for(var e=0;e<this.boxes.length;e++)this.boxes[e].write(t),this.size+=this.boxes[e].size;a.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},d.SampleEntry.prototype.write=function(t){this.writeHeader(t),t.writeUint8Array(this.data),this.size+=this.data.length,a.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},d.VisualSampleEntry.prototype.write=function(t){this.writeHeader(t),this.size+=70,t.writeUint16(0),t.writeUint16(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint16(this.width),t.writeUint16(this.height),t.writeUint32(this.horizresolution),t.writeUint32(this.vertresolution),t.writeUint32(0),t.writeUint16(this.frame_count),t.writeUint8(Math.min(31,this.compressorname.length)),t.writeString(this.compressorname,null,31),t.writeUint16(this.depth),t.writeInt16(-1),this.writeFooter(t)},d.AudioSampleEntry.prototype.write=function(t){this.writeHeader(t),this.size+=20,t.writeUint32(0),t.writeUint32(0),t.writeUint16(this.channel_count),t.writeUint16(this.samplesize),t.writeUint16(0),t.writeUint16(0),t.writeUint32(this.samplerate<<16),this.writeFooter(t)},d.stppSampleEntry.prototype.write=function(t){this.writeHeader(t),this.size+=this.namespace.length+1+this.schema_location.length+1+this.auxiliary_mime_types.length+1,t.writeCString(this.namespace),t.writeCString(this.schema_location),t.writeCString(this.auxiliary_mime_types),this.writeFooter(t)},d.SampleGroupEntry.prototype.write=function(t){t.writeUint8Array(this.data)},d.sbgpBox.prototype.write=function(t){this.version=1,this.flags=0,this.size=12+8*this.entries.length,this.writeHeader(t),t.writeString(this.grouping_type,null,4),t.writeUint32(this.grouping_type_parameter),t.writeUint32(this.entries.length);for(var e=0;e<this.entries.length;e++){var r=this.entries[e];t.writeInt32(r.sample_count),t.writeInt32(r.group_description_index)}},d.sgpdBox.prototype.write=function(t){var e,r;for(this.flags=0,this.size=12,e=0;e<this.entries.length;e++)r=this.entries[e],1===this.version&&(0===this.default_length&&(this.size+=4),this.size+=r.data.length);for(this.writeHeader(t),t.writeString(this.grouping_type,null,4),1===this.version&&t.writeUint32(this.default_length),this.version>=2&&t.writeUint32(this.default_sample_description_index),t.writeUint32(this.entries.length),e=0;e<this.entries.length;e++)r=this.entries[e],1===this.version&&0===this.default_length&&t.writeUint32(r.description_length),r.write(t)},d.sidxBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=20+12*this.references.length,this.writeHeader(t),t.writeUint32(this.reference_ID),t.writeUint32(this.timescale),t.writeUint32(this.earliest_presentation_time),t.writeUint32(this.first_offset),t.writeUint16(0),t.writeUint16(this.references.length);for(var e=0;e<this.references.length;e++){var r=this.references[e];t.writeUint32(r.reference_type<<31|r.referenced_size),t.writeUint32(r.subsegment_duration),t.writeUint32(r.starts_with_SAP<<31|r.SAP_type<<28|r.SAP_delta_time)}},d.smhdBox.prototype.write=function(t){this.version=0,this.flags=1,this.size=4,this.writeHeader(t),t.writeUint16(this.balance),t.writeUint16(0)},d.stcoBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4+4*this.chunk_offsets.length,this.writeHeader(t),t.writeUint32(this.chunk_offsets.length),t.writeUint32Array(this.chunk_offsets)},d.stscBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+12*this.first_chunk.length,this.writeHeader(t),t.writeUint32(this.first_chunk.length),e=0;e<this.first_chunk.length;e++)t.writeUint32(this.first_chunk[e]),t.writeUint32(this.samples_per_chunk[e]),t.writeUint32(this.sample_description_index[e])},d.stsdBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=0,this.writeHeader(t),t.writeUint32(this.entries.length),this.size+=4,e=0;e<this.entries.length;e++)this.entries[e].write(t),this.size+=this.entries[e].size;a.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},d.stshBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+8*this.shadowed_sample_numbers.length,this.writeHeader(t),t.writeUint32(this.shadowed_sample_numbers.length),e=0;e<this.shadowed_sample_numbers.length;e++)t.writeUint32(this.shadowed_sample_numbers[e]),t.writeUint32(this.sync_sample_numbers[e])},d.stssBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4+4*this.sample_numbers.length,this.writeHeader(t),t.writeUint32(this.sample_numbers.length),t.writeUint32Array(this.sample_numbers)},d.stszBox.prototype.write=function(t){var e,r=!0;if(this.version=0,this.flags=0,this.sample_sizes.length>0)for(e=0;e+1<this.sample_sizes.length;)if(this.sample_sizes[e+1]!==this.sample_sizes[0]){r=!1;break}else e++;else r=!1;this.size=8,r||(this.size+=4*this.sample_sizes.length),this.writeHeader(t),r?t.writeUint32(this.sample_sizes[0]):t.writeUint32(0),t.writeUint32(this.sample_sizes.length),r||t.writeUint32Array(this.sample_sizes)},d.sttsBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+8*this.sample_counts.length,this.writeHeader(t),t.writeUint32(this.sample_counts.length),e=0;e<this.sample_counts.length;e++)t.writeUint32(this.sample_counts[e]),t.writeUint32(this.sample_deltas[e])},d.tfdtBox.prototype.write=function(t){this.version=this.baseMediaDecodeTime>4294967295?1:0,this.flags=0,this.size=4,1===this.version&&(this.size+=4),this.writeHeader(t),1===this.version?t.writeUint64(this.baseMediaDecodeTime):t.writeUint32(this.baseMediaDecodeTime)},d.tfhdBox.prototype.write=function(t){this.version=0,this.size=4,this.flags&d.TFHD_FLAG_BASE_DATA_OFFSET&&(this.size+=8),this.flags&d.TFHD_FLAG_SAMPLE_DESC&&(this.size+=4),this.flags&d.TFHD_FLAG_SAMPLE_DUR&&(this.size+=4),this.flags&d.TFHD_FLAG_SAMPLE_SIZE&&(this.size+=4),this.flags&d.TFHD_FLAG_SAMPLE_FLAGS&&(this.size+=4),this.writeHeader(t),t.writeUint32(this.track_id),this.flags&d.TFHD_FLAG_BASE_DATA_OFFSET&&t.writeUint64(this.base_data_offset),this.flags&d.TFHD_FLAG_SAMPLE_DESC&&t.writeUint32(this.default_sample_description_index),this.flags&d.TFHD_FLAG_SAMPLE_DUR&&t.writeUint32(this.default_sample_duration),this.flags&d.TFHD_FLAG_SAMPLE_SIZE&&t.writeUint32(this.default_sample_size),this.flags&d.TFHD_FLAG_SAMPLE_FLAGS&&t.writeUint32(this.default_sample_flags)},d.tkhdBox.prototype.write=function(t){this.version=0,this.size=80,this.writeHeader(t),t.writeUint32(this.creation_time),t.writeUint32(this.modification_time),t.writeUint32(this.track_id),t.writeUint32(0),t.writeUint32(this.duration),t.writeUint32(0),t.writeUint32(0),t.writeInt16(this.layer),t.writeInt16(this.alternate_group),t.writeInt16(this.volume<<8),t.writeUint16(0),t.writeInt32Array(this.matrix),t.writeUint32(this.width),t.writeUint32(this.height)},d.trexBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=20,this.writeHeader(t),t.writeUint32(this.track_id),t.writeUint32(this.default_sample_description_index),t.writeUint32(this.default_sample_duration),t.writeUint32(this.default_sample_size),t.writeUint32(this.default_sample_flags)},d.trunBox.prototype.write=function(t){this.version=0,this.size=4,this.flags&d.TRUN_FLAGS_DATA_OFFSET&&(this.size+=4),this.flags&d.TRUN_FLAGS_FIRST_FLAG&&(this.size+=4),this.flags&d.TRUN_FLAGS_DURATION&&(this.size+=4*this.sample_duration.length),this.flags&d.TRUN_FLAGS_SIZE&&(this.size+=4*this.sample_size.length),this.flags&d.TRUN_FLAGS_FLAGS&&(this.size+=4*this.sample_flags.length),this.flags&d.TRUN_FLAGS_CTS_OFFSET&&(this.size+=4*this.sample_composition_time_offset.length),this.writeHeader(t),t.writeUint32(this.sample_count),this.flags&d.TRUN_FLAGS_DATA_OFFSET&&(this.data_offset_position=t.getPosition(),t.writeInt32(this.data_offset)),this.flags&d.TRUN_FLAGS_FIRST_FLAG&&t.writeUint32(this.first_sample_flags);for(var e=0;e<this.sample_count;e++)this.flags&d.TRUN_FLAGS_DURATION&&t.writeUint32(this.sample_duration[e]),this.flags&d.TRUN_FLAGS_SIZE&&t.writeUint32(this.sample_size[e]),this.flags&d.TRUN_FLAGS_FLAGS&&t.writeUint32(this.sample_flags[e]),this.flags&d.TRUN_FLAGS_CTS_OFFSET&&(0===this.version?t.writeUint32(this.sample_composition_time_offset[e]):t.writeInt32(this.sample_composition_time_offset[e]))},d["url Box"].prototype.write=function(t){this.version=0,this.location?(this.flags=0,this.size=this.location.length+1):(this.flags=1,this.size=0),this.writeHeader(t),this.location&&t.writeCString(this.location)},d["urn Box"].prototype.write=function(t){this.version=0,this.flags=0,this.size=this.name.length+1+(this.location?this.location.length+1:0),this.writeHeader(t),t.writeCString(this.name),this.location&&t.writeCString(this.location)},d.vmhdBox.prototype.write=function(t){this.version=0,this.flags=1,this.size=8,this.writeHeader(t),t.writeUint16(this.graphicsmode),t.writeUint16Array(this.opcolor)},d.cttsBox.prototype.unpack=function(t){var e,r,s;for(s=0,e=0;e<this.sample_counts.length;e++)for(r=0;r<this.sample_counts[e];r++)t[s].pts=t[s].dts+this.sample_offsets[e],s++},d.sttsBox.prototype.unpack=function(t){var e,r,s;for(s=0,e=0;e<this.sample_counts.length;e++)for(r=0;r<this.sample_counts[e];r++)0===s?t[s].dts=0:t[s].dts=t[s-1].dts+this.sample_deltas[e],s++},d.stcoBox.prototype.unpack=function(t){var e;for(e=0;e<this.chunk_offsets.length;e++)t[e].offset=this.chunk_offsets[e]},d.stscBox.prototype.unpack=function(t){var e,r,s,n,a;for(n=0,a=0,e=0;e<this.first_chunk.length;e++)for(r=0;r<(e+1<this.first_chunk.length?this.first_chunk[e+1]:1/0);r++)for(a++,s=0;s<this.samples_per_chunk[e];s++){if(!t[n])return;t[n].description_index=this.sample_description_index[e],t[n].chunk_index=a,n++}},d.stszBox.prototype.unpack=function(t){var e;for(e=0;e<this.sample_sizes.length;e++)t[e].size=this.sample_sizes[e]},d.DIFF_BOXES_PROP_NAMES=["boxes","entries","references","subsamples","items","item_infos","extents","associations","subsegments","ranges","seekLists","seekPoints","esd","levels"],d.DIFF_PRIMITIVE_ARRAY_PROP_NAMES=["compatible_brands","matrix","opcolor","sample_counts","sample_counts","sample_deltas","first_chunk","samples_per_chunk","sample_sizes","chunk_offsets","sample_offsets","sample_description_index","sample_duration"],d.boxEqualFields=function(t,e){var r;if(t&&!e)return!1;for(r in t)if(!(d.DIFF_BOXES_PROP_NAMES.indexOf(r)>-1)){if(t[r]instanceof d.Box||e[r]instanceof d.Box||typeof t[r]>"u"||typeof e[r]>"u"||"function"==typeof t[r]||"function"==typeof e[r]||t.subBoxNames&&t.subBoxNames.indexOf(r.slice(0,4))>-1||e.subBoxNames&&e.subBoxNames.indexOf(r.slice(0,4))>-1||"data"===r||"start"===r||"size"===r||"creation_time"===r||"modification_time"===r||d.DIFF_PRIMITIVE_ARRAY_PROP_NAMES.indexOf(r)>-1)continue;if(t[r]!==e[r])return!1}return!0},d.boxEqual=function(t,e){if(!d.boxEqualFields(t,e))return!1;for(var r=0;r<d.DIFF_BOXES_PROP_NAMES.length;r++){var s=d.DIFF_BOXES_PROP_NAMES[r];if(t[s]&&e[s]&&!d.boxEqual(t[s],e[s]))return!1}return!0},(f=function(){}).prototype.parseSample=function(t){var e,r={};r.resources=[];var s=new o(t.data.buffer);if(t.subsamples&&0!==t.subsamples.length){if(r.documentString=s.readString(t.subsamples[0].size),t.subsamples.length>1)for(e=1;e<t.subsamples.length;e++)r.resources[e]=s.readUint8Array(t.subsamples[e].size)}else r.documentString=s.readString(t.data.length);return"u">typeof DOMParser&&(r.document=new DOMParser().parseFromString(r.documentString,"application/xml")),r},(p=function(){}).prototype.parseSample=function(t){return new o(t.data.buffer).readString(t.data.length)},p.prototype.parseConfig=function(t){var e=new o(t.buffer);return e.readUint32(),e.readCString()},iT.XMLSubtitlein4Parser=f,iT.Textin4Parser=p,(c=function(t){this.stream=t||new l,this.boxes=[],this.mdats=[],this.moofs=[],this.isProgressive=!1,this.moovStartFound=!1,this.onMoovStart=null,this.moovStartSent=!1,this.onReady=null,this.readySent=!1,this.onSegment=null,this.onSamples=null,this.onError=null,this.sampleListBuilt=!1,this.fragmentedTracks=[],this.extractedTracks=[],this.isFragmentationInitialized=!1,this.sampleProcessingStarted=!1,this.nextMoofNumber=0,this.itemListBuilt=!1,this.onSidx=null,this.sidxSent=!1}).prototype.setSegmentOptions=function(t,e,r){var s=this.getTrackById(t);if(s){var n={};this.fragmentedTracks.push(n),n.id=t,n.user=e,n.trak=s,s.nextSample=0,n.segmentStream=null,n.nb_samples=1e3,n.rapAlignement=!0,r&&(r.nbSamples&&(n.nb_samples=r.nbSamples),r.rapAlignement&&(n.rapAlignement=r.rapAlignement))}},c.prototype.unsetSegmentOptions=function(t){for(var e=-1,r=0;r<this.fragmentedTracks.length;r++)this.fragmentedTracks[r].id==t&&(e=r);e>-1&&this.fragmentedTracks.splice(e,1)},c.prototype.setExtractionOptions=function(t,e,r){var s=this.getTrackById(t);if(s){var n={};this.extractedTracks.push(n),n.id=t,n.user=e,n.trak=s,s.nextSample=0,n.nb_samples=1e3,n.samples=[],r&&r.nbSamples&&(n.nb_samples=r.nbSamples)}},c.prototype.unsetExtractionOptions=function(t){for(var e=-1,r=0;r<this.extractedTracks.length;r++)this.extractedTracks[r].id==t&&(e=r);e>-1&&this.extractedTracks.splice(e,1)},c.prototype.parse=function(){var t,e,r;if(!(this.restoreParsePosition&&!this.restoreParsePosition()))for(;;)if(this.hasIncompleteMdat&&this.hasIncompleteMdat()){if(this.processIncompleteMdat())continue;return}else if(this.saveParsePosition&&this.saveParsePosition(),(e=d.parseOneBox(this.stream,!1)).code===d.ERR_NOT_ENOUGH_DATA){if(!this.processIncompleteBox)return;if(this.processIncompleteBox(e))continue;return}else{switch(t="uuid"!==(r=e.box).type?r.type:r.uuid,this.boxes.push(r),t){case"mdat":this.mdats.push(r);break;case"moof":this.moofs.push(r);break;case"moov":this.moovStartFound=!0,0===this.mdats.length&&(this.isProgressive=!0);default:void 0!==this[t]&&a.warn("ISOFile","Duplicate Box of type: "+t+", overriding previous occurrence"),this[t]=r}this.updateUsedBytes&&this.updateUsedBytes(r,e)}},c.prototype.checkBuffer=function(t){if(null==t)throw"Buffer must be defined and non empty";if(void 0===t.fileStart)throw"Buffer must have a fileStart property";return 0===t.byteLength?(a.warn("ISOFile","Ignoring empty buffer (fileStart: "+t.fileStart+")"),this.stream.logBufferLevel(),!1):(a.info("ISOFile","Processing buffer (fileStart: "+t.fileStart+")"),t.usedBytes=0,this.stream.insertBuffer(t),this.stream.logBufferLevel(),!!this.stream.initialized()||(a.warn("ISOFile","Not ready to start parsing"),!1))},c.prototype.appendBuffer=function(t,e){var r;if(this.checkBuffer(t))return this.parse(),this.moovStartFound&&!this.moovStartSent&&(this.moovStartSent=!0,this.onMoovStart&&this.onMoovStart()),this.moov?(this.sampleListBuilt||(this.buildSampleLists(),this.sampleListBuilt=!0),this.updateSampleLists(),this.onReady&&!this.readySent&&(this.readySent=!0,this.onReady(this.getInfo())),this.processSamples(e),this.nextSeekPosition?(r=this.nextSeekPosition,this.nextSeekPosition=void 0):r=this.nextParsePosition,this.stream.getEndFilePositionAfter&&(r=this.stream.getEndFilePositionAfter(r))):r=this.nextParsePosition?this.nextParsePosition:0,this.sidx&&this.onSidx&&!this.sidxSent&&(this.onSidx(this.sidx),this.sidxSent=!0),this.meta&&(this.flattenItemInfo&&!this.itemListBuilt&&(this.flattenItemInfo(),this.itemListBuilt=!0),this.processItems&&this.processItems(this.onItem)),this.stream.cleanBuffers&&(a.info("ISOFile","Done processing buffer (fileStart: "+t.fileStart+") - next buffer to fetch should have a fileStart position of "+r),this.stream.logBufferLevel(),this.stream.cleanBuffers(),this.stream.logBufferLevel(!0),a.info("ISOFile","Sample data size in memory: "+this.getAllocatedSampleDataSize())),r},c.prototype.getInfo=function(){var t,e,r,s,n,a,o={},h=/* @__PURE__ */new Date("1904-01-01T00:00:00Z").getTime();if(this.moov)for(o.hasMoov=!0,o.duration=this.moov.mvhd.duration,o.timescale=this.moov.mvhd.timescale,o.isFragmented=null!=this.moov.mvex,o.isFragmented&&this.moov.mvex.mehd&&(o.fragment_duration=this.moov.mvex.mehd.fragment_duration),o.isProgressive=this.isProgressive,o.hasIOD=null!=this.moov.iods,o.brands=[],o.brands.push(this.ftyp.major_brand),o.brands=o.brands.concat(this.ftyp.compatible_brands),o.created=new Date(h+1e3*this.moov.mvhd.creation_time),o.modified=new Date(h+1e3*this.moov.mvhd.modification_time),o.tracks=[],o.audioTracks=[],o.videoTracks=[],o.subtitleTracks=[],o.metadataTracks=[],o.hintTracks=[],o.otherTracks=[],t=0;t<this.moov.traks.length;t++){if(a=(r=this.moov.traks[t]).mdia.minf.stbl.stsd.entries[0],s={},o.tracks.push(s),s.id=r.tkhd.track_id,s.name=r.mdia.hdlr.name,s.references=[],r.tref)for(e=0;e<r.tref.boxes.length;e++)n={},s.references.push(n),n.type=r.tref.boxes[e].type,n.track_ids=r.tref.boxes[e].track_ids;r.edts&&(s.edits=r.edts.elst.entries),s.created=new Date(h+1e3*r.tkhd.creation_time),s.modified=new Date(h+1e3*r.tkhd.modification_time),s.movie_duration=r.tkhd.duration,s.movie_timescale=o.timescale,s.layer=r.tkhd.layer,s.alternate_group=r.tkhd.alternate_group,s.volume=r.tkhd.volume,s.matrix=r.tkhd.matrix,s.track_width=r.tkhd.width/65536,s.track_height=r.tkhd.height/65536,s.timescale=r.mdia.mdhd.timescale,s.cts_shift=r.mdia.minf.stbl.cslg,s.duration=r.mdia.mdhd.duration,s.samples_duration=r.samples_duration,s.codec=a.getCodec(),s.kind=r.udta&&r.udta.kinds.length?r.udta.kinds[0]:{schemeURI:"",value:""},s.language=r.mdia.elng?r.mdia.elng.extended_language:r.mdia.mdhd.languageString,s.nb_samples=r.samples.length,s.size=r.samples_size,s.bitrate=8*s.size*s.timescale/s.samples_duration,a.isAudio()?(s.type="audio",o.audioTracks.push(s),s.audio={},s.audio.sample_rate=a.getSampleRate(),s.audio.channel_count=a.getChannelCount(),s.audio.sample_size=a.getSampleSize()):a.isVideo()?(s.type="video",o.videoTracks.push(s),s.video={},s.video.width=a.getWidth(),s.video.height=a.getHeight()):a.isSubtitle()?(s.type="subtitles",o.subtitleTracks.push(s)):a.isHint()?(s.type="metadata",o.hintTracks.push(s)):a.isMetadata()?(s.type="metadata",o.metadataTracks.push(s)):(s.type="metadata",o.otherTracks.push(s))}else o.hasMoov=!1;if(o.mime="",o.hasMoov&&o.tracks){for(o.videoTracks&&o.videoTracks.length>0?o.mime+='video/mp4; codecs="':o.audioTracks&&o.audioTracks.length>0?o.mime+='audio/mp4; codecs="':o.mime+='application/mp4; codecs="',t=0;t<o.tracks.length;t++)0!==t&&(o.mime+=","),o.mime+=o.tracks[t].codec;o.mime+='"; profiles="',o.mime+=this.ftyp.compatible_brands.join(),o.mime+='"'}return o},c.prototype.setNextSeekPositionFromSample=function(t){t&&(this.nextSeekPosition?this.nextSeekPosition=Math.min(t.offset+t.alreadyRead,this.nextSeekPosition):this.nextSeekPosition=t.offset+t.alreadyRead)},c.prototype.processSamples=function(t){var e,r;if(this.sampleProcessingStarted){if(this.isFragmentationInitialized&&null!==this.onSegment)for(e=0;e<this.fragmentedTracks.length;e++){var s=this.fragmentedTracks[e];for(r=s.trak;r.nextSample<r.samples.length&&this.sampleProcessingStarted;){a.debug("ISOFile","Creating media fragment on track #"+s.id+" for sample "+r.nextSample);var n=this.createFragment(s.id,r.nextSample,s.segmentStream);if(n)s.segmentStream=n,r.nextSample++;else break;if((r.nextSample%s.nb_samples==0||t||r.nextSample>=r.samples.length)&&(a.info("ISOFile","Sending fragmented data on track #"+s.id+" for samples ["+Math.max(0,r.nextSample-s.nb_samples)+","+(r.nextSample-1)+"]"),a.info("ISOFile","Sample data size in memory: "+this.getAllocatedSampleDataSize()),this.onSegment&&this.onSegment(s.id,s.user,s.segmentStream.buffer,r.nextSample,t||r.nextSample>=r.samples.length),s.segmentStream=null,s!==this.fragmentedTracks[e]))break}}if(null!==this.onSamples)for(e=0;e<this.extractedTracks.length;e++){var o=this.extractedTracks[e];for(r=o.trak;r.nextSample<r.samples.length&&this.sampleProcessingStarted;){a.debug("ISOFile","Exporting on track #"+o.id+" sample #"+r.nextSample);var h=this.getSample(r,r.nextSample);if(h)r.nextSample++,o.samples.push(h);else{this.setNextSeekPositionFromSample(r.samples[r.nextSample]);break}if((r.nextSample%o.nb_samples==0||r.nextSample>=r.samples.length)&&(a.debug("ISOFile","Sending samples on track #"+o.id+" for sample "+r.nextSample),this.onSamples&&this.onSamples(o.id,o.user,o.samples),o.samples=[],o!==this.extractedTracks[e]))break}}}},c.prototype.getBox=function(t){var e=this.getBoxes(t,!0);return e.length?e[0]:null},c.prototype.getBoxes=function(t,e){var r=[];return c._sweep.call(this,t,r,e),r},c._sweep=function(t,e,r){for(var s in this.type&&this.type==t&&e.push(this),this.boxes){if(e.length&&r)return;c._sweep.call(this.boxes[s],t,e,r)}},c.prototype.getTrackSamplesInfo=function(t){var e=this.getTrackById(t);if(e)return e.samples},c.prototype.getTrackSample=function(t,e){var r=this.getTrackById(t);return this.getSample(r,e)},c.prototype.releaseUsedSamples=function(t,e){var r=0,s=this.getTrackById(t);s.lastValidSample||(s.lastValidSample=0);for(var n=s.lastValidSample;n<e;n++)r+=this.releaseSample(s,n);a.info("ISOFile","Track #"+t+" released samples up to "+e+" (released size: "+r+", remaining: "+this.samplesDataSize+")"),s.lastValidSample=e},c.prototype.start=function(){this.sampleProcessingStarted=!0,this.processSamples(!1)},c.prototype.stop=function(){this.sampleProcessingStarted=!1},c.prototype.flush=function(){a.info("ISOFile","Flushing remaining samples"),this.updateSampleLists(),this.processSamples(!0),this.stream.cleanBuffers(),this.stream.logBufferLevel(!0)},c.prototype.seekTrack=function(t,e,r){var s,n,o,h=1/0,l=0,u=0;if(0===r.samples.length)return a.info("ISOFile","No sample in track, cannot seek! Using time "+a.getDurationString(0,1)+" and offset: 0"),{offset:0,time:0};for(s=0;s<r.samples.length;s++){if(n=r.samples[s],0===s)u=0,o=n.timescale;else if(n.cts>t*n.timescale){u=s-1;break}e&&n.is_sync&&(l=s)}for(e&&(u=l),t=r.samples[u].cts,r.nextSample=u;r.samples[u].alreadyRead===r.samples[u].size&&r.samples[u+1];)u++;return h=r.samples[u].offset+r.samples[u].alreadyRead,a.info("ISOFile","Seeking to "+(e?"RAP":"")+" sample #"+r.nextSample+" on track "+r.tkhd.track_id+", time "+a.getDurationString(t,o)+" and offset: "+h),{offset:h,time:t/o}},c.prototype.getTrackDuration=function(t){var e;return t.samples?((e=t.samples[t.samples.length-1]).cts+e.duration)/e.timescale:1/0},c.prototype.seek=function(t,e){var r,s,n,o=this.moov,h={offset:1/0,time:1/0};if(this.moov){for(n=0;n<o.traks.length;n++)r=o.traks[n],!(t>this.getTrackDuration(r))&&((s=this.seekTrack(t,e,r)).offset<h.offset&&(h.offset=s.offset),s.time<h.time&&(h.time=s.time));return a.info("ISOFile","Seeking at time "+a.getDurationString(h.time,1)+" needs a buffer with a fileStart position of "+h.offset),h.offset===1/0?h={offset:this.nextParsePosition,time:0}:h.offset=this.stream.getEndFilePositionAfter(h.offset),a.info("ISOFile","Adjusted seek position (after checking data already in buffer): "+h.offset),h}throw"Cannot seek: moov not received!"},c.prototype.equal=function(t){for(var e=0;e<this.boxes.length&&e<t.boxes.length;){var r=this.boxes[e],s=t.boxes[e];if(!d.boxEqual(r,s))return!1;e++}return!0},iT.ISOFile=c,c.prototype.lastBoxStartPosition=0,c.prototype.parsingMdat=null,c.prototype.nextParsePosition=0,c.prototype.discardMdatData=!1,c.prototype.processIncompleteBox=function(t){var e;return"mdat"===t.type?(e=new d[t.type+"Box"](t.size),this.parsingMdat=e,this.boxes.push(e),this.mdats.push(e),e.start=t.start,e.hdr_size=t.hdr_size,this.stream.addUsedBytes(e.hdr_size),this.lastBoxStartPosition=e.start+e.size,this.stream.seek(e.start+e.size,!1,this.discardMdatData)?(this.parsingMdat=null,!0):(this.moovStartFound?this.nextParsePosition=this.stream.findEndContiguousBuf():this.nextParsePosition=e.start+e.size,!1)):("moov"===t.type&&(this.moovStartFound=!0,0===this.mdats.length&&(this.isProgressive=!0)),this.stream.mergeNextBuffer&&this.stream.mergeNextBuffer()?(this.nextParsePosition=this.stream.getEndPosition(),!0):(t.type?this.moovStartFound?this.nextParsePosition=this.stream.getEndPosition():this.nextParsePosition=this.stream.getPosition()+t.size:this.nextParsePosition=this.stream.getEndPosition(),!1))},c.prototype.hasIncompleteMdat=function(){return null!==this.parsingMdat},c.prototype.processIncompleteMdat=function(){var t;return t=this.parsingMdat,this.stream.seek(t.start+t.size,!1,this.discardMdatData)?(a.debug("ISOFile","Found 'mdat' end in buffered data"),this.parsingMdat=null,!0):(this.nextParsePosition=this.stream.findEndContiguousBuf(),!1)},c.prototype.restoreParsePosition=function(){return this.stream.seek(this.lastBoxStartPosition,!0,this.discardMdatData)},c.prototype.saveParsePosition=function(){this.lastBoxStartPosition=this.stream.getPosition()},c.prototype.updateUsedBytes=function(t,e){this.stream.addUsedBytes&&("mdat"===t.type?(this.stream.addUsedBytes(t.hdr_size),this.discardMdatData&&this.stream.addUsedBytes(t.size-t.hdr_size)):this.stream.addUsedBytes(t.size))},c.prototype.add=d.Box.prototype.add,c.prototype.addBox=d.Box.prototype.addBox,c.prototype.init=function(t){var e=t||{};this.add("ftyp").set("major_brand",e.brands&&e.brands[0]||"iso4").set("minor_version",0).set("compatible_brands",e.brands||["iso4"]);var r=this.add("moov");return r.add("mvhd").set("timescale",e.timescale||600).set("rate",e.rate||65536).set("creation_time",0).set("modification_time",0).set("duration",e.duration||0).set("volume",e.width?0:256).set("matrix",[65536,0,0,0,65536,0,0,0,1073741824]).set("next_track_id",1),r.add("mvex"),this},c.prototype.addTrack=function(t){this.moov||this.init(t);var e=t||{};e.width=e.width||320,e.height=e.height||320,e.id=e.id||this.moov.mvhd.next_track_id,e.type=e.type||"avc1";var r=this.moov.add("trak");this.moov.mvhd.next_track_id=e.id+1,r.add("tkhd").set("flags",d.TKHD_FLAG_ENABLED|d.TKHD_FLAG_IN_MOVIE|d.TKHD_FLAG_IN_PREVIEW).set("creation_time",0).set("modification_time",0).set("track_id",e.id).set("duration",e.duration||0).set("layer",e.layer||0).set("alternate_group",0).set("volume",1).set("matrix",[0,0,0,0,0,0,0,0,0]).set("width",e.width<<16).set("height",e.height<<16);var s=r.add("mdia");s.add("mdhd").set("creation_time",0).set("modification_time",0).set("timescale",e.timescale||1).set("duration",e.media_duration||0).set("language",e.language||"und"),s.add("hdlr").set("handler",e.hdlr||"vide").set("name",e.name||"Track created with MP4Box.js"),s.add("elng").set("extended_language",e.language||"fr-FR");var n=s.add("minf");if(void 0!==d[e.type+"SampleEntry"]){var a=new d[e.type+"SampleEntry"];a.data_reference_index=1;var h="";for(var l in d.sampleEntryCodes)for(var u=d.sampleEntryCodes[l],f=0;f<u.length;f++)if(u.indexOf(e.type)>-1){h=l;break}switch(h){case"Visual":if(n.add("vmhd").set("graphicsmode",0).set("opcolor",[0,0,0]),a.set("width",e.width).set("height",e.height).set("horizresolution",4718592).set("vertresolution",4718592).set("frame_count",1).set("compressorname",e.type+" Compressor").set("depth",24),e.avcDecoderConfigRecord){var p=new d.avcCBox;p.parse(new o(e.avcDecoderConfigRecord)),a.addBox(p)}else if(e.hevcDecoderConfigRecord){var c=new d.hvcCBox;c.parse(new o(e.hevcDecoderConfigRecord)),a.addBox(c)}break;case"Audio":n.add("smhd").set("balance",e.balance||0),a.set("channel_count",e.channel_count||2).set("samplesize",e.samplesize||16).set("samplerate",e.samplerate||65536);break;case"Hint":n.add("hmhd");break;case"Subtitle":n.add("sthd"),"stpp"===e.type&&a.set("namespace",e.namespace||"nonamespace").set("schema_location",e.schema_location||"").set("auxiliary_mime_types",e.auxiliary_mime_types||"");break;default:n.add("nmhd")}e.description&&a.addBox(e.description),e.description_boxes&&e.description_boxes.forEach(function(t){a.addBox(t)}),n.add("dinf").add("dref").addEntry(new d["url Box"]().set("flags",1));var m=n.add("stbl");return m.add("stsd").addEntry(a),m.add("stts").set("sample_counts",[]).set("sample_deltas",[]),m.add("stsc").set("first_chunk",[]).set("samples_per_chunk",[]).set("sample_description_index",[]),m.add("stco").set("chunk_offsets",[]),m.add("stsz").set("sample_sizes",[]),this.moov.mvex.add("trex").set("track_id",e.id).set("default_sample_description_index",e.default_sample_description_index||1).set("default_sample_duration",e.default_sample_duration||0).set("default_sample_size",e.default_sample_size||0).set("default_sample_flags",e.default_sample_flags||0),this.buildTrakSampleLists(r),e.id}},d.Box.prototype.computeSize=function(t){var e=t||new h;e.endianness=h.BIG_ENDIAN,this.write(e)},c.prototype.addSample=function(t,e,r){var s=r||{},n={},a=this.getTrackById(t);if(null!==a){n.number=a.samples.length,n.track_id=a.tkhd.track_id,n.timescale=a.mdia.mdhd.timescale,n.description_index=s.sample_description_index?s.sample_description_index-1:0,n.description=a.mdia.minf.stbl.stsd.entries[n.description_index],n.data=e,n.size=e.byteLength,n.alreadyRead=n.size,n.duration=s.duration||1,n.cts=s.cts||0,n.dts=s.dts||0,n.is_sync=s.is_sync||!1,n.is_leading=s.is_leading||0,n.depends_on=s.depends_on||0,n.is_depended_on=s.is_depended_on||0,n.has_redundancy=s.has_redundancy||0,n.degradation_priority=s.degradation_priority||0,n.offset=0,n.subsamples=s.subsamples,a.samples.push(n),a.samples_size+=n.size,a.samples_duration+=n.duration,void 0===a.first_dts&&(a.first_dts=s.dts),this.processSamples();var o=this.createSingleSampleMoof(n);return this.addBox(o),o.computeSize(),o.trafs[0].truns[0].data_offset=o.size+8,this.add("mdat").data=new Uint8Array(e),n}},c.prototype.createSingleSampleMoof=function(t){var e=0;e=t.is_sync?33554432:65536;var r=new d.moofBox;r.add("mfhd").set("sequence_number",this.nextMoofNumber),this.nextMoofNumber++;var s=r.add("traf"),n=this.getTrackById(t.track_id);return s.add("tfhd").set("track_id",t.track_id).set("flags",d.TFHD_FLAG_DEFAULT_BASE_IS_MOOF),s.add("tfdt").set("baseMediaDecodeTime",t.dts-(n.first_dts||0)),s.add("trun").set("flags",d.TRUN_FLAGS_DATA_OFFSET|d.TRUN_FLAGS_DURATION|d.TRUN_FLAGS_SIZE|d.TRUN_FLAGS_FLAGS|d.TRUN_FLAGS_CTS_OFFSET).set("data_offset",0).set("first_sample_flags",0).set("sample_count",1).set("sample_duration",[t.duration]).set("sample_size",[t.size]).set("sample_flags",[e]).set("sample_composition_time_offset",[t.cts-t.dts]),r},c.prototype.lastMoofIndex=0,c.prototype.samplesDataSize=0,c.prototype.resetTables=function(){var t,e,r,s,n,a;for(this.initial_duration=this.moov.mvhd.duration,this.moov.mvhd.duration=0,t=0;t<this.moov.traks.length;t++){(e=this.moov.traks[t]).tkhd.duration=0,e.mdia.mdhd.duration=0,(e.mdia.minf.stbl.stco||e.mdia.minf.stbl.co64).chunk_offsets=[],(r=e.mdia.minf.stbl.stsc).first_chunk=[],r.samples_per_chunk=[],r.sample_description_index=[],(e.mdia.minf.stbl.stsz||e.mdia.minf.stbl.stz2).sample_sizes=[],(s=e.mdia.minf.stbl.stts).sample_counts=[],s.sample_deltas=[],(n=e.mdia.minf.stbl.ctts)&&(n.sample_counts=[],n.sample_offsets=[]),a=e.mdia.minf.stbl.stss;var o=e.mdia.minf.stbl.boxes.indexOf(a);-1!=o&&(e.mdia.minf.stbl.boxes[o]=null)}},c.initSampleGroups=function(t,e,r,s,n){var a,o,h,l;function u(t,e,r){this.grouping_type=t,this.grouping_type_parameter=e,this.sbgp=r,this.last_sample_in_run=-1,this.entry_index=-1}for(e&&(e.sample_groups_info=[]),t.sample_groups_info||(t.sample_groups_info=[]),o=0;o<r.length;o++){for(l=r[o].grouping_type+"/"+r[o].grouping_type_parameter,h=new u(r[o].grouping_type,r[o].grouping_type_parameter,r[o]),e&&(e.sample_groups_info[l]=h),t.sample_groups_info[l]||(t.sample_groups_info[l]=h),a=0;a<s.length;a++)s[a].grouping_type===r[o].grouping_type&&(h.description=s[a],h.description.used=!0);if(n)for(a=0;a<n.length;a++)n[a].grouping_type===r[o].grouping_type&&(h.fragment_description=n[a],h.fragment_description.used=!0,h.is_fragment=!0)}if(e){if(n)for(o=0;o<n.length;o++)!n[o].used&&n[o].version>=2&&(l=n[o].grouping_type+"/0",(h=new u(n[o].grouping_type,0)).is_fragment=!0,e.sample_groups_info[l]||(e.sample_groups_info[l]=h))}else for(o=0;o<s.length;o++)!s[o].used&&s[o].version>=2&&(l=s[o].grouping_type+"/0",h=new u(s[o].grouping_type,0),t.sample_groups_info[l]||(t.sample_groups_info[l]=h))},c.setSampleGroupProperties=function(t,e,r,s){var n,a,o;for(n in e.sample_groups=[],s)e.sample_groups[n]={},e.sample_groups[n].grouping_type=s[n].grouping_type,e.sample_groups[n].grouping_type_parameter=s[n].grouping_type_parameter,r>=s[n].last_sample_in_run&&(s[n].last_sample_in_run<0&&(s[n].last_sample_in_run=0),s[n].entry_index++,s[n].entry_index<=s[n].sbgp.entries.length-1&&(s[n].last_sample_in_run+=s[n].sbgp.entries[s[n].entry_index].sample_count)),s[n].entry_index<=s[n].sbgp.entries.length-1?e.sample_groups[n].group_description_index=s[n].sbgp.entries[s[n].entry_index].group_description_index:e.sample_groups[n].group_description_index=-1,0!==e.sample_groups[n].group_description_index&&(o=s[n].fragment_description?s[n].fragment_description:s[n].description,e.sample_groups[n].group_description_index>0?(a=e.sample_groups[n].group_description_index>65535?(e.sample_groups[n].group_description_index>>16)-1:e.sample_groups[n].group_description_index-1,o&&a>=0&&(e.sample_groups[n].description=o.entries[a])):o&&o.version>=2&&o.default_group_description_index>0&&(e.sample_groups[n].description=o.entries[o.default_group_description_index-1]))},c.process_sdtp=function(t,e,r){e&&(t?(e.is_leading=t.is_leading[r],e.depends_on=t.sample_depends_on[r],e.is_depended_on=t.sample_is_depended_on[r],e.has_redundancy=t.sample_has_redundancy[r]):(e.is_leading=0,e.depends_on=0,e.is_depended_on=0,e.has_redundancy=0))},c.prototype.buildSampleLists=function(){var t,e;for(t=0;t<this.moov.traks.length;t++)e=this.moov.traks[t],this.buildTrakSampleLists(e)},c.prototype.buildTrakSampleLists=function(t){var e,r,s,n,a,o,h,l,u,d,f,p,m,g,y,_,b,w,v,S,E,U,x,T;if(t.samples=[],t.samples_duration=0,t.samples_size=0,r=t.mdia.minf.stbl.stco||t.mdia.minf.stbl.co64,s=t.mdia.minf.stbl.stsc,n=t.mdia.minf.stbl.stsz||t.mdia.minf.stbl.stz2,a=t.mdia.minf.stbl.stts,o=t.mdia.minf.stbl.ctts,h=t.mdia.minf.stbl.stss,l=t.mdia.minf.stbl.stsd,u=t.mdia.minf.stbl.subs,p=t.mdia.minf.stbl.stdp,d=t.mdia.minf.stbl.sbgps,f=t.mdia.minf.stbl.sgpds,w=-1,v=-1,S=-1,E=-1,U=0,x=0,T=0,c.initSampleGroups(t,null,d,f),!(typeof n>"u")){for(e=0;e<n.sample_sizes.length;e++){var A={};A.number=e,A.track_id=t.tkhd.track_id,A.timescale=t.mdia.mdhd.timescale,A.alreadyRead=0,t.samples[e]=A,A.size=n.sample_sizes[e],t.samples_size+=A.size,0===e?(g=1,m=0,A.chunk_index=g,A.chunk_run_index=m,b=s.samples_per_chunk[m],_=0,y=m+1<s.first_chunk.length?s.first_chunk[m+1]-1:1/0):e<b?(A.chunk_index=g,A.chunk_run_index=m):(g++,A.chunk_index=g,_=0,g<=y||(y=++m+1<s.first_chunk.length?s.first_chunk[m+1]-1:1/0),A.chunk_run_index=m,b+=s.samples_per_chunk[m]),A.description_index=s.sample_description_index[A.chunk_run_index]-1,A.description=l.entries[A.description_index],A.offset=r.chunk_offsets[A.chunk_index-1]+_,_+=A.size,e>w&&(v++,w<0&&(w=0),w+=a.sample_counts[v]),e>0?(t.samples[e-1].duration=a.sample_deltas[v],t.samples_duration+=t.samples[e-1].duration,A.dts=t.samples[e-1].dts+t.samples[e-1].duration):A.dts=0,o?(e>=S&&(E++,S<0&&(S=0),S+=o.sample_counts[E]),A.cts=t.samples[e].dts+o.sample_offsets[E]):A.cts=A.dts,h?(e==h.sample_numbers[U]-1?(A.is_sync=!0,U++):(A.is_sync=!1,A.degradation_priority=0),u&&u.entries[x].sample_delta+T==e+1&&(A.subsamples=u.entries[x].subsamples,T+=u.entries[x].sample_delta,x++)):A.is_sync=!0,c.process_sdtp(t.mdia.minf.stbl.sdtp,A,A.number),p?A.degradation_priority=p.priority[e]:A.degradation_priority=0,u&&u.entries[x].sample_delta+T==e&&(A.subsamples=u.entries[x].subsamples,T+=u.entries[x].sample_delta),(d.length>0||f.length>0)&&c.setSampleGroupProperties(t,A,e,t.sample_groups_info)}e>0&&(t.samples[e-1].duration=Math.max(t.mdia.mdhd.duration-t.samples[e-1].dts,0),t.samples_duration+=t.samples[e-1].duration)}},c.prototype.updateSampleLists=function(){var t,e,r,s,n,a,o,h,l,u,f,p,m,g;if(void 0!==this.moov){for(;this.lastMoofIndex<this.moofs.length;)if(l=this.moofs[this.lastMoofIndex],this.lastMoofIndex++,"moof"==l.type)for(t=0;t<l.trafs.length;t++){for(u=l.trafs[t],f=this.getTrackById(u.tfhd.track_id),p=this.getTrexById(u.tfhd.track_id),s=u.tfhd.flags&d.TFHD_FLAG_SAMPLE_DESC?u.tfhd.default_sample_description_index:p?p.default_sample_description_index:1,n=u.tfhd.flags&d.TFHD_FLAG_SAMPLE_DUR?u.tfhd.default_sample_duration:p?p.default_sample_duration:0,a=u.tfhd.flags&d.TFHD_FLAG_SAMPLE_SIZE?u.tfhd.default_sample_size:p?p.default_sample_size:0,o=u.tfhd.flags&d.TFHD_FLAG_SAMPLE_FLAGS?u.tfhd.default_sample_flags:p?p.default_sample_flags:0,u.sample_number=0,u.sbgps.length>0&&c.initSampleGroups(f,u,u.sbgps,f.mdia.minf.stbl.sgpds,u.sgpds),e=0;e<u.truns.length;e++){var y=u.truns[e];for(r=0;r<y.sample_count;r++){(m={}).moof_number=this.lastMoofIndex,m.number_in_traf=u.sample_number,u.sample_number++,m.number=f.samples.length,u.first_sample_index=f.samples.length,f.samples.push(m),m.track_id=f.tkhd.track_id,m.timescale=f.mdia.mdhd.timescale,m.description_index=s-1,m.description=f.mdia.minf.stbl.stsd.entries[m.description_index],m.size=a,y.flags&d.TRUN_FLAGS_SIZE&&(m.size=y.sample_size[r]),f.samples_size+=m.size,m.duration=n,y.flags&d.TRUN_FLAGS_DURATION&&(m.duration=y.sample_duration[r]),f.samples_duration+=m.duration,f.first_traf_merged||r>0?m.dts=f.samples[f.samples.length-2].dts+f.samples[f.samples.length-2].duration:(u.tfdt?m.dts=u.tfdt.baseMediaDecodeTime:m.dts=0,f.first_traf_merged=!0),m.cts=m.dts,y.flags&d.TRUN_FLAGS_CTS_OFFSET&&(m.cts=m.dts+y.sample_composition_time_offset[r]),g=o,y.flags&d.TRUN_FLAGS_FLAGS?g=y.sample_flags[r]:0===r&&y.flags&d.TRUN_FLAGS_FIRST_FLAG&&(g=y.first_sample_flags),m.is_sync=!(g>>16&1),m.is_leading=g>>26&3,m.depends_on=g>>24&3,m.is_depended_on=g>>22&3,m.has_redundancy=g>>20&3,m.degradation_priority=65535&g;var _=!!(u.tfhd.flags&d.TFHD_FLAG_BASE_DATA_OFFSET),b=!!(u.tfhd.flags&d.TFHD_FLAG_DEFAULT_BASE_IS_MOOF),w=!!(y.flags&d.TRUN_FLAGS_DATA_OFFSET),v=0;v=_?u.tfhd.base_data_offset:b||0===e?l.start:h,0===e&&0===r?w?m.offset=v+y.data_offset:m.offset=v:m.offset=h,h=m.offset+m.size,(u.sbgps.length>0||u.sgpds.length>0||f.mdia.minf.stbl.sbgps.length>0||f.mdia.minf.stbl.sgpds.length>0)&&c.setSampleGroupProperties(f,m,m.number_in_traf,u.sample_groups_info)}}if(u.subs){f.has_fragment_subsamples=!0;var S=u.first_sample_index;for(e=0;e<u.subs.entries.length;e++)S+=u.subs.entries[e].sample_delta,(m=f.samples[S-1]).subsamples=u.subs.entries[e].subsamples}}}},c.prototype.getSample=function(t,e){var r,s=t.samples[e];if(!this.moov)return null;if(s.data){if(s.alreadyRead==s.size)return s}else s.data=new Uint8Array(s.size),s.alreadyRead=0,this.samplesDataSize+=s.size,a.debug("ISOFile","Allocating sample #"+e+" on track #"+t.tkhd.track_id+" of size "+s.size+" (total: "+this.samplesDataSize+")");for(;;){var n=this.stream.findPosition(!0,s.offset+s.alreadyRead,!1);if(!(n>-1))return null;var o=(r=this.stream.buffers[n]).byteLength-(s.offset+s.alreadyRead-r.fileStart);if(s.size-s.alreadyRead<=o)return a.debug("ISOFile","Getting sample #"+e+" data (alreadyRead: "+s.alreadyRead+" offset: "+(s.offset+s.alreadyRead-r.fileStart)+" read size: "+(s.size-s.alreadyRead)+" full size: "+s.size+")"),h.memcpy(s.data.buffer,s.alreadyRead,r,s.offset+s.alreadyRead-r.fileStart,s.size-s.alreadyRead),r.usedBytes+=s.size-s.alreadyRead,this.stream.logBufferLevel(),s.alreadyRead=s.size,s;if(0===o)return null;a.debug("ISOFile","Getting sample #"+e+" partial data (alreadyRead: "+s.alreadyRead+" offset: "+(s.offset+s.alreadyRead-r.fileStart)+" read size: "+o+" full size: "+s.size+")"),h.memcpy(s.data.buffer,s.alreadyRead,r,s.offset+s.alreadyRead-r.fileStart,o),s.alreadyRead+=o,r.usedBytes+=o,this.stream.logBufferLevel()}},c.prototype.releaseSample=function(t,e){var r=t.samples[e];return r.data?(this.samplesDataSize-=r.size,r.data=null,r.alreadyRead=0,r.size):0},c.prototype.getAllocatedSampleDataSize=function(){return this.samplesDataSize},c.prototype.getCodecs=function(){var t,e="";for(t=0;t<this.moov.traks.length;t++){var r=this.moov.traks[t];t>0&&(e+=","),e+=r.mdia.minf.stbl.stsd.entries[0].getCodec()}return e},c.prototype.getTrexById=function(t){var e;if(!this.moov||!this.moov.mvex)return null;for(e=0;e<this.moov.mvex.trexs.length;e++){var r=this.moov.mvex.trexs[e];if(r.track_id==t)return r}return null},c.prototype.getTrackById=function(t){if(void 0===this.moov)return null;for(var e=0;e<this.moov.traks.length;e++){var r=this.moov.traks[e];if(r.tkhd.track_id==t)return r}return null},c.prototype.items=[],c.prototype.itemsDataSize=0,c.prototype.flattenItemInfo=function(){var t,e,r,s=this.items,n=this.meta;if(null!=n&&void 0!==n.hdlr&&void 0!==n.iinf){for(t=0;t<n.iinf.item_infos.length;t++)(r={}).id=n.iinf.item_infos[t].item_ID,s[r.id]=r,r.ref_to=[],r.name=n.iinf.item_infos[t].item_name,n.iinf.item_infos[t].protection_index>0&&(r.protection=n.ipro.protections[n.iinf.item_infos[t].protection_index-1]),n.iinf.item_infos[t].item_type?r.type=n.iinf.item_infos[t].item_type:r.type="mime",r.content_type=n.iinf.item_infos[t].content_type,r.content_encoding=n.iinf.item_infos[t].content_encoding;if(n.iloc)for(t=0;t<n.iloc.items.length;t++){var o=n.iloc.items[t];switch(r=s[o.item_ID],0!==o.data_reference_index&&(a.warn("Item storage with reference to other files: not supported"),r.source=n.dinf.boxes[o.data_reference_index-1]),o.construction_method){case 0:break;case 1:case 2:a.warn("Item storage with construction_method : not supported")}for(r.extents=[],r.size=0,e=0;e<o.extents.length;e++)r.extents[e]={},r.extents[e].offset=o.extents[e].extent_offset+o.base_offset,r.extents[e].length=o.extents[e].extent_length,r.extents[e].alreadyRead=0,r.size+=r.extents[e].length}if(n.pitm&&(s[n.pitm.item_id].primary=!0),n.iref)for(t=0;t<n.iref.references.length;t++){var h=n.iref.references[t];for(e=0;e<h.references.length;e++)s[h.from_item_ID].ref_to.push({type:h.type,id:h.references[e]})}if(n.iprp)for(var l=0;l<n.iprp.ipmas.length;l++){var u=n.iprp.ipmas[l];for(t=0;t<u.associations.length;t++){var d=u.associations[t];for(void 0===(r=s[d.id]).properties&&(r.properties={},r.properties.boxes=[]),e=0;e<d.props.length;e++){var f=d.props[e];if(f.property_index>0&&f.property_index-1<n.iprp.ipco.boxes.length){var p=n.iprp.ipco.boxes[f.property_index-1];r.properties[p.type]=p,r.properties.boxes.push(p)}}}}}},c.prototype.getItem=function(t){var e,r;if(!this.meta)return null;if(!(r=this.items[t]).data&&r.size)r.data=new Uint8Array(r.size),r.alreadyRead=0,this.itemsDataSize+=r.size,a.debug("ISOFile","Allocating item #"+t+" of size "+r.size+" (total: "+this.itemsDataSize+")");else if(r.alreadyRead===r.size)return r;for(var s=0;s<r.extents.length;s++){var n=r.extents[s];if(n.alreadyRead!==n.length){var o=this.stream.findPosition(!0,n.offset+n.alreadyRead,!1);if(!(o>-1))return null;var l=(e=this.stream.buffers[o]).byteLength-(n.offset+n.alreadyRead-e.fileStart);if(!(n.length-n.alreadyRead<=l))return a.debug("ISOFile","Getting item #"+t+" extent #"+s+" partial data (alreadyRead: "+n.alreadyRead+" offset: "+(n.offset+n.alreadyRead-e.fileStart)+" read size: "+l+" full extent size: "+n.length+" full item size: "+r.size+")"),h.memcpy(r.data.buffer,r.alreadyRead,e,n.offset+n.alreadyRead-e.fileStart,l),n.alreadyRead+=l,r.alreadyRead+=l,e.usedBytes+=l,this.stream.logBufferLevel(),null;a.debug("ISOFile","Getting item #"+t+" extent #"+s+" data (alreadyRead: "+n.alreadyRead+" offset: "+(n.offset+n.alreadyRead-e.fileStart)+" read size: "+(n.length-n.alreadyRead)+" full extent size: "+n.length+" full item size: "+r.size+")"),h.memcpy(r.data.buffer,r.alreadyRead,e,n.offset+n.alreadyRead-e.fileStart,n.length-n.alreadyRead),e.usedBytes+=n.length-n.alreadyRead,this.stream.logBufferLevel(),r.alreadyRead+=n.length-n.alreadyRead,n.alreadyRead=n.length}}return r.alreadyRead===r.size?r:null},c.prototype.releaseItem=function(t){var e=this.items[t];if(!e.data)return 0;this.itemsDataSize-=e.size,e.data=null,e.alreadyRead=0;for(var r=0;r<e.extents.length;r++)e.extents[r].alreadyRead=0;return e.size},c.prototype.processItems=function(t){for(var e in this.items){var r=this.items[e];this.getItem(r.id),t&&!r.sent&&(t(r),r.sent=!0,r.data=null)}},c.prototype.hasItem=function(t){for(var e in this.items){var r=this.items[e];if(r.name===t)return r.id}return -1},c.prototype.getMetaHandler=function(){return this.meta?this.meta.hdlr.handler:null},c.prototype.getPrimaryItem=function(){return this.meta&&this.meta.pitm?this.getItem(this.meta.pitm.item_id):null},c.prototype.itemToFragmentedTrackFile=function(t){var e=t||{},r=null;if(null==(r=e.itemId?this.getItem(e.itemId):this.getPrimaryItem()))return null;var s=new c;s.discardMdatData=!1;var n={type:r.type,description_boxes:r.properties.boxes};r.properties.ispe&&(n.width=r.properties.ispe.image_width,n.height=r.properties.ispe.image_height);var a=s.addTrack(n);return a?(s.addSample(a,r.data),s):null},c.prototype.write=function(t){for(var e=0;e<this.boxes.length;e++)this.boxes[e].write(t)},c.prototype.createFragment=function(t,e,r){var s=this.getTrackById(t),n=this.getSample(s,e);if(null==n)return this.setNextSeekPositionFromSample(s.samples[e]),null;var o=r||new h;o.endianness=h.BIG_ENDIAN;var l=this.createSingleSampleMoof(n);l.write(o),l.trafs[0].truns[0].data_offset=l.size+8,a.debug("MP4Box","Adjusting data_offset with new value "+l.trafs[0].truns[0].data_offset),o.adjustUint32(l.trafs[0].truns[0].data_offset_position,l.trafs[0].truns[0].data_offset);var u=new d.mdatBox;return u.data=n.data,u.write(o),o},c.writeInitializationSegment=function(t,e,r,s){a.debug("ISOFile","Generating initialization segment");var n,o=new h;o.endianness=h.BIG_ENDIAN,t.write(o);var l=e.add("mvex");for(r&&l.add("mehd").set("fragment_duration",r),n=0;n<e.traks.length;n++)l.add("trex").set("track_id",e.traks[n].tkhd.track_id).set("default_sample_description_index",1).set("default_sample_duration",s).set("default_sample_size",0).set("default_sample_flags",65536);return e.write(o),o.buffer},c.prototype.save=function(t){var e=new h;e.endianness=h.BIG_ENDIAN,this.write(e),e.save(t)},c.prototype.getBuffer=function(){var t=new h;return t.endianness=h.BIG_ENDIAN,this.write(t),t.buffer},c.prototype.initializeSegmentation=function(){var t,e,r,s;for(null===this.onSegment&&a.warn("MP4Box","No segmentation callback set!"),this.isFragmentationInitialized||(this.isFragmentationInitialized=!0,this.nextMoofNumber=0,this.resetTables()),e=[],t=0;t<this.fragmentedTracks.length;t++){var n=new d.moovBox;n.mvhd=this.moov.mvhd,n.boxes.push(n.mvhd),r=this.getTrackById(this.fragmentedTracks[t].id),n.boxes.push(r),n.traks.push(r),(s={}).id=r.tkhd.track_id,s.user=this.fragmentedTracks[t].user,s.buffer=c.writeInitializationSegment(this.ftyp,n,this.moov.mvex&&this.moov.mvex.mehd?this.moov.mvex.mehd.fragment_duration:void 0,this.moov.traks[t].samples.length>0?this.moov.traks[t].samples[0].duration:0),e.push(s)}return e},d.Box.prototype.printHeader=function(t){this.size+=8,this.size>4294967296&&(this.size+=8),"uuid"===this.type&&(this.size+=16),t.log(t.indent+"size:"+this.size),t.log(t.indent+"type:"+this.type)},d.FullBox.prototype.printHeader=function(t){this.size+=4,d.Box.prototype.printHeader.call(this,t),t.log(t.indent+"version:"+this.version),t.log(t.indent+"flags:"+this.flags)},d.Box.prototype.print=function(t){this.printHeader(t)},d.ContainerBox.prototype.print=function(t){this.printHeader(t);for(var e=0;e<this.boxes.length;e++)if(this.boxes[e]){var r=t.indent;t.indent+=" ",this.boxes[e].print(t),t.indent=r}},c.prototype.print=function(t){t.indent="";for(var e=0;e<this.boxes.length;e++)this.boxes[e]&&this.boxes[e].print(t)},d.mvhdBox.prototype.print=function(t){d.FullBox.prototype.printHeader.call(this,t),t.log(t.indent+"creation_time: "+this.creation_time),t.log(t.indent+"modification_time: "+this.modification_time),t.log(t.indent+"timescale: "+this.timescale),t.log(t.indent+"duration: "+this.duration),t.log(t.indent+"rate: "+this.rate),t.log(t.indent+"volume: "+(this.volume>>8)),t.log(t.indent+"matrix: "+this.matrix.join(", ")),t.log(t.indent+"next_track_id: "+this.next_track_id)},d.tkhdBox.prototype.print=function(t){d.FullBox.prototype.printHeader.call(this,t),t.log(t.indent+"creation_time: "+this.creation_time),t.log(t.indent+"modification_time: "+this.modification_time),t.log(t.indent+"track_id: "+this.track_id),t.log(t.indent+"duration: "+this.duration),t.log(t.indent+"volume: "+(this.volume>>8)),t.log(t.indent+"matrix: "+this.matrix.join(", ")),t.log(t.indent+"layer: "+this.layer),t.log(t.indent+"alternate_group: "+this.alternate_group),t.log(t.indent+"width: "+this.width),t.log(t.indent+"height: "+this.height)},(m={}).createFile=function(t,e){var r=new c(e);return r.discardMdatData=!(void 0===t||t),r},iT.createFile=m.createFile;let iA=/* @__PURE__ */ix(iT),iC={sampleRate:48e3,channelCount:2,codec:"mp4a.40.2"};function iI(t,e){let r=e.videoTracks[0],s={};if(null!=r){let n=function(t){for(let e of t.mdia.minf.stbl.stsd.entries){let t=e.avcC??e.hvcC??e.vpcC;if(null!=t){let e=new iA.DataStream(void 0,0,iA.DataStream.BIG_ENDIAN);return t.write(e),new Uint8Array(e.buffer.slice(8))}}throw Error("avcC, hvcC or VPX not found")}(t.getTrackById(r.id)).buffer,{descKey:a,type:o}=r.codec.startsWith("avc1")?{descKey:"avcDecoderConfigRecord",type:"avc1"}:r.codec.startsWith("hvc1")?{descKey:"hevcDecoderConfigRecord",type:"hvc1"}:{descKey:"",type:""};""!==a&&(s.videoTrackConf={timescale:r.timescale,duration:r.duration,width:r.video.width,height:r.video.height,brands:e.brands,type:o,[a]:n}),s.videoDecoderConf={codec:r.codec,codedHeight:r.video.height,codedWidth:r.video.width,description:n}}let n=e.audioTracks[0];if(null!=n){let e=iB(t);s.audioTrackConf={timescale:n.timescale,samplerate:n.audio.sample_rate,channel_count:n.audio.channel_count,hdlr:"soun",type:n.codec.startsWith("mp4a")?"mp4a":n.codec,description:iB(t)},s.audioDecoderConf={codec:n.codec.startsWith("mp4a")?iC.codec:n.codec,numberOfChannels:n.audio.channel_count,sampleRate:n.audio.sample_rate,...null==e?{}:function(t){var e;let r=null==(e=t.esd.descs[0])?void 0:e.descs[0];if(null==r)return{};let[s,n]=r.data;return{sampleRate:[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350][((7&s)<<1)+(n>>7)],numberOfChannels:(127&n)>>3}}(e)}}return s}function iB(t,e="mp4a"){var r;let s=null==(r=t.moov)?void 0:r.traks.map(t=>t.mdia.minf.stbl.stsd.entries).flat().find(({type:t})=>t===e);return null==s?void 0:s.esds}class ik{constructor(){ey(this,"readable"),ey(this,"writable"),ew(this,A,0);let t=iA.createFile(),e=!1;this.readable=new ReadableStream({start:e=>{t.onReady=r=>{var s,n;let a=null==(s=r.videoTracks[0])?void 0:s.id;null!=a&&t.setExtractionOptions(a,"video",{nbSamples:100});let o=null==(n=r.audioTracks[0])?void 0:n.id;null!=o&&t.setExtractionOptions(o,"audio",{nbSamples:100}),e.enqueue({chunkType:"ready",data:{info:r,file:t}}),t.start()};let r={};t.onSamples=(s,n,a)=>{e.enqueue({chunkType:"samples",data:{id:s,type:n,samples:a.map(t=>({...t}))}}),r[s]=(r[s]??0)+a.length,t.releaseUsedSamples(s,r[s])},t.onFlush=()=>{e.close()}},cancel:()=>{t.stop(),e=!0}},{highWaterMark:50}),this.writable=new WritableStream({write:async r=>{if(e){this.writable.abort();return}let s=r.buffer;s.fileStart=eb(this,A),ev(this,A,eb(this,A)+s.byteLength),t.appendBuffer(s)},close:()=>{var e;t.flush(),t.stop(),null==(e=t.onFlush)||e.call(t)}})}}A=new WeakMap;let iF=0;function iR(t){return"file"===t.kind&&t.createReader instanceof Function}let iP=class t{constructor(t,e={audio:!0}){if(ew(this,C,e5.create(`MP4Clip id:${iF++},`)),ey(this,"ready"),ew(this,I,!1),ew(this,B,{duration:0,width:0,height:0,audioSampleRate:0,audioChanCount:0}),ew(this,k),ew(this,F,1),ew(this,R,[]),ew(this,P,[]),ew(this,z,null),ew(this,L,null),ew(this,D,{video:null,audio:null}),ew(this,M,{audio:!0}),ey(this,"tickInterceptor",async(t,e)=>e),ew(this,O,new AbortController),!(t instanceof ReadableStream)&&!iR(t)&&!Array.isArray(t.videoSamples))throw Error("Illegal argument");ev(this,M,{...e}),ev(this,F,"object"==typeof e.audio&&"volume"in e.audio?e.audio.volume:1);let r=async t=>(await eH(eb(this,k),t),await eb(this,k).stream());ev(this,k,iR(t)?t:"localFile"in t?t.localFile:e1()),this.ready=(t instanceof ReadableStream?r(t).then(t=>iL(t,eb(this,M))):iR(t)?t.stream().then(t=>iL(t,eb(this,M))):Promise.resolve(t)).then(async({videoSamples:t,audioSamples:e,decoderConf:r})=>{var s,n,a;ev(this,R,t),ev(this,P,e),ev(this,D,r);let{videoFrameFinder:o,audioFrameFinder:h}=(s={video:null==r.video?null:{...r.video,hardwareAcceleration:eb(this,M).__unsafe_hardwareAcceleration__},audio:r.audio},n=await eb(this,k).createReader(),{audioFrameFinder:null==(a=!1!==eb(this,M).audio?eb(this,F):null)||null==s.audio||0===e.length?null:new iM(n,e,s.audio,{volume:a,targetSampleRate:iC.sampleRate}),videoFrameFinder:null==s.video||0===t.length?null:new iD(n,t,s.video)});return ev(this,z,o),ev(this,L,h),ev(this,B,function(t,e,r){let s={duration:0,width:0,height:0,audioSampleRate:0,audioChanCount:0};null!=t.video&&e.length>0&&(s.width=t.video.codedWidth??0,s.height=t.video.codedHeight??0),null!=t.audio&&r.length>0&&(s.audioSampleRate=iC.sampleRate,s.audioChanCount=iC.channelCount);let n=0,a=0;if(e.length>0)for(let t=e.length-1;t>=0;t--){let r=e[t];if(!r.deleted){n=r.cts+r.duration;break}}if(r.length>0){let t=r.at(-1);a=t.cts+t.duration}return s.duration=Math.max(n,a),s}(r,t,e)),eb(this,C).info("MP4Clip meta:",eb(this,B)),{...eb(this,B)}})}get meta(){return{...eb(this,B)}}async tick(t){var e,r;if(t>=eb(this,B).duration)return await this.tickInterceptor(t,{audio:[],state:"done"});let[s,n]=await Promise.all([(null==(e=eb(this,L))?void 0:e.find(t))??[],null==(r=eb(this,z))?void 0:r.find(t)]);return null==n?await this.tickInterceptor(t,{audio:s,state:"success"}):await this.tickInterceptor(t,{video:n,audio:s,state:"success"})}async thumbnails(t=100,e){eb(this,O).abort(),ev(this,O,new AbortController);let r=eb(this,O).signal;await this.ready;let s="generate thumbnails aborted";if(r.aborted)throw Error(s);let{width:n,height:a}=eb(this,B),o=function(t,e,r){let s=new OffscreenCanvas(t,e),n=s.getContext("2d");return async a=>(n.drawImage(a,0,0,t,e),a.close(),await s.convertToBlob(r))}(t,Math.round(t/n*a),{quality:.1,type:"image/png"});return new Promise(async(t,n)=>{let a=[],h=eb(this,D).video;if(null==h||0===eb(this,R).length){l();return}async function l(){r.aborted||t(await Promise.all(a.map(async t=>({ts:t.ts,img:await t.img}))))}function u(t){a.push({ts:t.timestamp,img:o(t)})}r.addEventListener("abort",()=>{n(Error(s))});let{start:d=0,end:f=eb(this,B).duration,step:p}=e??{};if(p){let t=d,e=new iD(await eb(this,k).createReader(),eb(this,R),{...h,hardwareAcceleration:eb(this,M).__unsafe_hardwareAcceleration__});for(;t<=f&&!r.aborted;){let r=await e.find(t);r&&u(r),t+=p}e.destroy(),l()}else await iY(eb(this,R),eb(this,k),h,r,{start:d,end:f},(t,e)=>{u(t),e&&l()})})}async split(e){if(await this.ready,e<=0||e>=eb(this,B).duration)throw Error('"time" out of bounds');let[r,s]=function(t,e){if(0===t.length)return[];let r=0,s=0,n=-1;for(let a=0;a<t.length;a++){let o=t[a];if(-1===n&&e<o.cts&&(n=a-1),o.is_idr){if(-1===n)r=a;else{s=a;break}}}let a=t[n];if(null==a)throw Error("Not found video sample by time");let o=t.slice(0,0===s?t.length:s).map(t=>({...t}));for(let t=r;t<o.length;t++){let r=o[t];e<r.cts&&(r.deleted=!0,r.cts=-1)}let h=t.slice(a.is_idr?s:r).map(t=>({...t,cts:t.cts-e}));for(let t of h){if(t.cts>=0)break;t.deleted=!0,t.cts=-1}return[o,h]}(eb(this,R),e),[n,a]=function(t,e){if(0===t.length)return[];let r=-1;for(let s=0;s<t.length;s++)if(!(e>t[s].cts)){r=s;break}if(-1===r)throw Error("Not found audio sample by time");return[t.slice(0,r),t.slice(r).map(t=>({...t,cts:t.cts-e}))]}(eb(this,P),e),o=new t({localFile:eb(this,k),videoSamples:r??[],audioSamples:n??[],decoderConf:eb(this,D)},eb(this,M)),h=new t({localFile:eb(this,k),videoSamples:s??[],audioSamples:a??[],decoderConf:eb(this,D)},eb(this,M));return await Promise.all([o.ready,h.ready]),[o,h]}async clone(){await this.ready;let e=new t({localFile:eb(this,k),videoSamples:[...eb(this,R)],audioSamples:[...eb(this,P)],decoderConf:eb(this,D)},eb(this,M));return await e.ready,e.tickInterceptor=this.tickInterceptor,e}async splitTrack(){await this.ready;let e=[];if(eb(this,R).length>0){let r=new t({localFile:eb(this,k),videoSamples:[...eb(this,R)],audioSamples:[],decoderConf:{video:eb(this,D).video,audio:null}},eb(this,M));await r.ready,r.tickInterceptor=this.tickInterceptor,e.push(r)}if(eb(this,P).length>0){let r=new t({localFile:eb(this,k),videoSamples:[],audioSamples:[...eb(this,P)],decoderConf:{audio:eb(this,D).audio,video:null}},eb(this,M));await r.ready,r.tickInterceptor=this.tickInterceptor,e.push(r)}return e}destroy(){var t,e;eb(this,I)||(eb(this,C).info("MP4Clip destroy"),ev(this,I,!0),null==(t=eb(this,z))||t.destroy(),null==(e=eb(this,L))||e.destroy())}};C=new WeakMap,I=new WeakMap,B=new WeakMap,k=new WeakMap,F=new WeakMap,R=new WeakMap,P=new WeakMap,z=new WeakMap,L=new WeakMap,D=new WeakMap,M=new WeakMap,O=new WeakMap;let iz=iP;async function iL(t,e={}){let r;let s={video:null,audio:null},n=[],a=[];return new Promise(async(h,l)=>{let u=-1,d=-1,f=iE(t.pipeThrough(new ik),{onChunk:async({chunkType:t,data:h})=>{if("ready"===t){r=h.info;let{videoDecoderConf:t,audioDecoderConf:e}=iI(h.file,h.info);s.video=t??null,s.audio=e??null,null==t&&null==e&&(f(),l(Error("MP4Clip must contain at least one video or audio track"))),e5.info("mp4BoxFile moov ready",{...h.info,tracks:null,videoTracks:null,audioTracks:null},s)}else if("samples"===t){if("video"===h.type)for(let t of(-1===u&&(u=h.samples[0].dts),h.samples))n.push(o(t,u,"video"));else if("audio"===h.type&&e.audio)for(let t of(-1===d&&(d=h.samples[0].dts),h.samples))a.push(o(t,d,"audio"))}},onDone:()=>{let t=n.at(-1)??a.at(-1);if(null==r){l(Error("MP4Clip stream is done, but not emit ready"));return}if(null==t){l(Error("MP4Clip stream not contain any sample"));return}let e=n[0];null!=e&&e.cts<2e5&&(e.duration+=e.cts,e.cts=0),e5.info("mp4 stream parsed"),h({videoSamples:n,audioSamples:a,decoderConf:s})}})});function o(t,e=0,r){return{...t,is_idr:"video"===r&&t.is_sync&&function(t){let e=new DataView(t.buffer),r=0;for(;r<t.byteLength-4;){if((31&e.getUint8(r+4))==5)return!0;r+=e.getUint32(r)+4}return!1}(t.data),cts:(t.cts-e)/t.timescale*1e6,dts:(t.dts-e)/t.timescale*1e6,duration:t.duration/t.timescale*1e6,timescale:1e6,data:"video"===r?null:t.data}}}class iD{constructor(t,e,r){ew(this,N,null),ew(this,G,0),ew(this,Y,{abort:!1,st:performance.now()}),ey(this,"find",async t=>((null==eb(this,N)||t<=eb(this,G)||t-eb(this,G)>3e6)&&eb(this,Q).call(this,t),eb(this,Y).abort=!0,ev(this,G,t),ev(this,Y,{abort:!1,st:performance.now()}),await eb(this,$).call(this,t,eb(this,N),eb(this,Y)))),ew(this,W,0),ew(this,V,!1),ew(this,H,0),ew(this,X,[]),ew(this,j,0),ew(this,Z,0),ew(this,$,async(t,e,r)=>{if(null==e||"closed"===e.state||r.abort)return null;if(eb(this,X).length>0){let s=eb(this,X)[0];return t<s.timestamp?null:(eb(this,X).shift(),t>s.timestamp+(s.duration??0)?(s.close(),await eb(this,$).call(this,t,e,r)):(eb(this,X).length<10&&eb(this,q).call(this,e).catch(e=>{throw eb(this,Q).call(this,t),e}),s))}if(eb(this,K)||eb(this,j)<eb(this,Z)&&e.decodeQueueSize>0){if(performance.now()-r.st>3e3)throw Error(`MP4Clip.tick video timeout, ${JSON.stringify(eb(this,J).call(this))}`);await iv(15)}else{if(eb(this,H)>=this.samples.length)return null;try{await eb(this,q).call(this,e)}catch(e){throw eb(this,Q).call(this,t),e}}return await eb(this,$).call(this,t,e,r)}),ew(this,K,!1),ew(this,q,async t=>{var e,r;if(eb(this,K))return;ev(this,K,!0);let s=eb(this,H)+1,n=!1;for(;s<this.samples.length;s++){let t=this.samples[s];if(n||t.deleted||(n=!0),t.is_idr)break}if(n){let n=this.samples.slice(eb(this,H),s);if((null==(e=n[0])?void 0:e.is_idr)!==!0)e5.warn("First sample not idr frame");else{let e=await iO(n,this.localFileReader);if("closed"===t.state)return;ev(this,W,(null==(r=e[0])?void 0:r.duration)??0),iN(t,e,{onDecodingError:t=>{if(eb(this,V))throw t;ev(this,V,!0),e5.warn("Downgrade to software decode"),eb(this,Q).call(this)}}),ev(this,Z,eb(this,Z)+e.length)}}ev(this,H,s),ev(this,K,!1)}),ew(this,Q,t=>{var e,r;if(ev(this,K,!1),eb(this,X).forEach(t=>t.close()),ev(this,X,[]),null==t||0===t)ev(this,H,0);else{let e=0;for(let r=0;r<this.samples.length;r++){let s=this.samples[r];if(s.is_idr&&(e=r),!(s.cts<t)){ev(this,H,e);break}}}ev(this,Z,0),ev(this,j,0),(null==(e=eb(this,N))?void 0:e.state)!=="closed"&&(null==(r=eb(this,N))||r.close()),ev(this,N,new VideoDecoder({output:t=>{if(ev(this,j,eb(this,j)+1),-1===t.timestamp){t.close();return}let e=t;null==t.duration&&(e=new VideoFrame(t,{duration:eb(this,W)}),t.close()),eb(this,X).push(e)},error:t=>{e5.error(`MP4Clip VideoDecoder err: ${t.message}`)}})),eb(this,N).configure({...this.conf,...eb(this,V)?{hardwareAcceleration:"prefer-software"}:{}})}),ew(this,J,()=>{var t,e;return{time:eb(this,G),decState:null==(t=eb(this,N))?void 0:t.state,decQSize:null==(e=eb(this,N))?void 0:e.decodeQueueSize,decCusorIdx:eb(this,H),sampleLen:this.samples.length,inputCnt:eb(this,Z),outputCnt:eb(this,j),cacheFrameLen:eb(this,X).length,softDeocde:eb(this,V)}}),ey(this,"destroy",()=>{var t,e;(null==(t=eb(this,N))?void 0:t.state)!=="closed"&&(null==(e=eb(this,N))||e.close()),ev(this,N,null),eb(this,Y).abort=!0,eb(this,X).forEach(t=>t.close()),ev(this,X,[]),this.localFileReader.close()}),this.localFileReader=t,this.samples=e,this.conf=r}}N=new WeakMap,G=new WeakMap,Y=new WeakMap,W=new WeakMap,V=new WeakMap,H=new WeakMap,X=new WeakMap,j=new WeakMap,Z=new WeakMap,$=new WeakMap,K=new WeakMap,q=new WeakMap,Q=new WeakMap,J=new WeakMap;class iM{constructor(t,e,r,s){ew(this,tt,1),ew(this,te),ew(this,ti,null),ew(this,tr,{abort:!1,st:performance.now()}),ey(this,"find",async t=>{if(null==eb(this,ti)||t<=eb(this,ts)||t-eb(this,ts)>1e5){eb(this,tl).call(this),ev(this,ts,t);for(let e=0;e<this.samples.length;e++)if(!(this.samples[e].cts<t)){ev(this,tn,e);break}return[]}eb(this,tr).abort=!0;let e=t-eb(this,ts);return ev(this,ts,t),ev(this,tr,{abort:!1,st:performance.now()}),await eb(this,to).call(this,e,eb(this,ti),eb(this,tr))}),ew(this,ts,0),ew(this,tn,0),ew(this,ta,{frameCnt:0,data:[]}),ew(this,to,async(t,e=null,r)=>{if(null==e||r.abort||"closed"===e.state)return[];let s=Math.ceil(t*(eb(this,te)/1e6));if(0===s)return[];let n=eb(this,ta).frameCnt-s;if(n>0)return n<iC.sampleRate/10&&eb(this,th).call(this,e),function(t,e){let r=[new Float32Array(e),new Float32Array(e)],s=0,n=0;for(;n<t.data.length;){let[a,o]=t.data[n];if(s+a.length>e){let h=e-s;r[0].set(a.subarray(0,h),s),r[1].set(o.subarray(0,h),s),t.data[n][0]=a.subarray(h,a.length),t.data[n][1]=o.subarray(h,o.length);break}r[0].set(a,s),r[1].set(o,s),s+=a.length,n++}return t.data=t.data.slice(n),t.frameCnt-=e,r}(eb(this,ta),s);if(e.decodeQueueSize>10){if(performance.now()-r.st>3e3)throw r.abort=!0,Error(`MP4Clip.tick audio timeout, ${JSON.stringify(eb(this,tu).call(this))}`);await iv(15)}else{if(eb(this,tn)>=this.samples.length-1)return[];eb(this,th).call(this,e)}return eb(this,to).call(this,t,e,r)}),ew(this,th,t=>{if(t.decodeQueueSize>100)return;let e=[],r=eb(this,tn);for(;r<this.samples.length;){let t=this.samples[r];if(r+=1,!t.deleted&&(e.push(t),e.length>=10))break}ev(this,tn,r),t.decode(e.map(t=>new EncodedAudioChunk({type:"key",timestamp:t.cts,duration:t.duration,data:t.data})))}),ew(this,tl,()=>{var t;ev(this,ts,0),ev(this,tn,0),ev(this,ta,{frameCnt:0,data:[]}),null==(t=eb(this,ti))||t.close(),ev(this,ti,function(t,e,r){let s=t=>{if(0!==t.length){if(1!==e.volume)for(let r of t)for(let t=0;t<r.length;t++)r[t]*=e.volume;1===t.length&&(t=[t[0],t[0]]),r(t)}},n=function(t){let e=[],r=0;function s(){let n=e[r];null!=n&&(t(n),r+=1,s())}let n=0;return t=>{let r=n;n+=1,t().then(t=>{e[r]=t,s()}).catch(t=>{e[r]=t,s()})}}(s),a=e.resampleRate!==t.sampleRate,o=new AudioDecoder({output:t=>{let r=im(t);a?n(()=>iw(r,t.sampleRate,{rate:e.resampleRate,chanCount:t.numberOfChannels})):s(r),t.close()},error:t=>{e5.error(`MP4Clip AudioDecoder err: ${t.message}`)}});return o.configure(t),{decode(t){for(let e of t)o.decode(e)},close(){"closed"!==o.state&&o.close()},get state(){return o.state},get decodeQueueSize(){return o.decodeQueueSize}}}(this.conf,{resampleRate:iC.sampleRate,volume:eb(this,tt)},t=>{eb(this,ta).data.push(t),eb(this,ta).frameCnt+=t[0].length}))}),ew(this,tu,()=>{var t,e;return{time:eb(this,ts),decState:null==(t=eb(this,ti))?void 0:t.state,decQSize:null==(e=eb(this,ti))?void 0:e.decodeQueueSize,decCusorIdx:eb(this,tn),sampleLen:this.samples.length,pcmLen:eb(this,ta).frameCnt}}),ey(this,"destroy",()=>{ev(this,ti,null),eb(this,tr).abort=!0,ev(this,ta,{frameCnt:0,data:[]}),this.localFileReader.close()}),this.localFileReader=t,this.samples=e,this.conf=r,ev(this,tt,s.volume),ev(this,te,s.targetSampleRate)}}async function iO(t,e){let r=t[0],s=t.at(-1);if(null==s)return[];let n=s.offset+s.size-r.offset;if(n<3e7){let s=new Uint8Array(await e.read(n,{at:r.offset}));return t.map(t=>{let e=t.offset-r.offset,n=s.subarray(e,e+t.size);return t.is_idr&&(n=iG(n)),new EncodedVideoChunk({type:t.is_sync?"key":"delta",timestamp:t.cts,duration:t.duration,data:n})})}return await Promise.all(t.map(async t=>{let r=await e.read(t.size,{at:t.offset});return t.is_idr&&(r=iG(new Uint8Array(r))),new EncodedVideoChunk({type:t.is_sync?"key":"delta",timestamp:t.cts,duration:t.duration,data:r})}))}function iN(t,e,r){let s=0;if("configured"===t.state){for(;s<e.length;s++)t.decode(e[s]);t.flush().catch(t=>{if(!(t instanceof Error))throw t;if(t.message.includes("Decoding error")&&null!=r.onDecodingError){r.onDecodingError(t);return}if(!t.message.includes("Aborted due to close"))throw t})}}function iG(t){let e=new DataView(t.buffer);return(31&e.getUint8(4))==6?t.subarray(e.getUint32(0)+4):t}async function iY(t,e,r,s,n,a){let o=await e.createReader(),h=0,l=new VideoDecoder({output:t=>{let e=(h+=1)===u.length;a(t,e),e&&o.close()},error:e5.error});s.addEventListener("abort",()=>{o.close(),l.close()});let u=await iO(t.filter(t=>!t.deleted&&t.is_sync&&t.cts>=n.start&&t.cts<=n.end),o);0===u.length||s.aborted||(l.configure(r),iN(l,u,{}))}tt=new WeakMap,te=new WeakMap,ti=new WeakMap,tr=new WeakMap,ts=new WeakMap,tn=new WeakMap,ta=new WeakMap,to=new WeakMap,th=new WeakMap,tl=new WeakMap,tu=new WeakMap;let iW=class t{constructor(t){ew(this,tc),ey(this,"ready"),ew(this,td,{duration:0,width:0,height:0}),ew(this,tf,null),ew(this,tp,[]);let e=t=>(ev(this,tf,t),eb(this,td).width=t.width,eb(this,td).height=t.height,eb(this,td).duration=1/0,{...eb(this,td)});if(t instanceof ReadableStream)this.ready=new Response(t).blob().then(t=>createImageBitmap(t)).then(e);else if(t instanceof ImageBitmap)this.ready=Promise.resolve(e(t));else if(Array.isArray(t)&&t.every(t=>t instanceof VideoFrame)){ev(this,tp,t);let e=eb(this,tp)[0];if(null==e)throw Error("The frame count must be greater than 0");ev(this,td,{width:e.displayWidth,height:e.displayHeight,duration:eb(this,tp).reduce((t,e)=>t+(e.duration??0),0)}),this.ready=Promise.resolve({...eb(this,td),duration:1/0})}else if("type"in t)this.ready=eS(this,tc,tm).call(this,t.stream,t.type).then(()=>({width:eb(this,td).width,height:eb(this,td).height,duration:1/0}));else throw Error("Illegal arguments")}get meta(){return{...eb(this,td)}}async tick(t){if(null!=eb(this,tf))return{video:await createImageBitmap(eb(this,tf)),state:"success"};let e=t%eb(this,td).duration;return{video:(eb(this,tp).find(t=>e>=t.timestamp&&e<=t.timestamp+(t.duration??0))??eb(this,tp)[0]).clone(),state:"success"}}async split(e){if(await this.ready,null!=eb(this,tf))return[new t(await createImageBitmap(eb(this,tf))),new t(await createImageBitmap(eb(this,tf)))];let r=-1;for(let t=0;t<eb(this,tp).length;t++)if(!(e>eb(this,tp)[t].timestamp)){r=t;break}if(-1===r)throw Error("Not found frame by time");let s=eb(this,tp).slice(0,r).map(t=>new VideoFrame(t)),n=eb(this,tp).slice(r).map(t=>new VideoFrame(t,{timestamp:t.timestamp-e}));return[new t(s),new t(n)]}async clone(){return await this.ready,new t(null==eb(this,tf)?eb(this,tp).map(t=>t.clone()):await createImageBitmap(eb(this,tf)))}destroy(){var t;e5.info("ImgClip destroy"),null==(t=eb(this,tf))||t.close(),eb(this,tp).forEach(t=>t.close())}};td=new WeakMap,tf=new WeakMap,tp=new WeakMap,tc=new WeakSet,tm=async function(t,e){ev(this,tp,await i_(t,e));let r=eb(this,tp)[0];if(null==r)throw Error("No frame available in gif");ev(this,td,{duration:eb(this,tp).reduce((t,e)=>t+(e.duration??0),0),width:r.codedWidth,height:r.codedHeight}),e5.info("ImgClip ready:",eb(this,td))};let iV=iW,iH=class t{constructor(t,e={}){ew(this,tw),ey(this,"ready"),ew(this,tg,{duration:0,width:0,height:0}),ew(this,ty,new Float32Array),ew(this,t_,new Float32Array),ew(this,tb),ew(this,tS,0),ew(this,tE,0),ev(this,tb,{loop:!1,volume:1,...e}),this.ready=eS(this,tw,tv).call(this,t).then(()=>({width:0,height:0,duration:e.loop?1/0:eb(this,tg).duration}))}get meta(){return{...eb(this,tg),sampleRate:iC.sampleRate,chanCount:2}}getPCMData(){return[eb(this,ty),eb(this,t_)]}async tick(t){if(!eb(this,tb).loop&&t>=eb(this,tg).duration)return{audio:[],state:"done"};let e=t-eb(this,tS);if(t<eb(this,tS)||e>3e6)return ev(this,tS,t),ev(this,tE,Math.ceil(eb(this,tS)/1e6*iC.sampleRate)),{audio:[new Float32Array(0),new Float32Array(0)],state:"success"};ev(this,tS,t);let r=Math.ceil(e/1e6*iC.sampleRate),s=eb(this,tE)+r,n=eb(this,tb).loop?[iS(eb(this,ty),eb(this,tE),s),iS(eb(this,t_),eb(this,tE),s)]:[eb(this,ty).slice(eb(this,tE),s),eb(this,t_).slice(eb(this,tE),s)];return ev(this,tE,s),{audio:n,state:"success"}}async split(e){await this.ready;let r=Math.ceil(e/1e6*iC.sampleRate);return[new t(this.getPCMData().map(t=>t.slice(0,r)),eb(this,tb)),new t(this.getPCMData().map(t=>t.slice(r)),eb(this,tb))]}async clone(){await this.ready;let e=new t(this.getPCMData(),eb(this,tb));return await e.ready,e}destroy(){ev(this,ty,new Float32Array(0)),ev(this,t_,new Float32Array(0)),e5.info("---- audioclip destroy ----")}};tg=new WeakMap,ty=new WeakMap,t_=new WeakMap,tb=new WeakMap,tw=new WeakSet,tv=async function(t){null==iH.ctx&&(iH.ctx=new AudioContext({sampleRate:iC.sampleRate}));let e=performance.now(),r=t instanceof ReadableStream?await iZ(t,iH.ctx):t;e5.info("Audio clip decoded complete:",performance.now()-e);let s=eb(this,tb).volume;if(1!==s)for(let t of r)for(let e=0;e<t.length;e+=1)t[e]*=s;eb(this,tg).duration=r[0].length/iC.sampleRate*1e6,ev(this,ty,r[0]),ev(this,t_,r[1]??eb(this,ty)),e5.info("Audio clip convert to AudioData, time:",performance.now()-e)},tS=new WeakMap,tE=new WeakMap,ey(iH,"ctx",null);let iX=iH;async function ij(t,e){let r=[];for(let e of t)await e.ready,r.push(e.getPCMData());return new iX(ic(r),e)}async function iZ(t,e){let r=await new Response(t).arrayBuffer();return ig(await e.decodeAudioData(r))}let i$=class t{constructor(t){ey(this,"ready"),ew(this,tU,{duration:0,width:0,height:0}),ew(this,tx,()=>{}),ey(this,"audioTrack"),ew(this,tT,null),ew(this,tA),ev(this,tA,t);let e=t.getVideoTracks()[0];if(null!=e){var r;let{width:t,height:s}=e.getSettings();e.contentHint="motion",eb(this,tU).width=t??0,eb(this,tU).height=s??0,ev(this,tT,new OffscreenCanvas(t??0,s??0)),ev(this,tx,(r=eb(this,tT).getContext("2d"),iE(new MediaStreamTrackProcessor({track:e}).readable,{onChunk:async t=>{r.drawImage(t,0,0),t.close()},onDone:async()=>{}})))}this.audioTrack=t.getAudioTracks()[0]??null,eb(this,tU).duration=1/0,this.ready=Promise.resolve(this.meta)}get meta(){return{...eb(this,tU)}}async tick(){return{video:null==eb(this,tT)?null:await createImageBitmap(eb(this,tT)),audio:[],state:"success"}}async split(){return[await this.clone(),await this.clone()]}async clone(){return new t(eb(this,tA).clone())}destroy(){eb(this,tA).getTracks().forEach(t=>t.stop()),eb(this,tx).call(this)}};tU=new WeakMap,tx=new WeakMap,tT=new WeakMap,tA=new WeakMap,ey(i$,"ctx",null);let iK=i$,iq=class t{constructor(t,e){var r;if(ew(this,tL),ey(this,"ready"),ew(this,tC,[]),ew(this,tI,{width:0,height:0,duration:0}),ew(this,tB,{color:"#FFF",textBgColor:null,type:"srt",fontSize:30,letterSpacing:null,bottomOffset:30,fontFamily:"Noto Sans SC",strokeStyle:"#000",lineWidth:null,lineCap:null,lineJoin:null,textShadow:{offsetX:2,offsetY:2,blur:4,color:"#000"},videoWidth:1280,videoHeight:720}),ew(this,tk),ew(this,tF),ew(this,tR,null),ew(this,tP,0),ew(this,tz,0),ev(this,tC,Array.isArray(t)?t:t.split(/\r|\n/).map(t=>t.trim()).filter(t=>t.length>0).map(t=>({lineStr:t,match:t.match(/(\d{2}:\d{2}:\d{2},\d{3}) --> (\d{2}:\d{2}:\d{2},\d{3})/)})).filter(({lineStr:t},e,r)=>{var s;return!(/^\d+$/.test(t)&&(null==(s=r[e+1])?void 0:s.match)!=null)}).reduce((t,{lineStr:e,match:r})=>{if(null==r){let r=t.at(-1);if(null==r)return t;r.text+=0===r.text.length?e:` ${e}`}else t.push({start:iJ(r[1]),end:iJ(r[2]),text:""});return t},[]).map(({start:t,end:e,text:r})=>({start:1e6*t,end:1e6*e,text:r}))),0===eb(this,tC).length)throw Error("No subtitles content");ev(this,tB,Object.assign(eb(this,tB),e)),ev(this,tz,null==e.textBgColor?0:(e.fontSize??50)*.2);let{fontSize:s,fontFamily:n,videoWidth:a,videoHeight:o,letterSpacing:h}=eb(this,tB);ev(this,tP,s+2*eb(this,tz)),ev(this,tk,new OffscreenCanvas(a,o)),ev(this,tF,eb(this,tk).getContext("2d")),eb(this,tF).font=`${s}px ${n}`,eb(this,tF).textAlign="center",eb(this,tF).textBaseline="top",eb(this,tF).letterSpacing=h??"0px",ev(this,tI,{width:a,height:o,duration:(null==(r=eb(this,tC).at(-1))?void 0:r.end)??0}),this.ready=Promise.resolve(this.meta)}get meta(){return{...eb(this,tI)}}async tick(t){var e,r;if(null!=eb(this,tR)&&t>=eb(this,tR).timestamp&&t<=eb(this,tR).timestamp+(eb(this,tR).duration??0))return{video:eb(this,tR).clone(),state:"success"};let s=0;for(;s<eb(this,tC).length&&!(t<=eb(this,tC)[s].end);s+=1);let n=eb(this,tC)[s]??eb(this,tC).at(-1);if(t>n.end)return{state:"done"};if(t<n.start){eb(this,tF).clearRect(0,0,eb(this,tk).width,eb(this,tk).height);let r=new VideoFrame(eb(this,tk),{timestamp:t,duration:n.start-t});return null==(e=eb(this,tR))||e.close(),ev(this,tR,r),{video:r.clone(),state:"success"}}eS(this,tL,tD).call(this,n.text);let a=new VideoFrame(eb(this,tk),{timestamp:t,duration:n.end-t});return null==(r=eb(this,tR))||r.close(),ev(this,tR,a),{video:a.clone(),state:"success"}}async split(e){await this.ready;let r=-1;for(let t=0;t<eb(this,tC).length;t++)if(!(e>eb(this,tC)[t].start)){r=t;break}if(-1===r)throw Error("Not found subtitle by time");let s=eb(this,tC).slice(0,r).map(t=>({...t})),n=s.at(-1),a=null;null!=n&&n.end>e&&(a={start:0,end:n.end-e,text:n.text},n.end=e);let o=eb(this,tC).slice(r).map(t=>({...t,start:t.start-e,end:t.end-e}));return null!=a&&o.unshift(a),[new t(s,eb(this,tB)),new t(o,eb(this,tB))]}async clone(){return new t(eb(this,tC).slice(0),eb(this,tB))}destroy(){var t;null==(t=eb(this,tR))||t.close()}};tC=new WeakMap,tI=new WeakMap,tB=new WeakMap,tk=new WeakMap,tF=new WeakMap,tR=new WeakMap,tP=new WeakMap,tz=new WeakMap,tL=new WeakSet,tD=function(t){let e=t.split(` `).reverse().map(t=>t.trim()),{width:r,height:s}=eb(this,tk),{color:n,fontSize:a,textBgColor:o,textShadow:h,strokeStyle:l,lineWidth:u,lineCap:d,lineJoin:f,bottomOffset:p}=eb(this,tB),c=eb(this,tF);c.clearRect(0,0,r,s),c.globalAlpha=.6;let m=p;for(let t of e){let e=c.measureText(t),p=r/2;null!=o&&(c.shadowOffsetX=0,c.shadowOffsetY=0,c.shadowBlur=0,c.fillStyle=o,c.globalAlpha=.5,c.fillRect(p-e.actualBoundingBoxLeft-eb(this,tz),s-m-eb(this,tP),e.width+2*eb(this,tz),eb(this,tP))),c.shadowColor=h.color,c.shadowOffsetX=h.offsetX,c.shadowOffsetY=h.offsetY,c.shadowBlur=h.blur,c.globalAlpha=1,null!=l&&(c.lineWidth=u??a/6,null!=d&&(c.lineCap=d),null!=f&&(c.lineJoin=f),c.strokeStyle=l,c.strokeText(t,p,s-m-eb(this,tP)+eb(this,tz))),c.fillStyle=n,c.fillText(t,p,s-m-eb(this,tP)+eb(this,tz)),m+=eb(this,tP)+.2*a}};let iQ=iq;function iJ(t){let e=t.match(/(\d{2}):(\d{2}):(\d{2}),(\d{3})/);if(null==e)throw Error(`time format error: ${t}`);let r=Number(e[1]);return 3600*r+60*Number(e[2])+Number(e[3])+Number(e[4])/1e3}class i0{constructor(){ew(this,tM,/* @__PURE__ */new Map),ey(this,"on",(t,e)=>{let r=eb(this,tM).get(t)??/* @__PURE__ */new Set;return r.add(e),eb(this,tM).has(t)||eb(this,tM).set(t,r),()=>{r.delete(e),0===r.size&&eb(this,tM).delete(t)}}),ey(this,"once",(t,e)=>{let r=this.on(t,(...t)=>{r(),e(...t)});return r}),ey(this,"emit",(t,...e)=>{let r=eb(this,tM).get(t);null!=r&&r.forEach(t=>t(...e))})}static forwardEvent(t,e,r){let s=r.map(r=>{let[s,n]=Array.isArray(r)?r:[r,r];return t.on(s,(...t)=>{e.emit(n,...t)})});return()=>{s.forEach(t=>t())}}destroy(){eb(this,tM).clear()}}tM=new WeakMap;let i1=(t,e)=>{let r=new Uint8Array(8);new DataView(r.buffer).setUint32(0,e);for(let e=0;e<4;e++)r[4+e]=t.charCodeAt(e);return r},i2=()=>{let t=new TextEncoder,e=t.encode("mdta"),r=t.encode("mp4 handler"),s=32+r.byteLength+1,n=new Uint8Array(s),a=new DataView(n.buffer);return n.set(i1("hdlr",s),0),a.setUint32(8,0),n.set(e,16),n.set(r,32),n},i3=t=>{let e=new TextEncoder,r=e.encode("mdta"),s=t.map(t=>{let s=e.encode(t),n=8+s.byteLength,a=new Uint8Array(n);return new DataView(a.buffer).setUint32(0,n),a.set(r,4),a.set(s,4+r.byteLength),a}),n=16+s.reduce((t,e)=>t+e.byteLength,0),a=new Uint8Array(n),o=new DataView(a.buffer);a.set(i1("keys",n),0),o.setUint32(8,0),o.setUint32(12,t.length);let h=16;for(let t of s)a.set(t,h),h+=t.byteLength;return a},i6=t=>{let e=new TextEncoder,r=e.encode("data"),s=Object.entries(t).map(([t,s],n)=>{let a=e.encode(s),o=24+a.byteLength,h=new Uint8Array(o),l=new DataView(h.buffer);return l.setUint32(0,o),l.setUint32(4,n+1),l.setUint32(8,16+a.byteLength),h.set(r,12),l.setUint32(16,1),h.set(a,24),h}),n=8+s.reduce((t,e)=>t+e.byteLength,0),a=new Uint8Array(n);a.set(i1("ilst",n),0);let o=8;for(let t of s)a.set(t,o),o+=t.byteLength;return a},i8=t=>{let e=i2(),r=i3(Object.keys(t)),s=i6(t),n=new Uint8Array(e.length+r.length+s.length);return n.set(e,0),n.set(r,e.length),n.set(s,e.length+r.length),n};function i4(t){e5.info("recodemux opts:",t);let e=iA.createFile(),r=new i0,s=(t,e)=>{let r=t.add("udta").add("meta");r.data=i8(e),r.size=r.data.byteLength},n=!1,a=()=>{null==e.moov||n||(n=!0,null!=t.metaDataTags&&s(e.moov,t.metaDataTags),null!=t.duration&&(e.moov.mvhd.duration=t.duration))};r.once("VideoReady",a),r.once("AudioReady",a);let o=null!=t.video?function(t,e,r){let s={timescale:1e6,width:t.width,height:t.height,brands:["isom","iso2","avc1","mp42","mp41"],avcDecoderConfigRecord:null,name:"Track created with WebAV"},n=-1,a=!1;r.once("AudioReady",()=>{a=!0});let o={encoder0:[],encoder1:[]},h=(t,a,h)=>{var l;if(-1===n&&null!=h){let t=null==(l=h.decoderConfig)?void 0:l.description;(function(t){let e=new Uint8Array(t);e[2].toString(2).slice(-2).includes("1")&&(e[2]=0)})(t),s.avcDecoderConfigRecord=t,n=e.addTrack(s),r.emit("VideoReady"),e5.info("VideoEncoder, video track ready, trackId:",n)}o[t].push(i7(a))},l="encoder1",u=0;function d(){if(!a)return;let t="encoder1"===l?"encoder0":"encoder1",r=o[l],s=o[t];if(0===r.length&&0===s.length)return;let h=r[0];if(null!=h&&h.cts-u<1e4){let t=function(t){let r=-1,s=0;for(;s<t.length;s++){let a=t[s];if(s>0&&a.is_sync)break;e.addSample(n,a.data,a),r=a.cts+a.duration}return t.splice(0,s),r}(r);t>u&&(u=t)}let f=s[0];null!=f&&f.cts-u<1e4&&(l=t,d())}let f=is(d,15),p=i5(t,(t,e)=>h("encoder0",t,e)),c=i5(t,(t,e)=>h("encoder1",t,e)),m=0;return{get encodeQueueSize(){return p.encodeQueueSize+c.encodeQueueSize},encode:(t,e)=>{e.keyFrame&&(m+=1),(m%2==0?p:c).encode(t,e)},flush:async()=>{await Promise.all(["configured"===p.state?await p.flush():null,"configured"===c.state?await c.flush():null]),f(),d()},close:()=>{"configured"===p.state&&p.close(),"configured"===c.state&&c.close()}}}(t.video,e,r):null,h=null!=t.audio?function(t,e,r){let s={timescale:1e6,samplerate:t.sampleRate,channel_count:t.channelCount,hdlr:"soun",type:"aac"===t.codec?"mp4a":"Opus",name:"Track created with WebAV"},n=-1,a=[],o=!1;r.once("VideoReady",()=>{o=!0,a.forEach(t=>{let r=i7(t);e.addSample(n,r.data,r)}),a=[]});let h=new AudioEncoder({error:e5.error,output:(t,h)=>{var l;if(-1===n){let t=null==(l=h.decoderConfig)?void 0:l.description;n=e.addTrack({...s,description:null==t?void 0:function(t){let e=t.byteLength,r=new Uint8Array([0,0,0,0,3,23+e,0,2,0,4,18+e,64,21,0,0,0,0,0,0,0,0,0,0,0,5,e,...new Uint8Array(t instanceof ArrayBuffer?t:t.buffer),6,1,2]),s=new iA.BoxParser.esdsBox(r.byteLength);return s.hdr_size=0,s.parse(new iA.DataStream(r,0,iA.DataStream.BIG_ENDIAN)),s}(t)}),r.emit("AudioReady"),e5.info("AudioEncoder, audio track ready, trackId:",n)}if(o){let r=i7(t);e.addSample(n,r.data,r)}else a.push(t)}});return h.configure({codec:"aac"===t.codec?iC.codec:"opus",sampleRate:t.sampleRate,numberOfChannels:t.channelCount,bitrate:128e3}),h}(t.audio,e,r):null;return null==t.video&&r.emit("VideoReady"),null==t.audio&&r.emit("AudioReady"),{encodeVideo:(t,e)=>{null==o||o.encode(t,e),t.close()},encodeAudio:t=>{null!=h&&(h.encode(t),t.close())},getEncodeQueueSize:()=>(null==o?void 0:o.encodeQueueSize)??(null==h?void 0:h.encodeQueueSize)??0,flush:async()=>{await Promise.all([null==o?void 0:o.flush(),(null==h?void 0:h.state)==="configured"?h.flush():null])},close:()=>{r.destroy(),null==o||o.close(),(null==h?void 0:h.state)==="configured"&&h.close()},mp4file:e}}function i5(t,e){let r=new VideoEncoder({error:e5.error,output:e});return r.configure({codec:t.codec,framerate:t.expectFPS,hardwareAcceleration:t.__unsafe_hardwareAcceleration__,bitrate:t.bitrate,width:t.width,height:t.height,alpha:"discard",avc:{format:"avc"}}),r}function i9(t,e,r){let s=0,n=0,a=t.boxes,o=!1,h=()=>{var e;if(!o){if(null==a.find(t=>"moof"===t.type))return null;o=!0}if(n>=a.length)return null;let r=new iA.DataStream;r.endianness=iA.DataStream.BIG_ENDIAN;let s=n;try{for(;s<a.length;)a[s].write(r),delete a[s],s+=1}catch(r){let t=a[s];throw r instanceof Error&&null!=t?Error(`${r.message} | deltaBuf( boxType: ${t.type}, boxSize: ${t.size}, boxDataLen: ${(null==(e=t.data)?void 0:e.length)??-1})`):r}return function(t){if(null!=t.moov){for(var e=0;e<t.moov.traks.length;e++)t.moov.traks[e].samples=[];t.mdats=[],t.moofs=[]}}(t),n=a.length,new Uint8Array(r.buffer)},l=!1,u=!1,d=null;return{stream:new ReadableStream({start(r){s=self.setInterval(()=>{let t=h();null==t||u||r.enqueue(t)},e),d=e=>{if(clearInterval(s),t.flush(),null!=e){r.error(e);return}let n=h();null==n||u||r.enqueue(n),u||r.close()},l&&d()},cancel(){u=!0,clearInterval(s),null==r||r()}}),stop:t=>{l||(l=!0,null==d||d(t))}}}function i7(t){let e=new ArrayBuffer(t.byteLength);t.copyTo(e);let r=t.timestamp;return{duration:t.duration??0,dts:r,cts:r,is_sync:"key"===t.type,data:e}}async function rt(t){let e=iA.createFile(),r=function(t){let e=0,r=t.boxes,s=[],n=0;async function a(){let a=c(r,e);e=r.length,s.forEach(({track:e,id:r})=>{let s=e.samples.at(-1);null!=s&&(n=Math.max(n,s.cts+s.duration)),t.releaseUsedSamples(r,e.samples.length),e.samples=[]}),t.mdats=[],t.moofs=[],null!=a&&await (null==d?void 0:d.write(a))}let o=[];function h(){if(o.length>0)return!0;let n=r.findIndex(t=>"moov"===t.type);if(-1===n)return!1;if(o=r.slice(0,n+1),e=n+1,0===s.length)for(let e=1;;e+=1){let r=t.getTrackById(e);if(null==r)break;s.push({track:r,id:e})}return!0}let l=0,u=e1(),d=null,f=(async()=>{d=await u.createWriter(),l=self.setInterval(()=>{h()&&a()},100)})(),p=!1;return async()=>{if(p)throw Error("File exported");if(p=!0,await f,clearInterval(l),!h()||null==d)return null;t.flush(),await a(),await (null==d?void 0:d.close());let e=o.find(t=>"moov"===t.type);if(null==e)return null;e.mvhd.duration=n;let r=e1(),s=c(o,0);return await eH(r,s),await eH(r,u,{overwrite:!1}),await r.stream()};function c(t,e){if(e>=t.length)return null;let r=new iA.DataStream;r.endianness=iA.DataStream.BIG_ENDIAN;for(let s=e;s<t.length;s++)null!==t[s]&&(t[s].write(r),delete t[s]);return new Uint8Array(r.buffer)}}(e);await re(t,e);let s=await r();if(null==s)throw Error("Can not generate file from streams");return s}async function re(t,e){let r=0,s=0,n=0,a=0,o=0,h=0,l=null,u=null;for(let d of t)await new Promise(async t=>{iE(d.pipeThrough(new ik),{onDone:t,onChunk:async({chunkType:t,data:d})=>{if("ready"===t){let{videoTrackConf:t,audioTrackConf:s}=iI(d.file,d.info);0===r&&null!=t&&(r=e.addTrack(t)),0===a&&null!=s&&(a=e.addTrack(s))}else if("samples"===t){let{type:t,samples:f}=d,p="video"===t?r:a,c="video"===t?s:o,m="video"===t?n:h;f.forEach(t=>{e.addSample(p,t.data,{duration:t.duration,dts:t.dts+c,cts:t.cts+m,is_sync:t.is_sync})});let g=f.at(-1);if(null==g)return;"video"===t?l=g:"audio"===t&&(u=g)}}})}),null!=l&&(s+=l.dts,n+=l.cts),null!=u&&(o+=u.dts,h+=u.cts)}async function ri(t){return await rt([t])}function rr(t,e){e5.info("mixinMP4AndAudio, opts:",{volume:e.volume,loop:e.loop});let r=iA.createFile(),{stream:s,stop:n}=i9(r,500),a=null,o=null,h=[],l=0,u=0,d=0,f=!0,p=48e3;function c(t){let r=h.map(r=>e.loop?iS(r,d,d+t):r.slice(d,d+t));if(d+=t,1!==e.volume)for(let t of r)for(let r=0;r<t.length;r++)t[r]*=e.volume;return r}async function m(t){let e=t[0],r=t[t.length-1],s=ib([c(Math.floor((r.cts+r.duration-e.cts)/r.timescale*p))]);0!==s.length&&(null==o||o.encode(s,e.cts/e.timescale*1e6))}async function g(t){if(null==a)return;let e=ic((await a.decode(t)).map(im)),r=c(e[0].length),s=t[0];null==o||o.encode(ib([e,r]),s.cts/s.timescale*1e6)}return iE(t.pipeThrough(new ik),{onDone:async()=>{await (null==o?void 0:o.stop()),null==a||a.close(),n()},onChunk:async({chunkType:t,data:s})=>{if("ready"===t){let{videoTrackConf:t,audioTrackConf:n,audioDecoderConf:d}=iI(s.file,s.info);0===l&&null!=t&&(l=r.addTrack(t));let c=n??{timescale:1e6,samplerate:p,channel_count:iC.channelCount,hdlr:"soun",name:"SoundHandler",type:"mp4a"};0===u&&(u=r.addTrack(c),p=(null==n?void 0:n.samplerate)??p,f=null!=n);let m=new AudioContext({sampleRate:p});h=ig(await m.decodeAudioData(await new Response(e.stream).arrayBuffer())),null!=d&&(a=function(t){let e=[],r=new AudioDecoder({output:t=>{e.push(t)},error:e5.error});return r.configure(t),{decode:async t=>{t.forEach(t=>{r.decode(new EncodedAudioChunk({type:t.is_sync?"key":"delta",timestamp:1e6*t.cts/t.timescale,duration:1e6*t.duration/t.timescale,data:t.data}))}),await r.flush();let s=e;return e=[],s},close:()=>{r.close()}}}(d)),o=function(t,e){let r=new AudioEncoder({output:t=>{e(i7(t))},error:e5.error});r.configure({codec:t.codec,sampleRate:t.sampleRate,numberOfChannels:t.numberOfChannels});let s=null;function n(e,r){return new AudioData({timestamp:r,numberOfChannels:t.numberOfChannels,numberOfFrames:e.length/t.numberOfChannels,sampleRate:t.sampleRate,format:"f32-planar",data:e})}return{encode:async(t,e)=>{null!=s&&r.encode(n(s.data,s.ts)),s={data:t,ts:e}},stop:async()=>{null!=s&&(function(t,e,r){let s=t.length-1,n=Math.min(r/2,s);for(let r=0;r<n;r++)for(let a=1;a<=e;a++)t[Math.floor(s/a)-r]*=r/n}(s.data,t.numberOfChannels,t.sampleRate),r.encode(n(s.data,s.ts)),s=null),await r.flush(),r.close()}}}(d??{codec:"mp4a"===c.type?iC.codec:c.type,numberOfChannels:c.channel_count,sampleRate:c.samplerate},t=>r.addSample(u,t.data,t))}else if("samples"===t){let{id:t,type:e,samples:n}=s;if("video"===e){n.forEach(e=>r.addSample(t,e.data,e)),f||await m(n);return}"audio"===e&&await g(n)}}}),s}var rs=/* @__PURE__ */function(){function t(){this.listeners={}}var e=t.prototype;return e.on=function(t,e){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(e)},e.off=function(t,e){if(!this.listeners[t])return!1;var r=this.listeners[t].indexOf(e);return this.listeners[t]=this.listeners[t].slice(0),this.listeners[t].splice(r,1),r>-1},e.trigger=function(t){var e=this.listeners[t];if(e){if(2==arguments.length)for(var r=e.length,s=0;s<r;++s)e[s].call(this,arguments[1]);else for(var n=Array.prototype.slice.call(arguments,1),a=e.length,o=0;o<a;++o)e[o].apply(this,n)}},e.dispose=function(){this.listeners={}},e.pipe=function(t){this.on("data",function(e){t.push(e)})},t}();function rn(){return(rn=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var s in r)({}).hasOwnProperty.call(r,s)&&(t[s]=r[s])}return t}).apply(null,arguments)}"u">typeof window?tO=window:"u">typeof iU?tO=iU:"u">typeof self?tO=self:tO={};let ra=/* @__PURE__ */ix(tO);/*! @name m3u8-parser @version 7.1.0 @license Apache-2.0 */class ro extends rs{constructor(){super(),this.buffer=""}push(t){let e;for(this.buffer+=t,e=this.buffer.indexOf(` `);e>-1;e=this.buffer.indexOf(` `))this.trigger("data",this.buffer.substring(0,e)),this.buffer=this.buffer.substring(e+1)}}let rh=function(t){let e=/([0-9.]*)?@?([0-9.]*)?/.exec(t||""),r={};return e[1]&&(r.length=parseInt(e[1],10)),e[2]&&(r.offset=parseInt(e[2],10)),r},rl=function(t){let e={};if(!t)return e;let r=t.split(RegExp('(?:^|,)((?:[^=]*)=(?:"[^"]*"|[^,]*))')),s=r.length,n;for(;s--;)""!==r[s]&&((n=/([^=]*)=(.*)/.exec(r[s]).slice(1))[0]=n[0].replace(/^\s+|\s+$/g,""),n[1]=n[1].replace(/^\s+|\s+$/g,""),n[1]=n[1].replace(/^['"](.*)['"]$/g,"$1"),e[n[0]]=n[1]);return e};class ru extends rs{constructor(){super(),this.customParsers=[],this.tagMappers=[]}push(t){let e,r;if(0!==(t=t.trim()).length){if("#"!==t[0]){this.trigger("data",{type:"uri",uri:t});return}this.tagMappers.reduce((e,r)=>{let s=r(t);return s===t?e:e.concat([s])},[t]).forEach(t=>{for(let e=0;e<this.customParsers.length;e++)if(this.customParsers[e].call(this,t))return;if(0!==t.indexOf("#EXT")){this.trigger("data",{type:"comment",text:t.slice(1)});return}if(t=t.replace("\r",""),e=/^#EXTM3U/.exec(t)){this.trigger("data",{type:"tag",tagType:"m3u"});return}if(e=/^#EXTINF:([0-9\.]*)?,?(.*)?$/.exec(t)){r={type:"tag",tagType:"inf"},e[1]&&(r.duration=parseFloat(e[1])),e[2]&&(r.title=e[2]),this.trigger("data",r);return}if(e=/^#EXT-X-TARGETDURATION:([0-9.]*)?/.exec(t)){r={type:"tag",tagType:"targetduration"},e[1]&&(r.duration=parseInt(e[1],10)),this.trigger("data",r);return}if(e=/^#EXT-X-VERSION:([0-9.]*)?/.exec(t)){r={type:"tag",tagType:"version"},e[1]&&(r.version=parseInt(e[1],10)),this.trigger("data",r);return}if(e=/^#EXT-X-MEDIA-SEQUENCE:(\-?[0-9.]*)?/.exec(t)){r={type:"tag",tagType:"media-sequence"},e[1]&&(r.number=parseInt(e[1],10)),this.trigger("data",r);return}if(e=/^#EXT-X-DISCONTINUITY-SEQUENCE:(\-?[0-9.]*)?/.exec(t)){r={type:"tag",tagType:"discontinuity-sequence"},e[1]&&(r.number=parseInt(e[1],10)),this.trigger("data",r);return}if(e=/^#EXT-X-PLAYLIST-TYPE:(.*)?$/.exec(t)){r={type:"tag",tagType:"playlist-type"},e[1]&&(r.playlistType=e[1]),this.trigger("data",r);return}if(e=/^#EXT-X-BYTERANGE:(.*)?$/.exec(t)){r=rn(rh(e[1]),{type:"tag",tagType:"byterange"}),this.trigger("data",r);return}if(e=/^#EXT-X-ALLOW-CACHE:(YES|NO)?/.exec(t)){r={type:"tag",tagType:"allow-cache"},e[1]&&(r.allowed=!/NO/.test(e[1])),this.trigger("data",r);return}if(e=/^#EXT-X-MAP:(.*)$/.exec(t)){if(r={type:"tag",tagType:"map"},e[1]){let t=rl(e[1]);t.URI&&(r.uri=t.URI),t.BYTERANGE&&(r.byterange=rh(t.BYTERANGE))}this.trigger("data",r);return}if(e=/^#EXT-X-STREAM-INF:(.*)$/.exec(t)){if(r={type:"tag",tagType:"stream-inf"},e[1]){if(r.attributes=rl(e[1]),r.attributes.RESOLUTION){let t=r.attributes.RESOLUTION.split("x"),e={};t[0]&&(e.width=parseInt(t[0],10)),t[1]&&(e.height=parseInt(t[1],10)),r.attributes.RESOLUTION=e}r.attributes.BANDWIDTH&&(r.attributes.BANDWIDTH=parseInt(r.attributes.BANDWIDTH,10)),r.attributes["FRAME-RATE"]&&(r.attributes["FRAME-RATE"]=parseFloat(r.attributes["FRAME-RATE"])),r.attributes["PROGRAM-ID"]&&(r.attributes["PROGRAM-ID"]=parseInt(r.attributes["PROGRAM-ID"],10))}this.trigger("data",r);return}if(e=/^#EXT-X-MEDIA:(.*)$/.exec(t)){r={type:"tag",tagType:"media"},e[1]&&(r.attributes=rl(e[1])),this.trigger("data",r);return}if(e=/^#EXT-X-ENDLIST/.exec(t)){this.trigger("data",{type:"tag",tagType:"endlist"});return}if(e=/^#EXT-X-DISCONTINUITY/.exec(t)){this.trigger("data",{type:"tag",tagType:"discontinuity"});return}if(e=/^#EXT-X-PROGRAM-DATE-TIME:(.*)$/.exec(t)){r={type:"tag",tagType:"program-date-time"},e[1]&&(r.dateTimeString=e[1],r.dateTimeObject=new Date(e[1])),this.trigger("data",r);return}if(e=/^#EXT-X-KEY:(.*)$/.exec(t)){r={type:"tag",tagType:"key"},e[1]&&(r.attributes=rl(e[1]),r.attributes.IV&&("0x"===r.attributes.IV.substring(0,2).toLowerCase()&&(r.attributes.IV=r.attributes.IV.substring(2)),r.attributes.IV=r.attributes.IV.match(/.{8}/g),r.attributes.IV[0]=parseInt(r.attributes.IV[0],16),r.attributes.IV[1]=parseInt(r.attributes.IV[1],16),r.attributes.IV[2]=parseInt(r.attributes.IV[2],16),r.attributes.IV[3]=parseInt(r.attributes.IV[3],16),r.attributes.IV=new Uint32Array(r.attributes.IV))),this.trigger("data",r);return}if(e=/^#EXT-X-START:(.*)$/.exec(t)){r={type:"tag",tagType:"start"},e[1]&&(r.attributes=rl(e[1]),r.attributes["TIME-OFFSET"]=parseFloat(r.attributes["TIME-OFFSET"]),r.attributes.PRECISE=/YES/.test(r.attributes.PRECISE)),this.trigger("data",r);return}if(e=/^#EXT-X-CUE-OUT-CONT:(.*)?$/.exec(t)){r={type:"tag",tagType:"cue-out-cont"},e[1]?r.data=e[1]:r.data="",this.trigger("data",r);return}if(e=/^#EXT-X-CUE-OUT:(.*)?$/.exec(t)){r={type:"tag",tagType:"cue-out"},e[1]?r.data=e[1]:r.data="",this.trigger("data",r);return}if(e=/^#EXT-X-CUE-IN:(.*)?$/.exec(t)){r={type:"tag",tagType:"cue-in"},e[1]?r.data=e[1]:r.data="",this.trigger("data",r);return}if((e=/^#EXT-X-SKIP:(.*)$/.exec(t))&&e[1]){(r={type:"tag",tagType:"skip"}).attributes=rl(e[1]),r.attributes.hasOwnProperty("SKIPPED-SEGMENTS")&&(r.attributes["SKIPPED-SEGMENTS"]=parseInt(r.attributes["SKIPPED-SEGMENTS"],10)),r.attributes.hasOwnProperty("RECENTLY-REMOVED-DATERANGES")&&(r.attributes["RECENTLY-REMOVED-DATERANGES"]=r.attributes["RECENTLY-REMOVED-DATERANGES"].split(" ")),this.trigger("data",r);return}if((e=/^#EXT-X-PART:(.*)$/.exec(t))&&e[1]){(r={type:"tag",tagType:"part"}).attributes=rl(e[1]),["DURATION"].forEach(function(t){r.attributes.hasOwnProperty(t)&&(r.attributes[t]=parseFloat(r.attributes[t]))}),["INDEPENDENT","GAP"].forEach(function(t){r.attributes.hasOwnProperty(t)&&(r.attributes[t]=/YES/.test(r.attributes[t]))}),r.attributes.hasOwnProperty("BYTERANGE")&&(r.attributes.byterange=rh(r.attributes.BYTERANGE)),this.trigger("data",r);return}if((e=/^#EXT-X-SERVER-CONTROL:(.*)$/.exec(t))&&e[1]){(r={type:"tag",tagType:"server-control"}).attributes=rl(e[1]),["CAN-SKIP-UNTIL","PART-HOLD-BACK","HOLD-BACK"].forEach(function(t){r.attributes.hasOwnProperty(t)&&(r.attributes[t]=parseFloat(r.attributes[t]))}),["CAN-SKIP-DATERANGES","CAN-BLOCK-RELOAD"].forEach(function(t){r.attributes.hasOwnProperty(t)&&(r.attributes[t]=/YES/.test(r.attributes[t]))}),this.trigger("data",r);return}if((e=/^#EXT-X-PART-INF:(.*)$/.exec(t))&&e[1]){(r={type:"tag",tagType:"part-inf"}).attributes=rl(e[1]),["PART-TARGET"].forEach(function(t){r.attributes.hasOwnProperty(t)&&(r.attributes[t]=parseFloat(r.attributes[t]))}),this.trigger("data",r);return}if((e=/^#EXT-X-PRELOAD-HINT:(.*)$/.exec(t))&&e[1]){(r={type:"tag",tagType:"preload-hint"}).attributes=rl(e[1]),["BYTERANGE-START","BYTERANGE-LENGTH"].forEach(function(t){if(r.attributes.hasOwnProperty(t)){r.attributes[t]=parseInt(r.attributes[t],10);let e="BYTERANGE-LENGTH"===t?"length":"offset";r.attributes.byterange=r.attributes.byterange||{},r.attributes.byterange[e]=r.attributes[t],delete r.attributes[t]}}),this.trigger("data",r);return}if((e=/^#EXT-X-RENDITION-REPORT:(.*)$/.exec(t))&&e[1]){(r={type:"tag",tagType:"rendition-report"}).attributes=rl(e[1]),["LAST-MSN","LAST-PART"].forEach(function(t){r.attributes.hasOwnProperty(t)&&(r.attributes[t]=parseInt(r.attributes[t],10))}),this.trigger("data",r);return}if((e=/^#EXT-X-DATERANGE:(.*)$/.exec(t))&&e[1]){(r={type:"tag",tagType:"daterange"}).attributes=rl(e[1]),["ID","CLASS"].forEach(function(t){r.attributes.hasOwnProperty(t)&&(r.attributes[t]=String(r.attributes[t]))}),["START-DATE","END-DATE"].forEach(function(t){r.attributes.hasOwnProperty(t)&&(r.attributes[t]=new Date(r.attributes[t]))}),["DURATION","PLANNED-DURATION"].forEach(function(t){r.attributes.hasOwnProperty(t)&&(r.attributes[t]=parseFloat(r.attributes[t]))}),["END-ON-NEXT"].forEach(function(t){r.attributes.hasOwnProperty(t)&&(r.attributes[t]=/YES/i.test(r.attributes[t]))}),["SCTE35-CMD"," SCTE35-OUT","SCTE35-IN"].forEach(function(t){r.attributes.hasOwnProperty(t)&&(r.attributes[t]=r.attributes[t].toString(16))});let t=/^X-([A-Z]+-)+[A-Z]+$/;for(let e in r.attributes){if(!t.test(e))continue;let s=/[0-9A-Fa-f]{6}/g.test(r.attributes[e]),n=/^\d+(\.\d+)?$/.test(r.attributes[e]);r.attributes[e]=s?r.attributes[e].toString(16):n?parseFloat(r.attributes[e]):String(r.attributes[e])}this.trigger("data",r);return}if(e=/^#EXT-X-INDEPENDENT-SEGMENTS/.exec(t)){this.trigger("data",{type:"tag",tagType:"independent-segments"});return}if(e=/^#EXT-X-CONTENT-STEERING:(.*)$/.exec(t)){(r={type:"tag",tagType:"content-steering"}).attributes=rl(e[1]),this.trigger("data",r);return}this.trigger("data",{type:"tag",data:t.slice(4)})})}}addParser({expression:t,customType:e,dataParser:r,segment:s}){"function"!=typeof r&&(r=t=>t),this.customParsers.push(n=>{if(t.exec(n))return this.trigger("data",{type:"custom",data:r(n),customType:e,segment:s}),!0})}addTagMapper({expression:t,map:e}){this.tagMappers.push(r=>t.test(r)?e(r):r)}}let rd=t=>t.toLowerCase().replace(/-(\w)/g,t=>t[1].toUpperCase()),rf=function(t){let e={};return Object.keys(t).forEach(function(r){e[rd(r)]=t[r]}),e},rp=function(t){let{serverControl:e,targetDuration:r,partTargetDuration:s}=t;if(!e)return;let n="#EXT-X-SERVER-CONTROL",a="holdBack",o="partHoldBack",h=r&&3*r,l=s&&2*s;r&&!e.hasOwnProperty(a)&&(e[a]=h,this.trigger("info",{message:`${n} defaulting HOLD-BACK to targetDuration * 3 (${h}).`})),h&&e[a]<h&&(this.trigger("warn",{message:`${n} clamping HOLD-BACK (${e[a]}) to targetDuration * 3 (${h})`}),e[a]=h),s&&!e.hasOwnProperty(o)&&(e[o]=3*s,this.trigger("info",{message:`${n} defaulting PART-HOLD-BACK to partTargetDuration * 3 (${e[o]}).`})),s&&e[o]<l&&(this.trigger("warn",{message:`${n} clamping PART-HOLD-BACK (${e[o]}) to partTargetDuration * 2 (${l}).`}),e[o]=l)};class rc extends rs{constructor(){super(),this.lineStream=new ro,this.parseStream=new ru,this.lineStream.pipe(this.parseStream),this.lastProgramDateTime=null;let t=this,e=[],r={},s,n,a=!1,o=function(){},h={AUDIO:{},VIDEO:{},"CLOSED-CAPTIONS":{},SUBTITLES:{}},l=0;this.manifest={allowCache:!0,discontinuityStarts:[],dateRanges:[],segments:[]};let u=0,d=0,f={};this.on("end",()=>{!r.uri&&(r.parts||r.preloadHints)&&(!r.map&&s&&(r.map=s),!r.key&&n&&(r.key=n),r.timeline||"number"!=typeof l||(r.timeline=l),this.manifest.preloadSegment=r)}),this.parseStream.on("data",function(p){let c,m;({tag(){(({version(){p.version&&(this.manifest.version=p.version)},"allow-cache"(){this.manifest.allowCache=p.allowed,"allowed"in p||(this.trigger("info",{message:"defaulting allowCache to YES"}),this.manifest.allowCache=!0)},byterange(){let t={};"length"in p&&(r.byterange=t,t.length=p.length,"offset"in p||(p.offset=u)),"offset"in p&&(r.byterange=t,t.offset=p.offset),u=t.offset+t.length},endlist(){this.manifest.endList=!0},inf(){"mediaSequence"in this.manifest||(this.manifest.mediaSequence=0,this.trigger("info",{message:"defaulting media sequence to zero"})),"discontinuitySequence"in this.manifest||(this.manifest.discontinuitySequence=0,this.trigger("info",{message:"defaulting discontinuity sequence to zero"})),p.title&&(r.title=p.title),p.duration>0&&(r.duration=p.duration),0===p.duration&&(r.duration=.01,this.trigger("info",{message:"updating zero segment duration to a small value"})),this.manifest.segments=e},key(){if(!p.attributes){this.trigger("warn",{message:"ignoring key declaration without attribute list"});return}if("NONE"===p.attributes.METHOD){n=null;return}if(!p.attributes.URI){this.trigger("warn",{message:"ignoring key declaration without URI"});return}if("com.apple.streamingkeydelivery"===p.attributes.KEYFORMAT){this.manifest.contentProtection=this.manifest.contentProtection||{},this.manifest.contentProtection["com.apple.fps.1_0"]={attributes:p.attributes};return}if("com.microsoft.playready"===p.attributes.KEYFORMAT){this.manifest.contentProtection=this.manifest.contentProtection||{},this.manifest.contentProtection["com.microsoft.playready"]={uri:p.attributes.URI};return}if("urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"===p.attributes.KEYFORMAT){if(-1===["SAMPLE-AES","SAMPLE-AES-CTR","SAMPLE-AES-CENC"].indexOf(p.attributes.METHOD)){this.trigger("warn",{message:"invalid key method provided for Widevine"});return}if("SAMPLE-AES-CENC"===p.attributes.METHOD&&this.trigger("warn",{message:"SAMPLE-AES-CENC is deprecated, please use SAMPLE-AES-CTR instead"}),"data:text/plain;base64,"!==p.attributes.URI.substring(0,23)){this.trigger("warn",{message:"invalid key URI provided for Widevine"});return}if(!(p.attributes.KEYID&&"0x"===p.attributes.KEYID.substring(0,2))){this.trigger("warn",{message:"invalid key ID provided for Widevine"});return}this.manifest.contentProtection=this.manifest.contentProtection||{},this.manifest.contentProtection["com.widevine.alpha"]={attributes:{schemeIdUri:p.attributes.KEYFORMAT,keyId:p.attributes.KEYID.substring(2)},pssh:function(t){for(var e=ra.atob?ra.atob(t):ep.from(t,"base64").toString("binary"),r=new Uint8Array(e.length),s=0;s<e.length;s++)r[s]=e.charCodeAt(s);return r}(p.attributes.URI.split(",")[1])};return}p.attributes.METHOD||this.trigger("warn",{message:"defaulting key method to AES-128"}),n={method:p.attributes.METHOD||"AES-128",uri:p.attributes.URI},"u">typeof p.attributes.IV&&(n.iv=p.attributes.IV)},"media-sequence"(){if(!isFinite(p.number)){this.trigger("warn",{message:"ignoring invalid media sequence: "+p.number});return}this.manifest.mediaSequence=p.number},"discontinuity-sequence"(){if(!isFinite(p.number)){this.trigger("warn",{message:"ignoring invalid discontinuity sequence: "+p.number});return}this.manifest.discontinuitySequence=p.number,l=p.number},"playlist-type"(){if(!/VOD|EVENT/.test(p.playlistType)){this.trigger("warn",{message:"ignoring unknown playlist type: "+p.playlist});return}this.manifest.playlistType=p.playlistType},map(){s={},p.uri&&(s.uri=p.uri),p.byterange&&(s.byterange=p.byterange),n&&(s.key=n)},"stream-inf"(){if(this.manifest.playlists=e,this.manifest.mediaGroups=this.manifest.mediaGroups||h,!p.attributes){this.trigger("warn",{message:"ignoring empty stream-inf attributes"});return}r.attributes||(r.attributes={}),rn(r.attributes,p.attributes)},media(){if(this.manifest.mediaGroups=this.manifest.mediaGroups||h,!(p.attributes&&p.attributes.TYPE&&p.attributes["GROUP-ID"]&&p.attributes.NAME)){this.trigger("warn",{message:"ignoring incomplete or missing media group"});return}let t=this.manifest.mediaGroups[p.attributes.TYPE];t[p.attributes["GROUP-ID"]]=t[p.attributes["GROUP-ID"]]||{},c=t[p.attributes["GROUP-ID"]],(m={default:/yes/i.test(p.attributes.DEFAULT)}).default?m.autoselect=!0:m.autoselect=/yes/i.test(p.attributes.AUTOSELECT),p.attributes.LANGUAGE&&(m.language=p.attributes.LANGUAGE),p.attributes.URI&&(m.uri=p.attributes.URI),p.attributes["INSTREAM-ID"]&&(m.instreamId=p.attributes["INSTREAM-ID"]),p.attributes.CHARACTERISTICS&&(m.characteristics=p.attributes.CHARACTERISTICS),p.attributes.FORCED&&(m.forced=/yes/i.test(p.attributes.FORCED)),c[p.attributes.NAME]=m},discontinuity(){l+=1,r.discontinuity=!0,this.manifest.discontinuityStarts.push(e.length)},"program-date-time"(){typeof this.manifest.dateTimeString>"u"&&(this.manifest.dateTimeString=p.dateTimeString,this.manifest.dateTimeObject=p.dateTimeObject),r.dateTimeString=p.dateTimeString,r.dateTimeObject=p.dateTimeObject;let{lastProgramDateTime:t}=this;this.lastProgramDateTime=new Date(p.dateTimeString).getTime(),null===t&&this.manifest.segments.reduceRight((t,e)=>(e.programDateTime=t-1e3*e.duration,e.programDateTime),this.lastProgramDateTime)},targetduration(){if(!isFinite(p.duration)||p.duration<0){this.trigger("warn",{message:"ignoring invalid target duration: "+p.duration});return}this.manifest.targetDuration=p.duration,rp.call(this,this.manifest)},start(){if(!p.attributes||isNaN(p.attributes["TIME-OFFSET"])){this.trigger("warn",{message:"ignoring start declaration without appropriate attribute list"});return}this.manifest.start={timeOffset:p.attributes["TIME-OFFSET"],precise:p.attributes.PRECISE}},"cue-out"(){r.cueOut=p.data},"cue-out-cont"(){r.cueOutCont=p.data},"cue-in"(){r.cueIn=p.data},skip(){this.manifest.skip=rf(p.attributes),this.warnOnMissingAttributes_("#EXT-X-SKIP",p.attributes,["SKIPPED-SEGMENTS"])},part(){a=!0;let t=this.manifest.segments.length,e=rf(p.attributes);r.parts=r.parts||[],r.parts.push(e),e.byterange&&(e.byterange.hasOwnProperty("offset")||(e.byterange.offset=d),d=e.byterange.offset+e.byterange.length);let s=r.parts.length-1;this.warnOnMissingAttributes_(`#EXT-X-PART #${s} for segment #${t}`,p.attributes,["URI","DURATION"]),this.manifest.renditionReports&&this.manifest.renditionReports.forEach((t,e)=>{t.hasOwnProperty("lastPart")||this.trigger("warn",{message:`#EXT-X-RENDITION-REPORT #${e} lacks required attribute(s): LAST-PART`})})},"server-control"(){let t=this.manifest.serverControl=rf(p.attributes);t.hasOwnProperty("canBlockReload")||(t.canBlockReload=!1,this.trigger("info",{message:"#EXT-X-SERVER-CONTROL defaulting CAN-BLOCK-RELOAD to false"})),rp.call(this,this.manifest),t.canSkipDateranges&&!t.hasOwnProperty("canSkipUntil")&&this.trigger("warn",{message:"#EXT-X-SERVER-CONTROL lacks required attribute CAN-SKIP-UNTIL which is required when CAN-SKIP-DATERANGES is set"})},"preload-hint"(){let t=this.manifest.segments.length,e=rf(p.attributes),s=e.type&&"PART"===e.type;r.preloadHints=r.preloadHints||[],r.preloadHints.push(e),e.byterange&&(e.byterange.hasOwnProperty("offset")||(e.byterange.offset=s?d:0,s&&(d=e.byterange.offset+e.byterange.length)));let n=r.preloadHints.length-1;if(this.warnOnMissingAttributes_(`#EXT-X-PRELOAD-HINT #${n} for segment #${t}`,p.attributes,["TYPE","URI"]),e.type)for(let s=0;s<r.preloadHints.length-1;s++){let a=r.preloadHints[s];a.type&&a.type===e.type&&this.trigger("warn",{message:`#EXT-X-PRELOAD-HINT #${n} for segment #${t} has the same TYPE ${e.type} as preload hint #${s}`})}},"rendition-report"(){let t=rf(p.attributes);this.manifest.renditionReports=this.manifest.renditionReports||[],this.manifest.renditionReports.push(t);let e=this.manifest.renditionReports.length-1,r=["LAST-MSN","URI"];a&&r.push("LAST-PART"),this.warnOnMissingAttributes_(`#EXT-X-RENDITION-REPORT #${e}`,p.attributes,r)},"part-inf"(){this.manifest.partInf=rf(p.attributes),this.warnOnMissingAttributes_("#EXT-X-PART-INF",p.attributes,["PART-TARGET"]),this.manifest.partInf.partTarget&&(this.manifest.partTargetDuration=this.manifest.partInf.partTarget),rp.call(this,this.manifest)},daterange(){this.manifest.dateRanges.push(rf(p.attributes));let t=this.manifest.dateRanges.length-1;this.warnOnMissingAttributes_(`#EXT-X-DATERANGE #${t}`,p.attributes,["ID","START-DATE"]);let e=this.manifest.dateRanges[t];e.endDate&&e.startDate&&new Date(e.endDate)<new Date(e.startDate)&&this.trigger("warn",{message:"EXT-X-DATERANGE END-DATE must be equal to or later than the value of the START-DATE"}),e.duration&&e.duration<0&&this.trigger("warn",{message:"EXT-X-DATERANGE DURATION must not be negative"}),e.plannedDuration&&e.plannedDuration<0&&this.trigger("warn",{message:"EXT-X-DATERANGE PLANNED-DURATION must not be negative"});let r=!!e.endOnNext;if(r&&!e.class&&this.trigger("warn",{message:"EXT-X-DATERANGE with an END-ON-NEXT=YES attribute must have a CLASS attribute"}),r&&(e.duration||e.endDate)&&this.trigger("warn",{message:"EXT-X-DATERANGE with an END-ON-NEXT=YES attribute must not contain DURATION or END-DATE attributes"}),e.duration&&e.endDate){let r=e.startDate.getTime()+1e3*e.duration;this.manifest.dateRanges[t].endDate=new Date(r)}if(f[e.id]){for(let t in f[e.id])if(e[t]&&JSON.stringify(f[e.id][t])!==JSON.stringify(e[t])){this.trigger("warn",{message:"EXT-X-DATERANGE tags with the same ID in a playlist must have the same attributes values"});break}let t=this.manifest.dateRanges.findIndex(t=>t.id===e.id);this.manifest.dateRanges[t]=rn(this.manifest.dateRanges[t],e),f[e.id]=rn(f[e.id],e),this.manifest.dateRanges.pop()}else f[e.id]=e},"independent-segments"(){this.manifest.independentSegments=!0},"content-steering"(){this.manifest.contentSteering=rf(p.attributes),this.warnOnMissingAttributes_("#EXT-X-CONTENT-STEERING",p.attributes,["SERVER-URI"])}})[p.tagType]||o).call(t)},uri(){r.uri=p.uri,e.push(r),!this.manifest.targetDuration||"duration"in r||(this.trigger("warn",{message:"defaulting segment duration to the target duration"}),r.duration=this.manifest.targetDuration),n&&(r.key=n),r.timeline=l,s&&(r.map=s),d=0,null!==this.lastProgramDateTime&&(r.programDateTime=this.lastProgramDateTime,this.lastProgramDateTime+=1e3*r.duration),r={}},comment(){},custom(){p.segment?(r.custom=r.custom||{},r.custom[p.customType]=p.data):(this.manifest.custom=this.manifest.custom||{},this.manifest.custom[p.customType]=p.data)}})[p.type].call(t)})}warnOnMissingAttributes_(t,e,r){let s=[];r.forEach(function(t){e.hasOwnProperty(t)||s.push(t)}),s.length&&this.trigger("warn",{message:`${t} lacks required attribute(s): ${s.join(", ")}`})}push(t){this.lineStream.push(t)}end(){this.lineStream.push(` `),this.manifest.dateRanges.length&&null===this.lastProgramDateTime&&this.trigger("warn",{message:"A playlist with EXT-X-DATERANGE tag must contain atleast one EXT-X-PROGRAM-DATE-TIME tag"}),this.lastProgramDateTime=null,this.trigger("end")}addParser(t){this.parseStream.addParser(t)}addTagMapper(t){this.parseStream.addTagMapper(t)}}async function rm(t,e=10){let r=new rc;r.push(await (await fetch(t)).text()),r.end();let s=r.manifest.segments.reduce((t,e)=>(t[e.map.uri]=t[e.map.uri]??[],t[e.map.uri].push(e),t),{}),n=new URL(t,location.href),a={};async function o(t,r,s){async function o(t){return(await fetch(t)).arrayBuffer()}let h=function(e){let n=0,a=0,o=[];async function h(){if(n<e&&o.length){let e=o.shift();n++;try{await (null==e?void 0:e()),a++,s.emit("progress",Math.round(a/t.length*100)/100),h()}catch(t){o=[],r.error(t),s.destroy(),e5.error(t)}n--}}return async function(t){o.push(t),h()}}(e);for(let[,e]of t.entries()){let t=new URL(e.uri,n).href;h(()=>a[t]=o(t))}}async function h(t){let e=await a[t];return delete a[t],e}return{load(t=0,e=1/0){let r={},a=0,l=0;for(let[n,o]of Object.entries(s)){let s=0,h=[],u=-1,d=-1;for(let r=0;r<o.length;r++){let n=o[r];if(s+=n.duration,-1===u&&s>t/1e6&&(u=r,a=(s-n.duration)*1e6),u>-1&&-1===d&&s>=e/1e6){d=r+1,l=1e6*s;break}}e>=1e6*s&&(d=o.length,l=1e6*s),d>u&&(h=h.concat(o.slice(u,d))),h.length>0&&(r[n]={actualStartTime:a,actualEndTime:l,segments:h})}return 0===Object.keys(r).length?null:Object.entries(r).map(([t,{actualStartTime:e,actualEndTime:r,segments:s}])=>{let a=0,l=new i0;return{actualStartTime:e,actualEndTime:r,on:l.on,stream:new ReadableStream({start:async e=>{o(s,e,l),e.enqueue(new Uint8Array(await (await fetch(new URL(t,n).href)).arrayBuffer()))},pull:async t=>{let e=new URL(s[a].uri,n).href;t.enqueue(new Uint8Array(await h(e))),(a+=1)>=s.length&&(t.close(),l.destroy())}})}})}}}let rg=`#version 300 es layout (location = 0) in vec4 a_position; layout (location = 1) in vec2 a_texCoord; out vec2 v_texCoord; void main () { gl_Position = a_position; v_texCoord = a_texCoord; } `,ry=`#version 300 es precision mediump float; out vec4 FragColor; in vec2 v_texCoord; uniform sampler2D frameTexture; uniform vec3 keyColor; // \u{8272}\u{5EA6}\u{7684}\u{76F8}\u{4F3C}\u{5EA6}\u{8BA1}\u{7B97} uniform float similarity; // \u{900F}\u{660E}\u{5EA6}\u{7684}\u{5E73}\u{6ED1}\u{5EA6}\u{8BA1}\u{7B97} uniform float smoothness; // \u{964D}\u{4F4E}\u{7EFF}\u{5E55}\u{9971}\u{548C}\u{5EA6}\u{FF0C}\u{63D0}\u{9AD8}\u{62A0}\u{56FE}\u{51C6}\u{786E}\u{5EA6} uniform float spill; vec2 RGBtoUV(vec3 rgb) { return vec2( rgb.r * -0.169 + rgb.g * -0.331 + rgb.b * 0.5 + 0.5, rgb.r * 0.5 + rgb.g * -0.419 + rgb.b * -0.081 + 0.5 ); } void main() { // \u{83B7}\u{53D6}\u{5F53}\u{524D}\u{50CF}\u{7D20}\u{7684}rgba\u{503C} vec4 rgba = texture(frameTexture, v_texCoord); // \u{8BA1}\u{7B97}\u{5F53}\u{524D}\u{50CF}\u{7D20}\u{4E0E}\u{7EFF}\u{5E55}\u{50CF}\u{7D20}\u{7684}\u{8272}\u{5EA6}\u{5DEE}\u{503C} vec2 chromaVec = RGBtoUV(rgba.rgb) - RGBtoUV(keyColor); // \u{8BA1}\u{7B97}\u{5F53}\u{524D}\u{50CF}\u{7D20}\u{4E0E}\u{7EFF}\u{5E55}\u{50CF}\u{7D20}\u{7684}\u{8272}\u{5EA6}\u{8DDD}\u{79BB}\u{FF08}\u{5411}\u{91CF}\u{957F}\u{5EA6}\u{FF09}, \u{8D8A}\u{76F8}\u{50CF}\u{5219}\u{8272}\u{5EA6}\u{8DDD}\u{79BB}\u{8D8A}\u{5C0F} float chromaDist = sqrt(dot(chromaVec, chromaVec)); // \u{8BBE}\u{7F6E}\u{4E86}\u{4E00}\u{4E2A}\u{76F8}\u{4F3C}\u{5EA6}\u{9608}\u{503C}\u{FF0C}baseMask\u{4E3A}\u{8D1F}\u{FF0C}\u{5219}\u{8868}\u{660E}\u{662F}\u{7EFF}\u{5E55}\u{FF0C}\u{4E3A}\u{6B63}\u{5219}\u{8868}\u{660E}\u{4E0D}\u{662F}\u{7EFF}\u{5E55} float baseMask = chromaDist - similarity; // \u{5982}\u{679C}baseMask\u{4E3A}\u{8D1F}\u{6570}\u{FF0C}fullMask\u{7B49}\u{4E8E}0\u{FF1B}baseMask\u{4E3A}\u{6B63}\u{6570}\u{FF0C}\u{8D8A}\u{5927}\u{FF0C}\u{5219}\u{900F}\u{660E}\u{5EA6}\u{8D8A}\u{4F4E} float fullMask = pow(clamp(baseMask / smoothness, 0., 1.), 1.5); rgba.a = fullMask; // \u{8BBE}\u{7F6E}\u{900F}\u{660E}\u{5EA6} // \u{5982}\u{679C}baseMask\u{4E3A}\u{8D1F}\u{6570}\u{FF0C}spillVal\u{7B49}\u{4E8E}0\u{FF1B}baseMask\u{4E3A}\u{6574}\u{6570}\u{FF0C}\u{8D8A}\u{5C0F}\u{FF0C}\u{9971}\u{548C}\u{5EA6}\u{8D8A}\u{4F4E} float spillVal = pow(clamp(baseMask / spill, 0., 1.), 1.5); float desat = clamp(rgba.r * 0.2126 + rgba.g * 0.7152 + rgba.b * 0.0722, 0., 1.); // \u{8BA1}\u{7B97}\u{5F53}\u{524D}\u{50CF}\u{7D20}\u{7684}\u{7070}\u{5EA6}\u{503C} rgba.rgb = mix(vec3(desat, desat, desat), rgba.rgb, spillVal); FragColor = rgba; } `,r_=[-1,1,-1,-1,1,-1,1,-1,1,1,-1,1],rb=[0,1,0,0,1,0,1,0,1,1,0,1];function rw(t,e,r){let s=t.createShader(e);if(t.shaderSource(s,r),t.compileShader(s),!t.getShaderParameter(s,t.COMPILE_STATUS)){let e=t.getShaderInfoLog(s);throw t.deleteShader(s),Error(e??"An error occurred compiling the shaders")}return s}let rv=t=>{let e=null,r=null,s=t.keyColor,n=null;return async a=>{var o,h;if((null==e||null==r||null==n)&&(null==s&&(s=function(t){let e=new OffscreenCanvas(1,1).getContext("2d");e.drawImage(t,0,0);let{data:[r,s,n]}=e.getImageData(0,0,1,1);return[r,s,n]}(a)),{cvs:e,gl:r}=function(t){let e="document"in globalThis?globalThis.document.createElement("canvas"):new OffscreenCanvas(t.width,t.height);e.width=t.width,e.height=t.height;let r=e.getContext("webgl2",{premultipliedAlpha:!1,alpha:!0});if(null==r)throw Error("Cant create gl context");let s=function(t,e,r){let s=rw(t,t.VERTEX_SHADER,e),n=rw(t,t.FRAGMENT_SHADER,r),a=t.createProgram();if(t.attachShader(a,s),t.attachShader(a,n),t.linkProgram(a),!t.getProgramParameter(a,t.LINK_STATUS))throw Error(t.getProgramInfoLog(a)??"Unable to initialize the shader program");return a}(r,rg,ry);r.useProgram(s),r.uniform3fv(r.getUniformLocation(s,"keyColor"),t.keyColor.map(t=>t/255)),r.uniform1f(r.getUniformLocation(s,"similarity"),t.similarity),r.uniform1f(r.getUniformLocation(s,"smoothness"),t.smoothness),r.uniform1f(r.getUniformLocation(s,"spill"),t.spill);let n=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,n),r.bufferData(r.ARRAY_BUFFER,new Float32Array(r_),r.STATIC_DRAW);let a=r.getAttribLocation(s,"a_position");r.vertexAttribPointer(a,2,r.FLOAT,!1,2*Float32Array.BYTES_PER_ELEMENT,0),r.enableVertexAttribArray(a);let o=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,o),r.bufferData(r.ARRAY_BUFFER,new Float32Array(rb),r.STATIC_DRAW);let h=r.getAttribLocation(s,"a_texCoord");return r.vertexAttribPointer(h,2,r.FLOAT,!1,2*Float32Array.BYTES_PER_ELEMENT,0),r.enableVertexAttribArray(h),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,1),{cvs:e,gl:r}}({...a instanceof VideoFrame?{width:a.codedWidth,height:a.codedHeight}:{width:a.width,height:a.height},keyColor:s,...t}),n=function(t){let e=t.createTexture();if(null==e)throw Error("Create WebGL texture error");t.bindTexture(t.TEXTURE_2D,e);let r=t.RGBA,s=t.RGBA,n=t.UNSIGNED_BYTE,a=new Uint8Array([0,0,255,255]);return t.texImage2D(t.TEXTURE_2D,0,r,1,1,0,s,n,a),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),e}(r)),o=r,h=n,o.bindTexture(o.TEXTURE_2D,h),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,o.RGBA,o.UNSIGNED_BYTE,a),o.drawArrays(o.TRIANGLES,0,6),null!=globalThis.VideoFrame&&a instanceof globalThis.VideoFrame){let t=new VideoFrame(e,{alpha:"keep",timestamp:a.timestamp,duration:a.duration??void 0});return a.close(),t}return createImageBitmap(e,{imageOrientation:a instanceof ImageBitmap?"flipY":"none"})}},rS=class t{constructor(t,e,r,s,n){ew(this,tX),ew(this,tN,new i0),ey(this,"on",eb(this,tN).on),ew(this,tG,0),ew(this,tY,0),ew(this,tW,0),ew(this,tV,0),ew(this,tH,0),ey(this,"master",null),ey(this,"fixedAspectRatio",!1),this.x=t??0,this.y=e??0,this.w=r??0,this.h=s??0,this.master=n??null}get x(){return eb(this,tG)}set x(t){eS(this,tX,tj).call(this,"x",t)}get y(){return eb(this,tY)}set y(t){eS(this,tX,tj).call(this,"y",t)}get w(){return eb(this,tW)}set w(t){eS(this,tX,tj).call(this,"w",t)}get h(){return eb(this,tV)}set h(t){eS(this,tX,tj).call(this,"h",t)}get angle(){return eb(this,tH)}set angle(t){eS(this,tX,tj).call(this,"angle",t)}get center(){let{x:t,y:e,w:r,h:s}=this;return{x:t+r/2,y:e+s/2}}get ctrls(){let{w:e,h:r}=this,s=t.CTRL_SIZE,n=s/2,a=e/2,o=r/2,h=1.5*s,l=h/2;return{...this.fixedAspectRatio?{}:{t:new t(-n,-o-n,s,s,this),b:new t(-n,o-n,s,s,this),l:new t(-a-n,-n,s,s,this),r:new t(a-n,-n,s,s,this)},lt:new t(-a-n,-o-n,s,s,this),lb:new t(-a-n,o-n,s,s,this),rt:new t(a-n,-o-n,s,s,this),rb:new t(a-n,o-n,s,s,this),rotate:new t(-l,-o-2*s-l,h,h,this)}}clone(){let{x:e,y:r,w:s,h:n,master:a}=this,o=new t(e,r,s,n,a);return o.angle=this.angle,o.fixedAspectRatio=this.fixedAspectRatio,o}checkHit(t,e){let{angle:r,center:s,x:n,y:a,w:o,h:h,master:l}=this,u=(null==l?void 0:l.center)??s,d=(null==l?void 0:l.angle)??r;null==l&&(n-=u.x,a-=u.y);let f=t-u.x,p=e-u.y,c=f,m=p;return 0!==d&&(c=f*Math.cos(d)+p*Math.sin(d),m=p*Math.cos(d)-f*Math.sin(d)),!(c<n||c>n+o||m<a||m>a+h)}};tN=new WeakMap,tG=new WeakMap,tY=new WeakMap,tW=new WeakMap,tV=new WeakMap,tH=new WeakMap,tX=new WeakSet,tj=function(t,e){let r=this[t]!==e;switch(t){case"x":ev(this,tG,e);break;case"y":ev(this,tY,e);break;case"w":ev(this,tW,e);break;case"h":ev(this,tV,e);break;case"angle":ev(this,tH,e)}r&&eb(this,tN).emit("propsChange",{[t]:e})},ey(rS,"CTRL_SIZE",16),ey(rS,"CTRL_KEYS",["t","b","l","r","lt","lb","rt","rb","rotate"]);let rE=rS;class rU{constructor(){ey(this,"rect",new rE),ey(this,"time",{offset:0,duration:0}),ey(this,"visible",!0),ew(this,tZ,new i0),ey(this,"on",eb(this,tZ).on),ew(this,t$,0),ey(this,"opacity",1),ey(this,"flip",null),ew(this,tK,null),ew(this,tq,null),ey(this,"ready",Promise.resolve()),this.rect.on("propsChange",t=>{eb(this,tZ).emit("propsChange",{rect:t})})}get zIndex(){return eb(this,t$)}set zIndex(t){let e=eb(this,t$)!==t;ev(this,t$,t),e&&eb(this,tZ).emit("propsChange",{zIndex:t})}_render(t){let{rect:{center:e,angle:r}}=this;t.setTransform("horizontal"===this.flip?-1:1,0,0,"vertical"===this.flip?-1:1,e.x,e.y),t.rotate((null==this.flip?1:-1)*r),t.globalAlpha=this.opacity}setAnimation(t,e){ev(this,tK,Object.entries(t).map(([t,e])=>{let r={from:0,to:100}[t]??Number(t.slice(0,-1));if(isNaN(r)||r>100||r<0)throw Error("keyFrame must between 0~100");return[r/100,e]})),ev(this,tq,Object.assign({},eb(this,tq),{duration:1e6*e.duration,delay:(e.delay??0)*1e6,iterCount:e.iterCount??1/0}))}animate(t){if(null==eb(this,tK)||null==eb(this,tq)||t<eb(this,tq).delay)return;let e=function(t,e,r){if(t/r.duration>=r.iterCount)return{};let s=t%r.duration,n=t===r.duration?1:s/r.duration,a=e.findIndex(t=>t[0]>=n);if(-1===a)return{};let o=e[a-1],h=e[a],l=h[1];if(null==o)return l;let u=o[1],d={},f=(n-o[0])/(h[0]-o[0]);for(let t in l)null!=u[t]&&(d[t]=(l[t]-u[t])*f+u[t]);return d}(t,eb(this,tK),eb(this,tq));for(let t in e)switch(t){case"opacity":this.opacity=e[t];break;case"x":case"y":case"w":case"h":case"angle":this.rect[t]=e[t]}}copyStateTo(t){ev(t,tK,eb(this,tK)),ev(t,tq,eb(this,tq)),t.visible=this.visible,t.zIndex=this.zIndex,t.opacity=this.opacity,t.flip=this.flip,t.rect=this.rect.clone(),t.time={...this.time}}destroy(){eb(this,tZ).destroy()}}tZ=new WeakMap,t$=new WeakMap,tK=new WeakMap,tq=new WeakMap;let rx=class t extends rU{constructor(t){super(),ew(this,tQ),ew(this,tJ,null),ew(this,t0,!1),ev(this,tQ,t),this.ready=t.ready.then(({width:t,height:e,duration:r})=>{this.rect.w=0===this.rect.w?t:this.rect.w,this.rect.h=0===this.rect.h?e:this.rect.h,this.time.duration=0===this.time.duration?r:this.time.duration})}async offscreenRender(t,e){var r;this.animate(e),super._render(t);let{w:s,h:n}=this.rect,{video:a,audio:o,state:h}=await eb(this,tQ).tick(e);if("done"===h)return{audio:o??[],done:!0};let l=a??eb(this,tJ);return null!=l&&t.drawImage(l,-s/2,-n/2,s,n),null!=a&&(null==(r=eb(this,tJ))||r.close(),ev(this,tJ,a)),{audio:o??[],done:!1}}async clone(){let e=new t(await eb(this,tQ).clone());return await e.ready,this.copyStateTo(e),e}destroy(){var t;eb(this,t0)||(ev(this,t0,!0),e5.info("OffscreenSprite destroy"),super.destroy(),null==(t=eb(this,tJ))||t.close(),ev(this,tJ,null),eb(this,tQ).destroy())}};tQ=new WeakMap,tJ=new WeakMap,t0=new WeakMap;let rT=rx;class rA extends rU{constructor(t){super(),ew(this,t8),ew(this,t1),ew(this,t2,null),ew(this,t3,[]),ew(this,t6,!1),ew(this,t5,-1),ew(this,t9,!1),ev(this,t1,t),this.ready=t.ready.then(({width:t,height:e,duration:r})=>{this.rect.w=0===this.rect.w?t:this.rect.w,this.rect.h=0===this.rect.h?e:this.rect.h,this.time.duration=0===this.time.duration?r:this.time.duration})}getClip(){return eb(this,t1)}preFrame(t){eS(this,t8,t4).call(this,t)}render(t,e){this.animate(e),super._render(t);let{w:r,h:s}=this.rect;eb(this,t5)!==e&&eS(this,t8,t4).call(this,e),ev(this,t5,e);let n=eb(this,t3);ev(this,t3,[]);let a=eb(this,t2);return null!=a&&t.drawImage(a,-r/2,-s/2,r,s),{audio:n}}destroy(){var t;eb(this,t9)||(ev(this,t9,!0),e5.info("VisibleSprite destroy"),super.destroy(),null==(t=eb(this,t2))||t.close(),ev(this,t2,null),eb(this,t1).destroy())}}t1=new WeakMap,t2=new WeakMap,t3=new WeakMap,t6=new WeakMap,t8=new WeakSet,t4=function(t){eb(this,t6)||(ev(this,t6,!0),eb(this,t1).tick(t).then(({video:t,audio:e})=>{var r;null!=t&&(null==(r=eb(this,t2))||r.close(),ev(this,t2,t??null)),ev(this,t3,e??[])}).finally(()=>{ev(this,t6,!1)}))},t5=new WeakMap,t9=new WeakMap;let rC=0;async function rI(t){t()>50&&(await iv(15),await rI(t))}class rB{constructor(t={}){ew(this,eh),ew(this,t7,e5.create(`id:${rC++},`)),ew(this,et,!1),ew(this,ee,[]),ew(this,ei),ew(this,er),ew(this,es,null),ew(this,en),ew(this,ea),ew(this,eo,new i0),ey(this,"on",eb(this,eo).on);let{width:e=0,height:r=0}=t;ev(this,ei,new OffscreenCanvas(e,r));let s=eb(this,ei).getContext("2d",{alpha:!1});if(null==s)throw Error("Can not create 2d offscreen context");ev(this,er,s),ev(this,en,Object.assign({bgColor:"#000",width:0,height:0,videoCodec:"avc1.42E032",audio:!0,bitrate:5e6,metaDataTags:null},t)),ev(this,ea,e*r>0)}static async isSupported(t={videoCodec:"avc1.42E032"}){return null!=self.OffscreenCanvas&&null!=self.VideoEncoder&&null!=self.VideoDecoder&&null!=self.VideoFrame&&null!=self.AudioEncoder&&null!=self.AudioDecoder&&null!=self.AudioData&&((await self.VideoEncoder.isConfigSupported({codec:t.videoCodec,width:1280,height:720})).supported??!1)&&(await self.AudioEncoder.isConfigSupported({codec:iC.codec,sampleRate:iC.sampleRate,numberOfChannels:iC.channelCount})).supported}async addSprite(t,e={}){eb(this,t7).info("Combinator add sprite",t);let r=await t.clone();eb(this,t7).info("Combinator add sprite ready",t),eb(this,ee).push(Object.assign(r,{main:e.main??!1,expired:!1})),eb(this,ee).sort((t,e)=>t.zIndex-e.zIndex)}output(){if(0===eb(this,ee).length)throw Error("No sprite added");let t=eb(this,ee).find(t=>t.main),e=null!=t?t.time.offset+t.time.duration:Math.max(...eb(this,ee).map(t=>t.time.offset+t.time.duration));if(e===1/0)throw Error("Unable to determine the end time, please specify a main sprite, or limit the duration of ImgClip, AudioCli");-1===e&&eb(this,t7).warn("Unable to determine the end time, process value don't update"),eb(this,t7).info(`start combinate video, maxTime:${e}`);let r=eS(this,eh,el).call(this,e),s=performance.now(),n=eS(this,eh,eu).call(this,r,e,{onProgress:t=>{eb(this,t7).debug("OutputProgress:",t),eb(this,eo).emit("OutputProgress",t)},onEnded:async()=>{await r.flush(),eb(this,t7).info("===== output ended =====, cost:",performance.now()-s),eb(this,eo).emit("OutputProgress",1),this.destroy()},onError:t=>{eb(this,eo).emit("error",t),o(t),this.destroy()}});ev(this,es,()=>{n(),r.close(),o()});let{stream:a,stop:o}=i9(r.mp4file,500,this.destroy);return a}destroy(){var t;eb(this,et)||(ev(this,et,!0),null==(t=eb(this,es))||t.call(this),eb(this,eo).destroy())}}t7=new WeakMap,et=new WeakMap,ee=new WeakMap,ei=new WeakMap,er=new WeakMap,es=new WeakMap,en=new WeakMap,ea=new WeakMap,eo=new WeakMap,eh=new WeakSet,el=function(t){let{width:e,height:r,videoCodec:s,bitrate:n,audio:a,metaDataTags:o}=eb(this,en);return i4({video:eb(this,ea)?{width:e,height:r,expectFPS:30,codec:s,bitrate:n,__unsafe_hardwareAcceleration__:eb(this,en).__unsafe_hardwareAcceleration__}:null,audio:!1===a?null:{codec:"aac",sampleRate:iC.sampleRate,channelCount:iC.channelCount},duration:t,metaDataTags:o})},eu=function(t,e,{onProgress:r,onEnded:s,onError:n}){let a=0,o=!1,h=null;(async()=>{let r=0,{width:n,height:l}=eb(this,ei),d=eb(this,er),f=0;for(;;){if(null!=h)return;if(o||-1!==e&&f>e||0===eb(this,ee).length){u(),await s();return}a=f/e,d.fillStyle=eb(this,en).bgColor,d.fillRect(0,0,n,l);let p=[];for(let t of eb(this,ee)){if(o)break;if(f<t.time.offset||t.expired)continue;d.save();let{audio:e,done:r}=await t.offscreenRender(d,f-t.time.offset);if(p.push(e),d.restore(),t.time.duration>0&&f>t.time.offset+t.time.duration||r){if(t.main){u(),await s();return}t.destroy(),t.expired=!0}}if(o)return;if(!1!==eb(this,en).audio){if(p.flat().every(t=>0===t.length))t.encodeAudio(function(t,e,r){let s=Math.floor(33e3*r/1e6);return new AudioData({timestamp:t,numberOfChannels:iC.channelCount,numberOfFrames:s,sampleRate:r,format:"f32-planar",data:new Float32Array(2*s)})}(f,0,iC.sampleRate));else{let e=ib(p);t.encodeAudio(new AudioData({timestamp:f,numberOfChannels:iC.channelCount,numberOfFrames:e.length/iC.channelCount,sampleRate:iC.sampleRate,format:"f32-planar",data:e}))}}if(eb(this,ea)){let e=new VideoFrame(eb(this,ei),{duration:33e3,timestamp:f});t.encodeVideo(e,{keyFrame:r%150==0}),d.resetTransform(),d.clearRect(0,0,n,l),r+=1}f+=33e3,await rI(t.getEncodeQueueSize)}})().catch(t=>{h=t,eb(this,t7).error(t),u(),n(t)});let l=setInterval(()=>{r(a)},500),u=()=>{o||(o=!0,clearInterval(l),eb(this,ee).forEach(t=>t.destroy()))};return u}},{"718a311db185ef08":"juSMc","@parcel/transformer-js/src/esmodule-helpers.js":"9pCYc"}],juSMc:[function(t,e,r){var s=t("9c62938f1dccc73c"),n=t("aceacb6a4531a9d2"),a="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;function o(t){if(t>2147483647)throw RangeError('The value "'+t+'" is invalid for option "size"');var e=new Uint8Array(t);return Object.setPrototypeOf(e,h.prototype),e}function h(t,e,r){if("number"==typeof t){if("string"==typeof e)throw TypeError('The "string" argument must be of type string. Received type number');return d(t)}return l(t,e,r)}function l(t,e,r){if("string"==typeof t)return function(t,e){if(("string"!=typeof e||""===e)&&(e="utf8"),!h.isEncoding(e))throw TypeError("Unknown encoding: "+e);var r=0|m(t,e),s=o(r),n=s.write(t,e);return n!==r&&(s=s.slice(0,n)),s}(t,e);if(ArrayBuffer.isView(t))return function(t){if(B(t,Uint8Array)){var e=new Uint8Array(t);return p(e.buffer,e.byteOffset,e.byteLength)}return f(t)}(t);if(null==t)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(B(t,ArrayBuffer)||t&&B(t.buffer,ArrayBuffer)||"undefined"!=typeof SharedArrayBuffer&&(B(t,SharedArrayBuffer)||t&&B(t.buffer,SharedArrayBuffer)))return p(t,e,r);if("number"==typeof t)throw TypeError('The "value" argument must not be of type number. Received type number');var s=t.valueOf&&t.valueOf();if(null!=s&&s!==t)return h.from(s,e,r);var n=function(t){if(h.isBuffer(t)){var e,r=0|c(t.length),s=o(r);return 0===s.length||t.copy(s,0,0,r),s}return void 0!==t.length?"number"!=typeof t.length||(e=t.length)!=e?o(0):f(t):"Buffer"===t.type&&Array.isArray(t.data)?f(t.data):void 0}(t);if(n)return n;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return h.from(t[Symbol.toPrimitive]("string"),e,r);throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function u(t){if("number"!=typeof t)throw TypeError('"size" argument must be of type number');if(t<0)throw RangeError('The value "'+t+'" is invalid for option "size"')}function d(t){return u(t),o(t<0?0:0|c(t))}function f(t){for(var e=t.length<0?0:0|c(t.length),r=o(e),s=0;s<e;s+=1)r[s]=255&t[s];return r}function p(t,e,r){var s;if(e<0||t.byteLength<e)throw RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw RangeError('"length" is outside of buffer bounds');return Object.setPrototypeOf(s=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),h.prototype),s}function c(t){if(t>=2147483647)throw RangeError("Attempt to allocate Buffer larger than maximum size: 0x7fffffff bytes");return 0|t}function m(t,e){if(h.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||B(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);var r=t.length,s=arguments.length>2&&!0===arguments[2];if(!s&&0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return A(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return C(t).length;default:if(n)return s?-1:A(t).length;e=(""+e).toLowerCase(),n=!0}}function g(t,e,r){var n,a,o=!1;if((void 0===e||e<0)&&(e=0),e>this.length||((void 0===r||r>this.length)&&(r=this.length),r<=0||(r>>>=0)<=(e>>>=0)))return"";for(t||(t="utf8");;)switch(t){case"hex":return function(t,e,r){var s=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>s)&&(r=s);for(var n="",a=e;a<r;++a)n+=k[t[a]];return n}(this,e,r);case"utf8":case"utf-8":return w(this,e,r);case"ascii":return function(t,e,r){var s="";r=Math.min(t.length,r);for(var n=e;n<r;++n)s+=String.fromCharCode(127&t[n]);return s}(this,e,r);case"latin1":case"binary":return function(t,e,r){var s="";r=Math.min(t.length,r);for(var n=e;n<r;++n)s+=String.fromCharCode(t[n]);return s}(this,e,r);case"base64":return n=e,a=r,0===n&&a===this.length?s.fromByteArray(this):s.fromByteArray(this.slice(n,a));case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return function(t,e,r){for(var s=t.slice(e,r),n="",a=0;a<s.length-1;a+=2)n+=String.fromCharCode(s[a]+256*s[a+1]);return n}(this,e,r);default:if(o)throw TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),o=!0}}function y(t,e,r){var s=t[e];t[e]=t[r],t[r]=s}function _(t,e,r,s,n){var a;if(0===t.length)return -1;if("string"==typeof r?(s=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),(a=r=+r)!=a&&(r=n?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(n)return -1;r=t.length-1}else if(r<0){if(!n)return -1;r=0}if("string"==typeof e&&(e=h.from(e,s)),h.isBuffer(e))return 0===e.length?-1:b(t,e,r,s,n);if("number"==typeof e)return(e&=255,"function"==typeof Uint8Array.prototype.indexOf)?n?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):b(t,[e],r,s,n);throw TypeError("val must be string, number or Buffer")}function b(t,e,r,s,n){var a,o=1,h=t.length,l=e.length;if(void 0!==s&&("ucs2"===(s=String(s).toLowerCase())||"ucs-2"===s||"utf16le"===s||"utf-16le"===s)){if(t.length<2||e.length<2)return -1;o=2,h/=2,l/=2,r/=2}function u(t,e){return 1===o?t[e]:t.readUInt16BE(e*o)}if(n){var d=-1;for(a=r;a<h;a++)if(u(t,a)===u(e,-1===d?0:a-d)){if(-1===d&&(d=a),a-d+1===l)return d*o}else -1!==d&&(a-=a-d),d=-1}else for(r+l>h&&(r=h-l),a=r;a>=0;a--){for(var f=!0,p=0;p<l;p++)if(u(t,a+p)!==u(e,p)){f=!1;break}if(f)return a}return -1}function w(t,e,r){r=Math.min(t.length,r);for(var s=[],n=e;n<r;){var a,o,h,l,u=t[n],d=null,f=u>239?4:u>223?3:u>191?2:1;if(n+f<=r)switch(f){case 1:u<128&&(d=u);break;case 2:(192&(a=t[n+1]))==128&&(l=(31&u)<<6|63&a)>127&&(d=l);break;case 3:a=t[n+1],o=t[n+2],(192&a)==128&&(192&o)==128&&(l=(15&u)<<12|(63&a)<<6|63&o)>2047&&(l<55296||l>57343)&&(d=l);break;case 4:a=t[n+1],o=t[n+2],h=t[n+3],(192&a)==128&&(192&o)==128&&(192&h)==128&&(l=(15&u)<<18|(63&a)<<12|(63&o)<<6|63&h)>65535&&l<1114112&&(d=l)}null===d?(d=65533,f=1):d>65535&&(d-=65536,s.push(d>>>10&1023|55296),d=56320|1023&d),s.push(d),n+=f}return function(t){var e=t.length;if(e<=4096)return String.fromCharCode.apply(String,t);for(var r="",s=0;s<e;)r+=String.fromCharCode.apply(String,t.slice(s,s+=4096));return r}(s)}function v(t,e,r){if(t%1!=0||t<0)throw RangeError("offset is not uint");if(t+e>r)throw RangeError("Trying to access beyond buffer length")}function S(t,e,r,s,n,a){if(!h.isBuffer(t))throw TypeError('"buffer" argument must be a Buffer instance');if(e>n||e<a)throw RangeError('"value" argument is out of bounds');if(r+s>t.length)throw RangeError("Index out of range")}function E(t,e,r,s,n,a){if(r+s>t.length||r<0)throw RangeError("Index out of range")}function U(t,e,r,s,a){return e=+e,r>>>=0,a||E(t,e,r,4,34028234663852886e22,-34028234663852886e22),n.write(t,e,r,s,23,4),r+4}function x(t,e,r,s,a){return e=+e,r>>>=0,a||E(t,e,r,8,17976931348623157e292,-17976931348623157e292),n.write(t,e,r,s,52,8),r+8}r.Buffer=h,r.SlowBuffer=function(t){return+t!=t&&(t=0),h.alloc(+t)},r.INSPECT_MAX_BYTES=50,r.kMaxLength=2147483647,h.TYPED_ARRAY_SUPPORT=function(){try{var t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),h.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(h.prototype,"parent",{enumerable:!0,get:function(){if(h.isBuffer(this))return this.buffer}}),Object.defineProperty(h.prototype,"offset",{enumerable:!0,get:function(){if(h.isBuffer(this))return this.byteOffset}}),h.poolSize=8192,h.from=function(t,e,r){return l(t,e,r)},Object.setPrototypeOf(h.prototype,Uint8Array.prototype),Object.setPrototypeOf(h,Uint8Array),h.alloc=function(t,e,r){return(u(t),t<=0)?o(t):void 0!==e?"string"==typeof r?o(t).fill(e,r):o(t).fill(e):o(t)},h.allocUnsafe=function(t){return d(t)},h.allocUnsafeSlow=function(t){return d(t)},h.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==h.prototype},h.compare=function(t,e){if(B(t,Uint8Array)&&(t=h.from(t,t.offset,t.byteLength)),B(e,Uint8Array)&&(e=h.from(e,e.offset,e.byteLength)),!h.isBuffer(t)||!h.isBuffer(e))throw TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;for(var r=t.length,s=e.length,n=0,a=Math.min(r,s);n<a;++n)if(t[n]!==e[n]){r=t[n],s=e[n];break}return r<s?-1:s<r?1:0},h.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},h.concat=function(t,e){if(!Array.isArray(t))throw TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return h.alloc(0);if(void 0===e)for(r=0,e=0;r<t.length;++r)e+=t[r].length;var r,s=h.allocUnsafe(e),n=0;for(r=0;r<t.length;++r){var a=t[r];if(B(a,Uint8Array))n+a.length>s.length?h.from(a).copy(s,n):Uint8Array.prototype.set.call(s,a,n);else if(h.isBuffer(a))a.copy(s,n);else throw TypeError('"list" argument must be an Array of Buffers');n+=a.length}return s},h.byteLength=m,h.prototype._isBuffer=!0,h.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)y(this,e,e+1);return this},h.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)y(this,e,e+3),y(this,e+1,e+2);return this},h.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)y(this,e,e+7),y(this,e+1,e+6),y(this,e+2,e+5),y(this,e+3,e+4);return this},h.prototype.toString=function(){var t=this.length;return 0===t?"":0==arguments.length?w(this,0,t):g.apply(this,arguments)},h.prototype.toLocaleString=h.prototype.toString,h.prototype.equals=function(t){if(!h.isBuffer(t))throw TypeError("Argument must be a Buffer");return this===t||0===h.compare(this,t)},h.prototype.inspect=function(){var t="",e=r.INSPECT_MAX_BYTES;return t=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(t+=" ... "),"<Buffer "+t+">"},a&&(h.prototype[a]=h.prototype.inspect),h.prototype.compare=function(t,e,r,s,n){if(B(t,Uint8Array)&&(t=h.from(t,t.offset,t.byteLength)),!h.isBuffer(t))throw TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===s&&(s=0),void 0===n&&(n=this.length),e<0||r>t.length||s<0||n>this.length)throw RangeError("out of range index");if(s>=n&&e>=r)return 0;if(s>=n)return -1;if(e>=r)return 1;if(e>>>=0,r>>>=0,s>>>=0,n>>>=0,this===t)return 0;for(var a=n-s,o=r-e,l=Math.min(a,o),u=this.slice(s,n),d=t.slice(e,r),f=0;f<l;++f)if(u[f]!==d[f]){a=u[f],o=d[f];break}return a<o?-1:o<a?1:0},h.prototype.includes=function(t,e,r){return -1!==this.indexOf(t,e,r)},h.prototype.indexOf=function(t,e,r){return _(this,t,e,r,!0)},h.prototype.lastIndexOf=function(t,e,r){return _(this,t,e,r,!1)},h.prototype.write=function(t,e,r,s){if(void 0===e)s="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)s=e,r=this.length,e=0;else if(isFinite(e))e>>>=0,isFinite(r)?(r>>>=0,void 0===s&&(s="utf8")):(s=r,r=void 0);else throw Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var n,a,o,h,l,u,d,f,p=this.length-e;if((void 0===r||r>p)&&(r=p),t.length>0&&(r<0||e<0)||e>this.length)throw RangeError("Attempt to write outside buffer bounds");s||(s="utf8");for(var c=!1;;)switch(s){case"hex":return function(t,e,r,s){r=Number(r)||0;var n=t.length-r;s?(s=Number(s))>n&&(s=n):s=n;var a=e.length;s>a/2&&(s=a/2);for(var o=0;o<s;++o){var h=parseInt(e.substr(2*o,2),16);if(h!=h)break;t[r+o]=h}return o}(this,t,e,r);case"utf8":case"utf-8":return n=e,a=r,I(A(t,this.length-n),this,n,a);case"ascii":case"latin1":case"binary":return o=e,h=r,I(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(t),this,o,h);case"base64":return l=e,u=r,I(C(t),this,l,u);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return d=e,f=r,I(function(t,e){for(var r,s,n=[],a=0;a<t.length&&!((e-=2)<0);++a)s=(r=t.charCodeAt(a))>>8,n.push(r%256),n.push(s);return n}(t,this.length-d),this,d,f);default:if(c)throw TypeError("Unknown encoding: "+s);s=(""+s).toLowerCase(),c=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},h.prototype.slice=function(t,e){var r=this.length;t=~~t,e=void 0===e?r:~~e,t<0?(t+=r)<0&&(t=0):t>r&&(t=r),e<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);var s=this.subarray(t,e);return Object.setPrototypeOf(s,h.prototype),s},h.prototype.readUintLE=h.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||v(t,e,this.length);for(var s=this[t],n=1,a=0;++a<e&&(n*=256);)s+=this[t+a]*n;return s},h.prototype.readUintBE=h.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||v(t,e,this.length);for(var s=this[t+--e],n=1;e>0&&(n*=256);)s+=this[t+--e]*n;return s},h.prototype.readUint8=h.prototype.readUInt8=function(t,e){return t>>>=0,e||v(t,1,this.length),this[t]},h.prototype.readUint16LE=h.prototype.readUInt16LE=function(t,e){return t>>>=0,e||v(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUint16BE=h.prototype.readUInt16BE=function(t,e){return t>>>=0,e||v(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUint32LE=h.prototype.readUInt32LE=function(t,e){return t>>>=0,e||v(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUint32BE=h.prototype.readUInt32BE=function(t,e){return t>>>=0,e||v(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||v(t,e,this.length);for(var s=this[t],n=1,a=0;++a<e&&(n*=256);)s+=this[t+a]*n;return s>=(n*=128)&&(s-=Math.pow(2,8*e)),s},h.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||v(t,e,this.length);for(var s=e,n=1,a=this[t+--s];s>0&&(n*=256);)a+=this[t+--s]*n;return a>=(n*=128)&&(a-=Math.pow(2,8*e)),a},h.prototype.readInt8=function(t,e){return(t>>>=0,e||v(t,1,this.length),128&this[t])?-((255-this[t]+1)*1):this[t]},h.prototype.readInt16LE=function(t,e){t>>>=0,e||v(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},h.prototype.readInt16BE=function(t,e){t>>>=0,e||v(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},h.prototype.readInt32LE=function(t,e){return t>>>=0,e||v(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,e){return t>>>=0,e||v(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,e){return t>>>=0,e||v(t,4,this.length),n.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,e){return t>>>=0,e||v(t,4,this.length),n.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,e){return t>>>=0,e||v(t,8,this.length),n.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,e){return t>>>=0,e||v(t,8,this.length),n.read(this,t,!1,52,8)},h.prototype.writeUintLE=h.prototype.writeUIntLE=function(t,e,r,s){if(t=+t,e>>>=0,r>>>=0,!s){var n=Math.pow(2,8*r)-1;S(this,t,e,r,n,0)}var a=1,o=0;for(this[e]=255&t;++o<r&&(a*=256);)this[e+o]=t/a&255;return e+r},h.prototype.writeUintBE=h.prototype.writeUIntBE=function(t,e,r,s){if(t=+t,e>>>=0,r>>>=0,!s){var n=Math.pow(2,8*r)-1;S(this,t,e,r,n,0)}var a=r-1,o=1;for(this[e+a]=255&t;--a>=0&&(o*=256);)this[e+a]=t/o&255;return e+r},h.prototype.writeUint8=h.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,1,255,0),this[e]=255&t,e+1},h.prototype.writeUint16LE=h.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},h.prototype.writeUint16BE=h.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},h.prototype.writeUint32LE=h.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},h.prototype.writeUint32BE=h.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},h.prototype.writeIntLE=function(t,e,r,s){if(t=+t,e>>>=0,!s){var n=Math.pow(2,8*r-1);S(this,t,e,r,n-1,-n)}var a=0,o=1,h=0;for(this[e]=255&t;++a<r&&(o*=256);)t<0&&0===h&&0!==this[e+a-1]&&(h=1),this[e+a]=(t/o>>0)-h&255;return e+r},h.prototype.writeIntBE=function(t,e,r,s){if(t=+t,e>>>=0,!s){var n=Math.pow(2,8*r-1);S(this,t,e,r,n-1,-n)}var a=r-1,o=1,h=0;for(this[e+a]=255&t;--a>=0&&(o*=256);)t<0&&0===h&&0!==this[e+a+1]&&(h=1),this[e+a]=(t/o>>0)-h&255;return e+r},h.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},h.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},h.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},h.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},h.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},h.prototype.writeFloatLE=function(t,e,r){return U(this,t,e,!0,r)},h.prototype.writeFloatBE=function(t,e,r){return U(this,t,e,!1,r)},h.prototype.writeDoubleLE=function(t,e,r){return x(this,t,e,!0,r)},h.prototype.writeDoubleBE=function(t,e,r){return x(this,t,e,!1,r)},h.prototype.copy=function(t,e,r,s){if(!h.isBuffer(t))throw TypeError("argument should be a Buffer");if(r||(r=0),s||0===s||(s=this.length),e>=t.length&&(e=t.length),e||(e=0),s>0&&s<r&&(s=r),s===r||0===t.length||0===this.length)return 0;if(e<0)throw RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw RangeError("Index out of range");if(s<0)throw RangeError("sourceEnd out of bounds");s>this.length&&(s=this.length),t.length-e<s-r&&(s=t.length-e+r);var n=s-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,s):Uint8Array.prototype.set.call(t,this.subarray(r,s),e),n},h.prototype.fill=function(t,e,r,s){if("string"==typeof t){if("string"==typeof e?(s=e,e=0,r=this.length):"string"==typeof r&&(s=r,r=this.length),void 0!==s&&"string"!=typeof s)throw TypeError("encoding must be a string");if("string"==typeof s&&!h.isEncoding(s))throw TypeError("Unknown encoding: "+s);if(1===t.length){var n,a=t.charCodeAt(0);("utf8"===s&&a<128||"latin1"===s)&&(t=a)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<r)throw RangeError("Out of range index");if(r<=e)return this;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(n=e;n<r;++n)this[n]=t;else{var o=h.isBuffer(t)?t:h.from(t,s),l=o.length;if(0===l)throw TypeError('The value "'+t+'" is invalid for argument "value"');for(n=0;n<r-e;++n)this[n+e]=o[n%l]}return this};var T=/[^+/0-9A-Za-z-_]/g;function A(t,e){e=e||1/0;for(var r,s=t.length,n=null,a=[],o=0;o<s;++o){if((r=t.charCodeAt(o))>55295&&r<57344){if(!n){if(r>56319||o+1===s){(e-=3)>-1&&a.push(239,191,189);continue}n=r;continue}if(r<56320){(e-=3)>-1&&a.push(239,191,189),n=r;continue}r=(n-55296<<10|r-56320)+65536}else n&&(e-=3)>-1&&a.push(239,191,189);if(n=null,r<128){if((e-=1)<0)break;a.push(r)}else if(r<2048){if((e-=2)<0)break;a.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;a.push(r>>12|224,r>>6&63|128,63&r|128)}else if(r<1114112){if((e-=4)<0)break;a.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}else throw Error("Invalid code point")}return a}function C(t){return s.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(T,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function I(t,e,r,s){for(var n=0;n<s&&!(n+r>=e.length)&&!(n>=t.length);++n)e[n+r]=t[n];return n}function B(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}var k=function(){for(var t="0123456789abcdef",e=Array(256),r=0;r<16;++r)for(var s=16*r,n=0;n<16;++n)e[s+n]=t[r]+t[n];return e}()},{"9c62938f1dccc73c":"iaOvk",aceacb6a4531a9d2:"9RC4J"}],iaOvk:[function(t,e,r){r.byteLength=function(t){var e=u(t),r=e[0],s=e[1];return(r+s)*3/4-s},r.toByteArray=function(t){var e,r,s=u(t),o=s[0],h=s[1],l=new a((o+h)*3/4-h),d=0,f=h>0?o-4:o;for(r=0;r<f;r+=4)e=n[t.charCodeAt(r)]<<18|n[t.charCodeAt(r+1)]<<12|n[t.charCodeAt(r+2)]<<6|n[t.charCodeAt(r+3)],l[d++]=e>>16&255,l[d++]=e>>8&255,l[d++]=255&e;return 2===h&&(e=n[t.charCodeAt(r)]<<2|n[t.charCodeAt(r+1)]>>4,l[d++]=255&e),1===h&&(e=n[t.charCodeAt(r)]<<10|n[t.charCodeAt(r+1)]<<4|n[t.charCodeAt(r+2)]>>2,l[d++]=e>>8&255,l[d++]=255&e),l},r.fromByteArray=function(t){for(var e,r=t.length,n=r%3,a=[],o=0,h=r-n;o<h;o+=16383)a.push(function(t,e,r){for(var n,a=[],o=e;o<r;o+=3)a.push(s[(n=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(255&t[o+2]))>>18&63]+s[n>>12&63]+s[n>>6&63]+s[63&n]);return a.join("")}(t,o,o+16383>h?h:o+16383));return 1===n?a.push(s[(e=t[r-1])>>2]+s[e<<4&63]+"=="):2===n&&a.push(s[(e=(t[r-2]<<8)+t[r-1])>>10]+s[e>>4&63]+s[e<<2&63]+"="),a.join("")};for(var s=[],n=[],a="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",h=0,l=o.length;h<l;++h)s[h]=o[h],n[o.charCodeAt(h)]=h;function u(t){var e=t.length;if(e%4>0)throw Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");-1===r&&(r=e);var s=r===e?0:4-r%4;return[r,s]}n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63},{}],"9RC4J":[function(t,e,r){/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh<https://feross.org/opensource>*/r.read=function(t,e,r,s,n){var a,o,h=8*n-s-1,l=(1<<h)-1,u=l>>1,d=-7,f=r?n-1:0,p=r?-1:1,c=t[e+f];for(f+=p,a=c&(1<<-d)-1,c>>=-d,d+=h;d>0;a=256*a+t[e+f],f+=p,d-=8);for(o=a&(1<<-d)-1,a>>=-d,d+=s;d>0;o=256*o+t[e+f],f+=p,d-=8);if(0===a)a=1-u;else{if(a===l)return o?NaN:1/0*(c?-1:1);o+=Math.pow(2,s),a-=u}return(c?-1:1)*o*Math.pow(2,a-s)},r.write=function(t,e,r,s,n,a){var o,h,l,u=8*a-n-1,d=(1<<u)-1,f=d>>1,p=23===n?5960464477539062e-23:0,c=s?0:a-1,m=s?1:-1,g=e<0||0===e&&1/e<0?1:0;for(isNaN(e=Math.abs(e))||e===1/0?(h=isNaN(e)?1:0,o=d):(o=Math.floor(Math.log(e)/Math.LN2),e*(l=Math.pow(2,-o))<1&&(o--,l*=2),o+f>=1?e+=p/l:e+=p*Math.pow(2,1-f),e*l>=2&&(o++,l/=2),o+f>=d?(h=0,o=d):o+f>=1?(h=(e*l-1)*Math.pow(2,n),o+=f):(h=e*Math.pow(2,f-1)*Math.pow(2,n),o=0));n>=8;t[r+c]=255&h,c+=m,h/=256,n-=8);for(o=o<<n|h,u+=n;u>0;t[r+c]=255&o,c+=m,o/=256,u-=8);t[r+c-m]|=128*g}},{}],"9pCYc":[function(t,e,r){r.interopDefault=function(t){return t&&t.__esModule?t:{default:t}},r.defineInteropFlag=function(t){Object.defineProperty(t,"__esModule",{value:!0})},r.exportAll=function(t,e){return Object.keys(t).forEach(function(r){"default"===r||"__esModule"===r||Object.prototype.hasOwnProperty.call(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[r]}})}),e},r.export=function(t,e,r){Object.defineProperty(t,e,{enumerable:!0,get:r})}},{}]},["jc2x7"],"jc2x7","parcelRequire4dc0"); |