@omnimedia/omnitool 1.1.0-52 → 1.1.0-55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/package.json +1 -1
  2. package/s/demo/routines/transcode-test.ts +2 -2
  3. package/s/demo/routines/transitions-test.ts +2 -2
  4. package/s/driver/driver.ts +26 -5
  5. package/s/driver/fns/schematic.ts +2 -0
  6. package/s/driver/fns/work.ts +41 -20
  7. package/s/timeline/parts/waveform.ts +1 -1
  8. package/s/timeline/renderers/export/parts/cursor.ts +75 -56
  9. package/s/timeline/renderers/export/parts/produce-video.ts +2 -3
  10. package/s/timeline/renderers/player/parts/playback.ts +33 -6
  11. package/s/timeline/renderers/player/player.ts +2 -14
  12. package/s/timeline/renderers/renderers.test.ts +1 -3
  13. package/s/timeline/sugar/o.ts +10 -10
  14. package/x/demo/demo.bundle.min.js +9 -9
  15. package/x/demo/demo.bundle.min.js.map +4 -4
  16. package/x/demo/routines/transcode-test.js +2 -2
  17. package/x/demo/routines/transcode-test.js.map +1 -1
  18. package/x/demo/routines/transitions-test.js +2 -2
  19. package/x/demo/routines/transitions-test.js.map +1 -1
  20. package/x/driver/driver.d.ts +14 -2
  21. package/x/driver/driver.js +26 -5
  22. package/x/driver/driver.js.map +1 -1
  23. package/x/driver/driver.worker.bundle.min.js +1 -1
  24. package/x/driver/driver.worker.bundle.min.js.map +3 -3
  25. package/x/driver/fns/host.d.ts +2 -0
  26. package/x/driver/fns/schematic.d.ts +2 -0
  27. package/x/driver/fns/work.d.ts +2 -0
  28. package/x/driver/fns/work.js +33 -20
  29. package/x/driver/fns/work.js.map +1 -1
  30. package/x/index.html +2 -2
  31. package/x/tests.bundle.min.js +16 -16
  32. package/x/tests.bundle.min.js.map +4 -4
  33. package/x/tests.html +1 -1
  34. package/x/timeline/parts/waveform.js +1 -1
  35. package/x/timeline/parts/waveform.js.map +1 -1
  36. package/x/timeline/renderers/export/parts/cursor.d.ts +4 -5
  37. package/x/timeline/renderers/export/parts/cursor.js +68 -50
  38. package/x/timeline/renderers/export/parts/cursor.js.map +1 -1
  39. package/x/timeline/renderers/export/parts/produce-video.js +2 -3
  40. package/x/timeline/renderers/export/parts/produce-video.js.map +1 -1
  41. package/x/timeline/renderers/player/parts/playback.d.ts +9 -5
  42. package/x/timeline/renderers/player/parts/playback.js +25 -6
  43. package/x/timeline/renderers/player/parts/playback.js.map +1 -1
  44. package/x/timeline/renderers/player/player.js +2 -9
  45. package/x/timeline/renderers/player/player.js.map +1 -1
  46. package/x/timeline/renderers/renderers.test.js +1 -2
  47. package/x/timeline/renderers/renderers.test.js.map +1 -1
  48. package/x/timeline/sugar/o.d.ts +1 -0
  49. package/x/timeline/sugar/o.js +10 -10
  50. package/x/timeline/sugar/o.js.map +1 -1
@@ -31,8 +31,8 @@ export function setupTranscodeTest(driver, source) {
31
31
  });
32
32
  const audio = driver.decodeAudio({ source });
