@tmhs/screencast-mcp 0.50.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/README.md +5 -4
- package/dist/index.js +166 -165
- package/dist/wgcRecorder.js +5 -5
- package/package.json +2 -2
package/dist/wgcRecorder.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{spawn as
|
|
1
|
+
import{spawn as S}from"node:child_process";import{existsSync as H,rmSync as P}from"node:fs";var u=class extends Error{hint;constructor(e,n){super(e),this.name="ScreencastError",this.hint=n}};function _(t){return!t||t.device.trim().length===0?[]:["-f","dshow","-i",`audio=${t.device}`]}var j="160k";function C(t=j){return["-c:a","aac",...t?["-b:a",t]:[]]}var tt=168*3600;function I(t,e,n=!0){if(!Number.isSafeInteger(t)||t<=0)throw new u("Invalid window handle.");return["-hide_banner","-nostats","-loglevel","info","-f","lavfi","-i",`gfxcapture=hwnd=${t}:max_framerate=${e}${n?"":":capture_cursor=0"},hwdownload,format=bgra,crop=trunc(iw/2)*2:trunc(ih/2)*2,format=yuv420p`,"-flush_packets","1","-f","rawvideo","-"]}function R(t){let e=t.indexOf("Output #0");if(e<0)return null;let n=/Video: rawvideo[^\n]*?, (\d{2,5})x(\d{2,5})/.exec(t.slice(e));return n?{width:Number(n[1]),height:Number(n[2])}:null}function T(t,e){return t*e*3/2}var g=class{parts=[];length=0;frameBytes=0;push(e){e.length&&(this.parts.push(e),this.length+=e.length)}get buffered(){return this.length}take(){let e=this.frameBytes;if(e<=0||this.length<e)return null;let n=Math.floor(this.length/e),w=this.parts.length===1&&this.parts[0]?this.parts[0]:Buffer.concat(this.parts,this.length),c=n*e,U=w.subarray(c-e,c),E=this.length-c;return this.parts=E?[Buffer.from(w.subarray(c))]:[],this.length=E,U}};function M(t,e,n){return["-hide_banner","-nostats","-loglevel","error","-y","-f","rawvideo","-pix_fmt","yuv420p","-s",`${t}x${e}`,"-framerate",String(n.fps),"-i","pipe:0",...n.audioDevice?[..._({device:n.audioDevice}),"-map","0:v","-map","1:a"]:[],...n.encode,...n.audioDevice?[...C(),"-shortest"]:[],"-movflags","+frag_keyframe+empty_moov+default_base_moof",n.output]}function O(t,e){return Math.floor(t*e/1e3)+1}var k=3;function N(t){return`${t}.stop`}function D(t){return`Input #0, wgc, from 'window':
|
|
2
2
|
Duration: N/A, start: ${(t/1e3).toFixed(6)}, bitrate: N/A
|
|
3
|
-
`}function
|
|
3
|
+
`}function W(t,e,n){return`Add-Type @"
|
|
4
4
|
using System;using System.Runtime.InteropServices;
|
|
5
5
|
public class ScNudge{
|
|
6
6
|
[StructLayout(LayoutKind.Sequential)] public struct RECT{public int L,T,R,B;}
|
|
@@ -10,7 +10,7 @@ public class ScNudge{
|
|
|
10
10
|
"@
|
|
11
11
|
$r=New-Object ScNudge+RECT;$r.R=1;$r.B=1
|
|
12
12
|
${n?`$p=Get-Process -Id ${n} -ErrorAction SilentlyContinue
|
|
13
|
-
`:""}while([ScNudge]::IsWindow([IntPtr]${t})${n?" -and $p -and !$p.HasExited":""}){[void][ScNudge]::RedrawWindow([IntPtr]${t},[ref]$r,[IntPtr]::Zero,0x0105);Start-Sleep -Milliseconds ${e}}`}var
|
|
13
|
+
`:""}while([ScNudge]::IsWindow([IntPtr]${t})${n?" -and $p -and !$p.HasExited":""}){[void][ScNudge]::RedrawWindow([IntPtr]${t},[ref]$r,[IntPtr]::Zero,0x0105);Start-Sleep -Milliseconds ${e}}`}var Q=4,r=JSON.parse(process.argv[2]??"{}"),B=r.firstFrameTimeoutMs??1e4,s=t=>process.stderr.write(t.endsWith(`
|
|
14
14
|
`)?t:`${t}
|
|
15
|
-
`),
|
|
16
|
-
`).filter(t=>/error|fail|invalid/i.test(t)).slice(-3).join(" ")||"gfxcapture exited"}`),
|
|
15
|
+
`),d=S(r.ffmpeg,I(r.hwnd,r.fps,r.cursor!==!1),{stdio:["ignore","pipe","pipe"],windowsHide:!0}),F=S("powershell",["-NoProfile","-NonInteractive","-Command",W(r.hwnd,200,process.pid)],{stdio:"ignore",windowsHide:!0}),m="",o=null,y=0,$=new g,h=null,i=null,x=0,b=0,v=null,a=!1,L=!1,A=N(r.output);function l(t){if(t&&t.exitCode===null&&t.signalCode===null)try{t.kill()}catch{}}function f(t){l(F),l(d),l(i),P(A,{force:!0}),process.exit(t)}function z(){if(!o||a)return;let t=$.take();t&&(h=t),h&&!i&&q()}d.stderr.on("data",t=>{o||(m=(m+t.toString()).slice(-8e3),o=R(m),o&&(y=T(o.width,o.height),$.frameBytes=y,z()))});d.stdout.on("data",t=>{$.push(t),z()});function q(){i=S(r.ffmpeg,M(o.width,o.height,r),{stdio:["pipe","ignore","pipe"],windowsHide:!0}),i.stderr?.on("data",e=>s(e.toString())),i.on("exit",e=>f(e===0&&L?k:e??1)),i.stdin?.on("error",()=>{}),x=Date.now(),s(D(x)),s(`wgc: ${o.width}x${o.height} at ${r.fps} fps`);let t=()=>{let e=O(Date.now()-x,r.fps);for(;b<e&&h&&i?.stdin?.writable;){if((i.stdin.writableLength??0)>Q*y){b=e;break}i.stdin.write(h),b++}};t(),v=setInterval(t,Math.max(5,Math.floor(1e3/r.fps/2))),r.maxDurationSec>0&&G(r.maxDurationSec*1e3)}function G(t){let e=Math.min(t,2147483647);setTimeout(()=>t>e?G(t-e):p(),e)}function p(){a||(a=!0,v&&clearInterval(v),l(F),l(d),i||(s("wgc: no frame was captured from the window"),f(1)),i.stdin?.end())}d.on("exit",()=>{a||(i||(s(`wgc: capture failed: ${m.split(`
|
|
16
|
+
`).filter(t=>/error|fail|invalid/i.test(t)).slice(-3).join(" ")||"gfxcapture exited"}`),f(1)),s("wgc: the window closed; recording ended"),L=!0,p())});setTimeout(()=>{!i&&!a&&(s(`wgc: the window produced no frame in ${B/1e3}s`),a=!0,f(1))},B);P(A,{force:!0});setInterval(()=>{H(A)&&p()},250).unref();for(let t of["SIGINT","SIGTERM"])process.on(t,()=>f(1));process.stdin.on("data",t=>{t.toString().includes("q")&&p()});process.stdin.on("end",p);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmhs/screencast-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.1",
|
|
4
4
|
"description": "Let AI agents record the Windows screen, watch it as frames, and edit it with ffmpeg",
|
|
5
5
|
"mcpName": "io.github.TMHSDigital/screencast-mcp",
|
|
6
6
|
"type": "module",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"eslint": "^10.14.0",
|
|
80
80
|
"jsdom": "^31.0.0",
|
|
81
81
|
"tsx": "^4.19.4",
|
|
82
|
-
"typescript": "
|
|
82
|
+
"typescript": "~6.0.3",
|
|
83
83
|
"typescript-eslint": "^8.72.1",
|
|
84
84
|
"vitest": "^5.1.0"
|
|
85
85
|
}
|