diff --git "a/assets/output-B3Y5HpO5.js" "b/assets/output-B3Y5HpO5.js" new file mode 100644--- /dev/null +++ "b/assets/output-B3Y5HpO5.js" @@ -0,0 +1 @@ +import{o as e}from"./chunk-B78Zgmat.js";import{t}from"./__vite-browser-external-BaycPy5b.js";function n(e){if(!e)throw Error(`Assertion failed.`)}const r=e=>e&&e[e.length-1];var i=class e{constructor(e){this.bytes=e,this.pos=0}seekToByte(e){this.pos=8*e}readBit(){let e=Math.floor(this.pos/8),t=this.bytes[e]??0,n=7-(this.pos&7),r=(t&1<>n;return this.pos++,r}readBits(e){if(e===1)return this.readBit();let t=0;for(let n=0;n>n-e-1<e.constructor===Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e),o=e=>e.constructor===DataView?e:ArrayBuffer.isView(e)?new DataView(e.buffer,e.byteOffset,e.byteLength):new DataView(e),s=new TextEncoder,c=e=>{for(let t=0;t255)return!1;return!0},l=e=>e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer||ArrayBuffer.isView(e);var u=class{constructor(){this.currentPromise=Promise.resolve()}async acquire(){let e,t=new Promise(t=>{e=t}),n=this.currentPromise;return this.currentPromise=t,await n,e}};const d=()=>{let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}},f=e=>{throw Error(`Unexpected value: ${e}`)},p=(e,t,n,r)=>{n>>>=0,n&=16777215,r?(e.setUint8(t,n&255),e.setUint8(t+1,n>>>8&255),e.setUint8(t+2,n>>>16&255)):(e.setUint8(t,n>>>16&255),e.setUint8(t+1,n>>>8&255),e.setUint8(t+2,n&255))},m=(e,t,n,r)=>{n=h(n,-8388608,8388607),n<0&&(n=n+16777216&16777215),p(e,t,n,r)},h=(e,t,n)=>Math.max(t,Math.min(n,e));var g=/^[a-z]{3}$/;const _=e=>g.test(e),v=1e6*(1+2**-52);var ee=class{constructor(){this.currentPromise=Promise.resolve()}call(e){return this.currentPromise=this.currentPromise.then(e)}};const y=function*(e){for(let t in e){let n=e[t];n!==void 0&&(yield{key:t,value:n})}},te=()=>{Symbol.dispose??=Symbol(`Symbol.dispose`)};var ne=class{constructor(e,t){if(this.data=e,this.mimeType=t,!(e instanceof Uint8Array))throw TypeError(`data must be a Uint8Array.`);if(typeof t!=`string`)throw TypeError(`mimeType must be a string.`)}},re=class{constructor(e,t,n,r){if(this.data=e,this.mimeType=t,this.name=n,this.description=r,!(e instanceof Uint8Array))throw TypeError(`data must be a Uint8Array.`);if(t!==void 0&&typeof t!=`string`)throw TypeError(`mimeType, when provided, must be a string.`);if(n!==void 0&&typeof n!=`string`)throw TypeError(`name, when provided, must be a string.`);if(r!==void 0&&typeof r!=`string`)throw TypeError(`description, when provided, must be a string.`)}};const b=e=>{if(!e||typeof e!=`object`)throw TypeError(`tags must be an object.`);if(e.title!==void 0&&typeof e.title!=`string`)throw TypeError(`tags.title, when provided, must be a string.`);if(e.description!==void 0&&typeof e.description!=`string`)throw TypeError(`tags.description, when provided, must be a string.`);if(e.artist!==void 0&&typeof e.artist!=`string`)throw TypeError(`tags.artist, when provided, must be a string.`);if(e.album!==void 0&&typeof e.album!=`string`)throw TypeError(`tags.album, when provided, must be a string.`);if(e.albumArtist!==void 0&&typeof e.albumArtist!=`string`)throw TypeError(`tags.albumArtist, when provided, must be a string.`);if(e.trackNumber!==void 0&&(!Number.isInteger(e.trackNumber)||e.trackNumber<=0))throw TypeError(`tags.trackNumber, when provided, must be a positive integer.`);if(e.tracksTotal!==void 0&&(!Number.isInteger(e.tracksTotal)||e.tracksTotal<=0))throw TypeError(`tags.tracksTotal, when provided, must be a positive integer.`);if(e.discNumber!==void 0&&(!Number.isInteger(e.discNumber)||e.discNumber<=0))throw TypeError(`tags.discNumber, when provided, must be a positive integer.`);if(e.discsTotal!==void 0&&(!Number.isInteger(e.discsTotal)||e.discsTotal<=0))throw TypeError(`tags.discsTotal, when provided, must be a positive integer.`);if(e.genre!==void 0&&typeof e.genre!=`string`)throw TypeError(`tags.genre, when provided, must be a string.`);if(e.date!==void 0&&(!(e.date instanceof Date)||Number.isNaN(e.date.getTime())))throw TypeError(`tags.date, when provided, must be a valid Date.`);if(e.lyrics!==void 0&&typeof e.lyrics!=`string`)throw TypeError(`tags.lyrics, when provided, must be a string.`);if(e.images!==void 0){if(!Array.isArray(e.images))throw TypeError(`tags.images, when provided, must be an array.`);for(let t of e.images){if(!t||typeof t!=`object`)throw TypeError(`Each image in tags.images must be an object.`);if(!(t.data instanceof Uint8Array))throw TypeError(`Each image.data must be a Uint8Array.`);if(typeof t.mimeType!=`string`)throw TypeError(`Each image.mimeType must be a string.`);if(![`coverFront`,`coverBack`,`unknown`].includes(t.kind))throw TypeError(`Each image.kind must be 'coverFront', 'coverBack', or 'unknown'.`)}}if(e.comment!==void 0&&typeof e.comment!=`string`)throw TypeError(`tags.comment, when provided, must be a string.`);if(e.raw!==void 0){if(!e.raw||typeof e.raw!=`object`)throw TypeError(`tags.raw, when provided, must be an object.`);for(let t of Object.values(e.raw))if(t!==null&&typeof t!=`string`&&!(t instanceof Uint8Array)&&!(t instanceof ne)&&!(t instanceof re))throw TypeError(`Each value in tags.raw must be a string, Uint8Array, RichImageData, AttachedFile, or null.`)}},x=e=>e.title===void 0&&e.description===void 0&&e.artist===void 0&&e.album===void 0&&e.albumArtist===void 0&&e.trackNumber===void 0&&e.tracksTotal===void 0&&e.discNumber===void 0&&e.discsTotal===void 0&&e.genre===void 0&&e.date===void 0&&e.lyrics===void 0&&(!e.images||e.images.length===0)&&e.comment===void 0&&(e.raw===void 0||Object.keys(e.raw).length===0),S=e=>{if(!e||typeof e!=`object`)throw TypeError(`disposition must be an object.`);if(e.default!==void 0&&typeof e.default!=`boolean`)throw TypeError(`disposition.default must be a boolean.`);if(e.forced!==void 0&&typeof e.forced!=`boolean`)throw TypeError(`disposition.forced must be a boolean.`);if(e.original!==void 0&&typeof e.original!=`boolean`)throw TypeError(`disposition.original must be a boolean.`);if(e.commentary!==void 0&&typeof e.commentary!=`boolean`)throw TypeError(`disposition.commentary must be a boolean.`);if(e.hearingImpaired!==void 0&&typeof e.hearingImpaired!=`boolean`)throw TypeError(`disposition.hearingImpaired must be a boolean.`);if(e.visuallyImpaired!==void 0&&typeof e.visuallyImpaired!=`boolean`)throw TypeError(`disposition.visuallyImpaired must be a boolean.`)},C=[`avc`,`hevc`,`vp9`,`av1`,`vp8`],w=[`pcm-s16`,`pcm-s16be`,`pcm-s24`,`pcm-s24be`,`pcm-s32`,`pcm-s32be`,`pcm-f32`,`pcm-f32be`,`pcm-f64`,`pcm-f64be`,`pcm-u8`,`pcm-s8`,`ulaw`,`alaw`],T=[...[`aac`,`opus`,`mp3`,`vorbis`,`flac`],...w],E=[`webvtt`],ie=(e,t,n)=>{if(e===`aac`)return t>=2&&n<=24e3?`mp4a.40.29`:n<=24e3?`mp4a.40.5`:`mp4a.40.2`;if(e===`mp3`)return`mp3`;if(e===`opus`)return`opus`;if(e===`vorbis`)return`vorbis`;if(e===`flac`)return`flac`;if(w.includes(e))return e;throw TypeError(`Unhandled codec '${e}'.`)},D=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],O=[-1,1,2,3,4,5,6,8],k=e=>{if(!e||e.byteLength<2)throw TypeError(`AAC description must be at least 2 bytes long.`);let t=new i(e),n=t.readBits(5);n===31&&(n=32+t.readBits(6));let r=t.readBits(4),a=null;r===15?a=t.readBits(24):r=1&&o<=7&&(s=O[o]),{objectType:n,frequencyIndex:r,sampleRate:a,channelConfiguration:o,numberOfChannels:s}},A=e=>{let t=D.indexOf(e.sampleRate),n=null;t===-1&&(t=15,n=e.sampleRate);let r=O.indexOf(e.numberOfChannels);if(r===-1)throw TypeError(`Unsupported number of channels: ${e.numberOfChannels}`);let a=13;e.objectType>=32&&(a+=6),t===15&&(a+=24);let o=Math.ceil(a/8),s=new Uint8Array(o),c=new i(s);return e.objectType<32?c.writeBits(5,e.objectType):(c.writeBits(5,31),c.writeBits(6,e.objectType-32)),c.writeBits(4,t),t===15&&c.writeBits(24,n),c.writeBits(4,r),s};var j=/^pcm-([usf])(\d+)+(be)?$/;const M=e=>{if(n(w.includes(e)),e===`ulaw`)return{dataType:`ulaw`,sampleSize:1,littleEndian:!0,silentValue:255};if(e===`alaw`)return{dataType:`alaw`,sampleSize:1,littleEndian:!0,silentValue:213};let t=j.exec(e);n(t);let r;r=t[1]===`u`?`unsigned`:t[1]===`s`?`signed`:`float`;let i=Number(t[2])/8,a=t[3]!==`be`;return{dataType:r,sampleSize:i,littleEndian:a,silentValue:e===`pcm-u8`?2**7:0}},ae=e=>e.startsWith(`avc1`)||e.startsWith(`avc3`)?`avc`:e.startsWith(`hev1`)||e.startsWith(`hvc1`)?`hevc`:e===`vp8`?`vp8`:e.startsWith(`vp09`)?`vp9`:e.startsWith(`av01`)?`av1`:e.startsWith(`mp4a.40`)||e===`mp4a.67`?`aac`:e===`mp3`||e===`mp4a.69`||e===`mp4a.6B`||e===`mp4a.6b`?`mp3`:e===`opus`?`opus`:e===`vorbis`?`vorbis`:e===`flac`?`flac`:e===`ulaw`?`ulaw`:e===`alaw`?`alaw`:j.test(e)?e:e===`webvtt`?`webvtt`:null,oe=e=>e===`aac`?{aac:{format:`aac`}}:e===`opus`?{opus:{format:`opus`}}:{};var se=[`mp4a`,`mp3`,`opus`,`vorbis`,`flac`,`ulaw`,`alaw`,`pcm`];const ce=e=>{if(!e)throw TypeError(`Audio chunk metadata must be provided.`);if(typeof e!=`object`)throw TypeError(`Audio chunk metadata must be an object.`);if(!e.decoderConfig)throw TypeError(`Audio chunk metadata must include a decoder configuration.`);if(typeof e.decoderConfig!=`object`)throw TypeError(`Audio chunk metadata decoder configuration must be an object.`);if(typeof e.decoderConfig.codec!=`string`)throw TypeError(`Audio chunk metadata decoder configuration must specify a codec string.`);if(!se.some(t=>e.decoderConfig.codec.startsWith(t)))throw TypeError(`Audio chunk metadata decoder configuration codec string must be a valid audio codec string as specified in the WebCodecs Codec Registry.`);if(!Number.isInteger(e.decoderConfig.sampleRate)||e.decoderConfig.sampleRate<=0)throw TypeError(`Audio chunk metadata decoder configuration must specify a valid sampleRate (positive integer).`);if(!Number.isInteger(e.decoderConfig.numberOfChannels)||e.decoderConfig.numberOfChannels<=0)throw TypeError(`Audio chunk metadata decoder configuration must specify a valid numberOfChannels (positive integer).`);if(e.decoderConfig.description!==void 0&&!l(e.decoderConfig.description))throw TypeError(`Audio chunk metadata decoder configuration description, when defined, must be an ArrayBuffer or an ArrayBuffer view.`);if(e.decoderConfig.codec.startsWith(`mp4a`)&&e.decoderConfig.codec!==`mp4a.69`&&e.decoderConfig.codec!==`mp4a.6B`&&e.decoderConfig.codec!==`mp4a.6b`){if(![`mp4a.40.2`,`mp4a.40.02`,`mp4a.40.5`,`mp4a.40.05`,`mp4a.40.29`,`mp4a.67`].includes(e.decoderConfig.codec))throw TypeError(`Audio chunk metadata decoder configuration codec string for AAC must be a valid AAC codec string as specified in https://www.w3.org/TR/webcodecs-aac-codec-registration/.`);if(!e.decoderConfig.description)throw TypeError(`Audio chunk metadata decoder configuration for AAC must include a description, which is expected to be an AudioSpecificConfig as specified in ISO 14496-3.`)}else if(e.decoderConfig.codec.startsWith(`mp3`)||e.decoderConfig.codec.startsWith(`mp4a`)){if(e.decoderConfig.codec!==`mp3`&&e.decoderConfig.codec!==`mp4a.69`&&e.decoderConfig.codec!==`mp4a.6B`&&e.decoderConfig.codec!==`mp4a.6b`)throw TypeError(`Audio chunk metadata decoder configuration codec string for MP3 must be "mp3", "mp4a.69" or "mp4a.6B".`)}else if(e.decoderConfig.codec.startsWith(`opus`)){if(e.decoderConfig.codec!==`opus`)throw TypeError(`Audio chunk metadata decoder configuration codec string for Opus must be "opus".`);if(e.decoderConfig.description&&e.decoderConfig.description.byteLength<18)throw TypeError(`Audio chunk metadata decoder configuration description, when specified, is expected to be an Identification Header as specified in Section 5.1 of RFC 7845.`)}else if(e.decoderConfig.codec.startsWith(`vorbis`)){if(e.decoderConfig.codec!==`vorbis`)throw TypeError(`Audio chunk metadata decoder configuration codec string for Vorbis must be "vorbis".`);if(!e.decoderConfig.description)throw TypeError(`Audio chunk metadata decoder configuration for Vorbis must include a description, which is expected to adhere to the format described in https://www.w3.org/TR/webcodecs-vorbis-codec-registration/.`)}else if(e.decoderConfig.codec.startsWith(`flac`)){if(e.decoderConfig.codec!==`flac`)throw TypeError(`Audio chunk metadata decoder configuration codec string for FLAC must be "flac".`);if(!e.decoderConfig.description||e.decoderConfig.description.byteLength<42)throw TypeError(`Audio chunk metadata decoder configuration for FLAC must include a description, which is expected to adhere to the format described in https://www.w3.org/TR/webcodecs-flac-codec-registration/.`)}else if((e.decoderConfig.codec.startsWith(`pcm`)||e.decoderConfig.codec.startsWith(`ulaw`)||e.decoderConfig.codec.startsWith(`alaw`))&&!w.includes(e.decoderConfig.codec))throw TypeError(`Audio chunk metadata decoder configuration codec string for PCM must be one of the supported PCM codecs (${w.join(`, `)}).`)};var le=class{constructor(e){this.mutex=new u,this.firstMediaStreamTimestamp=null,this.trackTimestampInfo=new WeakMap,this.output=e}onTrackClose(e){}validateAndNormalizeTimestamp(e,t,n){t+=e.source._timestampOffset;let r=this.trackTimestampInfo.get(e);if(!r){if(!n)throw Error(`First packet must be a key packet.`);r={maxTimestamp:t,maxTimestampBeforeLastKeyPacket:t},this.trackTimestampInfo.set(e,r)}if(t<0)throw Error(`Timestamps must be non-negative (got ${t}s).`);if(n&&(r.maxTimestampBeforeLastKeyPacket=r.maxTimestamp),t`u`)throw Error(`Your browser does not support EncodedVideoChunk.`);return new EncodedVideoChunk({data:this.data,type:this.type,timestamp:this.microsecondTimestamp,duration:this.microsecondDuration})}alphaToEncodedVideoChunk(e=this.type){if(!this.sideData.alpha)throw TypeError(`This packet does not contain alpha side data.`);if(this.isMetadataOnly)throw TypeError(`Metadata-only packets cannot be converted to a video chunk.`);if(typeof EncodedVideoChunk>`u`)throw Error(`Your browser does not support EncodedVideoChunk.`);return new EncodedVideoChunk({data:this.sideData.alpha,type:e,timestamp:this.microsecondTimestamp,duration:this.microsecondDuration})}toEncodedAudioChunk(){if(this.isMetadataOnly)throw TypeError(`Metadata-only packets cannot be converted to an audio chunk.`);if(typeof EncodedAudioChunk>`u`)throw Error(`Your browser does not support EncodedAudioChunk.`);return new EncodedAudioChunk({data:this.data,type:this.type,timestamp:this.microsecondTimestamp,duration:this.microsecondDuration})}static fromEncodedChunk(t,n){if(!(t instanceof EncodedVideoChunk||t instanceof EncodedAudioChunk))throw TypeError(`chunk must be an EncodedVideoChunk or EncodedAudioChunk.`);let r=new Uint8Array(t.byteLength);return t.copyTo(r),new e(r,t.type,t.timestamp/1e6,(t.duration??0)/1e6,void 0,void 0,n)}clone(t){if(t!==void 0&&(typeof t!=`object`||!t))throw TypeError(`options, when provided, must be an object.`);if(t?.timestamp!==void 0&&!Number.isFinite(t.timestamp))throw TypeError(`options.timestamp, when provided, must be a number.`);if(t?.duration!==void 0&&!Number.isFinite(t.duration))throw TypeError(`options.duration, when provided, must be a number.`);return new e(this.data,this.type,t?.timestamp??this.timestamp,t?.duration??this.duration,this.sequenceNumber,this.byteLength)}};const de=e=>{let t=8191,n=e,r=4096,i=0,a=12,o=0;for(n<0&&(n=-n,i=128),n+=33,n>t&&(n=t);(n&r)!==r&&a>=5;)r>>=1,a--;return o=n>>a-4&15,~(i|a-5<<4|o)&255},fe=e=>{let t=4095,n=2048,r=0,i=11,a=0,o=e;for(o<0&&(o=-o,r=128),o>t&&(o=t);(o&n)!==n&&i>=5;)n>>=1,i--;return a=o>>(i===4?1:i-4)&15,(r|i-4<<4|a)^85};te();var F=-1/0,I=-1/0,L=null;typeof FinalizationRegistry<`u`&&(L=new FinalizationRegistry(e=>{let t=Date.now();e.type===`video`?(t-F>=1e3&&(console.error(`A VideoSample was garbage collected without first being closed. For proper resource management, make sure to call close() on all your VideoSamples as soon as you're done using them.`),F=t),typeof VideoFrame<`u`&&e.data instanceof VideoFrame&&e.data.close()):(t-I>=1e3&&(console.error(`An AudioSample was garbage collected without first being closed. For proper resource management, make sure to call close() on all your AudioSamples as soon as you're done using them.`),I=t),typeof AudioData<`u`&&e.data instanceof AudioData&&e.data.close())})),Symbol.dispose;var R=new Set([`f32`,`f32-planar`,`s16`,`s16-planar`,`s32`,`s32-planar`,`u8`,`u8-planar`]),z=class e{get microsecondTimestamp(){return Math.trunc(v*this.timestamp)}get microsecondDuration(){return Math.trunc(v*this.duration)}constructor(e){if(this._closed=!1,H(e)){if(e.format===null)throw TypeError(`AudioData with null format is not supported.`);this._data=e,this.format=e.format,this.sampleRate=e.sampleRate,this.numberOfFrames=e.numberOfFrames,this.numberOfChannels=e.numberOfChannels,this.timestamp=e.timestamp/1e6,this.duration=e.numberOfFrames/e.sampleRate}else{if(!e||typeof e!=`object`)throw TypeError(`Invalid AudioDataInit: must be an object.`);if(!R.has(e.format))throw TypeError(`Invalid AudioDataInit: invalid format.`);if(!Number.isFinite(e.sampleRate)||e.sampleRate<=0)throw TypeError(`Invalid AudioDataInit: sampleRate must be > 0.`);if(!Number.isInteger(e.numberOfChannels)||e.numberOfChannels===0)throw TypeError(`Invalid AudioDataInit: numberOfChannels must be an integer > 0.`);if(!Number.isFinite(e?.timestamp))throw TypeError(`init.timestamp must be a number.`);let t=e.data.byteLength/(B(e.format)*e.numberOfChannels);if(!Number.isInteger(t))throw TypeError(`Invalid AudioDataInit: data size is not a multiple of frame size.`);this.format=e.format,this.sampleRate=e.sampleRate,this.numberOfFrames=t,this.numberOfChannels=e.numberOfChannels,this.timestamp=e.timestamp,this.duration=t/e.sampleRate;let n;if(e.data instanceof ArrayBuffer)n=new Uint8Array(e.data);else if(ArrayBuffer.isView(e.data))n=new Uint8Array(e.data.buffer,e.data.byteOffset,e.data.byteLength);else throw TypeError(`Invalid AudioDataInit: data is not a BufferSource.`);let r=this.numberOfFrames*this.numberOfChannels*B(this.format);if(n.byteLength=this.numberOfFrames)throw RangeError(`frameOffset out of range`);let r=e.frameCount===void 0?this.numberOfFrames-n:e.frameCount;if(r>this.numberOfFrames-n)throw RangeError(`frameCount out of range`);let i=B(t),a=V(t);if(a&&e.planeIndex>=this.numberOfChannels||!a&&e.planeIndex!==0)throw RangeError(`planeIndex out of range`);return(a?r:r*this.numberOfChannels)*i}copyTo(e,t){if(!l(e))throw TypeError(`destination must be an ArrayBuffer or an ArrayBuffer view.`);if(!t||typeof t!=`object`)throw TypeError(`options must be an object.`);if(!Number.isInteger(t.planeIndex)||t.planeIndex<0)throw TypeError(`planeIndex must be a non-negative integer.`);if(t.format!==void 0&&!R.has(t.format))throw TypeError(`Invalid format.`);if(t.frameOffset!==void 0&&(!Number.isInteger(t.frameOffset)||t.frameOffset<0))throw TypeError(`frameOffset must be a non-negative integer.`);if(t.frameCount!==void 0&&(!Number.isInteger(t.frameCount)||t.frameCount<0))throw TypeError(`frameCount must be a non-negative integer.`);if(this._closed)throw Error(`AudioSample is closed.`);let{planeIndex:n,format:r,frameCount:i,frameOffset:a}=t,s=r??this.format;if(!s)throw Error(`Destination format not determined`);let c=this.numberOfFrames,u=this.numberOfChannels,d=a??0;if(d>=c)throw RangeError(`frameOffset out of range`);let f=i===void 0?c-d:i;if(f>c-d)throw RangeError(`frameCount out of range`);let p=B(s),m=V(s);if(m&&n>=u||!m&&n!==0)throw RangeError(`planeIndex out of range`);let h=(m?f:f*u)*p;if(e.byteLength0;){let a=Math.min(o,c),l=new Float32Array(r*a);for(let e=0;e0;){let a=Math.min(o,c),u=new Float32Array(r*a);for(let e=0;e{switch(e){case`u8`:case`u8-planar`:return 1;case`s16`:case`s16-planar`:return 2;case`s32`:case`s32-planar`:return 4;case`f32`:case`f32-planar`:return 4;default:throw Error(`Unknown AudioSampleFormat`)}},V=e=>{switch(e){case`u8-planar`:case`s16-planar`:case`s32-planar`:case`f32-planar`:return!0;default:return!1}},pe=e=>{switch(e){case`u8`:case`u8-planar`:return(e,t)=>(e.getUint8(t)-128)/128;case`s16`:case`s16-planar`:return(e,t)=>e.getInt16(t,!0)/32768;case`s32`:case`s32-planar`:return(e,t)=>e.getInt32(t,!0)/2147483648;case`f32`:case`f32-planar`:return(e,t)=>e.getFloat32(t,!0)}},me=e=>{switch(e){case`u8`:case`u8-planar`:return(e,t,n)=>e.setUint8(t,h((n+1)*127.5,0,255));case`s16`:case`s16-planar`:return(e,t,n)=>e.setInt16(t,h(Math.round(n*32767),-32768,32767),!0);case`s32`:case`s32-planar`:return(e,t,n)=>e.setInt32(t,h(Math.round(n*2147483647),-2147483648,2147483647),!0);case`f32`:case`f32-planar`:return(e,t,n)=>e.setFloat32(t,n,!0)}},H=e=>typeof AudioData<`u`&&e instanceof AudioData;const he=e=>{let t=127,n=0,r=e;for(;t^2147483647;)n=r&~t,n<<=1,n|=r&t,t=(t+1<<8)-1,r=n;return n};var ge;(function(e){e[e.Unsynchronisation=128]=`Unsynchronisation`,e[e.ExtendedHeader=64]=`ExtendedHeader`,e[e.ExperimentalIndicator=32]=`ExperimentalIndicator`,e[e.Footer=16]=`Footer`})(ge||={});var U;(function(e){e[e.ISO_8859_1=0]=`ISO_8859_1`,e[e.UTF_16_WITH_BOM=1]=`UTF_16_WITH_BOM`,e[e.UTF_16_BE_NO_BOM=2]=`UTF_16_BE_NO_BOM`,e[e.UTF_8=3]=`UTF_8`})(U||={});var _e=class{constructor(e){this.helper=new Uint8Array(8),this.helperView=o(this.helper),this.writer=e}writeId3V2Tag(e){let t=this.writer.getPos();this.writeAscii(`ID3`),this.writeU8(4),this.writeU8(0),this.writeU8(0),this.writeSynchsafeU32(0);let n=this.writer.getPos(),r=new Set;for(let{key:t,value:n}of y(e))switch(t){case`title`:this.writeId3V2TextFrame(`TIT2`,n),r.add(`TIT2`);break;case`description`:this.writeId3V2TextFrame(`TIT3`,n),r.add(`TIT3`);break;case`artist`:this.writeId3V2TextFrame(`TPE1`,n),r.add(`TPE1`);break;case`album`:this.writeId3V2TextFrame(`TALB`,n),r.add(`TALB`);break;case`albumArtist`:this.writeId3V2TextFrame(`TPE2`,n),r.add(`TPE2`);break;case`trackNumber`:{let t=e.tracksTotal===void 0?n.toString():`${n}/${e.tracksTotal}`;this.writeId3V2TextFrame(`TRCK`,t),r.add(`TRCK`)}break;case`discNumber`:{let t=e.discsTotal===void 0?n.toString():`${n}/${e.discsTotal}`;this.writeId3V2TextFrame(`TPOS`,t),r.add(`TPOS`)}break;case`genre`:this.writeId3V2TextFrame(`TCON`,n),r.add(`TCON`);break;case`date`:this.writeId3V2TextFrame(`TDRC`,n.toISOString().slice(0,10)),r.add(`TDRC`);break;case`lyrics`:this.writeId3V2LyricsFrame(n),r.add(`USLT`);break;case`comment`:this.writeId3V2CommentFrame(n),r.add(`COMM`);break;case`images`:{let e={coverFront:3,coverBack:4,unknown:0};for(let t of n){let n=e[t.kind]??0,r=t.description??``;this.writeId3V2ApicFrame(t.mimeType,n,r,t.data)}}break;case`tracksTotal`:case`discsTotal`:break;case`raw`:break;default:f(t)}if(e.raw)for(let t in e.raw){let n=e.raw[t];if(n==null||t.length!==4||r.has(t))continue;let i;if(typeof n==`string`){let e=s.encode(n);i=new Uint8Array(e.byteLength+2),i[0]=U.UTF_8,i.set(e,1)}else if(n instanceof Uint8Array)i=n;else continue;this.writeAscii(t),this.writeSynchsafeU32(i.byteLength),this.writeU16(0),this.writer.write(i)}let i=this.writer.getPos(),a=i-n;return this.writer.seek(t+6),this.writeSynchsafeU32(a),this.writer.seek(i),a+10}writeU8(e){this.helper[0]=e,this.writer.write(this.helper.subarray(0,1))}writeU16(e){this.helperView.setUint16(0,e,!1),this.writer.write(this.helper.subarray(0,2))}writeU32(e){this.helperView.setUint32(0,e,!1),this.writer.write(this.helper.subarray(0,4))}writeAscii(e){for(let t=0;tK)throw Error(`ArrayBuffer exceeded maximum size of ${K} bytes. Please consider using another target.`);if(this.supportsResize)this.buffer.resize(t);else{let e=new ArrayBuffer(t),n=new Uint8Array(e);n.set(this.bytes,0),this.buffer=e,this.bytes=n}}}write(e){this.maybeTrackWrites(e),this.ensureSize(this.pos+e.byteLength),this.bytes.set(e,this.pos),this.target.onwrite?.(this.pos,this.pos+e.byteLength),this.pos+=e.byteLength,this.maxPos=Math.max(this.maxPos,this.pos)}seek(e){this.pos=e}getPos(){return this.pos}async flush(){}async finalize(){this.ensureSize(this.pos),this.target.buffer=this.buffer.slice(0,Math.max(this.maxPos,this.pos))}async close(){}getSlice(e,t){return this.bytes.slice(e,t)}};t();var q=class{constructor(){this._output=null,this.onwrite=null}},be=class extends q{constructor(){super(...arguments),this.buffer=null}_createWriter(){return new ye(this)}},xe=class{constructor(e){this.writer=e,this.helper=new Uint8Array(8),this.helperView=new DataView(this.helper.buffer)}writeU16(e){this.helperView.setUint16(0,e,!0),this.writer.write(this.helper.subarray(0,2))}writeU32(e){this.helperView.setUint32(0,e,!0),this.writer.write(this.helper.subarray(0,4))}writeU64(e){this.helperView.setUint32(0,e,!0),this.helperView.setUint32(4,Math.floor(e/2**32),!0),this.writer.write(this.helper)}writeAscii(e){this.writer.write(new TextEncoder().encode(e))}},Se=class extends le{constructor(e,t){super(e),this.headerWritten=!1,this.dataSize=0,this.sampleRate=null,this.sampleCount=0,this.riffSizePos=null,this.dataSizePos=null,this.ds64RiffSizePos=null,this.ds64DataSizePos=null,this.ds64SampleCountPos=null,this.format=t,this.writer=e._writer,this.riffWriter=new xe(e._writer),this.isRf64=!!t._options.large}async start(){}async getMimeType(){return`audio/wav`}async addEncodedVideoPacket(){throw Error(`WAVE does not support video.`)}async addEncodedAudioPacket(e,t,r){let i=await this.mutex.acquire();try{if(this.headerWritten||=(ce(r),n(r),n(r.decoderConfig),this.writeHeader(e,r.decoderConfig),this.sampleRate=r.decoderConfig.sampleRate,!0),this.validateAndNormalizeTimestamp(e,t.timestamp,t.type===`key`),!this.isRf64&&this.writer.getPos()+t.data.byteLength>=2**32)throw Error("Adding more audio data would exceed the maximum RIFF size of 4 GiB. To write larger files, use RF64 by setting `large: true` in the WavOutputFormatOptions.");this.writer.write(t.data),this.dataSize+=t.data.byteLength,this.sampleCount+=Math.round(t.duration*this.sampleRate),await this.writer.flush()}finally{i()}}async addSubtitleCue(){throw Error(`WAVE does not support subtitles.`)}writeHeader(e,t){this.format._options.onHeader&&this.writer.startTrackingWrites();let n,r=e.source._codec,i=M(r);n=i.dataType===`ulaw`?W.MULAW:i.dataType===`alaw`?W.ALAW:i.dataType===`float`?W.IEEE_FLOAT:W.PCM;let a=t.numberOfChannels,o=t.sampleRate,s=i.sampleSize*a;if(this.riffWriter.writeAscii(this.isRf64?`RF64`:`RIFF`),this.isRf64?this.riffWriter.writeU32(4294967295):(this.riffSizePos=this.writer.getPos(),this.riffWriter.writeU32(0)),this.riffWriter.writeAscii(`WAVE`),this.isRf64&&(this.riffWriter.writeAscii(`ds64`),this.riffWriter.writeU32(28),this.ds64RiffSizePos=this.writer.getPos(),this.riffWriter.writeU64(0),this.ds64DataSizePos=this.writer.getPos(),this.riffWriter.writeU64(0),this.ds64SampleCountPos=this.writer.getPos(),this.riffWriter.writeU64(0),this.riffWriter.writeU32(0)),this.riffWriter.writeAscii(`fmt `),this.riffWriter.writeU32(16),this.riffWriter.writeU16(n),this.riffWriter.writeU16(a),this.riffWriter.writeU32(o),this.riffWriter.writeU32(o*s),this.riffWriter.writeU16(s),this.riffWriter.writeU16(8*i.sampleSize),!x(this.output._metadataTags)){let e=this.format._options.metadataFormat??`info`;e===`info`?this.writeInfoChunk(this.output._metadataTags):e===`id3`?this.writeId3Chunk(this.output._metadataTags):f(e)}if(this.riffWriter.writeAscii(`data`),this.isRf64?this.riffWriter.writeU32(4294967295):(this.dataSizePos=this.writer.getPos(),this.riffWriter.writeU32(0)),this.format._options.onHeader){let{data:e,start:t}=this.writer.stopTrackingWrites();this.format._options.onHeader(e,t)}}writeInfoChunk(e){let t=this.writer.getPos();this.riffWriter.writeAscii(`LIST`),this.riffWriter.writeU32(0),this.riffWriter.writeAscii(`INFO`);let n=new Set,r=(e,t)=>{if(!c(t)){console.warn(`Didn't write tag '${e}' because '${t}' is not ISO 8859-1-compatible.`);return}let r=t.length+1,i=new Uint8Array(r);for(let e=0;eC.includes(e))}getSupportedAudioCodecs(){return this.getSupportedCodecs().filter(e=>T.includes(e))}getSupportedSubtitleCodecs(){return this.getSupportedCodecs().filter(e=>E.includes(e))}_codecUnsupportedHint(e){return``}},Ce=class extends J{constructor(e={}){if(!e||typeof e!=`object`)throw TypeError(`options must be an object.`);if(e.large!==void 0&&typeof e.large!=`boolean`)throw TypeError(`options.large, when provided, must be a boolean.`);if(e.metadataFormat!==void 0&&![`info`,`id3`].includes(e.metadataFormat))throw TypeError(`options.metadataFormat, when provided, must be either 'info' or 'id3'.`);if(e.onHeader!==void 0&&typeof e.onHeader!=`function`)throw TypeError(`options.onHeader, when provided, must be a function.`);super(),this._options=e}_createMuxer(e){return new Se(e,this)}get _name(){return`WAVE`}getSupportedTrackCounts(){return{video:{min:0,max:0},audio:{min:1,max:1},subtitle:{min:0,max:0},total:{min:1,max:1}}}get fileExtension(){return`.wav`}get mimeType(){return`audio/wav`}getSupportedCodecs(){return[...w.filter(e=>[`pcm-s16`,`pcm-s24`,`pcm-s32`,`pcm-f32`,`pcm-u8`,`ulaw`,`alaw`].includes(e))]}get supportsVideoRotationMetadata(){return!1}};const we=e=>{if(!e||typeof e!=`object`)throw TypeError(`Encoding config must be an object.`);if(!T.includes(e.codec))throw TypeError(`Invalid audio codec '${e.codec}'. Must be one of: ${T.join(`, `)}.`);if(e.bitrate===void 0&&(!w.includes(e.codec)||e.codec===`flac`))throw TypeError(`config.bitrate must be provided for compressed audio codecs.`);if(e.bitrate!==void 0&&!(e.bitrate instanceof X)&&(!Number.isInteger(e.bitrate)||e.bitrate<=0))throw TypeError(`config.bitrate, when provided, must be a positive integer or a quality.`);if(e.onEncodedPacket!==void 0&&typeof e.onEncodedPacket!=`function`)throw TypeError(`config.onEncodedChunk, when provided, must be a function.`);if(e.onEncoderConfig!==void 0&&typeof e.onEncoderConfig!=`function`)throw TypeError(`config.onEncoderConfig, when provided, must be a function.`);Y(e.codec,e)},Y=(e,t)=>{if(!t||typeof t!=`object`)throw TypeError(`Encoding options must be an object.`);if(t.bitrateMode!==void 0&&![`constant`,`variable`].includes(t.bitrateMode))throw TypeError(`bitrateMode, when provided, must be 'constant' or 'variable'.`);if(t.fullCodecString!==void 0&&typeof t.fullCodecString!=`string`)throw TypeError(`fullCodecString, when provided, must be a string.`);if(t.fullCodecString!==void 0&&ae(t.fullCodecString)!==e)throw TypeError(`fullCodecString, when provided, must be a string that matches the specified codec (${e}).`)},Te=e=>{let t=e.bitrate instanceof X?e.bitrate._toAudioBitrate(e.codec):e.bitrate;return{codec:e.fullCodecString??ie(e.codec,e.numberOfChannels,e.sampleRate),numberOfChannels:e.numberOfChannels,sampleRate:e.sampleRate,bitrate:t,bitrateMode:e.bitrateMode,...oe(e.codec)}};var X=class{constructor(e){this._factor=e}_toVideoBitrate(e,t,n){let r=3e6*(t*n/(1920*1080))**.95*{avc:1,hevc:.6,vp9:.6,av1:.4,vp8:1.2}[e]*this._factor;return Math.ceil(r/1e3)*1e3}_toAudioBitrate(e){if(w.includes(e)||e===`flac`)return;let t={aac:128e3,opus:64e3,mp3:16e4,vorbis:64e3}[e];if(!t)throw Error(`Unhandled codec: ${e}`);let n=t*this._factor;return e===`aac`?n=[96e3,128e3,16e4,192e3].reduce((e,t)=>Math.abs(t-n)Math.abs(t-n){await this._flushAndClose(!1),this._closed=!0,!(e.output.state===`finalizing`||e.output.state===`finalized`)&&e.output._muxer.onTrackClose(e)})()}async _flushOrWaitForOngoingClose(e){return this._closingPromise?this._closingPromise:this._flushAndClose(e)}},De=class extends Z{constructor(e){if(super(),this._connectedTrack=null,!C.includes(e))throw TypeError(`Invalid video codec '${e}'. Must be one of: ${C.join(`, `)}.`);this._codec=e}},Q=class extends Z{constructor(e){if(super(),this._connectedTrack=null,!T.includes(e))throw TypeError(`Invalid audio codec '${e}'. Must be one of: ${T.join(`, `)}.`);this._codec=e}},Oe=class{constructor(e,t){this.source=e,this.encodingConfig=t,this.ensureEncoderPromise=null,this.encoderInitialized=!1,this.encoder=null,this.muxer=null,this.lastNumberOfChannels=null,this.lastSampleRate=null,this.isPcmEncoder=!1,this.outputSampleSize=null,this.writeOutputValue=null,this.customEncoder=null,this.customEncoderCallSerializer=new ee,this.customEncoderQueueSize=0,this.lastEndSampleIndex=null,this.error=null,this.errorNeedsNewStack=!0}async add(e,t){try{if(this.checkForEncoderError(),this.source._ensureValidAdd(),this.lastNumberOfChannels!==null&&this.lastSampleRate!==null){if(e.numberOfChannels!==this.lastNumberOfChannels||e.sampleRate!==this.lastSampleRate)throw Error(`Audio parameters must remain constant. Expected ${this.lastNumberOfChannels} channels at ${this.lastSampleRate} Hz, got ${e.numberOfChannels} channels at ${e.sampleRate} Hz.`)}else this.lastNumberOfChannels=e.numberOfChannels,this.lastSampleRate=e.sampleRate;this.encoderInitialized||(this.ensureEncoderPromise||this.ensureEncoder(e),this.encoderInitialized||await this.ensureEncoderPromise),n(this.encoderInitialized);{let t=Math.round(e.timestamp*e.sampleRate),n=Math.round((e.timestamp+e.duration)*e.sampleRate);if(this.lastEndSampleIndex===null)this.lastEndSampleIndex=n;else{let n=t-this.lastEndSampleIndex;if(n>=64){let t=new z({data:new Float32Array(n*e.numberOfChannels),format:`f32-planar`,sampleRate:e.sampleRate,numberOfChannels:e.numberOfChannels,numberOfFrames:n,timestamp:this.lastEndSampleIndex/e.sampleRate});await this.add(t,!0)}this.lastEndSampleIndex+=e.numberOfFrames}}if(this.customEncoder){this.customEncoderQueueSize++;let t=e.clone(),n=this.customEncoderCallSerializer.call(()=>this.customEncoder.encode(t)).then(()=>this.customEncoderQueueSize--).catch(e=>this.error??=e).finally(()=>{t.close()});this.customEncoderQueueSize>=4&&await n,await this.muxer.mutex.currentPromise}else if(this.isPcmEncoder)await this.doPcmEncoding(e,t);else{n(this.encoder);let r=e.toAudioData();this.encoder.encode(r),r.close(),t&&e.close(),this.encoder.encodeQueueSize>=4&&await new Promise(e=>this.encoder.addEventListener(`dequeue`,e,{once:!0})),await this.muxer.mutex.currentPromise}}finally{t&&e.close()}}async doPcmEncoding(e,t){n(this.outputSampleSize),n(this.writeOutputValue);let{numberOfChannels:r,numberOfFrames:i,sampleRate:a,timestamp:o}=e,s=2048,c=[];for(let t=0;t{let{numberOfChannels:i,sampleRate:o}=e,s=Te({numberOfChannels:i,sampleRate:o,...this.encodingConfig});this.encodingConfig.onEncoderConfig?.(s);let c=ue.find(e=>e.supports(this.encodingConfig.codec,s));if(c)this.customEncoder=new c,this.customEncoder.codec=this.encodingConfig.codec,this.customEncoder.config=s,this.customEncoder.onPacket=(e,t)=>{if(!(e instanceof P))throw TypeError(`The first argument passed to onPacket must be an EncodedPacket.`);if(t!==void 0&&(!t||typeof t!=`object`))throw TypeError(`The second argument passed to onPacket must be an object or undefined.`);this.encodingConfig.onEncodedPacket?.(e,t),this.muxer.addEncodedAudioPacket(this.source._connectedTrack,e,t).catch(e=>{this.error??=e,this.errorNeedsNewStack=!1})},await this.customEncoder.init();else if(w.includes(this.encodingConfig.codec))this.initPcmEncoder();else{if(typeof AudioEncoder>`u`)throw Error(`AudioEncoder is not supported by this browser.`);if(!(await AudioEncoder.isConfigSupported(s)).supported)throw Error(`This specific encoder configuration (${s.codec}, ${s.bitrate} bps, ${s.numberOfChannels} channels, ${s.sampleRate} Hz) is not supported by this browser. Consider using another codec or changing your audio parameters.`);this.encoder=new AudioEncoder({output:(e,t)=>{if(this.encodingConfig.codec===`aac`&&t?.decoderConfig){let e=!1;if(e=!t.decoderConfig.description||t.decoderConfig.description.byteLength<2?!0:k(a(t.decoderConfig.description)).objectType===0,e){let e=Number(r(s.codec.split(`.`)));t.decoderConfig.description=A({objectType:e,numberOfChannels:t.decoderConfig.numberOfChannels,sampleRate:t.decoderConfig.sampleRate})}}let n=P.fromEncodedChunk(e);this.encodingConfig.onEncodedPacket?.(n,t),this.muxer.addEncodedAudioPacket(this.source._connectedTrack,n,t).catch(e=>{this.error??=e,this.errorNeedsNewStack=!1})},error:e=>{e.stack=t.stack,this.error??=e}}),this.encoder.configure(s)}n(this.source._connectedTrack),this.muxer=this.source._connectedTrack.output._muxer,this.encoderInitialized=!0})()}initPcmEncoder(){this.isPcmEncoder=!0;let e=this.encodingConfig.codec,{dataType:t,sampleSize:r,littleEndian:i}=M(e);switch(this.outputSampleSize=r,r){case 1:t===`unsigned`?this.writeOutputValue=(e,t,n)=>e.setUint8(t,h((n+1)*127.5,0,255)):t===`signed`?this.writeOutputValue=(e,t,n)=>{e.setInt8(t,h(Math.round(n*128),-128,127))}:t===`ulaw`?this.writeOutputValue=(e,t,n)=>{let r=h(Math.floor(n*32767),-32768,32767);e.setUint8(t,de(r))}:t===`alaw`?this.writeOutputValue=(e,t,n)=>{let r=h(Math.floor(n*32767),-32768,32767);e.setUint8(t,fe(r))}:n(!1);break;case 2:t===`unsigned`?this.writeOutputValue=(e,t,n)=>e.setUint16(t,h((n+1)*32767.5,0,65535),i):t===`signed`?this.writeOutputValue=(e,t,n)=>e.setInt16(t,h(Math.round(n*32767),-32768,32767),i):n(!1);break;case 3:t===`unsigned`?this.writeOutputValue=(e,t,n)=>p(e,t,h((n+1)*8388607.5,0,16777215),i):t===`signed`?this.writeOutputValue=(e,t,n)=>m(e,t,h(Math.round(n*8388607),-8388608,8388607),i):n(!1);break;case 4:t===`unsigned`?this.writeOutputValue=(e,t,n)=>e.setUint32(t,h((n+1)*2147483647.5,0,4294967295),i):t===`signed`?this.writeOutputValue=(e,t,n)=>e.setInt32(t,h(Math.round(n*2147483647),-2147483648,2147483647),i):t===`float`?this.writeOutputValue=(e,t,n)=>e.setFloat32(t,n,i):n(!1);break;case 8:t===`float`?this.writeOutputValue=(e,t,n)=>e.setFloat64(t,n,i):n(!1);break;default:f(r),n(!1)}}async flushAndClose(e){e||this.checkForEncoderError(),this.customEncoder?(e||this.customEncoderCallSerializer.call(()=>this.customEncoder.flush()),await this.customEncoderCallSerializer.call(()=>this.customEncoder.close())):this.encoder&&(e||await this.encoder.flush(),this.encoder.state!==`closed`&&this.encoder.close()),e||this.checkForEncoderError()}getQueueSize(){return this.customEncoder?this.customEncoderQueueSize:this.isPcmEncoder?0:this.encoder?.encodeQueueSize??0}checkForEncoderError(){if(this.error)throw this.errorNeedsNewStack&&(this.error.stack=Error().stack),this.error}},ke=class extends Q{get errorPromise(){return this._errorPromiseAccessed=!0,this._promiseWithResolvers.promise}get paused(){return this._paused}constructor(e,t){if(!(e instanceof MediaStreamTrack)||e.kind!==`audio`)throw TypeError(`track must be an audio MediaStreamTrack.`);we(t),super(t.codec),this._abortController=null,this._audioContext=null,this._scriptProcessorNode=null,this._promiseWithResolvers=d(),this._errorPromiseAccessed=!1,this._paused=!1,this._lastSampleTimestamp=null,this._pauseOffset=0,this._encoder=new Oe(this,t),this._track=e}async _start(){this._errorPromiseAccessed||console.warn("Make sure not to ignore the `errorPromise` field on MediaStreamVideoTrackSource, so that any internal errors get bubbled up properly."),this._abortController=new AbortController;let e=null,t=!1,n=n=>{if(t){n.close();return}let r=n.timestamp;if(this._paused){if(e!==null){if(this._lastSampleTimestamp!==null){let e=r-this._lastSampleTimestamp;this._pauseOffset-=e}this._lastSampleTimestamp=r}n.close();return}if(e===null){e=n.timestamp;let t=this._connectedTrack.output._muxer;t.firstMediaStreamTimestamp===null?(t.firstMediaStreamTimestamp=performance.now()/1e3,this._timestampOffset=-e):this._timestampOffset=performance.now()/1e3-t.firstMediaStreamTimestamp-e}if(this._lastSampleTimestamp=r,this._encoder.getQueueSize()>=4){n.close();return}n.setTimestamp(r+this._pauseOffset),this._encoder.add(n,!0).catch(e=>{t=!0,this._abortController?.abort(),this._promiseWithResolvers.reject(e),this._audioContext?.suspend()})};if(typeof MediaStreamTrackProcessor<`u`){let e=new MediaStreamTrackProcessor({track:this._track}),t=new WritableStream({write:e=>n(new z(e))});e.readable.pipeTo(t,{signal:this._abortController.signal}).catch(e=>{e instanceof DOMException&&e.name===`AbortError`||this._promiseWithResolvers.reject(e)})}else{this._audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:this._track.getSettings().sampleRate});let e=this._audioContext.createMediaStreamSource(new MediaStream([this._track]));this._scriptProcessorNode=this._audioContext.createScriptProcessor(4096),this._audioContext.state===`suspended`&&await this._audioContext.resume(),e.connect(this._scriptProcessorNode),this._scriptProcessorNode.connect(this._audioContext.destination);let t=0;this._scriptProcessorNode.onaudioprocess=e=>{let r=z._fromAudioBuffer(e.inputBuffer,t);t+=e.inputBuffer.duration;for(let e of r)n(e)}}}pause(){this._paused=!0}resume(){this._paused=!1}async _flushAndClose(e){this._abortController&&=(this._abortController.abort(),null),this._audioContext&&(n(this._scriptProcessorNode),this._scriptProcessorNode.disconnect(),await this._audioContext.suspend()),await this._encoder.flushAndClose(e)}},Ae=class extends Z{constructor(e){if(super(),this._connectedTrack=null,!E.includes(e))throw TypeError(`Invalid subtitle codec '${e}'. Must be one of: ${E.join(`, `)}.`);this._codec=e}};const je=[`video`,`audio`,`subtitle`];var $=e=>{if(!e||typeof e!=`object`)throw TypeError(`metadata must be an object.`);if(e.languageCode!==void 0&&!_(e.languageCode))throw TypeError(`metadata.languageCode, when provided, must be a three-letter, ISO 639-2/T language code.`);if(e.name!==void 0&&typeof e.name!=`string`)throw TypeError(`metadata.name, when provided, must be a string.`);if(e.disposition!==void 0&&S(e.disposition),e.maximumPacketCount!==void 0&&(!Number.isInteger(e.maximumPacketCount)||e.maximumPacketCount<0))throw TypeError(`metadata.maximumPacketCount, when provided, must be a non-negative integer.`)},Me=class{constructor(e){if(this.state=`pending`,this._tracks=[],this._startPromise=null,this._cancelPromise=null,this._finalizePromise=null,this._mutex=new u,this._metadataTags={},!e||typeof e!=`object`)throw TypeError(`options must be an object.`);if(!(e.format instanceof J))throw TypeError(`options.format must be an OutputFormat.`);if(!(e.target instanceof q))throw TypeError(`options.target must be a Target.`);if(e.target._output)throw Error(`Target is already used for another output.`);e.target._output=this,this.format=e.format,this.target=e.target,this._writer=e.target._createWriter(),this._muxer=e.format._createMuxer(this)}addVideoTrack(e,t={}){if(!(e instanceof De))throw TypeError(`source must be a VideoSource.`);if($(t),t.rotation!==void 0&&![0,90,180,270].includes(t.rotation))throw TypeError(`Invalid video rotation: ${t.rotation}. Has to be 0, 90, 180 or 270.`);if(!this.format.supportsVideoRotationMetadata&&t.rotation)throw Error(`${this.format._name} does not support video rotation metadata.`);if(t.frameRate!==void 0&&(!Number.isFinite(t.frameRate)||t.frameRate<=0))throw TypeError(`Invalid video frame rate: ${t.frameRate}. Must be a positive number.`);this._addTrack(`video`,e,t)}addAudioTrack(e,t={}){if(!(e instanceof Q))throw TypeError(`source must be an AudioSource.`);$(t),this._addTrack(`audio`,e,t)}addSubtitleTrack(e,t={}){if(!(e instanceof Ae))throw TypeError(`source must be a SubtitleSource.`);$(t),this._addTrack(`subtitle`,e,t)}setMetadataTags(e){if(b(e),this.state!==`pending`)throw Error(`Cannot set metadata tags after output has been started or canceled.`);this._metadataTags=e}_addTrack(e,t,n){if(this.state!==`pending`)throw Error(`Cannot add track after output has been started or canceled.`);if(t._connectedTrack)throw Error(`Source is already used for a track.`);let r=this.format.getSupportedTrackCounts(),i=this._tracks.reduce((t,n)=>t+(n.type===e?1:0),0),a=r[e].max;if(i===a)throw Error(a===0?`${this.format._name} does not support ${e} tracks.`:`${this.format._name} does not support more than ${a} ${e} track${a===1?``:`s`}.`);let o=r.total.max;if(this._tracks.length===o)throw Error(`${this.format._name} does not support more than ${o} tracks${o===1?``:`s`} in total.`);let s={id:this._tracks.length+1,output:this,type:e,source:t,metadata:n};if(s.type===`video`){let e=this.format.getSupportedVideoCodecs();if(e.length===0)throw Error(`${this.format._name} does not support video tracks.`+this.format._codecUnsupportedHint(s.source._codec));if(!e.includes(s.source._codec))throw Error(`Codec '${s.source._codec}' cannot be contained within ${this.format._name}. Supported video codecs are: ${e.map(e=>`'${e}'`).join(`, `)}.`+this.format._codecUnsupportedHint(s.source._codec))}else if(s.type===`audio`){let e=this.format.getSupportedAudioCodecs();if(e.length===0)throw Error(`${this.format._name} does not support audio tracks.`+this.format._codecUnsupportedHint(s.source._codec));if(!e.includes(s.source._codec))throw Error(`Codec '${s.source._codec}' cannot be contained within ${this.format._name}. Supported audio codecs are: ${e.map(e=>`'${e}'`).join(`, `)}.`+this.format._codecUnsupportedHint(s.source._codec))}else if(s.type===`subtitle`){let e=this.format.getSupportedSubtitleCodecs();if(e.length===0)throw Error(`${this.format._name} does not support subtitle tracks.`+this.format._codecUnsupportedHint(s.source._codec));if(!e.includes(s.source._codec))throw Error(`Codec '${s.source._codec}' cannot be contained within ${this.format._name}. Supported subtitle codecs are: ${e.map(e=>`'${e}'`).join(`, `)}.`+this.format._codecUnsupportedHint(s.source._codec))}this._tracks.push(s),t._connectedTrack=s}async start(){let e=this.format.getSupportedTrackCounts();for(let t of je){let n=this._tracks.reduce((e,n)=>e+(n.type===t?1:0),0),r=e[t].min;if(n{this.state=`started`,this._writer.start();let e=await this._mutex.acquire();await this._muxer.start();let t=this._tracks.map(e=>e.source._start());await Promise.all(t),e()})()}getMimeType(){return this._muxer.getMimeType()}async cancel(){if(this._cancelPromise)return console.warn(`Output has already been canceled.`),this._cancelPromise;if(this.state===`finalizing`||this.state===`finalized`){console.warn(`Output has already been finalized.`);return}return this._cancelPromise=(async()=>{this.state=`canceled`;let e=await this._mutex.acquire(),t=this._tracks.map(e=>e.source._flushOrWaitForOngoingClose(!0));await Promise.all(t),await this._writer.close(),e()})()}async finalize(){if(this.state===`pending`)throw Error(`Cannot finalize before starting.`);if(this.state===`canceled`)throw Error(`Cannot finalize after canceling.`);return this._finalizePromise?(console.warn(`Output has already been finalized.`),this._finalizePromise):this._finalizePromise=(async()=>{this.state=`finalizing`;let e=await this._mutex.acquire(),t=this._tracks.map(e=>e.source._flushOrWaitForOngoingClose(!1));await Promise.all(t),await this._muxer.finalize(),await this._writer.flush(),await this._writer.finalize(),this.state=`finalized`,e()})()}};export{be as a,Ce as i,ke as n,Ee as r,Me as t}; \ No newline at end of file