@tmhs/screencast-mcp 0.51.0 → 0.51.1
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.
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -145,7 +145,7 @@ public static class ScElems{
|
|
|
145
145
|
${r(t)}`;return e===-1/0?n:Iy(n,e)}function Fy(t){return t.startsWith("#< CLIXML")?[...t.matchAll(/<S S="Error">([^<]*)<\/S>/g)].map(r=>r[1]).join("").replace(/_x000D__x000A_/g,`
|
|
146
146
|
`).replace(/>/g,">").replace(/</g,"<").replace(/&/g,"&").trim():t.trim()}var Hl=2e4;async function Vl(t,e,r={}){if(process.platform!=="win32")throw new l("The input event log is implemented for Windows only.");ac(`${t}.stop`,{force:!0});let n=Buffer.from(Cy(t,e,process.pid,r),"utf16le").toString("base64"),o=$y("powershell",["-NoProfile","-NonInteractive","-EncodedCommand",n],{stdio:["ignore","pipe","pipe"],windowsHide:!0}),i="";o.stderr?.on("data",c=>{i=(i+c.toString()).slice(-2e3)});let s=[];Ql.set(o,s);let a="";return o.stdout?.on("data",c=>{a+=c.toString();let u=a.split(/\r?\n/);a=u.pop()??"";for(let d of u){let p=My(d);if(p)if("taken"in p)s.push(p.taken);else try{r.onHotkey?.(p.pressed)}catch{}}}),await new Promise((c,u)=>{let d=!1,p=m=>{d||(d=!0,clearTimeout(f),o.kill(),u(new l(`Could not start the input event log: ${m}`)))},f=setTimeout(()=>p(`no response in ${Hl/1e3}s`),Hl);o.stdout?.on("data",m=>{!d&&m.toString().includes("ready")&&(d=!0,clearTimeout(f),c())}),o.on("error",m=>p(m.message)),o.on("exit",m=>p(Fy(i)||`helper exited with code ${m}`))}),ep.set(o,`${t}.stop`),o}var Ql=new WeakMap;function Zl(t){return[...Ql.get(t)??[]]}var ep=new WeakMap,Gl=2e3;function hi(t){if(t.exitCode!==null||t.signalCode!==null)return Promise.resolve();let e=ep.get(t);if(e)try{Xl(e,"")}catch{e=void 0}return new Promise(r=>{let n=setTimeout(()=>t.kill(),e?Gl:0),o=setTimeout(r,Gl+5e3);t.once("exit",()=>{clearTimeout(n),clearTimeout(o),r()})}).finally(()=>{e&&ac(e,{force:!0})})}function $e(t){let e=t.replace(/\.[^./\\]+$/,"");return{raw:`${e}.events.raw`,jsonl:`${e}.events.jsonl`}}function gi(t,e=!1){if(!e){let r=[t.jsonl,t.raw].find(n=>sc(n));if(r)throw new l(`Event log already exists: ${r}. Pass overwrite: true to replace it, or choose a different output path.`);return}ac(t.raw,{force:!0})}function tp(t,e){let r=sc(t.raw)?ql(t.raw,"utf8"):"",n=lc(r,e);Xl(t.jsonl,pc(n));try{ky(t.raw)}catch{}return n}var uo=new Map;function mo(t,e){let r=uo.get(t),n=r?Promise.all([r,e]).then(()=>{}):e;uo.set(t,n),n.finally(()=>{uo.get(t)===n&&uo.delete(t)})}async function Yt(t,e=1e4){let r=uo.get(t);r&&await Promise.race([r,new Promise(n=>setTimeout(n,e))])}import{existsSync as Li,mkdirSync as Dx,renameSync as Nx,rmSync as Lx,statSync as Bx,writeFileSync as Wx}from"node:fs";import{basename as jx,dirname as Ux,extname as Kp,join as vo}from"node:path";import{spawn as zp,spawnSync as Oi}from"node:child_process";import{existsSync as dx,mkdtempSync as mx,rmSync as fx,writeFileSync as hx}from"node:fs";import{tmpdir as gx}from"node:os";import{join as Bp}from"node:path";import{extname as Ei}from"node:path";import{homedir as Oy,tmpdir as Dy}from"node:os";import{basename as Ny,delimiter as Ly,dirname as By,join as Rr,isAbsolute as Wy,relative as jy,resolve as Kt,sep as Uy}from"node:path";import{mkdirSync as np,existsSync as zy,realpathSync as Hy}from"node:fs";function Ie(){let t=process.env.SCREENCAST_HOME;return t&&t.trim().length>0?t:Rr(Oy(),".screencast-mcp")}function we(t){let e=Rr(Ie(),t);return np(e,{recursive:!0}),e}function op(){let t=Ie();return np(t,{recursive:!0}),Rr(t,"sessions.json")}function ge(t=new Date){let e=t.toISOString().replace(/[-:T]/g,"").replace(/\..+/,""),r=String(t.getMilliseconds()).padStart(3,"0");return`${e.slice(0,8)}-${e.slice(8,14)}-${r}`}function be(t=4){return Math.random().toString(36).slice(2,2+t)}function un(t,e){return Rr(t.replace(/%/g,"%%"),e)}var ip=/\.(png|jpe?g|bmp|tiff?)$/i;function dc(t){return ip.test(t)}function Ee(t){return ip.test(t)?["-update","1",t]:[t]}function Ue(t=""){return Rr(Dy(),`screencast-${ge()}-${be()}${t}`)}var bi="SCREENCAST_ALLOWED_DIRS";function fo(t=process.env){let e=t[bi];return e?e.split(Ly).map(r=>r.trim()).filter(r=>r.length>0).map(r=>Kt(r)):[]}var cn=null;function ho(t){cn=t===null||t==="pending"?t:t.map(e=>Kt(e))}function Mr(t=process.env){let e=fo(t);if(cn===null&&e.length===0)return null;let r=Array.isArray(cn)?cn:[];return[Kt(Ie()),...e,...r]}function rp(t){let e=[],r=Kt(t);for(;;)try{return Rr(Hy.native(r),...e.reverse())}catch{let n=By(r);if(n===r)return Kt(t);e.push(Ny(r)),r=n}}function Ar(t,e){let r=jy(rp(e),rp(t));return r===""||r!==".."&&!r.startsWith(`..${Uy}`)&&!Wy(r)}function Gy(t){let e=t.trim();return/^[\\/]{2}/.test(e)?!/^[\\/]{2}\?[\\/][A-Za-z]:[\\/]/.test(e):!1}function Vt(t,e="Path"){if(Gy(t))throw new l(`${e} ${t} is a network or device path; only local files are allowed. Copy the file to a local folder first.`)}function sp(t,e="Input"){Vt(t,e);let r=Kt(t);if(cn==="pending"&&fo().length===0&&!Ar(r,Ie()))throw new l(`${e} ${r} is outside SCREENCAST_HOME and the client's workspace roots have not loaded yet. Retry the call in a moment.`);let n=Mr();if(!(n===null||n.some(o=>Ar(r,o))))throw new l(`${e} ${r} is outside the allowed directories: ${n.join(", ")}. Move it under one of them, or add its folder to ${bi} or the client's workspace roots.`)}function Qt(t){if(Vt(t,"Output"),cn==="pending"&&fo().length===0&&!Ar(t,Ie()))throw new l(`Output ${t} is outside SCREENCAST_HOME and the client's workspace roots have not loaded yet. Retry the call in a moment, or omit the path to write under SCREENCAST_HOME.`);let e=Mr();if(!(e===null||e.some(r=>Ar(t,r))))throw new l(`Output ${t} is outside the allowed directories: ${e.join(", ")}. Write under one of them (a relative path lands in SCREENCAST_HOME), or add the folder to ${bi} or the client's workspace roots.`)}function mc(t){if(!(Mr()!==null||Ar(t,Ie())))throw new l(`Refusing to replace ${t}: it is outside SCREENCAST_HOME and no allowed directories are set. Add its folder to ${bi} (or the client's workspace roots) to allow overwriting there, or write to a new path.`)}function Zt(t,e,r,n=!1){if(t&&t.trim().length>0){Vt(t,"Output");let o=Kt(e,t);if(Qt(o),zy(o)){if(!n)throw new l(`Output already exists: ${o}. Pass overwrite: true to replace it, or choose a different path.`);mc(o)}return o}return Rr(e,r)}function ln(t,e){if(!t||t.trim().length===0)return;Vt(t,"Output directory");let r=Kt(e,t);return Qt(r),r}var fc={draft:{preset:"ultrafast",crf:28},standard:{preset:"veryfast",crf:23},high:{preset:"medium",crf:18}},yi=30,xi="standard";function cp(t){return!t||t.device.trim().length===0?[]:["-f","dshow","-i",`audio=${t.device}`]}function go(t,e){if(!/^-?\d+$/.test(t.trim()))throw new l(`${e} must be an integer, got "${t}".`);return parseInt(t,10)}function up(t){let e=t.trim();if(e===""||e.toLowerCase()==="full")return{kind:"full"};let r=e.indexOf(":");if(r===-1)throw new l(`Unrecognized target "${t}". Use full | monitor:<index> | window:<title> | region:<x>,<y>,<w>,<h>.`);let n=e.slice(0,r).toLowerCase(),o=e.slice(r+1);if(n==="monitor"){let i=go(o,"monitor index");if(i<0)throw new l("monitor index must be >= 0.");return{kind:"monitor",index:i}}if(n==="window"){let i=o.trim();if(i==="")throw new l("window title must not be empty.");return{kind:"window",title:i}}if(n==="region"){let i=o.split(",").map(h=>h.trim());if(i.length!==4)throw new l(`region must be x,y,w,h (4 integers), got "${o}".`);let[s="",a="",c="",u=""]=i,[d,p,f,m]=[go(s,"region x"),go(a,"region y"),go(c,"region w"),go(u,"region h")];if(f<=0||m<=0)throw new l("region width and height must be positive.");return{kind:"region",x:d,y:p,w:f,h:m}}throw new l(`Unknown target kind "${n}". Use full | monitor | window | region.`)}function lp(t,e){let r=e.find(n=>n.index===t);if(!r){let n=e.map(o=>o.index).join(", ")||"none";throw new l(`monitor:${t} not found. Available monitor indexes: ${n}.`)}return r}function bo(t){if(t.length===0)return{x:0,y:0,w:0,h:0};let e=Math.min(...t.map(i=>i.x)),r=Math.min(...t.map(i=>i.y)),n=Math.max(...t.map(i=>i.x+i.width)),o=Math.max(...t.map(i=>i.y+i.height));return{x:e,y:r,w:n-e,h:o-r}}function pp(t,e){if(e.length===0)return;let r=bo(e);if(!(t.x>=r.x&&t.y>=r.y&&t.x+t.w<=r.x+r.w&&t.y+t.h<=r.y+r.h))throw new l(`region ${t.x},${t.y},${t.w},${t.h} is outside the virtual desktop (origin ${r.x},${r.y}, size ${r.w}x${r.h}). gdigrab captures the desktop, so the rectangle must fit inside it. Adjust the offset/size, or use monitor:<index> to capture a whole display.`)}function _e(t){let e=fc[t];if(!e)throw new l(`Unknown quality preset "${t}".`);return["-c:v","libx264","-preset",e.preset,"-crf",String(e.crf),"-pix_fmt","yuv420p"]}var qy="160k";function Cr(t=qy){return["-c:a","aac",...t?["-b:a",t]:[]]}var Pr=["-movflags","+faststart"];function Se(t){let e={aac:()=>Cr(t.bitrate),copy:()=>["-c:a","copy"],none:()=>["-an"],omit:()=>[]}[t.audio]();return[...t.video??_e(t.quality??"standard"),...e,...t.faststart?Pr:[]]}function tt(t){return t-t%2}function Si(t,e,r={}){switch(t.kind){case"full":{let n=bo(e);return r.evenSize&&e.length>0&&(n.w%2!==0||n.h%2!==0)?["-offset_x",String(n.x),"-offset_y",String(n.y),"-video_size",`${tt(n.w)}x${tt(n.h)}`,"-i","desktop"]:["-i","desktop"]}case"window":throw new l("Internal: a window target must be resolved to a region before building capture args. Call resolveCaptureTarget().");case"region":{let{w:n,h:o}=t;if(r.evenSize&&(n=tt(n),o=tt(o),n<=0||o<=0))throw new l(`region ${t.w}x${t.h} is too small to record: width and height must each be at least 2px (the video encoder needs even dimensions). Use a larger region, or take a screenshot instead.`);return["-offset_x",String(t.x),"-offset_y",String(t.y),"-video_size",`${n}x${o}`,"-i","desktop"]}case"monitor":{let n=lp(t.index,e),o=r.evenSize?tt(n.width):n.width,i=r.evenSize?tt(n.height):n.height;return["-offset_x",String(n.x),"-offset_y",String(n.y),"-video_size",`${o}x${i}`,"-i","desktop"]}}}function Xy(t){if(t.trim().length===0)throw new l("webcam device must not be empty.");return["-f","dshow","-use_wallclock_as_timestamps","1","-rtbufsize","256M","-i",`video=${t}`]}var hc=3600;function dp(t,e=process.env){if(t!==void 0)return mp(t);let r=e.SCREENCAST_MAX_RECORDING_SEC;if(r!==void 0&&r.trim()!==""){let n=Number(r);if(!Number.isInteger(n)||n<0||n>Mt)throw new l(`SCREENCAST_MAX_RECORDING_SEC must be an integer from 0 (no cap) to ${Mt} (7 days), got "${r}".`);return n}return hc}var Mt=168*3600;function mp(t){if(!Number.isInteger(t)||t<0||t>Mt)throw new l(`maxDurationSec must be an integer from 0 (no cap) to ${Mt} (7 days).`);return t}function Jy(t){if(!Number.isInteger(t)||t<1||t>120)throw new l("fps must be an integer between 1 and 120.");return t}function wi(t){return["-g",String(Math.max(1,Math.round(t*2)))]}var ap=["-movflags","+frag_keyframe+empty_moov+default_base_moof"];function vi(t,e){let r=Jy(e.fps??yi),n=e.quality??xi,o=e.monitors??[],i=mp(e.maxDurationSec??0),s=i>0?["-t",String(i)]:[],a=e.webcam,c=e.audio?2:1;return["-y",...e.videoInput??["-f","gdigrab","-framerate",String(r),...e.drawMouse===!1?["-draw_mouse","0"]:[],...Si(t,o,{evenSize:!0})],...cp(e.audio),...a?Xy(a.device):[],...a?["-map","0:v",...e.audio?["-map","1:a"]:[]]:[],...!e.videoInput&&t.kind==="full"&&o.length===0?["-vf","crop=trunc(iw/2)*2:trunc(ih/2)*2"]:[],...e.videoCodec??_e(n),...wi(r),...e.audio?Cr():[],...ap,...s,e.output,...a?["-map",`${c}:v`,...a.codec??_e(n),...wi(r),...ap,...s,a.output]:[]]}var Yy=30;function fp(t,e){if(!Number.isSafeInteger(t)||t<=0)throw new l("Invalid window handle.");return["-y","-v","error","-filter_complex",`gfxcapture=hwnd=${t}:max_framerate=30,hwdownload,format=bgra`,"-frames:v","1",...Ee(e)]}function $i(t,e,r=[]){return["-y","-f","gdigrab","-framerate",String(Yy),...Si(t,r),"-frames:v","1",...Ee(e)]}function ki(t,e){switch(t.kind){case"region":return{x:t.x,y:t.y,w:tt(t.w),h:tt(t.h)};case"monitor":{let r=lp(t.index,e);return{x:r.x,y:r.y,w:tt(r.width),h:tt(r.height)}}case"full":{let r=bo(e);return{x:r.x,y:r.y,w:tt(r.w),h:tt(r.h)}}case"window":throw new l("Internal: resolve a window target to a region first.")}}function gc(t){if(!/^[a-z]+$/.test(t))throw new l(`Invalid transition "${t}". Use a lowercase xfade name such as fade, dissolve, wipeleft, wiperight, slideup, or circleopen.`);return t}function er(t,e){if(t%2!==0)throw new l(`${e} must be even, got ${t}: H.264 output with yuv420p cannot encode odd dimensions. Use ${t-1} or ${t+1}.`);return t}var Ky=/[:,;=[\]'"\\\s]/;function Ne(t,e="color"){if(t.length===0||Ky.test(t))throw new l(`Invalid ${e} "${t}". Use a color name (black, white, red), a hex value (#RRGGBB or #RRGGBBAA), or name@alpha (e.g. white@0.5).`);return t}import{z as Ir}from"zod";var dn="standard";function bc(t){if(t===void 0)return null;let e=Number(t);return Number.isFinite(e)?e:null}function hp(t){if(!t)return null;let[e,r]=t.split("/"),n=Number(e),o=r===void 0?1:Number(r);return!Number.isFinite(n)||!Number.isFinite(o)||o===0||n===0?null:Math.round(n/o*1e3)/1e3}function Vy(t){let r=t?.side_data_list?.find(o=>o.rotation!==void 0)?.rotation??t?.tags?.rotate,n=r===void 0?NaN:Number(r);return Number.isFinite(n)?Math.round(n)%360:null}function Fr(t){let e=t.streams??[],r=e.find(u=>u.codec_type==="video"),n=e.find(u=>u.codec_type==="audio"),o=t.format?.duration,i=t.format?.size,s=o!==void 0?Number(o):null,a=Vy(r),c=a!==null&&Math.abs(a)%180===90;return{durationSec:s,videoDurationSec:r?bc(r.duration)??s:null,width:(c?r?.height:r?.width)??null,height:(c?r?.width:r?.height)??null,...a?{rotation:a}:{},fps:hp(r?.avg_frame_rate)??hp(r?.r_frame_rate),videoCodec:r?.codec_name??null,audioCodec:n?.codec_name??null,format:t.format?.format_name??null,sizeBytes:i!==void 0?Number(i):null,pixFmt:r?.pix_fmt??null,videoFrames:bc(r?.nb_frames),sampleRate:bc(n?.sample_rate),channels:n?.channels??null}}function Or(t){return["-v","quiet","-print_format","json","-show_format","-show_streams",t]}function wc(t,e){if(!Number.isFinite(t)||t<=0)throw new l(`${e} must be a positive number.`);return t}var _i=100,yc=1e3;function Ti(t,e,r){if(wc(e,"fps"),t===null||!(t>0))return{fps:e,requestedFrames:null,clamped:!1};let n=Math.ceil(t*e);return n<=r?{fps:e,requestedFrames:n,clamped:!1}:{fps:Math.max(1e-4,Math.floor(r/t*1e4)/1e4),requestedFrames:n,clamped:!0}}function bp(t,e){for(let r of t)if(/^frame_\d+\.png$/i.test(r))return`frame_${e}_`;return"frame_"}function Ai(t,e,r,n=_i,o=!1,i){wc(e,"fps");let s=o?`fps=${e},mpdecimate`:`fps=${e}`;return["-y",...i?["-ss",String(i.start),...i.duration!==void 0?["-t",String(i.duration)]:[]]:[],"-i",t,"-vf",s,...o?["-fps_mode","vfr"]:[],"-frames:v",String(n),r]}var ht=.1;function tr(t,e=ht){if(!Number.isFinite(e)||e<=0||e>=1)throw new l("sceneThreshold must be between 0 and 1 (exclusive).");return["-v","error","-i",t,"-an","-vf",`scale=320:-2,select='gt(scene\\,${e})',metadata=print:file=-`,"-f","null","-"]}function rr(t){let e=[],r=null;for(let n of t.split(/\r?\n/)){let o=n.match(/pts_time:\s*(-?[\d.]+)/);if(o){r=Number(o[1]);continue}let i=n.match(/lavfi\.scene_score=([\d.]+)/);i&&r!==null&&(e.push({timeSec:r,score:Number(i[1])}),r=null)}return e}function mn(t,e){return[0,...[...t].filter(n=>n.timeSec>0).sort((n,o)=>o.score-n.score).slice(0,Math.max(0,e-1)).map(n=>n.timeSec)].sort((n,o)=>n-o)}function fn(t,e,r){if(!Number.isFinite(e)||e<0)throw new l("timestamp must be a non-negative number.");return["-y","-ss",String(e),"-i",t,"-frames:v","1",...Ee(r)]}function V(t,e={}){let r=Ei(t).toLowerCase();return r===".mp4"||r===".mkv"||r===".mov"||e.audio&&wp.has(r)?r:".mp4"}var wp=new Set([".wav",".mp3",".m4a"]);function Ri(t){return wp.has(Ei(t).toLowerCase())}function Dr(t){if(t===void 0)return;let e=Ei(t).toLowerCase();if(e===".webm"||e===".gif")throw new l(`This tool writes H.264/AAC, which a ${e} file cannot hold. Use an .mp4, .mkv or .mov output, then convert (format: "webm") or export_gif the result.`)}function yp(t,e,r){let n=r.start;if(!Number.isFinite(n)||n<0)throw new l("start must be a non-negative number.");if(r.end===void 0&&r.duration===void 0)throw new l("trim requires either end or duration.");if(r.end!==void 0&&r.duration!==void 0)throw new l("trim takes end OR duration, not both.");let o=["-y","-ss",String(n),"-i",t];if(r.end!==void 0){if(r.end<=n)throw new l("end must be greater than start.");o.push("-t",String(Math.round((r.end-n)*1e3)/1e3))}else o.push("-t",String(wc(r.duration,"duration")));return r.exact===!1?o.push("-c","copy",e):o.push(...Se({quality:dn,audio:"aac",bitrate:null}),e),o}function wo(t){return t.map(e=>`file '${e.replace(/'/g,"'\\''")}'`).join(`
|
|
147
147
|
`)+`
|
|
148
|
-
`}function xp(t){if(t.length<2)throw new l("concat requires at least two input files.");return wo(t)}function hn(t,e,r={}){return["-y",...r.quiet?["-v","error"]:[],"-f","concat","-safe","0","-i",t,"-c","copy",e]}function Qy(t){let{videoFrames:e,videoDurationSec:r,fps:n}=t;return e===null||r===null||n===null?!1:e>r*n*1.05+2}function Sp(t,e){let r=[["videoCodec","video codec"],["width","width"],["height","height"],["pixFmt","pixel format"],["fps","frame rate"],["audioCodec","audio codec"],["sampleRate","audio sample rate"],["channels","audio channels"]],n=e[0];for(let[o,i]of e.entries()){if(Qy(i))return`${t[o]} holds hidden frames behind an edit list`;if(!(o===0||!n)){for(let[s,a]of r)if(i[s]!==n[s])return`${a} differs: ${t[0]} has ${n[s]??"none"}, ${t[o]} has ${i[s]??"none"}`}}return null}function vp(t,e,r,n={}){switch(r){case"gif":{let o=n.fps??12,i=n.width??720,s=`fps=${o},scale='min(${i},iw)':-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse`;return["-y","-i",t,"-vf",s,e]}case"webm":return["-y","-i",t,"-c:v","libvpx-vp9","-b:v","0","-crf","30","-deadline","good","-cpu-used","4","-row-mt","1",e];case"mp4":return["-y","-i",t,...Se({quality:"standard",audio:"omit",faststart:!0}),e];default:throw new l(`Unsupported convert format "${r}".`)}}function pn(t,e){if(!Number.isInteger(t)||t<0)throw new l(`${e} must be a non-negative integer.`);return t}function Ct(t,e){if(!Number.isInteger(t)||t<=0)throw new l(`${e} must be a positive integer.`);return t}function Mi(t,e){if(t!==void 0&&e!==void 0){if(e<=t)throw new l("end must be greater than start.");return`between(t,${t},${e})`}return t!==void 0?`gte(t,${t})`:e!==void 0?`lte(t,${e})`:""}function xc(t,e){let r=pn(t.x,"crop x"),n=pn(t.y,"crop y"),o=er(Ct(t.width,"crop width"),"crop width"),i=er(Ct(t.height,"crop height"),"crop height");if(e&&e.width!=null&&e.height!=null&&(r+o>e.width||n+i>e.height))throw new l(`crop region ${o}x${i}+${r}+${n} falls outside the ${e.width}x${e.height} frame.`);return`crop=${o}:${i}:${r}:${n}`}function $p(t,e,r,n,o=dn){return["-y","-i",t,"-vf",xc(r,n),...Se({quality:o,audio:"copy"}),e]}function Sc(t){if(t.width===void 0&&t.height===void 0)throw new l("scale requires width or height (or both).");return t.width!==void 0&&er(Ct(t.width,"scale width"),"scale width"),t.height!==void 0&&er(Ct(t.height,"scale height"),"scale height"),`scale=${t.width??-2}:${t.height??-2}`}function kp(t,e,r){let n=o=>Math.max(2,Math.round(o/2)*2);return r.width!==void 0&&r.height!==void 0?{width:r.width,height:r.height}:r.width!==void 0?{width:r.width,height:n(e*r.width/t)}:{width:n(t*r.height/e),height:r.height}}function Ep(t,e,r,n=dn){return["-y","-i",t,"-vf",Sc(r),...Se({quality:n,audio:"copy"}),e]}function vc(t){let e=t,r=[];for(;e>2;)r.push("atempo=2.0"),e/=2;for(;e<.5;)r.push("atempo=0.5"),e/=.5;return r.push(`atempo=${Number(e.toFixed(6))}`),r.join(",")}function _p(t,e,r,n,o=dn){if(!Number.isFinite(r)||r<=0)throw new l("speed factor must be a positive number.");let i=["-y","-i",t,"-filter:v",`setpts=PTS/${r}`];return n&&i.push("-filter:a",vc(r)),i.push(...Se({quality:o,audio:n?"aac":"none",bitrate:null}),e),i}var Zy="crop='min(iw,ih)':'min(iw,ih)',format=yuva420p,geq=lum='p(X,Y)':cb='p(X,Y)':cr='p(X,Y)':a='if(lte(hypot(X-W/2,Y-H/2),W/2),255,0)'";function Tp(t,e,r,n,o=dn){let i=pn(n.x,"overlay x"),s=pn(n.y,"overlay y"),a=Mi(n.start,n.end),c=a?`:enable='${a}'`:"",d=`[1:v]${`setpts=PTS-STARTPTS+${n.start??0}/TB`}`;if(n.scale&&(n.scale.width!==void 0||n.scale.height!==void 0)){n.scale.width!==void 0&&Ct(n.scale.width,"overlay scale width"),n.scale.height!==void 0&&Ct(n.scale.height,"overlay scale height");let m=n.scale.width??-1,h=n.scale.height??-1;d+=`,scale=${m}:${h}`}n.shape==="circle"&&(d+=`,${Zy}`);let p=`${d}[ovl];[0:v][ovl]overlay=${i}:${s}${c}[v]`,f=n.durationSec;return["-y","-i",t,"-i",e,"-filter_complex",p,"-map","[v]","-map","0:a?",...Se({quality:o,audio:"copy"}),...f!=null&&f>0?["-t",String(f)]:[],r]}var ex={light:23,medium:28,heavy:32};function Ap(t,e,r={}){let n=r.level??"medium",o=ex[n];if(o===void 0)throw new l(`Unknown compress level "${n}".`);let i=["-y","-i",t];return r.maxWidth!==void 0&&(Ct(r.maxWidth,"maxWidth"),i.push("-vf",`scale='trunc(min(${r.maxWidth},iw)/2)*2':-2`)),i.push(...Se({video:["-c:v","libx264","-preset","slow","-crf",String(o),"-pix_fmt","yuv420p"],audio:"aac",bitrate:"128k",faststart:!0}),e),i}var tx={mp3:["-c:a","libmp3lame","-q:a","2"],aac:Cr("192k"),wav:["-c:a","pcm_s16le"],copy:["-c:a","copy"]};function Rp(t){switch(t){case"aac":case"alac":return"m4a";case"mp3":return"mp3";case"opus":case"vorbis":return"ogg";case"flac":return"flac";default:return t&&t.startsWith("pcm_")?"wav":"mka"}}function Mp(t,e,r){let n=tx[r];if(!n)throw new l(`Unknown audio format "${r}".`);return["-y","-i",t,"-vn",...n,e]}function Cp(t,e,r,n=dn){if(!Number.isFinite(r.start)||r.start<0)throw new l("clip start must be a non-negative number.");if(!Number.isFinite(r.end)||r.end<=r.start)throw new l("clip end must be greater than start.");return["-y","-i",t,"-ss",String(r.start),"-t",String(r.end-r.start),...Se({quality:n,audio:"aac",bitrate:null}),e]}var Ci=["box","blur","pixelate"];function rx(t,e,r){return t.map((n,o)=>{let i=pn(n.x,`region[${o}] x`),s=pn(n.y,`region[${o}] y`),a=Ct(n.width,`region[${o}] width`),c=Ct(n.height,`region[${o}] height`);if(r&&r.width!=null&&r.height!=null&&(i+a>r.width||s+c>r.height))throw new l(`region[${o}] ${a}x${c}+${i}+${s} falls outside the ${r.width}x${r.height} frame.`);let u=Math.max(0,i-e),d=Math.max(0,s-e),p=i+a+e,f=s+c+e;return r&&r.width!=null&&(p=Math.min(p,r.width)),r&&r.height!=null&&(f=Math.min(f,r.height)),{x:u,y:d,w:p-u,h:f-d,enable:Mi(n.start,n.end)}})}var nx=8,gp=3,ox=16;function ix(t){let e=Math.min(t.w,t.h),r=i=>Math.max(0,Math.floor((i-1)/2)),n=Math.min(r(e),Math.max(nx,Math.min(20,Math.floor(e/4)))),o=Math.min(n,r(Math.ceil(e/2)));return`lr=${n}:lp=${gp}:cr=${o}:cp=${gp}`}function sx(t){let e=Math.max(ox,Math.ceil(Math.max(t.w,t.h)/16)),r=Math.max(1,Math.round(t.w/e)),n=Math.max(1,Math.round(t.h/e));return`scale=${r}:${n}:flags=area,scale=${t.w}:${t.h}:flags=neighbor`}function $c(t,e,r,n,o){if(t.length===0)throw new l("redact_region requires at least one region.");let i=e.style??"box",s=e.pad??0;if(!Number.isInteger(s)||s<0)throw new l("pad must be a non-negative integer.");let a=Ne(e.color??"black","color"),c=rx(t,s,r);if(i==="box"){let m=c.map(h=>{let g=h.enable?`:enable='${h.enable}'`:"";return`drawbox=x=${h.x}:y=${h.y}:w=${h.w}:h=${h.h}:color=${a}:t=fill${g}`}).join(",");return{steps:[`${n}${m}[${o}out]`],out:`[${o}out]`}}let u=c.length,d=[],p=[`${o}base`,...c.map((m,h)=>`${o}s${h}`)];d.push(`${n}split=${u+1}[${p.join("][")}]`),c.forEach((m,h)=>{let g=`crop=${m.w}:${m.h}:${m.x}:${m.y}`,w=i==="blur"?`boxblur=${ix(m)}`:sx(m);d.push(`[${o}s${h}]${g},${w}[${o}b${h}]`)});let f=`${o}base`;return c.forEach((m,h)=>{let g=m.enable?`:enable='${m.enable}'`:"",w=h===u-1?`${o}out`:`${o}c${h}`;d.push(`[${f}][${o}b${h}]overlay=${m.x}:${m.y}${g}[${w}]`),f=`${o}c${h}`}),{steps:d,out:`[${o}out]`}}function Pi(t,e){if(!dc(t))return Dr(e),{still:!1,ext:V(t)};if(e&&!dc(e))throw new l("An image input writes an image: give the output a .png or .jpg extension.");return{still:!0,ext:/\.jpe?g$/i.test(t)?Ei(t).toLowerCase():".png"}}function Pp(t,e,r,n={},o,i=!1){let s=i?r.map(({start:d,end:p,...f})=>f):r,{steps:a,out:c}=$c(s,n,o,"[0:v]","");if(i)return["-y","-i",t,"-filter_complex",a.join(";"),"-map",c,"-frames:v","1",...Ee(e)];let[u]=a;if((n.style??"box")==="box"&&u!==void 0){let d=u.slice(5,-c.length);return["-y","-i",t,"-vf",d,...Se({quality:"high",audio:"copy"}),e]}return["-y","-i",t,"-filter_complex",a.join(";"),"-map",c,"-map","0:a?",...Se({quality:"high",audio:"copy"}),e]}var gn=Ir.object({x:Ir.number().int().nonnegative(),y:Ir.number().int().nonnegative(),width:Ir.number().int().positive(),height:Ir.number().int().positive(),start:Ir.number().nonnegative().optional(),end:Ir.number().positive().optional()});var ax="screencast-mcp",Ip=new Set;function Fp(t){Ip.add(t)}function nr(t,e,r={}){for(let n of Ip)n.isConnected()&&n.sendLoggingMessage({level:t,logger:ax,data:{message:e,...r}}).catch(()=>{})}var Op=/^\s*(?:frame|size)=/,cx=/\b(?:warning|deprecated|dropp(?:ed|ing)|too full|discard\w*|non[- ]?monoton\w*|past duration|could not|cannot|failed|invalid|corrupt\w*|missing|error)\b/i,ux=/^\s*configuration:|deprecated pixel format used/i,Dp=20;function Np(t){return!Op.test(t)&&cx.test(t)&&!ux.test(t)}function lx(t){let e=new Set;for(let r of t.split(/[\r\n]+/)){let n=r.trim();if(n&&Np(n)&&e.add(n),e.size>=Dp)break}return[...e]}function Lp(t,e={}){let r=lx(t);r.length>0&&nr("warning","ffmpeg reported warnings.",{...e,warnings:r})}var px=1e4,Ii=class{constructor(e,r=nr,n=Date.now){this.data=e;this.send=r;this.now=n}data;send;now;partial="";seen=new Set;dropped=0;lastDropReport=-1/0;feed(e){let r=(this.partial+e).split(/[\r\n]/);this.partial=r.pop()??"";for(let n of r)this.line(n.trim())}line(e){if(e){if(Op.test(e)){let r=Number(/\bdrop=\s*(\d+)/.exec(e)?.[1]??0);r>this.dropped&&this.now()-this.lastDropReport>=px&&(this.lastDropReport=this.now(),this.dropped=r,this.send("warning",`The recording has dropped ${r} frame(s) so far.`,{...this.data(),dropped:r}));return}!Np(e)||this.seen.has(e)||this.seen.size>=Dp||(this.seen.add(e),this.send("warning",e,{...this.data(),source:"ffmpeg"}))}}};var bx="ffmpeg and ffprobe must be installed and on PATH (or set FFMPEG_PATH / FFPROBE_PATH). Windows: `winget install Gyan.FFmpeg` or `choco install ffmpeg`. macOS: `brew install ffmpeg`. Linux: `apt install ffmpeg`.";function Wp(t,e){let r=process.env[t];return r&&r.trim().length>0?r:e}function jp(t){try{return Oi(t,["-version"],{stdio:"ignore",windowsHide:!0}).status===0}catch{return!1}}function kc(){let t=Wp("FFMPEG_PATH","ffmpeg"),e=Wp("FFPROBE_PATH","ffprobe"),r=[];if(jp(t)||r.push("ffmpeg"),jp(e)||r.push("ffprobe"),r.length>0)throw new l(`Required ${r.join(" and ")} not found on PATH.`,bx);return{ffmpeg:t,ffprobe:e}}var Fi=null;function k(){return Fi||(Fi=kc(),Fi)}var bn=null;function or(){if(bn!==null)return bn;if(process.platform!=="win32")return bn=!1;try{let t=Oi(k().ffmpeg,["-hide_banner","-h","filter=gfxcapture"],{encoding:"utf8",windowsHide:!0,timeout:1e4});bn=/gfxcapture AVOptions/.test(t.stdout??"")}catch{bn=!1}return bn}var Up=new Map;function Ye(t){let e=Up.get(t);if(e!==void 0)return e;let r;try{let n=Oi(k().ffmpeg,["-hide_banner","-h",`filter=${t}`],{encoding:"utf8",windowsHide:!0,timeout:1e4});r=new RegExp(`^Filter ${t}\\b`,"m").test(n.stdout??"")}catch{r=!1}return Up.set(t,r),r}var Hp=["ignore","pipe","pipe"],xo=class extends l{};function ne(t,e,r=300*1e3,n={}){return new Promise((o,i)=>{let s=zp(t,e,{windowsHide:!0,stdio:Hp}),a="",c="",u=null,d,p=b=>{u||(u=b,s.kill("SIGKILL"),d=setTimeout(()=>i(b),5e3))},f=()=>p(new l(`${t} was cancelled.`)),m=setTimeout(()=>p(new l(`${t} timed out after ${Math.round(r/1e3)}s.`)),r),h,g=()=>{n.stallMs&&(clearTimeout(h),h=setTimeout(()=>p(new xo(`${t} wrote nothing for ${Math.round(n.stallMs/1e3)}s and was stopped.`)),n.stallMs))};g();let w=()=>{clearTimeout(m),clearTimeout(h),clearTimeout(d),n.signal?.removeEventListener("abort",f)};n.signal?.aborted?f():n.signal?.addEventListener("abort",f,{once:!0}),s.stdout?.on("data",b=>{g();let y=b.toString();a+=y,n.onStdout?.(y)}),s.stderr?.on("data",b=>{g(),c+=b.toString()}),s.on("error",b=>{w(),i(b)}),s.on("close",b=>{w(),u?i(u):o({code:b,stdout:a,stderr:c})})})}var wx=new Set(["-vf","-af","-filter_complex","-lavfi","-filter:v","-filter:a"]),yx=8e3,xx={"-vf":"-filter_script:v","-filter:v":"-filter_script:v","-af":"-filter_script:a","-filter:a":"-filter_script:a","-filter_complex":"-filter_complex_script","-lavfi":"-filter_complex_script"},yo=null;function Sx(){if(yo!==null)return yo;try{let t=Oi(k().ffmpeg,["-hide_banner","-version"],{encoding:"utf8",windowsHide:!0,timeout:1e4}),e=/^\s*libavutil\s+(\d+)\./m.exec(t.stdout??"");yo=e?.[1]===void 0||Number(e[1])>=59}catch{yo=!0}return yo}function Di(t,e){let r=null,n=[...t];for(let[i,s]of t.entries()){let a=t[i-1];if(a===void 0||!wx.has(a)||s.length<=yx)continue;r??=mx(Bp(gx(),"screencast-filter-"));let c=Bp(r,`filter${i}.txt`);hx(c,s),e??=Sx(),n[i-1]=e?`-/${a.slice(1)}`:xx[a]??a,n[i]=c}let o=r;return{args:n,cleanup:()=>o&&fx(o,{recursive:!0,force:!0})}}async function Nr(t,e=3e4,r={}){let n=[];return await Gp(t,e,o=>n.push(o),r),Buffer.concat(n)}async function Ni(t,e,r,n=3e4,o={}){if(!(e>0))throw new l("frameBytes must be positive.");let i=Buffer.alloc(0),s=0;return await Gp(t,n,a=>{i=i.length?Buffer.concat([i,a]):a;let c=0;for(;c+e<=i.length;c+=e)r(Buffer.from(i.subarray(c,c+e))),s++;i=i.subarray(c)},o),s}function Gp(t,e,r,n){let{ffmpeg:o}=k(),{args:i,cleanup:s}=Di(t);return new Promise((a,c)=>{let u=zp(o,i,{windowsHide:!0,stdio:Hp}),d="",p=null,f,m=b=>{p||(p=b,u.kill("SIGKILL"),f=setTimeout(()=>c(b),5e3))},h=()=>m(new l("ffmpeg was cancelled.")),g=setTimeout(()=>m(new l(`ffmpeg timed out after ${Math.round(e/1e3)}s.`)),e),w=()=>{clearTimeout(g),clearTimeout(f),n.signal?.removeEventListener("abort",h)};n.signal?.aborted?h():n.signal?.addEventListener("abort",h,{once:!0}),u.stdout?.on("data",b=>{if(!p)try{r(b)}catch(y){m(y)}}),u.stderr?.on("data",b=>d+=b.toString()),u.on("error",b=>{w(),c(b)}),u.on("close",b=>{w(),p?c(p):b===0?a():c(new l(`ffmpeg failed (exit ${b}):
|
|
148
|
+
`}function xp(t){if(t.length<2)throw new l("concat requires at least two input files.");return wo(t)}function hn(t,e,r={}){return["-y",...r.quiet?["-v","error"]:[],"-f","concat","-safe","0","-i",t,"-c","copy",e]}function Qy(t){let{videoFrames:e,videoDurationSec:r,fps:n}=t;return e===null||r===null||n===null?!1:e>r*n*1.05+2}function Sp(t,e){let r=[["videoCodec","video codec"],["width","width"],["height","height"],["pixFmt","pixel format"],["fps","frame rate"],["audioCodec","audio codec"],["sampleRate","audio sample rate"],["channels","audio channels"]],n=e[0];for(let[o,i]of e.entries()){if(Qy(i))return`${t[o]} holds hidden frames behind an edit list`;if(!(o===0||!n)){for(let[s,a]of r)if(i[s]!==n[s])return`${a} differs: ${t[0]} has ${n[s]??"none"}, ${t[o]} has ${i[s]??"none"}`}}return null}function vp(t,e,r,n={}){switch(r){case"gif":{let o=n.fps??12,i=n.width??720,s=`fps=${o},scale='min(${i},iw)':-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse`;return["-y","-i",t,"-vf",s,e]}case"webm":return["-y","-i",t,"-c:v","libvpx-vp9","-b:v","0","-crf","30","-deadline","good","-cpu-used","4","-row-mt","1",e];case"mp4":return["-y","-i",t,...Se({quality:"standard",audio:"omit",faststart:!0}),e];default:throw new l(`Unsupported convert format "${r}".`)}}function pn(t,e){if(!Number.isInteger(t)||t<0)throw new l(`${e} must be a non-negative integer.`);return t}function Ct(t,e){if(!Number.isInteger(t)||t<=0)throw new l(`${e} must be a positive integer.`);return t}function Mi(t,e){if(t!==void 0&&e!==void 0){if(e<=t)throw new l("end must be greater than start.");return`between(t,${t},${e})`}return t!==void 0?`gte(t,${t})`:e!==void 0?`lte(t,${e})`:""}function xc(t,e){let r=pn(t.x,"crop x"),n=pn(t.y,"crop y"),o=er(Ct(t.width,"crop width"),"crop width"),i=er(Ct(t.height,"crop height"),"crop height");if(e&&e.width!=null&&e.height!=null&&(r+o>e.width||n+i>e.height))throw new l(`crop region ${o}x${i}+${r}+${n} falls outside the ${e.width}x${e.height} frame.`);return`crop=${o}:${i}:${r}:${n}`}function $p(t,e,r,n,o=dn){return["-y","-i",t,"-vf",xc(r,n),...Se({quality:o,audio:"copy"}),e]}function Sc(t){if(t.width===void 0&&t.height===void 0)throw new l("scale requires width or height (or both).");return t.width!==void 0&&er(Ct(t.width,"scale width"),"scale width"),t.height!==void 0&&er(Ct(t.height,"scale height"),"scale height"),`scale=${t.width??-2}:${t.height??-2}`}function kp(t,e,r){let n=o=>Math.max(2,Math.round(o/2)*2);return r.width!==void 0&&r.height!==void 0?{width:r.width,height:r.height}:r.width!==void 0?{width:r.width,height:n(e*r.width/t)}:{width:n(t*r.height/e),height:r.height}}function Ep(t,e,r,n=dn){return["-y","-i",t,"-vf",Sc(r),...Se({quality:n,audio:"copy"}),e]}function vc(t){let e=t,r=[];for(;e>2;)r.push("atempo=2.0"),e/=2;for(;e<.5;)r.push("atempo=0.5"),e/=.5;return r.push(`atempo=${Number(e.toFixed(6))}`),r.join(",")}function _p(t,e,r,n,o=dn){if(!Number.isFinite(r)||r<=0)throw new l("speed factor must be a positive number.");let i=["-y","-i",t,"-filter:v",`setpts=PTS/${r}`];return n&&i.push("-filter:a",vc(r)),i.push(...Se({quality:o,audio:n?"aac":"none",bitrate:null}),e),i}var Zy="crop='min(iw,ih)':'min(iw,ih)',format=yuva420p,geq=lum='p(X,Y)':cb='p(X,Y)':cr='p(X,Y)':a='if(lte(hypot(X-W/2,Y-H/2),W/2),255,0)'";function Tp(t,e,r,n,o=dn){let i=pn(n.x,"overlay x"),s=pn(n.y,"overlay y"),a=Mi(n.start,n.end),c=a?`:enable='${a}'`:"",d=`[1:v]${`setpts=PTS-STARTPTS+${n.start??0}/TB`}`;if(n.scale&&(n.scale.width!==void 0||n.scale.height!==void 0)){n.scale.width!==void 0&&Ct(n.scale.width,"overlay scale width"),n.scale.height!==void 0&&Ct(n.scale.height,"overlay scale height");let m=n.scale.width??-1,h=n.scale.height??-1;d+=`,scale=${m}:${h}`}n.shape==="circle"&&(d+=`,${Zy}`);let p=`${d}[ovl];[0:v][ovl]overlay=${i}:${s}${c}[v]`,f=n.durationSec;return["-y","-i",t,"-i",e,"-filter_complex",p,"-map","[v]","-map","0:a?",...Se({quality:o,audio:"copy"}),...f!=null&&f>0?["-t",String(f)]:[],r]}var ex={light:23,medium:28,heavy:32};function Ap(t,e,r={}){let n=r.level??"medium",o=ex[n];if(o===void 0)throw new l(`Unknown compress level "${n}".`);let i=["-y","-i",t];return r.maxWidth!==void 0&&(Ct(r.maxWidth,"maxWidth"),i.push("-vf",`scale='trunc(min(${r.maxWidth},iw)/2)*2':-2`)),i.push(...Se({video:["-c:v","libx264","-preset","slow","-crf",String(o),"-pix_fmt","yuv420p"],audio:"aac",bitrate:"128k",faststart:!0}),e),i}var tx={mp3:["-c:a","libmp3lame","-q:a","2"],aac:Cr("192k"),wav:["-c:a","pcm_s16le"],copy:["-c:a","copy"]};function Rp(t){switch(t){case"aac":case"alac":return"m4a";case"mp3":return"mp3";case"opus":case"vorbis":return"ogg";case"flac":return"flac";default:return t&&t.startsWith("pcm_")?"wav":"mka"}}function Mp(t,e,r){let n=tx[r];if(!n)throw new l(`Unknown audio format "${r}".`);return["-y","-i",t,"-vn",...n,e]}function Cp(t,e,r,n=dn){if(!Number.isFinite(r.start)||r.start<0)throw new l("clip start must be a non-negative number.");if(!Number.isFinite(r.end)||r.end<=r.start)throw new l("clip end must be greater than start.");return["-y","-ss",String(r.start),"-i",t,"-t",String(r.end-r.start),...Se({quality:n,audio:"aac",bitrate:null}),e]}var Ci=["box","blur","pixelate"];function rx(t,e,r){return t.map((n,o)=>{let i=pn(n.x,`region[${o}] x`),s=pn(n.y,`region[${o}] y`),a=Ct(n.width,`region[${o}] width`),c=Ct(n.height,`region[${o}] height`);if(r&&r.width!=null&&r.height!=null&&(i+a>r.width||s+c>r.height))throw new l(`region[${o}] ${a}x${c}+${i}+${s} falls outside the ${r.width}x${r.height} frame.`);let u=Math.max(0,i-e),d=Math.max(0,s-e),p=i+a+e,f=s+c+e;return r&&r.width!=null&&(p=Math.min(p,r.width)),r&&r.height!=null&&(f=Math.min(f,r.height)),{x:u,y:d,w:p-u,h:f-d,enable:Mi(n.start,n.end)}})}var nx=8,gp=3,ox=16;function ix(t){let e=Math.min(t.w,t.h),r=i=>Math.max(0,Math.floor((i-1)/2)),n=Math.min(r(e),Math.max(nx,Math.min(20,Math.floor(e/4)))),o=Math.min(n,r(Math.ceil(e/2)));return`lr=${n}:lp=${gp}:cr=${o}:cp=${gp}`}function sx(t){let e=Math.max(ox,Math.ceil(Math.max(t.w,t.h)/16)),r=Math.max(1,Math.round(t.w/e)),n=Math.max(1,Math.round(t.h/e));return`scale=${r}:${n}:flags=area,scale=${t.w}:${t.h}:flags=neighbor`}function $c(t,e,r,n,o){if(t.length===0)throw new l("redact_region requires at least one region.");let i=e.style??"box",s=e.pad??0;if(!Number.isInteger(s)||s<0)throw new l("pad must be a non-negative integer.");let a=Ne(e.color??"black","color"),c=rx(t,s,r);if(i==="box"){let m=c.map(h=>{let g=h.enable?`:enable='${h.enable}'`:"";return`drawbox=x=${h.x}:y=${h.y}:w=${h.w}:h=${h.h}:color=${a}:t=fill${g}`}).join(",");return{steps:[`${n}${m}[${o}out]`],out:`[${o}out]`}}let u=c.length,d=[],p=[`${o}base`,...c.map((m,h)=>`${o}s${h}`)];d.push(`${n}split=${u+1}[${p.join("][")}]`),c.forEach((m,h)=>{let g=`crop=${m.w}:${m.h}:${m.x}:${m.y}`,w=i==="blur"?`boxblur=${ix(m)}`:sx(m);d.push(`[${o}s${h}]${g},${w}[${o}b${h}]`)});let f=`${o}base`;return c.forEach((m,h)=>{let g=m.enable?`:enable='${m.enable}'`:"",w=h===u-1?`${o}out`:`${o}c${h}`;d.push(`[${f}][${o}b${h}]overlay=${m.x}:${m.y}${g}[${w}]`),f=`${o}c${h}`}),{steps:d,out:`[${o}out]`}}function Pi(t,e){if(!dc(t))return Dr(e),{still:!1,ext:V(t)};if(e&&!dc(e))throw new l("An image input writes an image: give the output a .png or .jpg extension.");return{still:!0,ext:/\.jpe?g$/i.test(t)?Ei(t).toLowerCase():".png"}}function Pp(t,e,r,n={},o,i=!1){let s=i?r.map(({start:d,end:p,...f})=>f):r,{steps:a,out:c}=$c(s,n,o,"[0:v]","");if(i)return["-y","-i",t,"-filter_complex",a.join(";"),"-map",c,"-frames:v","1",...Ee(e)];let[u]=a;if((n.style??"box")==="box"&&u!==void 0){let d=u.slice(5,-c.length);return["-y","-i",t,"-vf",d,...Se({quality:"high",audio:"copy"}),e]}return["-y","-i",t,"-filter_complex",a.join(";"),"-map",c,"-map","0:a?",...Se({quality:"high",audio:"copy"}),e]}var gn=Ir.object({x:Ir.number().int().nonnegative(),y:Ir.number().int().nonnegative(),width:Ir.number().int().positive(),height:Ir.number().int().positive(),start:Ir.number().nonnegative().optional(),end:Ir.number().positive().optional()});var ax="screencast-mcp",Ip=new Set;function Fp(t){Ip.add(t)}function nr(t,e,r={}){for(let n of Ip)n.isConnected()&&n.sendLoggingMessage({level:t,logger:ax,data:{message:e,...r}}).catch(()=>{})}var Op=/^\s*(?:frame|size)=/,cx=/\b(?:warning|deprecated|dropp(?:ed|ing)|too full|discard\w*|non[- ]?monoton\w*|past duration|could not|cannot|failed|invalid|corrupt\w*|missing|error)\b/i,ux=/^\s*configuration:|deprecated pixel format used/i,Dp=20;function Np(t){return!Op.test(t)&&cx.test(t)&&!ux.test(t)}function lx(t){let e=new Set;for(let r of t.split(/[\r\n]+/)){let n=r.trim();if(n&&Np(n)&&e.add(n),e.size>=Dp)break}return[...e]}function Lp(t,e={}){let r=lx(t);r.length>0&&nr("warning","ffmpeg reported warnings.",{...e,warnings:r})}var px=1e4,Ii=class{constructor(e,r=nr,n=Date.now){this.data=e;this.send=r;this.now=n}data;send;now;partial="";seen=new Set;dropped=0;lastDropReport=-1/0;feed(e){let r=(this.partial+e).split(/[\r\n]/);this.partial=r.pop()??"";for(let n of r)this.line(n.trim())}line(e){if(e){if(Op.test(e)){let r=Number(/\bdrop=\s*(\d+)/.exec(e)?.[1]??0);r>this.dropped&&this.now()-this.lastDropReport>=px&&(this.lastDropReport=this.now(),this.dropped=r,this.send("warning",`The recording has dropped ${r} frame(s) so far.`,{...this.data(),dropped:r}));return}!Np(e)||this.seen.has(e)||this.seen.size>=Dp||(this.seen.add(e),this.send("warning",e,{...this.data(),source:"ffmpeg"}))}}};var bx="ffmpeg and ffprobe must be installed and on PATH (or set FFMPEG_PATH / FFPROBE_PATH). Windows: `winget install Gyan.FFmpeg` or `choco install ffmpeg`. macOS: `brew install ffmpeg`. Linux: `apt install ffmpeg`.";function Wp(t,e){let r=process.env[t];return r&&r.trim().length>0?r:e}function jp(t){try{return Oi(t,["-version"],{stdio:"ignore",windowsHide:!0}).status===0}catch{return!1}}function kc(){let t=Wp("FFMPEG_PATH","ffmpeg"),e=Wp("FFPROBE_PATH","ffprobe"),r=[];if(jp(t)||r.push("ffmpeg"),jp(e)||r.push("ffprobe"),r.length>0)throw new l(`Required ${r.join(" and ")} not found on PATH.`,bx);return{ffmpeg:t,ffprobe:e}}var Fi=null;function k(){return Fi||(Fi=kc(),Fi)}var bn=null;function or(){if(bn!==null)return bn;if(process.platform!=="win32")return bn=!1;try{let t=Oi(k().ffmpeg,["-hide_banner","-h","filter=gfxcapture"],{encoding:"utf8",windowsHide:!0,timeout:1e4});bn=/gfxcapture AVOptions/.test(t.stdout??"")}catch{bn=!1}return bn}var Up=new Map;function Ye(t){let e=Up.get(t);if(e!==void 0)return e;let r;try{let n=Oi(k().ffmpeg,["-hide_banner","-h",`filter=${t}`],{encoding:"utf8",windowsHide:!0,timeout:1e4});r=new RegExp(`^Filter ${t}\\b`,"m").test(n.stdout??"")}catch{r=!1}return Up.set(t,r),r}var Hp=["ignore","pipe","pipe"],xo=class extends l{};function ne(t,e,r=300*1e3,n={}){return new Promise((o,i)=>{let s=zp(t,e,{windowsHide:!0,stdio:Hp}),a="",c="",u=null,d,p=b=>{u||(u=b,s.kill("SIGKILL"),d=setTimeout(()=>i(b),5e3))},f=()=>p(new l(`${t} was cancelled.`)),m=setTimeout(()=>p(new l(`${t} timed out after ${Math.round(r/1e3)}s.`)),r),h,g=()=>{n.stallMs&&(clearTimeout(h),h=setTimeout(()=>p(new xo(`${t} wrote nothing for ${Math.round(n.stallMs/1e3)}s and was stopped.`)),n.stallMs))};g();let w=()=>{clearTimeout(m),clearTimeout(h),clearTimeout(d),n.signal?.removeEventListener("abort",f)};n.signal?.aborted?f():n.signal?.addEventListener("abort",f,{once:!0}),s.stdout?.on("data",b=>{g();let y=b.toString();a+=y,n.onStdout?.(y)}),s.stderr?.on("data",b=>{g(),c+=b.toString()}),s.on("error",b=>{w(),i(b)}),s.on("close",b=>{w(),u?i(u):o({code:b,stdout:a,stderr:c})})})}var wx=new Set(["-vf","-af","-filter_complex","-lavfi","-filter:v","-filter:a"]),yx=8e3,xx={"-vf":"-filter_script:v","-filter:v":"-filter_script:v","-af":"-filter_script:a","-filter:a":"-filter_script:a","-filter_complex":"-filter_complex_script","-lavfi":"-filter_complex_script"},yo=null;function Sx(){if(yo!==null)return yo;try{let t=Oi(k().ffmpeg,["-hide_banner","-version"],{encoding:"utf8",windowsHide:!0,timeout:1e4}),e=/^\s*libavutil\s+(\d+)\./m.exec(t.stdout??"");yo=e?.[1]===void 0||Number(e[1])>=59}catch{yo=!0}return yo}function Di(t,e){let r=null,n=[...t];for(let[i,s]of t.entries()){let a=t[i-1];if(a===void 0||!wx.has(a)||s.length<=yx)continue;r??=mx(Bp(gx(),"screencast-filter-"));let c=Bp(r,`filter${i}.txt`);hx(c,s),e??=Sx(),n[i-1]=e?`-/${a.slice(1)}`:xx[a]??a,n[i]=c}let o=r;return{args:n,cleanup:()=>o&&fx(o,{recursive:!0,force:!0})}}async function Nr(t,e=3e4,r={}){let n=[];return await Gp(t,e,o=>n.push(o),r),Buffer.concat(n)}async function Ni(t,e,r,n=3e4,o={}){if(!(e>0))throw new l("frameBytes must be positive.");let i=Buffer.alloc(0),s=0;return await Gp(t,n,a=>{i=i.length?Buffer.concat([i,a]):a;let c=0;for(;c+e<=i.length;c+=e)r(Buffer.from(i.subarray(c,c+e))),s++;i=i.subarray(c)},o),s}function Gp(t,e,r,n){let{ffmpeg:o}=k(),{args:i,cleanup:s}=Di(t);return new Promise((a,c)=>{let u=zp(o,i,{windowsHide:!0,stdio:Hp}),d="",p=null,f,m=b=>{p||(p=b,u.kill("SIGKILL"),f=setTimeout(()=>c(b),5e3))},h=()=>m(new l("ffmpeg was cancelled.")),g=setTimeout(()=>m(new l(`ffmpeg timed out after ${Math.round(e/1e3)}s.`)),e),w=()=>{clearTimeout(g),clearTimeout(f),n.signal?.removeEventListener("abort",h)};n.signal?.aborted?h():n.signal?.addEventListener("abort",h,{once:!0}),u.stdout?.on("data",b=>{if(!p)try{r(b)}catch(y){m(y)}}),u.stderr?.on("data",b=>d+=b.toString()),u.on("error",b=>{w(),c(b)}),u.on("close",b=>{w(),p?c(p):b===0?a():c(new l(`ffmpeg failed (exit ${b}):
|
|
149
149
|
${d.trim().split(`
|
|
150
150
|
`).slice(-6).join(`
|
|
151
151
|
`)}`))})}).finally(s)}async function Z(t,e,r={}){let{ffmpeg:n}=k(),o=Di(t);try{let i=await ne(n,o.args,e,r);if(i.code!==0){let s=i.stderr.trim().split(`
|
package/package.json
CHANGED