(self.webpackChunkscreenity=self.webpackChunkscreenity||[]).push([[499],{943(t,e,i){"use strict";i.r(e),i.d(e,{default:()=>p});var o=i(2030),r=i(5608),n=i(4709),a=i(7621),d=i(917),s=i(9917),w=i(1276);class c{async crop(t,e){const{left:i,top:c,width:p,height:h,outputFormat:u,videoBitrate:f,audioBitrate:g,onProgress:m}=e;if(i<0||c<0)throw new Error("Crop position cannot be negative");if(p<=0||h<=0)throw new Error("Crop dimensions must be positive");const l=new o.pd({formats:r.XE,source:new n.Z7(t)}),y=await l.getFormat(),k=(await l.getTracks()).find(t=>"video"===t.type);if(!k||!k.isVideoTrack())throw new Error("No video track found in input");const b=k.displayWidth,v=k.displayHeight;let E,C=p,B=h;i+C>b&&(C=b-i),c+B>v&&(B=v-c),C=Math.max(2,C-C%2),B=Math.max(2,B-B%2),e.width=C,e.height=B;const T=u||(y.name.toLowerCase().includes("mp4")?"mp4":"webm");E="mp4"===T?new a.si({fastStart:!1}):new a.wQ;const x=new d.Sn,H=new s.k7({format:E,target:x}),W=await w.d.init({input:l,output:H,video:{crop:{left:i,top:c,width:C,height:B},...f&&{bitrate:f}},...g&&{audio:{bitrate:g}}});if(!W.isValid){const t=W.discardedTracks.map(t=>`${t.track.type}: ${t.reason}`).join(", ");throw new Error(`Cropping failed - ${t}`)}if(m&&(W.onProgress=m),await W.execute(),!x.buffer)throw new Error("Cropping failed - no output buffer");return new Blob([x.buffer],{type:"mp4"===T?"video/mp4":"video/webm"})}async getDimensions(t){const e=new o.pd({formats:r.XE,source:new n.Z7(t)}),i=(await e.getTracks()).find(t=>"video"===t.type);if(!i||!i.isVideoTrack())throw new Error("No video track found");return{width:i.displayWidth,height:i.displayHeight,codedWidth:i.codedWidth,codedHeight:i.codedHeight}}}new c;const p=async function(t,e,i,o=()=>{}){return(new c).crop(e,{left:i.x,top:i.y,width:i.width,height:i.height,videoBitrate:5e6,audioBitrate:128e3,onProgress:o})}},1845(){}}]);