@tmhs/screencast-mcp 0.30.1 → 0.32.0
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 +2 -2
- package/dist/tools/exportPreset.d.ts.map +1 -1
- package/dist/tools/exportPreset.js +8 -6
- package/dist/tools/exportPreset.js.map +1 -1
- package/dist/tools/findText.js +1 -1
- package/dist/tools/findText.js.map +1 -1
- package/dist/tools/pipeline.d.ts.map +1 -1
- package/dist/tools/pipeline.js +2 -1
- package/dist/tools/pipeline.js.map +1 -1
- package/dist/tools/screenshot.js +1 -1
- package/dist/tools/screenshot.js.map +1 -1
- package/dist/tools/startRecording.d.ts.map +1 -1
- package/dist/tools/startRecording.js +49 -10
- package/dist/tools/startRecording.js.map +1 -1
- package/dist/tools/waitForChange.js +1 -1
- package/dist/tools/waitForChange.js.map +1 -1
- package/dist/utils/pipeline.d.ts.map +1 -1
- package/dist/utils/pipeline.js +3 -1
- package/dist/utils/pipeline.js.map +1 -1
- package/dist/utils/produce.d.ts +19 -2
- package/dist/utils/produce.d.ts.map +1 -1
- package/dist/utils/produce.js +33 -5
- package/dist/utils/produce.js.map +1 -1
- package/dist/utils/sessions.d.ts +3 -0
- package/dist/utils/sessions.d.ts.map +1 -1
- package/dist/utils/sessions.js.map +1 -1
- package/dist/utils/wgc.d.ts +41 -0
- package/dist/utils/wgc.d.ts.map +1 -0
- package/dist/utils/wgc.js +91 -0
- package/dist/utils/wgc.js.map +1 -0
- package/dist/utils/windows.d.ts +28 -5
- package/dist/utils/windows.d.ts.map +1 -1
- package/dist/utils/windows.js +45 -5
- package/dist/utils/windows.js.map +1 -1
- package/dist/wgcRecorder.d.ts +2 -0
- package/dist/wgcRecorder.d.ts.map +1 -0
- package/dist/wgcRecorder.js +134 -0
- package/dist/wgcRecorder.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recorder process for window recordings through Windows Graphics Capture
|
|
3
|
+
* (#113). See utils/wgc.ts for why it exists. Started by start_recording as
|
|
4
|
+
*
|
|
5
|
+
* node wgcRecorder.js '<WgcRecorderConfig as JSON>'
|
|
6
|
+
*
|
|
7
|
+
* and stopped like ffmpeg: "q" on stdin, stdin closing (the server went away),
|
|
8
|
+
* or the duration cap finalizes the file and exits 0. If the window closes,
|
|
9
|
+
* the recording ends there, also cleanly. Diagnostics go to stderr; the first
|
|
10
|
+
* frame prints an ffmpeg-style "start:" banner the session code reads.
|
|
11
|
+
*/
|
|
12
|
+
import { spawn } from "node:child_process";
|
|
13
|
+
import { buildWgcEncodeArgs, buildWgcGrabArgs, framesDue, parseRawSize, nudgeScript, startBanner, yuv420FrameBytes, } from "./utils/wgc.js";
|
|
14
|
+
/** Give up if the window produces no frame at all within this long. */
|
|
15
|
+
const FIRST_FRAME_TIMEOUT_MS = 10_000;
|
|
16
|
+
/** Skip a frame instead of queueing when the encoder is this far behind. */
|
|
17
|
+
const MAX_QUEUED_FRAMES = 4;
|
|
18
|
+
const cfg = JSON.parse(process.argv[2] ?? "{}");
|
|
19
|
+
const log = (s) => process.stderr.write(s.endsWith("\n") ? s : `${s}\n`);
|
|
20
|
+
const grab = spawn(cfg.ffmpeg, buildWgcGrabArgs(cfg.hwnd, cfg.fps), { stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
|
|
21
|
+
// Tiny repaints for the whole recording; see nudgeScript.
|
|
22
|
+
const nudge = spawn("powershell", ["-NoProfile", "-NonInteractive", "-Command", nudgeScript(cfg.hwnd, 200)], {
|
|
23
|
+
stdio: "ignore",
|
|
24
|
+
windowsHide: true,
|
|
25
|
+
});
|
|
26
|
+
let grabErr = "";
|
|
27
|
+
let size = null;
|
|
28
|
+
let frameBytes = 0;
|
|
29
|
+
let carry = Buffer.alloc(0);
|
|
30
|
+
let latest = null;
|
|
31
|
+
let encoder = null;
|
|
32
|
+
let startedAt = 0;
|
|
33
|
+
let written = 0;
|
|
34
|
+
let pacer = null;
|
|
35
|
+
let finishing = false;
|
|
36
|
+
/** Cut whole frames off the buffered bytes; the newest becomes `latest`. Runs
|
|
37
|
+
* from both handlers: the size line (stderr) and the frames (stdout) can
|
|
38
|
+
* arrive in either order, and a static window may send nothing more. */
|
|
39
|
+
function drain() {
|
|
40
|
+
if (!size || finishing)
|
|
41
|
+
return;
|
|
42
|
+
let off = 0;
|
|
43
|
+
while (carry.length - off >= frameBytes) {
|
|
44
|
+
latest = Buffer.from(carry.subarray(off, off + frameBytes));
|
|
45
|
+
off += frameBytes;
|
|
46
|
+
}
|
|
47
|
+
if (off)
|
|
48
|
+
carry = Buffer.from(carry.subarray(off));
|
|
49
|
+
if (latest && !encoder)
|
|
50
|
+
begin();
|
|
51
|
+
}
|
|
52
|
+
grab.stderr.on("data", (d) => {
|
|
53
|
+
if (size)
|
|
54
|
+
return;
|
|
55
|
+
grabErr = (grabErr + d.toString()).slice(-8000);
|
|
56
|
+
size = parseRawSize(grabErr);
|
|
57
|
+
if (size) {
|
|
58
|
+
frameBytes = yuv420FrameBytes(size.width, size.height);
|
|
59
|
+
drain();
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
grab.stdout.on("data", (chunk) => {
|
|
63
|
+
carry = carry.length ? Buffer.concat([carry, chunk]) : chunk;
|
|
64
|
+
drain();
|
|
65
|
+
});
|
|
66
|
+
function begin() {
|
|
67
|
+
encoder = spawn(cfg.ffmpeg, buildWgcEncodeArgs(size.width, size.height, cfg), {
|
|
68
|
+
stdio: ["pipe", "ignore", "pipe"],
|
|
69
|
+
windowsHide: true,
|
|
70
|
+
});
|
|
71
|
+
encoder.stderr?.on("data", (d) => log(d.toString()));
|
|
72
|
+
encoder.on("exit", (code) => process.exit(code ?? 1));
|
|
73
|
+
encoder.stdin?.on("error", () => {
|
|
74
|
+
// The encoder went away; its exit handler reports it.
|
|
75
|
+
});
|
|
76
|
+
startedAt = Date.now();
|
|
77
|
+
log(startBanner(startedAt));
|
|
78
|
+
log(`wgc: ${size.width}x${size.height} at ${cfg.fps} fps`);
|
|
79
|
+
const tick = () => {
|
|
80
|
+
const due = framesDue(Date.now() - startedAt, cfg.fps);
|
|
81
|
+
while (written < due && latest && encoder?.stdin?.writable) {
|
|
82
|
+
if ((encoder.stdin.writableLength ?? 0) > MAX_QUEUED_FRAMES * frameBytes) {
|
|
83
|
+
written = due; // behind: drop to stay on wall-clock time
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
encoder.stdin.write(latest);
|
|
87
|
+
written++;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
tick();
|
|
91
|
+
pacer = setInterval(tick, Math.max(5, Math.floor(1000 / cfg.fps / 2)));
|
|
92
|
+
if (cfg.maxDurationSec > 0)
|
|
93
|
+
setTimeout(finish, cfg.maxDurationSec * 1000);
|
|
94
|
+
}
|
|
95
|
+
function finish() {
|
|
96
|
+
if (finishing)
|
|
97
|
+
return;
|
|
98
|
+
finishing = true;
|
|
99
|
+
if (pacer)
|
|
100
|
+
clearInterval(pacer);
|
|
101
|
+
nudge.kill();
|
|
102
|
+
grab.kill();
|
|
103
|
+
if (!encoder) {
|
|
104
|
+
log("wgc: no frame was captured from the window");
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
encoder.stdin?.end();
|
|
108
|
+
// encoder's exit handler ends this process with its exit code.
|
|
109
|
+
}
|
|
110
|
+
grab.on("exit", () => {
|
|
111
|
+
if (finishing)
|
|
112
|
+
return;
|
|
113
|
+
if (!encoder) {
|
|
114
|
+
log(`wgc: capture failed: ${grabErr.split("\n").filter((l) => /error|fail|invalid/i.test(l)).slice(-3).join(" ") || "gfxcapture exited"}`);
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
log("wgc: the window closed; recording ended");
|
|
118
|
+
finish();
|
|
119
|
+
});
|
|
120
|
+
setTimeout(() => {
|
|
121
|
+
if (!encoder && !finishing) {
|
|
122
|
+
log(`wgc: the window produced no frame in ${FIRST_FRAME_TIMEOUT_MS / 1000}s`);
|
|
123
|
+
finishing = true;
|
|
124
|
+
nudge.kill();
|
|
125
|
+
grab.kill();
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
}, FIRST_FRAME_TIMEOUT_MS);
|
|
129
|
+
process.stdin.on("data", (d) => {
|
|
130
|
+
if (d.toString().includes("q"))
|
|
131
|
+
finish();
|
|
132
|
+
});
|
|
133
|
+
process.stdin.on("end", finish);
|
|
134
|
+
//# sourceMappingURL=wgcRecorder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wgcRecorder.js","sourceRoot":"","sources":["../src/wgcRecorder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,WAAW,EACX,WAAW,EACX,gBAAgB,GAEjB,MAAM,gBAAgB,CAAC;AAExB,uEAAuE;AACvE,MAAM,sBAAsB,GAAG,MAAM,CAAC;AACtC,4EAA4E;AAC5E,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAE5B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAsB,CAAC;AACrE,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAEjF,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAA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