(self.webpackChunkscreenity=self.webpackChunkscreenity||[]).push([[456],{1254(e,t,a){"use strict";a.r(t),a.d(t,{default:()=>m});var o=a(2030),r=a(4709),c=a(5608),n=a(917),i=a(9917),s=a(7621),d=a(388),u=a(4002),p=a(5374),w=a(4166),f=a(9136);class l{async mute(e,{muteStart:t=0,muteEnd:a=0,videoVolume:l=1,outputFormat:m="mp4",onProgress:h}={}){const v=await this._getDuration(e),C=new o.pd({source:new r.Z7(e),formats:c.XE}),b=new n.Sn,y=new i.k7({format:new s.si({fastStart:"in-memory"}),target:b}),g=await C.getPrimaryVideoTrack(),E=new d.lc(g),P=await f.Up.detectBestCodec("mp4"),k=P?.codec??"avc",V=new u.Fl({codec:k,bitrate:p.pr});y.addVideoTrack(V);const B=await C.getPrimaryAudioTrack(),M=!!B&&await B.canDecode().catch(()=>!1);let U=null,S=null;B&&M&&(U=new d.qw(B),S=new u.Ii({codec:"aac",bitrate:128e3}),y.addAudioTrack(S)),await y.start();for await(const e of E.samples(0,v))await V.add(e),e.close(),h&&h(e.timestamp/v);if(U&&S)for await(const e of U.samples()){const o=e.timestamp;if((o+e.duration<=t||o>=a)&&1===l){await S.add(e),e.close();continue}const r=e.numberOfChannels,c=e.sampleRate,n=e.numberOfFrames,i=new Float32Array(n*r);for(let t=0;t<r;t++){const a=i.subarray(t*n,(t+1)*n);e.copyTo(a,{format:"f32-planar",planeIndex:t})}for(let e=0;e<n;e++){const s=o+e/c,d=s>=t&&s<a?0:l;if(1!==d)for(let t=0;t<r;t++)i[t*n+e]*=d}const s=new w.B1({data:i,format:"f32-planar",numberOfChannels:r,sampleRate:c,timestamp:o,duration:n/c});await S.add(s),s.close(),e.close()}return await y.finalize(),new Blob([b.buffer],{type:"video/mp4"})}async _getDuration(e){return new Promise((t,a)=>{const o=document.createElement("video"),r=URL.createObjectURL(e);o.src=r,o.onloadedmetadata=()=>{URL.revokeObjectURL(r),t(o.duration)},o.onerror=e=>{URL.revokeObjectURL(r),a(e)}})}}const m=async function(e,t,a,o,r,c=()=>{}){return(new l).mute(t,{muteStart:a,muteEnd:o,outputFormat:"webm",videoBitrate:5e6,audioBitrate:128e3,onProgress:c})}},9136(e,t,a){"use strict";a.d(t,{K_:()=>p,Up:()=>w});var o=a(9917),r=a(7621),c=a(917),n=a(4709),i=a(5608),s=a(2030),d=a(1276);const u={avc:"H.264",hevc:"H.265 (HEVC)",vp9:"VP9",av1:"AV1",vp8:"VP8"};class p{constructor(){this.cachedMP4Codec=null,this.cachedWebMCodec=null}async convertToMP4(e,t={}){return this.convert(e,"mp4",t)}async convertToWebM(e,t={}){return this.convert(e,"webm",t)}async detectBestCodec(e){const t=("mp4"===e?new r.si({fastStart:!1}):new r.wQ).getSupportedVideoCodecs();for(const e of t)if(await this.canEncodeCodec(e))return{codec:e,displayName:u[e]||e.toUpperCase(),isPreferred:"avc"===e||"vp9"===e};return null}async canEncodeCodec(e){if("undefined"==typeof VideoEncoder)return!1;try{const t=this.getEncoderConfig(e);return(await VideoEncoder.isConfigSupported(t)).supported??!1}catch{return!1}}clearCache(){this.cachedMP4Codec=null,this.cachedWebMCodec=null}async convert(e,t,a){const{videoBitrate:u=5e6,audioBitrate:p=128e3,preferredVideoCodec:w,audioCodec:f,onProgress:l}=a;let m="mp4"===t?this.cachedMP4Codec:this.cachedWebMCodec;if(!m){if(w&&await this.canEncodeCodec(w))m=w;else{const e=await this.detectBestCodec(t);if(!e)throw new Error(`Cannot convert to ${t.toUpperCase()}: no supported video codec.`);m=e.codec}"mp4"===t?this.cachedMP4Codec=m:this.cachedWebMCodec=m}const h=f||("mp4"===t?"aac":"opus"),v=new s.pd({formats:i.XE,source:new n.Z7(e)}),C="mp4"===t?new r.si({fastStart:!1}):new r.wQ,b=a.target||new c.Sn,y=new o.k7({format:C,target:b}),g=await d.d.init({input:v,output:y,video:{codec:m,bitrate:u},audio:{codec:h,bitrate:p}});if(!g.isValid){const e=g.discardedTracks.map(e=>`${e.track.type}: ${e.reason}`).join(", ");throw new Error(`Conversion failed - ${e}`)}if(l&&(g.onProgress=l),await g.execute(),a.target)return null;if(!b.buffer)throw new Error("Conversion failed - no output buffer");return new Blob([b.buffer],{type:"mp4"===t?"video/mp4":"video/webm"})}getEncoderConfig(e){const t={width:1920,height:1080,bitrate:5e6};switch(e){case"avc":return{...t,codec:"avc1.42E01E"};case"hevc":return{...t,codec:"hev1.1.6.L93.B0"};default:return{...t,codec:e}}}}const w=new p},1845(){}}]);