33
33
  const { readable, done } = driver.encode({
34
- video,
35
- audio,
34
+ video: video.readable,
35
+ audio: audio.readable,
36
36
  config: {
37
37
  audio: { codec: "opus", bitrate: 128000 },
38
38
  video: { codec: "vp9", bitrate: 1000000 }
@@ -1 +1 @@
1
- {"version":3,"file":"transcode-test.js","sourceRoot":"","sources":["../../../s/demo/routines/transcode-test.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,kBAAkB,CAAC,MAAc,EAAE,MAAqB;IACvE,MAAM,UAAU,GAAG,EAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAC,CAAA;IAE9C,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;IAC/C,MAAM,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAA;IAC/B,MAAM,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAA;IACjC,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;IAEnC,KAAK,UAAU,GAAG;QAC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KAAK,CAAC,QAAQ;YACrB,KAAK,EAAE,KAAK,CAAC,QAAQ;YACrB,MAAM,EAAE;gBACP,KAAK,EAAE,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAC;gBACvC,KAAK,EAAE,EAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAC;aACvC;SACD,CAAC,CAAA;QAEF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,kBAAkB,EAAE,CAAA;QAChD,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,cAAc,EAAE,CAAA;QAE9C,MAAM,OAAO,CAAC,GAAG,CAAC;YACjB,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC;YACzB,IAAI;SACJ,CAAC,CAAA;IACH,CAAC;IAED,OAAO,EAAC,MAAM,EAAE,GAAG,EAAC,CAAA;AACrB,CAAC"}
@@ -22,8 +22,8 @@ export async function setupTransitionsTest(driver, source) {
22
22
  return frame;
23
23
  }
24
24
  });
25
- await driver.encode({
26
- video,
25
+ driver.encode({
26
+ video: video.readable,
27
27
  config: {
28
28
  audio: { codec: "opus", bitrate: 128000 },
29
29
  video: { codec: "vp9", bitrate: 1000000 }
@@ -1 +1 @@
1
- {"version":3,"file":"transitions-test.js","sourceRoot":"","sources":["../../../s/demo/routines/transitions-test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,MAAM,EAAC,MAAM,SAAS,CAAA;AAI3C,OAAO,EAAC,cAAc,EAAC,MAAM,yCAAyC,CAAA;AAEtE,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,MAAc,EAAE,MAAqB;IAC/E,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAA;IAC7B,MAAM,GAAG,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAC,CAAC,CAAA;IAC9D,MAAM,MAAM,GAAG,IAAI,MAAM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OAAO,EAAE,MAAM,EAAC;gBACvC,KAAK,EAAE,EAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAC;aACvC;SACD,CAAC,CAAA;IACH,CAAC;IAED,OAAO,EAAC,GAAG,EAAC,CAAA;AACb,CAAC"}
@@ -15,8 +15,20 @@ export declare class Driver {
15
15
  hello(): Promise<void>;
16
16
  getAudioDuration(source: DecoderSource): Promise<number>;
17
17
  getVideoDuration(source: DecoderSource): Promise<number | undefined>;
18
- decodeVideo(input: DecoderInput): ReadableStream<VideoFrame>;
19
- decodeAudio(input: DecoderInput): ReadableStream<AudioData>;
18
+ decodeVideo(input: DecoderInput): {
19
+ readable: ReadableStream<VideoFrame>;
20
+ /**
21
+ * use this to stop decoding (premature interruption)
22
+ * */
23
+ cancel(): void;
24
+ };
25
+ decodeAudio(input: DecoderInput): {
26
+ readable: ReadableStream<AudioData>;
27
+ /**
28
+ * use this to stop decoding (premature interruption)
29
+ * */
30
+ cancel(): void;
31
+ };
20
32
  encode({ audio, video, config }: EncoderInput): {
21
33
  readable: ReadableStream<StreamTargetChunk>;
22
34
  done: Promise<void>;
@@ -47,32 +47,53 @@ export class Driver {
47
47
  }
48
48
  decodeVideo(input) {
49
49
  let lastFrame = null;
50
+ const { port1, port2 } = new MessageChannel();
50
51
  const videoTransform = new TransformStream({
51
52
  async transform(chunk, controller) {
52
53
  const frame = await input.onFrame?.(chunk) ?? chunk;
53
- // below code is to prevent mem leaks and hardware accelerated decoder stall
54
54
  lastFrame?.close();
55
55
  controller.enqueue(frame);
56
56
  lastFrame = frame;
57
57
  }
58
58
  });
59
- this.thread.work.decodeVideo[tune]({ transfer: [videoTransform.writable] })({
59
+ this.thread.work.decodeVideo[tune]({ transfer: [videoTransform.writable, port2] })({
60
60
  source: input.source,
61
+ cancel: port2,
61
62
  video: videoTransform.writable,
62
63
  start: input.start,
63
64
  end: input.end
64
65
  });
65
- return videoTransform.readable;
66
+ return {
67
+ readable: videoTransform.readable,
68
+ /**
69
+ * use this to stop decoding (premature interruption)
70
+ * */
71
+ cancel() {
72
+ port1.postMessage("close");
73
+ port1.close();
74
+ }
75
+ };
66
76
  }
67
77
  decodeAudio(input) {
68
78
  const audioTransform = new TransformStream();
69
- this.thread.work.decodeAudio[tune]({ transfer: [audioTransform.writable] })({
79
+ const { port1, port2 } = new MessageChannel();
80
+ this.thread.work.decodeAudio[tune]({ transfer: [audioTransform.writable, port2] })({
70
81
  source: input.source,
82
+ cancel: port2,
71
83
  audio: audioTransform.writable,
72
84
  start: input.start,
73
85
  end: input.end
74
86
  });
75
- return audioTransform.readable;
87
+ return {
88
+ readable: audioTransform.readable,
89
+ /**
90
+ * use this to stop decoding (premature interruption)
91
+ * */
92
+ cancel() {
93
+ port1.postMessage("close");
94
+ port1.close();
95
+ }
96
+ };
76
97
  }
77
98
  encode({ audio, video, config }) {
78
99
  const { readable, writable } = new TransformStream();
@@ -1 +1 @@
1
- {"version":3,"file":"driver.js","sourceRoot":"","sources":["../../s/driver/driver.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,EAAE,EAAC,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAC,OAAO,EAAE,IAAI,EAAS,MAAM,eAAe,CAAA;AACnD,OAAO,EAAC,WAAW,EAAE,KAAK,EAAyB,MAAM,YAAY,CAAA;AAErE,OAAO,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAC,eAAe,EAAC,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAC,iBAAiB,EAAC,MAAM,gCAAgC,CAAA;AAOhE,MAAM,OAAO,MAAM;IAaV;IACA;IACA;IAdR,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,OAAuB;QACzC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAA;QAC7B,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,CAAkB;YACpD,KAAK,EAAE,gB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AAM,EAAE,KAAK,CAAC,MAAM;YACpB,MAAM,EAAE,KAAK;YACb,KAAK,EAAE,cAAc,CAAC,QAAQ;YAC9B,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,GAAG,EAAE,KAAK,CAAC,GAAG;SACd,CAAC,CAAA;QACF,OAAO;YACN,QAAQ,EAAE,cAAc,CAAC,QAAQ;YACjC;;iBAEK;YACL,MAAM;gBACL,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;gBAC1B,KAAK,CAAC,KAAK,EAAE,CAAA;YACd,CAAC;SACD,CAAA;IACF,CAAC;IAED,MAAM,CAAC,EAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAe;QAC1C,MAAM,EAAC,QAAQ,EAAE,QAAQ,EAAC,GAAG,IAAI,eAAe,EAAwC,CAAA;QACxF,MAAM,QAAQ,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAA;QAC1D,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAC,QAAQ,EAAC,CAAC,CAAC,EAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAC,CAAC,CAAA;QACxF,OAAO,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,SAAS,CACd,WAAwB;QAExB,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;IACpD,CAAC;CAED"}
@@ -94,7 +94,7 @@ import"./chunk-WCZ2O3UN.js";import"./chunk-3L3MB5NY.js";import"./chunk-BFBY7VYB.
94
94
 
95
95
  fragColor = result;
96
96
  }
97
- `),i=this.gl.createProgram();return this.gl.attachShader(i,e),this.gl.attachShader(i,r),this.gl.linkProgram(i),i}createShader(e,r){let i=this.gl.createShader(e);return this.gl.shaderSource(i,r),this.gl.compileShader(i),this.gl.getShaderParameter(i,this.gl.COMPILE_STATUS)||console.error("Shader compile error:",this.gl.getShaderInfoLog(i)),i}createVAO(){let e=this.gl.createVertexArray();this.gl.bindVertexArray(e);let r=new Float32Array([-1,-1,0,1,1,-1,1,1,-1,1,0,0,1,1,1,0]),i=this.gl.createBuffer();this.gl.bindBuffer(this.gl.ARRAY_BUFFER,i),this.gl.bufferData(this.gl.ARRAY_BUFFER,r,this.gl.STATIC_DRAW);let n=this.gl.getAttribLocation(this.colorProgram,"a_position"),s=this.gl.getAttribLocation(this.colorProgram,"a_texCoord");return this.gl.enableVertexAttribArray(n),this.gl.vertexAttribPointer(n,2,this.gl.FLOAT,!1,16,0),this.gl.enableVertexAttribArray(s),this.gl.vertexAttribPointer(s,2,this.gl.FLOAT,!1,16,8),e}createTexture(){let e=this.gl.createTexture();return this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR),e}updateTexture(e){this.lastFrame!==e&&((e.displayWidth!==this.canvas.width||e.displayHeight!==this.canvas.height)&&(this.canvas.width=e.displayWidth,this.canvas.height=e.displayHeight),this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,this.sourceTexture),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,e),this.lastFrame=e)}extractColor(e){return this.updateTexture(e),this.gl.useProgram(this.colorProgram),this.gl.viewport(0,0,this.canvas.width,this.canvas.height),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this.gl.bindVertexArray(this.vao),this.gl.drawArrays(this.gl.TRIANGLE_STRIP,0,4),new VideoFrame(this.canvas,{timestamp:e.timestamp,duration:e.duration??void 0,alpha:"discard"})}extractAlpha(e){this.updateTexture(e),this.gl.useProgram(this.alphaProgram),this.gl.uniform2f(this.alphaResolutionLocation,this.canvas.width,this.canvas.height),this.gl.viewport(0,0,this.canvas.width,this.canvas.height),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this.gl.bindVertexArray(this.vao),this.gl.drawArrays(this.gl.TRIANGLE_STRIP,0,4);let{width:r,height:i}=this.canvas,n=Math.ceil(r/2)*Math.ceil(i/2),s=r*i+n*2,o=Math.ceil(s/(r*4)),a=new Uint8Array(4*r*o);this.gl.readPixels(0,0,r,o,this.gl.RGBA,this.gl.UNSIGNED_BYTE,a),a=a.subarray(0,s),h(a[r*i]===128),h(a[a.length-1]===128);let c={format:"I420",codedWidth:r,codedHeight:i,timestamp:e.timestamp,duration:e.duration??void 0,transfer:[a.buffer]};return new VideoFrame(a,c)}close(){this.gl.getExtension("WEBGL_lose_context")?.loseContext(),this.gl=null}},Ri=class extends Vr{constructor(e){ol(e),super(e.codec),this._encoder=new No(this,e)}add(e,r){if(!(e instanceof Ee))throw new TypeError("videoSample must be a VideoSample.");return this._encoder.add(e,!1,r)}_flushAndClose(e){return this._encoder.flushAndClose(e)}};var Lr=class extends zr{constructor(e){if(super(),this._connectedTrack=null,!et.includes(e))throw new TypeError(`Invalid audio codec '${e}'. Must be one of: ${et.join(", ")}.`);this._codec=e}};var Uo=class{constructor(e,r){this.source=e,this.encodingConfig=r,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 ht,this.customEncoderQueueSize=0,this.lastEndSampleIndex=null,this.error=null,this.errorNeedsNewStack=!0}async add(e,r){try{if(this.checkForEncoderError(),this.source._ensureValidAdd(),this.lastNumberOfChannels!==null&&this.lastSampleRate!==null){if(e.numberOfChannels!==this.lastNumberOfChannels||e.sampleRate!==this.lastSampleRate)throw new 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),h(this.encoderInitialized);{let i=Math.round(e.timestamp*e.sampleRate),n=Math.round((e.timestamp+e.duration)*e.sampleRate);if(this.lastEndSampleIndex===null)this.lastEndSampleIndex=n;else{let s=i-this.lastEndSampleIndex;if(s>=64){let o=new Ae({data:new Float32Array(s*e.numberOfChannels),format:"f32-planar",sampleRate:e.sampleRate,numberOfChannels:e.numberOfChannels,numberOfFrames:s,timestamp:this.lastEndSampleIndex/e.sampleRate});await this.add(o,!0)}this.lastEndSampleIndex+=e.numberOfFrames}}if(this.customEncoder){this.customEncoderQueueSize++;let i=e.clone(),n=this.customEncoderCallSerializer.call(()=>this.customEncoder.encode(i)).then(()=>this.customEncoderQueueSize--).catch(s=>this.error??=s).finally(()=>{i.close()});this.customEncoderQueueSize>=4&&await n,await this.muxer.mutex.currentPromise}else if(this.isPcmEncoder)await this.doPcmEncoding(e,r);else{h(this.encoder);let i=e.toAudioData();this.encoder.encode(i),i.close(),r&&e.close(),this.encoder.encodeQueueSize>=4&&await new Promise(n=>this.encoder.addEventListener("dequeue",n,{once:!0})),await this.muxer.mutex.currentPromise}}finally{r&&e.close()}}async doPcmEncoding(e,r){h(this.outputSampleSize),h(this.writeOutputValue);let{numberOfChannels:i,numberOfFrames:n,sampleRate:s,timestamp:o}=e,a=2048,c=[];for(let f=0;f<n;f+=a){let m=Math.min(a,e.numberOfFrames-f),p=m*i*this.outputSampleSize,g=new ArrayBuffer(p),b=new DataView(g);c.push({frameCount:m,view:b})}let u=e.allocationSize({planeIndex:0,format:"f32-planar"}),l=new Float32Array(u/Float32Array.BYTES_PER_ELEMENT);for(let f=0;f<i;f++){e.copyTo(l,{planeIndex:f,format:"f32-planar"});for(let m=0;m<c.length;m++){let{frameCount:p,view:g}=c[m];for(let b=0;b<p;b++)this.writeOutputValue(g,(b*i+f)*this.outputSampleSize,l[m*a+b])}}r&&e.close();let d={decoderConfig:{codec:this.encodingConfig.codec,numberOfChannels:i,sampleRate:s}};for(let f=0;f<c.length;f++){let{frameCount:m,view:p}=c[f],g=p.buffer,b=f*a,w=new L(new Uint8Array(g),"key",o+b/s,m/s);this.encodingConfig.onEncodedPacket?.(w,d),await this.muxer.addEncodedAudioPacket(this.source._connectedTrack,w,d)}}ensureEncoder(e){let r=new Error;this.ensureEncoderPromise=(async()=>{let{numberOfChannels:i,sampleRate:n}=e,s=ul({numberOfChannels:i,sampleRate:n,...this.encodingConfig});this.encodingConfig.onEncoderConfig?.(s);let o=qc.find(a=>a.supports(this.encodingConfig.codec,s));if(o)this.customEncoder=new o,this.customEncoder.codec=this.encodingConfig.codec,this.customEncoder.config=s,this.customEncoder.onPacket=(a,c)=>{if(!(a instanceof L))throw new TypeError("The first argument passed to onPacket must be an EncodedPacket.");if(c!==void 0&&(!c||typeof c!="object"))throw new TypeError("The second argument passed to onPacket must be an object or undefined.");this.encodingConfig.onEncodedPacket?.(a,c),this.muxer.addEncodedAudioPacket(this.source._connectedTrack,a,c).catch(u=>{this.error??=u,this.errorNeedsNewStack=!1})},await this.customEncoder.init();else if(Y.includes(this.encodingConfig.codec))this.initPcmEncoder();else{if(typeof AudioEncoder>"u")throw new Error("AudioEncoder is not supported by this browser.");if(!(await AudioEncoder.isConfigSupported(s)).supported)throw new 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:(c,u)=>{if(this.encodingConfig.codec==="aac"&&u?.decoderConfig){let d=!1;if(!u.decoderConfig.description||u.decoderConfig.description.byteLength<2?d=!0:d=di(J(u.decoderConfig.description)).objectType===0,d){let f=Number(G(s.codec.split(".")));u.decoderConfig.description=Ec({objectType:f,numberOfChannels:u.decoderConfig.numberOfChannels,sampleRate:u.decoderConfig.sampleRate})}}let l=L.fromEncodedChunk(c);this.encodingConfig.onEncodedPacket?.(l,u),this.muxer.addEncodedAudioPacket(this.source._connectedTrack,l,u).catch(d=>{this.error??=d,this.errorNeedsNewStack=!1})},error:c=>{c.stack=r.stack,this.error??=c}}),this.encoder.configure(s)}h(this.source._connectedTrack),this.muxer=this.source._connectedTrack.output._muxer,this.encoderInitialized=!0})()}initPcmEncoder(){this.isPcmEncoder=!0;let e=this.encodingConfig.codec,{dataType:r,sampleSize:i,littleEndian:n}=Te(e);switch(this.outputSampleSize=i,i){case 1:r==="unsigned"?this.writeOutputValue=(s,o,a)=>s.setUint8(o,ee((a+1)*127.5,0,255)):r==="signed"?this.writeOutputValue=(s,o,a)=>{s.setInt8(o,ee(Math.round(a*128),-128,127))}:r==="ulaw"?this.writeOutputValue=(s,o,a)=>{let c=ee(Math.floor(a*32767),-32768,32767);s.setUint8(o,Hc(c))}:r==="alaw"?this.writeOutputValue=(s,o,a)=>{let c=ee(Math.floor(a*32767),-32768,32767);s.setUint8(o,Gc(c))}:h(!1);break;case 2:r==="unsigned"?this.writeOutputValue=(s,o,a)=>s.setUint16(o,ee((a+1)*32767.5,0,65535),n):r==="signed"?this.writeOutputValue=(s,o,a)=>s.setInt16(o,ee(Math.round(a*32767),-32768,32767),n):h(!1);break;case 3:r==="unsigned"?this.writeOutputValue=(s,o,a)=>oi(s,o,ee((a+1)*83886075e-1,0,16777215),n):r==="signed"?this.writeOutputValue=(s,o,a)=>uc(s,o,ee(Math.round(a*8388607),-8388608,8388607),n):h(!1);break;case 4:r==="unsigned"?this.writeOutputValue=(s,o,a)=>s.setUint32(o,ee((a+1)*21474836475e-1,0,4294967295),n):r==="signed"?this.writeOutputValue=(s,o,a)=>s.setInt32(o,ee(Math.round(a*2147483647),-2147483648,2147483647),n):r==="float"?this.writeOutputValue=(s,o,a)=>s.setFloat32(o,a,n):h(!1);break;case 8:r==="float"?this.writeOutputValue=(s,o,a)=>s.setFloat64(o,a,n):h(!1);break;default:ue(i),h(!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=new Error().stack),this.error}},Oi=class extends Lr{constructor(e){cl(e),super(e.codec),this._encoder=new Uo(this,e)}add(e){if(!(e instanceof Ae))throw new TypeError("audioSample must be an AudioSample.");return this._encoder.add(e,!1)}_flushAndClose(e){return this._encoder.flushAndClose(e)}};var Ni=class extends zr{constructor(e){if(super(),this._connectedTrack=null,!Nt.includes(e))throw new TypeError(`Invalid subtitle codec '${e}'. Must be one of: ${Nt.join(", ")}.`);this._codec=e}};var Mf=["video","audio","subtitle"],zo=t=>{if(!t||typeof t!="object")throw new TypeError("metadata must be an object.");if(t.languageCode!==void 0&&!lr(t.languageCode))throw new TypeError("metadata.languageCode, when provided, must be a three-letter, ISO 639-2/T language code.");if(t.name!==void 0&&typeof t.name!="string")throw new TypeError("metadata.name, when provided, must be a string.");if(t.disposition!==void 0&&gc(t.disposition),t.maximumPacketCount!==void 0&&(!Number.isInteger(t.maximumPacketCount)||t.maximumPacketCount<0))throw new TypeError("metadata.maximumPacketCount, when provided, must be a non-negative integer.")},Mi=class{constructor(e){if(this.state="pending",this._tracks=[],this._startPromise=null,this._cancelPromise=null,this._finalizePromise=null,this._mutex=new be,this._metadataTags={},!e||typeof e!="object")throw new TypeError("options must be an object.");if(!(e.format instanceof Nr))throw new TypeError("options.format must be an OutputFormat.");if(!(e.target instanceof Xt))throw new TypeError("options.target must be a Target.");if(e.target._output)throw new 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,r={}){if(!(e instanceof Vr))throw new TypeError("source must be a VideoSource.");if(zo(r),r.rotation!==void 0&&![0,90,180,270].includes(r.rotation))throw new TypeError(`Invalid video rotation: ${r.rotation}. Has to be 0, 90, 180 or 270.`);if(!this.format.supportsVideoRotationMetadata&&r.rotation)throw new Error(`${this.format._name} does not support video rotation metadata.`);if(r.frameRate!==void 0&&(!Number.isFinite(r.frameRate)||r.frameRate<=0))throw new TypeError(`Invalid video frame rate: ${r.frameRate}. Must be a positive number.`);this._addTrack("video",e,r)}addAudioTrack(e,r={}){if(!(e instanceof Lr))throw new TypeError("source must be an AudioSource.");zo(r),this._addTrack("audio",e,r)}addSubtitleTrack(e,r={}){if(!(e instanceof Ni))throw new TypeError("source must be a SubtitleSource.");zo(r),this._addTrack("subtitle",e,r)}setMetadataTags(e){if(pc(e),this.state!=="pending")throw new Error("Cannot set metadata tags after output has been started or canceled.");this._metadataTags=e}_addTrack(e,r,i){if(this.state!=="pending")throw new Error("Cannot add track after output has been started or canceled.");if(r._connectedTrack)throw new Error("Source is already used for a track.");let n=this.format.getSupportedTrackCounts(),s=this._tracks.reduce((u,l)=>u+(l.type===e?1:0),0),o=n[e].max;if(s===o)throw new Error(o===0?`${this.format._name} does not support ${e} tracks.`:`${this.format._name} does not support more than ${o} ${e} track${o===1?"":"s"}.`);let a=n.total.max;if(this._tracks.length===a)throw new Error(`${this.format._name} does not support more than ${a} tracks${a===1?"":"s"} in total.`);let c={id:this._tracks.length+1,output:this,type:e,source:r,metadata:i};if(c.type==="video"){let u=this.format.getSupportedVideoCodecs();if(u.length===0)throw new Error(`${this.format._name} does not support video tracks.`+this.format._codecUnsupportedHint(c.source._codec));if(!u.includes(c.source._codec))throw new Error(`Codec '${c.source._codec}' cannot be contained within ${this.format._name}. Supported video codecs are: ${u.map(l=>`'${l}'`).join(", ")}.`+this.format._codecUnsupportedHint(c.source._codec))}else if(c.type==="audio"){let u=this.format.getSupportedAudioCodecs();if(u.length===0)throw new Error(`${this.format._name} does not support audio tracks.`+this.format._codecUnsupportedHint(c.source._codec));if(!u.includes(c.source._codec))throw new Error(`Codec '${c.source._codec}' cannot be contained within ${this.format._name}. Supported audio codecs are: ${u.map(l=>`'${l}'`).join(", ")}.`+this.format._codecUnsupportedHint(c.source._codec))}else if(c.type==="subtitle"){let u=this.format.getSupportedSubtitleCodecs();if(u.length===0)throw new Error(`${this.format._name} does not support subtitle tracks.`+this.format._codecUnsupportedHint(c.source._codec));if(!u.includes(c.source._codec))throw new Error(`Codec '${c.source._codec}' cannot be contained within ${this.format._name}. Supported subtitle codecs are: ${u.map(l=>`'${l}'`).join(", ")}.`+this.format._codecUnsupportedHint(c.source._codec))}this._tracks.push(c),r._connectedTrack=c}async start(){let e=this.format.getSupportedTrackCounts();for(let i of Mf){let n=this._tracks.reduce((o,a)=>o+(a.type===i?1:0),0),s=e[i].min;if(n<s)throw new Error(s===e[i].max?`${this.format._name} requires exactly ${s} ${i} track${s===1?"":"s"}.`:`${this.format._name} requires at least ${s} ${i} track${s===1?"":"s"}.`)}let r=e.total.min;if(this._tracks.length<r)throw new Error(r===e.total.max?`${this.format._name} requires exactly ${r} track${r===1?"":"s"}.`:`${this.format._name} requires at least ${r} track${r===1?"":"s"}.`);if(this.state==="canceled")throw new Error("Output has been canceled.");return this._startPromise?(console.warn("Output has already been started."),this._startPromise):this._startPromise=(async()=>{this.state="started",this._writer.start();let i=await this._mutex.acquire();await this._muxer.start();let n=this._tracks.map(s=>s.source._start());await Promise.all(n),i()})()}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(),r=this._tracks.map(i=>i.source._flushOrWaitForOngoingClose(!0));await Promise.all(r),await this._writer.close(),e()})()}async finalize(){if(this.state==="pending")throw new Error("Cannot finalize before starting.");if(this.state==="canceled")throw new 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(),r=this._tracks.map(i=>i.source._flushOrWaitForOngoingClose(!1));await Promise.all(r),await this._muxer.finalize(),await this._writer.flush(),await this._writer.finalize(),this.state="finalized",e()})()}};ms.set(Rs);var ll=async t=>t instanceof Blob?new vi(t):new _i(t),dl=tn.work(t=>({async hello(){await t.host.world()},async decodeAudio({source:e,audio:r,start:i,end:n}){let o=await new Fr({source:await ll(e),formats:os}).getPrimaryAudioTrack(),a=await o?.canDecode(),c=r.getWriter();if(a&&o){let u=new wi(o);for await(let l of u.samples(i,n)){let d=l.toAudioData();await c.write(d),l.close(),d.close()}await c.close()}},async decodeVideo({source:e,video:r,start:i,end:n}){let o=await new Fr({source:await ll(e),formats:os}).getPrimaryVideoTrack(),a=await o?.canDecode(),c=r.getWriter();if(a&&o){let u=new bi(o);for await(let l of u.samples(i,n)){let d=l.toVideoFrame();await c.write(d),l.close(),d.close()}await c.close()}},async encode({video:e,audio:r,config:i,writable:n}){let s=new Mi({format:new Mr,target:new Fi(n,{chunked:!0})});async function o(){if(!e)return;let l=new Ri(i.video);s.addVideoTrack(l);for await(let d of e){let f=new Ee(d);await l.add(f),f.close()}}async function a(){if(!r)return;let l=new Oi(i.audio);s.addAudioTrack(l);for await(let d of r){let f=new Ae(d);await l.add(f),f.close(),d.close()}}let c=a(),u=o();await s.start(),await Promise.all([c,u]),await s.finalize()}}));await tn.worker(dl);
97
+ `),i=this.gl.createProgram();return this.gl.attachShader(i,e),this.gl.attachShader(i,r),this.gl.linkProgram(i),i}createShader(e,r){let i=this.gl.createShader(e);return this.gl.shaderSource(i,r),this.gl.compileShader(i),this.gl.getShaderParameter(i,this.gl.COMPILE_STATUS)||console.error("Shader compile error:",this.gl.getShaderInfoLog(i)),i}createVAO(){let e=this.gl.createVertexArray();this.gl.bindVertexArray(e);let r=new Float32Array([-1,-1,0,1,1,-1,1,1,-1,1,0,0,1,1,1,0]),i=this.gl.createBuffer();this.gl.bindBuffer(this.gl.ARRAY_BUFFER,i),this.gl.bufferData(this.gl.ARRAY_BUFFER,r,this.gl.STATIC_DRAW);let n=this.gl.getAttribLocation(this.colorProgram,"a_position"),s=this.gl.getAttribLocation(this.colorProgram,"a_texCoord");return this.gl.enableVertexAttribArray(n),this.gl.vertexAttribPointer(n,2,this.gl.FLOAT,!1,16,0),this.gl.enableVertexAttribArray(s),this.gl.vertexAttribPointer(s,2,this.gl.FLOAT,!1,16,8),e}createTexture(){let e=this.gl.createTexture();return this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR),e}updateTexture(e){this.lastFrame!==e&&((e.displayWidth!==this.canvas.width||e.displayHeight!==this.canvas.height)&&(this.canvas.width=e.displayWidth,this.canvas.height=e.displayHeight),this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,this.sourceTexture),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,e),this.lastFrame=e)}extractColor(e){return this.updateTexture(e),this.gl.useProgram(this.colorProgram),this.gl.viewport(0,0,this.canvas.width,this.canvas.height),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this.gl.bindVertexArray(this.vao),this.gl.drawArrays(this.gl.TRIANGLE_STRIP,0,4),new VideoFrame(this.canvas,{timestamp:e.timestamp,duration:e.duration??void 0,alpha:"discard"})}extractAlpha(e){this.updateTexture(e),this.gl.useProgram(this.alphaProgram),this.gl.uniform2f(this.alphaResolutionLocation,this.canvas.width,this.canvas.height),this.gl.viewport(0,0,this.canvas.width,this.canvas.height),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this.gl.bindVertexArray(this.vao),this.gl.drawArrays(this.gl.TRIANGLE_STRIP,0,4);let{width:r,height:i}=this.canvas,n=Math.ceil(r/2)*Math.ceil(i/2),s=r*i+n*2,o=Math.ceil(s/(r*4)),a=new Uint8Array(4*r*o);this.gl.readPixels(0,0,r,o,this.gl.RGBA,this.gl.UNSIGNED_BYTE,a),a=a.subarray(0,s),h(a[r*i]===128),h(a[a.length-1]===128);let c={format:"I420",codedWidth:r,codedHeight:i,timestamp:e.timestamp,duration:e.duration??void 0,transfer:[a.buffer]};return new VideoFrame(a,c)}close(){this.gl.getExtension("WEBGL_lose_context")?.loseContext(),this.gl=null}},Ri=class extends Vr{constructor(e){ol(e),super(e.codec),this._encoder=new No(this,e)}add(e,r){if(!(e instanceof Ee))throw new TypeError("videoSample must be a VideoSample.");return this._encoder.add(e,!1,r)}_flushAndClose(e){return this._encoder.flushAndClose(e)}};var Lr=class extends zr{constructor(e){if(super(),this._connectedTrack=null,!et.includes(e))throw new TypeError(`Invalid audio codec '${e}'. Must be one of: ${et.join(", ")}.`);this._codec=e}};var Uo=class{constructor(e,r){this.source=e,this.encodingConfig=r,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 ht,this.customEncoderQueueSize=0,this.lastEndSampleIndex=null,this.error=null,this.errorNeedsNewStack=!0}async add(e,r){try{if(this.checkForEncoderError(),this.source._ensureValidAdd(),this.lastNumberOfChannels!==null&&this.lastSampleRate!==null){if(e.numberOfChannels!==this.lastNumberOfChannels||e.sampleRate!==this.lastSampleRate)throw new 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),h(this.encoderInitialized);{let i=Math.round(e.timestamp*e.sampleRate),n=Math.round((e.timestamp+e.duration)*e.sampleRate);if(this.lastEndSampleIndex===null)this.lastEndSampleIndex=n;else{let s=i-this.lastEndSampleIndex;if(s>=64){let o=new Ae({data:new Float32Array(s*e.numberOfChannels),format:"f32-planar",sampleRate:e.sampleRate,numberOfChannels:e.numberOfChannels,numberOfFrames:s,timestamp:this.lastEndSampleIndex/e.sampleRate});await this.add(o,!0)}this.lastEndSampleIndex+=e.numberOfFrames}}if(this.customEncoder){this.customEncoderQueueSize++;let i=e.clone(),n=this.customEncoderCallSerializer.call(()=>this.customEncoder.encode(i)).then(()=>this.customEncoderQueueSize--).catch(s=>this.error??=s).finally(()=>{i.close()});this.customEncoderQueueSize>=4&&await n,await this.muxer.mutex.currentPromise}else if(this.isPcmEncoder)await this.doPcmEncoding(e,r);else{h(this.encoder);let i=e.toAudioData();this.encoder.encode(i),i.close(),r&&e.close(),this.encoder.encodeQueueSize>=4&&await new Promise(n=>this.encoder.addEventListener("dequeue",n,{once:!0})),await this.muxer.mutex.currentPromise}}finally{r&&e.close()}}async doPcmEncoding(e,r){h(this.outputSampleSize),h(this.writeOutputValue);let{numberOfChannels:i,numberOfFrames:n,sampleRate:s,timestamp:o}=e,a=2048,c=[];for(let f=0;f<n;f+=a){let m=Math.min(a,e.numberOfFrames-f),p=m*i*this.outputSampleSize,g=new ArrayBuffer(p),b=new DataView(g);c.push({frameCount:m,view:b})}let u=e.allocationSize({planeIndex:0,format:"f32-planar"}),l=new Float32Array(u/Float32Array.BYTES_PER_ELEMENT);for(let f=0;f<i;f++){e.copyTo(l,{planeIndex:f,format:"f32-planar"});for(let m=0;m<c.length;m++){let{frameCount:p,view:g}=c[m];for(let b=0;b<p;b++)this.writeOutputValue(g,(b*i+f)*this.outputSampleSize,l[m*a+b])}}r&&e.close();let d={decoderConfig:{codec:this.encodingConfig.codec,numberOfChannels:i,sampleRate:s}};for(let f=0;f<c.length;f++){let{frameCount:m,view:p}=c[f],g=p.buffer,b=f*a,w=new L(new Uint8Array(g),"key",o+b/s,m/s);this.encodingConfig.onEncodedPacket?.(w,d),await this.muxer.addEncodedAudioPacket(this.source._connectedTrack,w,d)}}ensureEncoder(e){let r=new Error;this.ensureEncoderPromise=(async()=>{let{numberOfChannels:i,sampleRate:n}=e,s=ul({numberOfChannels:i,sampleRate:n,...this.encodingConfig});this.encodingConfig.onEncoderConfig?.(s);let o=qc.find(a=>a.supports(this.encodingConfig.codec,s));if(o)this.customEncoder=new o,this.customEncoder.codec=this.encodingConfig.codec,this.customEncoder.config=s,this.customEncoder.onPacket=(a,c)=>{if(!(a instanceof L))throw new TypeError("The first argument passed to onPacket must be an EncodedPacket.");if(c!==void 0&&(!c||typeof c!="object"))throw new TypeError("The second argument passed to onPacket must be an object or undefined.");this.encodingConfig.onEncodedPacket?.(a,c),this.muxer.addEncodedAudioPacket(this.source._connectedTrack,a,c).catch(u=>{this.error??=u,this.errorNeedsNewStack=!1})},await this.customEncoder.init();else if(Y.includes(this.encodingConfig.codec))this.initPcmEncoder();else{if(typeof AudioEncoder>"u")throw new Error("AudioEncoder is not supported by this browser.");if(!(await AudioEncoder.isConfigSupported(s)).supported)throw new 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:(c,u)=>{if(this.encodingConfig.codec==="aac"&&u?.decoderConfig){let d=!1;if(!u.decoderConfig.description||u.decoderConfig.description.byteLength<2?d=!0:d=di(J(u.decoderConfig.description)).objectType===0,d){let f=Number(G(s.codec.split(".")));u.decoderConfig.description=Ec({objectType:f,numberOfChannels:u.decoderConfig.numberOfChannels,sampleRate:u.decoderConfig.sampleRate})}}let l=L.fromEncodedChunk(c);this.encodingConfig.onEncodedPacket?.(l,u),this.muxer.addEncodedAudioPacket(this.source._connectedTrack,l,u).catch(d=>{this.error??=d,this.errorNeedsNewStack=!1})},error:c=>{c.stack=r.stack,this.error??=c}}),this.encoder.configure(s)}h(this.source._connectedTrack),this.muxer=this.source._connectedTrack.output._muxer,this.encoderInitialized=!0})()}initPcmEncoder(){this.isPcmEncoder=!0;let e=this.encodingConfig.codec,{dataType:r,sampleSize:i,littleEndian:n}=Te(e);switch(this.outputSampleSize=i,i){case 1:r==="unsigned"?this.writeOutputValue=(s,o,a)=>s.setUint8(o,ee((a+1)*127.5,0,255)):r==="signed"?this.writeOutputValue=(s,o,a)=>{s.setInt8(o,ee(Math.round(a*128),-128,127))}:r==="ulaw"?this.writeOutputValue=(s,o,a)=>{let c=ee(Math.floor(a*32767),-32768,32767);s.setUint8(o,Hc(c))}:r==="alaw"?this.writeOutputValue=(s,o,a)=>{let c=ee(Math.floor(a*32767),-32768,32767);s.setUint8(o,Gc(c))}:h(!1);break;case 2:r==="unsigned"?this.writeOutputValue=(s,o,a)=>s.setUint16(o,ee((a+1)*32767.5,0,65535),n):r==="signed"?this.writeOutputValue=(s,o,a)=>s.setInt16(o,ee(Math.round(a*32767),-32768,32767),n):h(!1);break;case 3:r==="unsigned"?this.writeOutputValue=(s,o,a)=>oi(s,o,ee((a+1)*83886075e-1,0,16777215),n):r==="signed"?this.writeOutputValue=(s,o,a)=>uc(s,o,ee(Math.round(a*8388607),-8388608,8388607),n):h(!1);break;case 4:r==="unsigned"?this.writeOutputValue=(s,o,a)=>s.setUint32(o,ee((a+1)*21474836475e-1,0,4294967295),n):r==="signed"?this.writeOutputValue=(s,o,a)=>s.setInt32(o,ee(Math.round(a*2147483647),-2147483648,2147483647),n):r==="float"?this.writeOutputValue=(s,o,a)=>s.setFloat32(o,a,n):h(!1);break;case 8:r==="float"?this.writeOutputValue=(s,o,a)=>s.setFloat64(o,a,n):h(!1);break;default:ue(i),h(!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=new Error().stack),this.error}},Oi=class extends Lr{constructor(e){cl(e),super(e.codec),this._encoder=new Uo(this,e)}add(e){if(!(e instanceof Ae))throw new TypeError("audioSample must be an AudioSample.");return this._encoder.add(e,!1)}_flushAndClose(e){return this._encoder.flushAndClose(e)}};var Ni=class extends zr{constructor(e){if(super(),this._connectedTrack=null,!Nt.includes(e))throw new TypeError(`Invalid subtitle codec '${e}'. Must be one of: ${Nt.join(", ")}.`);this._codec=e}};var Mf=["video","audio","subtitle"],zo=t=>{if(!t||typeof t!="object")throw new TypeError("metadata must be an object.");if(t.languageCode!==void 0&&!lr(t.languageCode))throw new TypeError("metadata.languageCode, when provided, must be a three-letter, ISO 639-2/T language code.");if(t.name!==void 0&&typeof t.name!="string")throw new TypeError("metadata.name, when provided, must be a string.");if(t.disposition!==void 0&&gc(t.disposition),t.maximumPacketCount!==void 0&&(!Number.isInteger(t.maximumPacketCount)||t.maximumPacketCount<0))throw new TypeError("metadata.maximumPacketCount, when provided, must be a non-negative integer.")},Mi=class{constructor(e){if(this.state="pending",this._tracks=[],this._startPromise=null,this._cancelPromise=null,this._finalizePromise=null,this._mutex=new be,this._metadataTags={},!e||typeof e!="object")throw new TypeError("options must be an object.");if(!(e.format instanceof Nr))throw new TypeError("options.format must be an OutputFormat.");if(!(e.target instanceof Xt))throw new TypeError("options.target must be a Target.");if(e.target._output)throw new 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,r={}){if(!(e instanceof Vr))throw new TypeError("source must be a VideoSource.");if(zo(r),r.rotation!==void 0&&![0,90,180,270].includes(r.rotation))throw new TypeError(`Invalid video rotation: ${r.rotation}. Has to be 0, 90, 180 or 270.`);if(!this.format.supportsVideoRotationMetadata&&r.rotation)throw new Error(`${this.format._name} does not support video rotation metadata.`);if(r.frameRate!==void 0&&(!Number.isFinite(r.frameRate)||r.frameRate<=0))throw new TypeError(`Invalid video frame rate: ${r.frameRate}. Must be a positive number.`);this._addTrack("video",e,r)}addAudioTrack(e,r={}){if(!(e instanceof Lr))throw new TypeError("source must be an AudioSource.");zo(r),this._addTrack("audio",e,r)}addSubtitleTrack(e,r={}){if(!(e instanceof Ni))throw new TypeError("source must be a SubtitleSource.");zo(r),this._addTrack("subtitle",e,r)}setMetadataTags(e){if(pc(e),this.state!=="pending")throw new Error("Cannot set metadata tags after output has been started or canceled.");this._metadataTags=e}_addTrack(e,r,i){if(this.state!=="pending")throw new Error("Cannot add track after output has been started or canceled.");if(r._connectedTrack)throw new Error("Source is already used for a track.");let n=this.format.getSupportedTrackCounts(),s=this._tracks.reduce((u,l)=>u+(l.type===e?1:0),0),o=n[e].max;if(s===o)throw new Error(o===0?`${this.format._name} does not support ${e} tracks.`:`${this.format._name} does not support more than ${o} ${e} track${o===1?"":"s"}.`);let a=n.total.max;if(this._tracks.length===a)throw new Error(`${this.format._name} does not support more than ${a} tracks${a===1?"":"s"} in total.`);let c={id:this._tracks.length+1,output:this,type:e,source:r,metadata:i};if(c.type==="video"){let u=this.format.getSupportedVideoCodecs();if(u.length===0)throw new Error(`${this.format._name} does not support video tracks.`+this.format._codecUnsupportedHint(c.source._codec));if(!u.includes(c.source._codec))throw new Error(`Codec '${c.source._codec}' cannot be contained within ${this.format._name}. Supported video codecs are: ${u.map(l=>`'${l}'`).join(", ")}.`+this.format._codecUnsupportedHint(c.source._codec))}else if(c.type==="audio"){let u=this.format.getSupportedAudioCodecs();if(u.length===0)throw new Error(`${this.format._name} does not support audio tracks.`+this.format._codecUnsupportedHint(c.source._codec));if(!u.includes(c.source._codec))throw new Error(`Codec '${c.source._codec}' cannot be contained within ${this.format._name}. Supported audio codecs are: ${u.map(l=>`'${l}'`).join(", ")}.`+this.format._codecUnsupportedHint(c.source._codec))}else if(c.type==="subtitle"){let u=this.format.getSupportedSubtitleCodecs();if(u.length===0)throw new Error(`${this.format._name} does not support subtitle tracks.`+this.format._codecUnsupportedHint(c.source._codec));if(!u.includes(c.source._codec))throw new Error(`Codec '${c.source._codec}' cannot be contained within ${this.format._name}. Supported subtitle codecs are: ${u.map(l=>`'${l}'`).join(", ")}.`+this.format._codecUnsupportedHint(c.source._codec))}this._tracks.push(c),r._connectedTrack=c}async start(){let e=this.format.getSupportedTrackCounts();for(let i of Mf){let n=this._tracks.reduce((o,a)=>o+(a.type===i?1:0),0),s=e[i].min;if(n<s)throw new Error(s===e[i].max?`${this.format._name} requires exactly ${s} ${i} track${s===1?"":"s"}.`:`${this.format._name} requires at least ${s} ${i} track${s===1?"":"s"}.`)}let r=e.total.min;if(this._tracks.length<r)throw new Error(r===e.total.max?`${this.format._name} requires exactly ${r} track${r===1?"":"s"}.`:`${this.format._name} requires at least ${r} track${r===1?"":"s"}.`);if(this.state==="canceled")throw new Error("Output has been canceled.");return this._startPromise?(console.warn("Output has already been started."),this._startPromise):this._startPromise=(async()=>{this.state="started",this._writer.start();let i=await this._mutex.acquire();await this._muxer.start();let n=this._tracks.map(s=>s.source._start());await Promise.all(n),i()})()}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(),r=this._tracks.map(i=>i.source._flushOrWaitForOngoingClose(!0));await Promise.all(r),await this._writer.close(),e()})()}async finalize(){if(this.state==="pending")throw new Error("Cannot finalize before starting.");if(this.state==="canceled")throw new 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(),r=this._tracks.map(i=>i.source._flushOrWaitForOngoingClose(!1));await Promise.all(r),await this._muxer.finalize(),await this._writer.flush(),await this._writer.finalize(),this.state="finalized",e()})()}};ms.set(Rs);var ll=async t=>t instanceof Blob?new vi(t):new _i(t),dl=tn.work(t=>({async hello(){await t.host.world()},async decodeAudio({source:e,audio:r,start:i,end:n,cancel:s}){let o=new Fr({source:await ll(e),formats:os}),a=await o.getPrimaryAudioTrack(),c=await a?.canDecode(),u=r.getWriter();if(!c||!a)return;let d=new wi(a).samples(i,n);s.onmessage=async()=>{d.return(),o.dispose(),s.close()};for await(let f of d){let m=f.toAudioData();f.close(),await u.write(m),m.close()}await u.close()},async decodeVideo({source:e,video:r,start:i,end:n,cancel:s}){let o=new Fr({source:await ll(e),formats:os}),a=await o.getPrimaryVideoTrack(),c=await a?.canDecode(),u=r.getWriter();if(!c||!a)return;let d=new bi(a).samples(i,n);s.onmessage=async()=>{d.return(),o.dispose(),s.close()};for await(let f of d){let m=f.toVideoFrame();f.close(),await u.write(m),m.close()}await u.close()},async encode({video:e,audio:r,config:i,writable:n}){let s=new Mi({format:new Mr,target:new Fi(n,{chunked:!0})});async function o(){if(!e)return;let l=new Ri(i.video);s.addVideoTrack(l);for await(let d of e){let f=new Ee(d);await l.add(f),f.close(),d.close()}}async function a(){if(!r)return;let l=new Oi(i.audio);s.addAudioTrack(l);for await(let d of r){let f=new Ae(d);await l.add(f),f.close(),d.close()}}let c=a(),u=o();await s.start(),await Promise.all([c,u]),await s.finalize()}}));await tn.worker(dl);
98
98
  /*! Bundled license information:
99
99
 
100
100
  mediabunny/dist/modules/src/misc.js: