@tmhs/screencast-mcp 0.49.0 → 0.50.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 +13 -8
- package/dist/index.js +550 -106
- package/dist/wgcRecorder.js +15 -139
- package/package.json +8 -4
- package/assets/.gitkeep +0 -0
- package/assets/icon.png +0 -0
- package/dist/cli.js +0 -516
- package/dist/context.js +0 -50
- package/dist/prompts.js +0 -95
- package/dist/resources.js +0 -93
- package/dist/server.js +0 -174
- package/dist/setup.js +0 -438
- package/dist/tools/addMarker.js +0 -93
- package/dist/tools/assembleHighlights.js +0 -69
- package/dist/tools/backdrop.js +0 -89
- package/dist/tools/bugReport.js +0 -266
- package/dist/tools/burnSubtitles.js +0 -56
- package/dist/tools/callout.js +0 -103
- package/dist/tools/chapters.js +0 -156
- package/dist/tools/clip.js +0 -52
- package/dist/tools/compress.js +0 -51
- package/dist/tools/concat.js +0 -67
- package/dist/tools/contactSheet.js +0 -135
- package/dist/tools/convert.js +0 -46
- package/dist/tools/crop.js +0 -43
- package/dist/tools/cursor.js +0 -87
- package/dist/tools/cutByTranscript.js +0 -86
- package/dist/tools/cutIdle.js +0 -84
- package/dist/tools/deleteRecording.js +0 -119
- package/dist/tools/denoise.js +0 -60
- package/dist/tools/doctor.js +0 -146
- package/dist/tools/exportGif.js +0 -57
- package/dist/tools/exportPreset.js +0 -48
- package/dist/tools/extractAudio.js +0 -65
- package/dist/tools/findText.js +0 -196
- package/dist/tools/getMediaInfo.js +0 -36
- package/dist/tools/getSession.js +0 -40
- package/dist/tools/indexRecording.js +0 -195
- package/dist/tools/keystrokeOverlay.js +0 -131
- package/dist/tools/listAudioDevices.js +0 -35
- package/dist/tools/listSessions.js +0 -28
- package/dist/tools/listTargets.js +0 -76
- package/dist/tools/listVideoDevices.js +0 -26
- package/dist/tools/musicBed.js +0 -55
- package/dist/tools/narrate.js +0 -86
- package/dist/tools/normalizeAudio.js +0 -60
- package/dist/tools/overlay.js +0 -62
- package/dist/tools/pauseRecording.js +0 -44
- package/dist/tools/pipeline.js +0 -400
- package/dist/tools/readEvents.js +0 -98
- package/dist/tools/redactRegion.js +0 -70
- package/dist/tools/reframe.js +0 -46
- package/dist/tools/resumeRecording.js +0 -46
- package/dist/tools/reviewRecording.js +0 -163
- package/dist/tools/sampleFrames.js +0 -200
- package/dist/tools/saveReplay.js +0 -90
- package/dist/tools/scale.js +0 -44
- package/dist/tools/screenDiff.js +0 -86
- package/dist/tools/screenshot.js +0 -76
- package/dist/tools/searchRecording.js +0 -79
- package/dist/tools/speed.js +0 -46
- package/dist/tools/startRecording.js +0 -398
- package/dist/tools/stepGuide.js +0 -250
- package/dist/tools/stopRecording.js +0 -132
- package/dist/tools/titleCard.js +0 -67
- package/dist/tools/transcribe.js +0 -66
- package/dist/tools/trim.js +0 -57
- package/dist/tools/waitForChange.js +0 -128
- package/dist/tools/xfadeTransition.js +0 -58
- package/dist/tools/zoom.js +0 -149
- package/dist/utils/anim.js +0 -54
- package/dist/utils/animExport.js +0 -56
- package/dist/utils/argPaths.js +0 -39
- package/dist/utils/audio.js +0 -113
- package/dist/utils/audioDevices.js +0 -107
- package/dist/utils/backdrop.js +0 -151
- package/dist/utils/bugReport.js +0 -172
- package/dist/utils/callout.js +0 -90
- package/dist/utils/calloutAssets.js +0 -42
- package/dist/utils/capabilities.js +0 -96
- package/dist/utils/captions.js +0 -103
- package/dist/utils/chapters.js +0 -227
- package/dist/utils/consent.js +0 -29
- package/dist/utils/cursor.js +0 -317
- package/dist/utils/diff.js +0 -184
- package/dist/utils/errors.js +0 -29
- package/dist/utils/events.js +0 -403
- package/dist/utils/expr.js +0 -11
- package/dist/utils/ffmpeg.js +0 -285
- package/dist/utils/fontCoverage.js +0 -177
- package/dist/utils/fonts.js +0 -154
- package/dist/utils/gpu.js +0 -219
- package/dist/utils/idle.js +0 -91
- package/dist/utils/images.js +0 -38
- package/dist/utils/jobs.js +0 -129
- package/dist/utils/keystrokes.js +0 -155
- package/dist/utils/lifecycle.js +0 -233
- package/dist/utils/logging.js +0 -75
- package/dist/utils/media.js +0 -574
- package/dist/utils/monitors.js +0 -124
- package/dist/utils/narrate.js +0 -233
- package/dist/utils/ocr.js +0 -222
- package/dist/utils/ocrScan.js +0 -91
- package/dist/utils/paths.js +0 -155
- package/dist/utils/pause.js +0 -190
- package/dist/utils/pipeline.js +0 -361
- package/dist/utils/player.js +0 -85
- package/dist/utils/pool.js +0 -29
- package/dist/utils/produce.js +0 -298
- package/dist/utils/recipes.js +0 -71
- package/dist/utils/recorder.js +0 -173
- package/dist/utils/recordingFiles.js +0 -32
- package/dist/utils/recordingIndex.js +0 -312
- package/dist/utils/replay.js +0 -283
- package/dist/utils/resolveTarget.js +0 -25
- package/dist/utils/retention.js +0 -48
- package/dist/utils/roots.js +0 -43
- package/dist/utils/sessions.js +0 -499
- package/dist/utils/sheet.js +0 -59
- package/dist/utils/stepGuide.js +0 -231
- package/dist/utils/steps.js +0 -88
- package/dist/utils/still.js +0 -38
- package/dist/utils/targetList.js +0 -64
- package/dist/utils/targets.js +0 -265
- package/dist/utils/timeline.js +0 -85
- package/dist/utils/toolSpec.js +0 -31
- package/dist/utils/toolsets.js +0 -134
- package/dist/utils/transcriptCut.js +0 -149
- package/dist/utils/validate.js +0 -23
- package/dist/utils/waitLoop.js +0 -50
- package/dist/utils/wgc.js +0 -84
- package/dist/utils/windows.js +0 -192
- package/dist/utils/zoom.js +0 -234
package/dist/utils/waitLoop.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { diffFrames, SettleTracker } from "./diff.js";
|
|
2
|
-
const defaultSleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
3
|
-
export async function waitLoop(o) {
|
|
4
|
-
const now = o.now ?? Date.now;
|
|
5
|
-
const sleep = o.sleep ?? defaultSleep;
|
|
6
|
-
const startedAt = now();
|
|
7
|
-
const baseline = await o.grab();
|
|
8
|
-
const settle = new SettleTracker(baseline, o.width, o.height, o.diff);
|
|
9
|
-
let lastChangeAt = startedAt;
|
|
10
|
-
let everChanged = false;
|
|
11
|
-
let regions = [];
|
|
12
|
-
let outcome = "timeout";
|
|
13
|
-
while (now() - startedAt < o.timeoutMs) {
|
|
14
|
-
if (o.signal.aborted) {
|
|
15
|
-
outcome = "cancelled";
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
await sleep(o.intervalMs);
|
|
19
|
-
const current = await o.grab().catch((error) => {
|
|
20
|
-
if (o.signal.aborted)
|
|
21
|
-
return null;
|
|
22
|
-
throw error;
|
|
23
|
-
});
|
|
24
|
-
if (!current) {
|
|
25
|
-
outcome = "cancelled";
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
if (o.mode === "change") {
|
|
29
|
-
const d = diffFrames(baseline, current, o.width, o.height, o.diff);
|
|
30
|
-
if (d.regions.length > 0) {
|
|
31
|
-
regions = d.regions;
|
|
32
|
-
outcome = "changed";
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
const changed = settle.push(current);
|
|
38
|
-
if (changed.length > 0) {
|
|
39
|
-
everChanged = true;
|
|
40
|
-
lastChangeAt = now();
|
|
41
|
-
regions = changed;
|
|
42
|
-
}
|
|
43
|
-
else if (now() - lastChangeAt >= o.settleMs) {
|
|
44
|
-
outcome = "settled";
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return { outcome, regions, everChanged, startedAt };
|
|
50
|
-
}
|
package/dist/utils/wgc.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { ScreencastError } from "./errors.js";
|
|
2
|
-
export function buildWgcGrabArgs(hwnd, fps, cursor = true) {
|
|
3
|
-
if (!Number.isSafeInteger(hwnd) || hwnd <= 0)
|
|
4
|
-
throw new ScreencastError("Invalid window handle.");
|
|
5
|
-
return [
|
|
6
|
-
"-hide_banner", "-nostats", "-loglevel", "info",
|
|
7
|
-
"-f", "lavfi",
|
|
8
|
-
"-i", `gfxcapture=hwnd=${hwnd}:max_framerate=${fps}${cursor ? "" : ":capture_cursor=0"},hwdownload,format=bgra,crop=trunc(iw/2)*2:trunc(ih/2)*2,format=yuv420p`,
|
|
9
|
-
"-flush_packets", "1",
|
|
10
|
-
"-f", "rawvideo", "-",
|
|
11
|
-
];
|
|
12
|
-
}
|
|
13
|
-
export function parseRawSize(stderr) {
|
|
14
|
-
const out = stderr.indexOf("Output #0");
|
|
15
|
-
if (out < 0)
|
|
16
|
-
return null;
|
|
17
|
-
const m = /Video: rawvideo[^\n]*?, (\d{2,5})x(\d{2,5})/.exec(stderr.slice(out));
|
|
18
|
-
return m ? { width: Number(m[1]), height: Number(m[2]) } : null;
|
|
19
|
-
}
|
|
20
|
-
export function yuv420FrameBytes(width, height) {
|
|
21
|
-
return (width * height * 3) / 2;
|
|
22
|
-
}
|
|
23
|
-
export class FrameAssembler {
|
|
24
|
-
parts = [];
|
|
25
|
-
length = 0;
|
|
26
|
-
frameBytes = 0;
|
|
27
|
-
push(chunk) {
|
|
28
|
-
if (!chunk.length)
|
|
29
|
-
return;
|
|
30
|
-
this.parts.push(chunk);
|
|
31
|
-
this.length += chunk.length;
|
|
32
|
-
}
|
|
33
|
-
get buffered() {
|
|
34
|
-
return this.length;
|
|
35
|
-
}
|
|
36
|
-
take() {
|
|
37
|
-
const fb = this.frameBytes;
|
|
38
|
-
if (fb <= 0 || this.length < fb)
|
|
39
|
-
return null;
|
|
40
|
-
const frames = Math.floor(this.length / fb);
|
|
41
|
-
const all = this.parts.length === 1 && this.parts[0] ? this.parts[0] : Buffer.concat(this.parts, this.length);
|
|
42
|
-
const end = frames * fb;
|
|
43
|
-
const frame = all.subarray(end - fb, end);
|
|
44
|
-
const rest = this.length - end;
|
|
45
|
-
this.parts = rest ? [Buffer.from(all.subarray(end))] : [];
|
|
46
|
-
this.length = rest;
|
|
47
|
-
return frame;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export function buildWgcEncodeArgs(width, height, cfg) {
|
|
51
|
-
return [
|
|
52
|
-
"-hide_banner", "-nostats", "-loglevel", "error", "-y",
|
|
53
|
-
"-f", "rawvideo", "-pix_fmt", "yuv420p", "-s", `${width}x${height}`, "-framerate", String(cfg.fps),
|
|
54
|
-
"-i", "pipe:0",
|
|
55
|
-
...cfg.encode,
|
|
56
|
-
"-movflags", "+frag_keyframe+empty_moov+default_base_moof",
|
|
57
|
-
cfg.output,
|
|
58
|
-
];
|
|
59
|
-
}
|
|
60
|
-
export function framesDue(elapsedMs, fps) {
|
|
61
|
-
return Math.floor((elapsedMs * fps) / 1000) + 1;
|
|
62
|
-
}
|
|
63
|
-
export const WGC_WINDOW_CLOSED_EXIT = 3;
|
|
64
|
-
export function wgcStopFile(output) {
|
|
65
|
-
return `${output}.stop`;
|
|
66
|
-
}
|
|
67
|
-
export function startBanner(epochMs) {
|
|
68
|
-
return `Input #0, wgc, from 'window':\n Duration: N/A, start: ${(epochMs / 1000).toFixed(6)}, bitrate: N/A\n`;
|
|
69
|
-
}
|
|
70
|
-
export function nudgeScript(hwnd, intervalMs, parentPid) {
|
|
71
|
-
const watch = parentPid ? `$p=Get-Process -Id ${parentPid} -ErrorAction SilentlyContinue
|
|
72
|
-
` : "";
|
|
73
|
-
const alive = parentPid ? ` -and $p -and !$p.HasExited` : "";
|
|
74
|
-
return `Add-Type @"
|
|
75
|
-
using System;using System.Runtime.InteropServices;
|
|
76
|
-
public class ScNudge{
|
|
77
|
-
[StructLayout(LayoutKind.Sequential)] public struct RECT{public int L,T,R,B;}
|
|
78
|
-
[DllImport("user32.dll")] public static extern bool RedrawWindow(IntPtr h,ref RECT r,IntPtr g,uint f);
|
|
79
|
-
[DllImport("user32.dll")] public static extern bool IsWindow(IntPtr h);
|
|
80
|
-
}
|
|
81
|
-
"@
|
|
82
|
-
$r=New-Object ScNudge+RECT;$r.R=1;$r.B=1
|
|
83
|
-
${watch}while([ScNudge]::IsWindow([IntPtr]${hwnd})${alive}){[void][ScNudge]::RedrawWindow([IntPtr]${hwnd},[ref]$r,[IntPtr]::Zero,0x0105);Start-Sleep -Milliseconds ${intervalMs}}`;
|
|
84
|
-
}
|
package/dist/utils/windows.js
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { errorMessage, ScreencastError } from "./errors.js";
|
|
2
|
-
import { runPowerShell } from "./monitors.js";
|
|
3
|
-
export const MAX_CANDIDATES = 5;
|
|
4
|
-
export function parseWindowSelector(wanted) {
|
|
5
|
-
const h = /^hwnd=(0x[0-9a-f]+|\d+)$/i.exec(wanted.trim());
|
|
6
|
-
if (h)
|
|
7
|
-
return { kind: "hwnd", hwnd: Number(h[1]) };
|
|
8
|
-
const e = /^exe=(.+)$/i.exec(wanted.trim());
|
|
9
|
-
if (e?.[1])
|
|
10
|
-
return { kind: "exe", exe: e[1].trim().toLowerCase().replace(/\.exe$/, "") };
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
export function selectWindow(query, wanted, opts = {}) {
|
|
14
|
-
const windows = Array.isArray(query.windows) ? query.windows : [];
|
|
15
|
-
const visible = windows.filter((w) => !w.cloaked);
|
|
16
|
-
try {
|
|
17
|
-
return matchWindow(query, visible, wanted, opts);
|
|
18
|
-
}
|
|
19
|
-
catch (err) {
|
|
20
|
-
if (!(err instanceof NoWindowMatch) || visible.length === windows.length)
|
|
21
|
-
throw err;
|
|
22
|
-
let hit;
|
|
23
|
-
try {
|
|
24
|
-
hit = matchWindow(query, windows, wanted, opts);
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
throw err;
|
|
28
|
-
}
|
|
29
|
-
if (!opts.allowCloaked) {
|
|
30
|
-
throw new ScreencastError(`Window "${hit.matchedTitle}" is cloaked: Windows reports it as open but it is not on screen ` +
|
|
31
|
-
"(a suspended app, or a window on another virtual desktop), so a screen capture would record whatever is there instead.", "Bring the window up on this desktop, or use backend: \"wgc\", which captures the window's own surface.");
|
|
32
|
-
}
|
|
33
|
-
return { ...hit, cloaked: true };
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
class NoWindowMatch extends ScreencastError {
|
|
37
|
-
}
|
|
38
|
-
function matchWindow(query, all, wanted, opts) {
|
|
39
|
-
const selector = parseWindowSelector(wanted);
|
|
40
|
-
if (selector) {
|
|
41
|
-
const hits = selector.kind === "hwnd"
|
|
42
|
-
? all.filter((w) => w.hwnd === selector.hwnd)
|
|
43
|
-
: all.filter((w) => (w.exe ?? "").toLowerCase().replace(/\.exe$/, "") === selector.exe);
|
|
44
|
-
if (hits.length === 0) {
|
|
45
|
-
throw new NoWindowMatch(selector.kind === "hwnd"
|
|
46
|
-
? `No visible top-level window with handle ${wanted.trim().slice(5)}. It may have closed; handles change when an app restarts.`
|
|
47
|
-
: `No visible window belonging to ${selector.exe}.exe. Is the app running with a window open (and not minimized)?`);
|
|
48
|
-
}
|
|
49
|
-
return toBounds(query, hits, selector.kind);
|
|
50
|
-
}
|
|
51
|
-
const needle = wanted.trim().toLowerCase();
|
|
52
|
-
const exact = all.filter((w) => w.title.toLowerCase() === needle);
|
|
53
|
-
const substring = all.filter((w) => w.title.toLowerCase().includes(needle));
|
|
54
|
-
const quote = (ws) => ws.slice(0, MAX_CANDIDATES).map((w) => `"${w.title}"`).join(", ");
|
|
55
|
-
if (exact.length === 0 && opts.exactOnly) {
|
|
56
|
-
throw new NoWindowMatch(`No visible window titled exactly "${wanted}" (exactTitle is on).` +
|
|
57
|
-
(substring.length > 0 ? ` Windows containing it: ${quote(substring)}.` : ""));
|
|
58
|
-
}
|
|
59
|
-
const matchKind = exact.length > 0 ? "exact" : "substring";
|
|
60
|
-
const matches = exact.length > 0 ? exact : substring;
|
|
61
|
-
if (matches.length === 0) {
|
|
62
|
-
throw new NoWindowMatch(`No visible window matching title "${wanted}". Open the window (it must ` +
|
|
63
|
-
`be on screen and not minimized), or use an exact/substring of its title, ` +
|
|
64
|
-
`or target it by window:exe=<app.exe> or window:hwnd=<handle>.`);
|
|
65
|
-
}
|
|
66
|
-
return toBounds(query, matches, matchKind);
|
|
67
|
-
}
|
|
68
|
-
function toBounds(query, matches, matchKind) {
|
|
69
|
-
const chosen = matches[0];
|
|
70
|
-
if (!chosen)
|
|
71
|
-
throw new NoWindowMatch("No visible window matched.");
|
|
72
|
-
if (chosen.minimized) {
|
|
73
|
-
throw new ScreencastError(`Window "${chosen.title}" is minimized. Restore it before capturing - ` +
|
|
74
|
-
`window capture grabs whatever is on screen at the window's rectangle.`);
|
|
75
|
-
}
|
|
76
|
-
const v = query.virtual;
|
|
77
|
-
const x = Math.max(chosen.left, v.x);
|
|
78
|
-
const y = Math.max(chosen.top, v.y);
|
|
79
|
-
const right = Math.min(chosen.right, v.x + v.w);
|
|
80
|
-
const bottom = Math.min(chosen.bottom, v.y + v.h);
|
|
81
|
-
let width = right - x;
|
|
82
|
-
let height = bottom - y;
|
|
83
|
-
if (width <= 0 || height <= 0) {
|
|
84
|
-
throw new ScreencastError(`Window "${chosen.title}" has no visible on-screen area to capture ` +
|
|
85
|
-
`(off-screen or fully occluded by the desktop edge).`);
|
|
86
|
-
}
|
|
87
|
-
width -= width % 2;
|
|
88
|
-
height -= height % 2;
|
|
89
|
-
if (width <= 0 || height <= 0) {
|
|
90
|
-
throw new ScreencastError(`Window "${chosen.title}" is too small to capture.`);
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
x, y, width, height,
|
|
94
|
-
matchedTitle: chosen.title,
|
|
95
|
-
...(chosen.hwnd !== undefined ? { hwnd: chosen.hwnd } : {}),
|
|
96
|
-
...(chosen.clientX !== undefined && chosen.clientY !== undefined ? { client: { x: chosen.clientX, y: chosen.clientY } } : {}),
|
|
97
|
-
matchCount: matches.length,
|
|
98
|
-
matchKind,
|
|
99
|
-
candidates: matches.slice(0, MAX_CANDIDATES).map((w) => w.title),
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
export function windowMatchReport(w) {
|
|
103
|
-
const reasons = [];
|
|
104
|
-
if (w.matchKind === "substring")
|
|
105
|
-
reasons.push("the title matched only as a substring");
|
|
106
|
-
if (w.matchCount > 1)
|
|
107
|
-
reasons.push(`${w.matchCount} windows matched and the topmost was used`);
|
|
108
|
-
if (w.cloaked)
|
|
109
|
-
reasons.push("the window is cloaked (not on screen: suspended, or on another virtual desktop)");
|
|
110
|
-
return {
|
|
111
|
-
matchedWindow: w.matchedTitle,
|
|
112
|
-
matchCount: w.matchCount,
|
|
113
|
-
matchKind: w.matchKind,
|
|
114
|
-
region: { x: w.x, y: w.y, width: w.width, height: w.height },
|
|
115
|
-
...(reasons.length > 0
|
|
116
|
-
? {
|
|
117
|
-
windowWarning: `Check this is the intended window: ${reasons.join(", and ")}. ` +
|
|
118
|
-
`Candidates: ${w.candidates.map((t) => `"${t}"`).join(", ")}. ` +
|
|
119
|
-
"Pass the full title with exactTitle: true to match only that window.",
|
|
120
|
-
}
|
|
121
|
-
: {}),
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
const PS_ENUM = `
|
|
125
|
-
$ErrorActionPreference='Stop'
|
|
126
|
-
Add-Type @"
|
|
127
|
-
using System;using System.Text;using System.Collections.Generic;using System.Runtime.InteropServices;
|
|
128
|
-
public class WinShim{
|
|
129
|
-
[DllImport("user32.dll")] public static extern bool EnumWindows(EnumWindowsProc f,IntPtr l);
|
|
130
|
-
public delegate bool EnumWindowsProc(IntPtr h,IntPtr l);
|
|
131
|
-
[DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr h);
|
|
132
|
-
[DllImport("user32.dll")] public static extern bool IsIconic(IntPtr h);
|
|
133
|
-
[DllImport("user32.dll",CharSet=CharSet.Unicode)] public static extern int GetWindowText(IntPtr h,StringBuilder s,int n);
|
|
134
|
-
[DllImport("user32.dll")] public static extern int GetWindowTextLength(IntPtr h);
|
|
135
|
-
[DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr h,out RECT r);
|
|
136
|
-
[DllImport("user32.dll")] public static extern int GetSystemMetrics(int i);
|
|
137
|
-
[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr h,out uint p);
|
|
138
|
-
[DllImport("user32.dll")] public static extern bool ClientToScreen(IntPtr h,ref PT p);
|
|
139
|
-
public struct PT{public int X,Y;}
|
|
140
|
-
[DllImport("user32.dll")] public static extern IntPtr SetProcessDpiAwarenessContext(IntPtr v);
|
|
141
|
-
public struct RECT{public int Left,Top,Right,Bottom;}
|
|
142
|
-
static List<IntPtr> _h;
|
|
143
|
-
static bool Col(IntPtr h,IntPtr l){_h.Add(h);return true;}
|
|
144
|
-
public static IntPtr[] Z(){_h=new List<IntPtr>();EnumWindows(Col,IntPtr.Zero);return _h.ToArray();}
|
|
145
|
-
public static string T(IntPtr h){int n=GetWindowTextLength(h);if(n==0)return "";var s=new StringBuilder(n+1);GetWindowText(h,s,s.Capacity);return s.ToString();}
|
|
146
|
-
[DllImport("dwmapi.dll")] public static extern int DwmGetWindowAttribute(IntPtr h,int a,out RECT r,int n);
|
|
147
|
-
public static int[] R(IntPtr h){RECT r;if(DwmGetWindowAttribute(h,9,out r,Marshal.SizeOf(typeof(RECT)))!=0){GetWindowRect(h,out r);}return new int[]{r.Left,r.Top,r.Right,r.Bottom};}
|
|
148
|
-
[DllImport("dwmapi.dll",EntryPoint="DwmGetWindowAttribute")] public static extern int DwmInt(IntPtr h,int a,out int v,int n);
|
|
149
|
-
public static bool Ck(IntPtr h){int v;return DwmInt(h,14,out v,4)==0&&v!=0;}
|
|
150
|
-
public static bool Ic(IntPtr h){return IsIconic(h);}
|
|
151
|
-
public static bool Vis(IntPtr h){return IsWindowVisible(h);}
|
|
152
|
-
public static int SM(int i){return GetSystemMetrics(i);}
|
|
153
|
-
public static uint P(IntPtr h){uint p;GetWindowThreadProcessId(h,out p);return p;}
|
|
154
|
-
public static int[] C(IntPtr h){PT p=new PT();ClientToScreen(h,ref p);return new int[]{p.X,p.Y};}
|
|
155
|
-
}
|
|
156
|
-
"@
|
|
157
|
-
try{[void][WinShim]::SetProcessDpiAwarenessContext([IntPtr](-4))}catch{}
|
|
158
|
-
$ws=New-Object System.Collections.ArrayList
|
|
159
|
-
$exes=@{}
|
|
160
|
-
foreach($h in [WinShim]::Z()){
|
|
161
|
-
if(-not [WinShim]::Vis($h)){continue}
|
|
162
|
-
$t=[WinShim]::T($h)
|
|
163
|
-
if([string]::IsNullOrEmpty($t)){continue}
|
|
164
|
-
$r=[WinShim]::R($h)
|
|
165
|
-
$procId=[WinShim]::P($h)
|
|
166
|
-
$c=[WinShim]::C($h)
|
|
167
|
-
if(-not $exes.ContainsKey($procId)){$exes[$procId]=try{(Get-Process -Id $procId -ErrorAction Stop).ProcessName+'.exe'}catch{''}}
|
|
168
|
-
[void]$ws.Add([pscustomobject]@{title=$t;left=$r[0];top=$r[1];right=$r[2];bottom=$r[3];minimized=[bool][WinShim]::Ic($h);hwnd=[int64]$h;exe=$exes[$procId];pid=$procId;clientX=$c[0];clientY=$c[1];cloaked=[WinShim]::Ck($h)})
|
|
169
|
-
}
|
|
170
|
-
$v=[pscustomobject]@{x=[WinShim]::SM(76);y=[WinShim]::SM(77);w=[WinShim]::SM(78);h=[WinShim]::SM(79)}
|
|
171
|
-
[pscustomobject]@{virtual=$v;windows=@($ws)}|ConvertTo-Json -Compress -Depth 4
|
|
172
|
-
`;
|
|
173
|
-
export async function getRawWindows() {
|
|
174
|
-
if (process.platform !== "win32") {
|
|
175
|
-
throw new ScreencastError("Window capture is implemented for Windows (gdigrab) only.");
|
|
176
|
-
}
|
|
177
|
-
const stdout = await runPowerShell(PS_ENUM, "windows");
|
|
178
|
-
let parsed;
|
|
179
|
-
try {
|
|
180
|
-
parsed = JSON.parse(stdout);
|
|
181
|
-
}
|
|
182
|
-
catch (err) {
|
|
183
|
-
throw new ScreencastError(`Could not parse window geometry: ${errorMessage(err)}`);
|
|
184
|
-
}
|
|
185
|
-
const obj = parsed;
|
|
186
|
-
const windows = Array.isArray(obj.windows) ? obj.windows : obj.windows ? [obj.windows] : [];
|
|
187
|
-
const v = obj.virtual ?? { x: 0, y: 0, w: 0, h: 0 };
|
|
188
|
-
return { virtual: v, windows };
|
|
189
|
-
}
|
|
190
|
-
export async function resolveWindowBounds(title, opts = {}) {
|
|
191
|
-
return selectWindow(await getRawWindows(), title, opts);
|
|
192
|
-
}
|
package/dist/utils/zoom.js
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
import { ScreencastError } from "./errors.js";
|
|
2
|
-
import { diffFrames } from "./diff.js";
|
|
3
|
-
import { resolveQuality } from "./targets.js";
|
|
4
|
-
import { sumExpr } from "./expr.js";
|
|
5
|
-
export const DEFAULT_TRANSITION_SEC = 0.6;
|
|
6
|
-
export const MAX_ZOOM = 6;
|
|
7
|
-
export const DEFAULT_AUTO_MAX_ZOOM = 2.5;
|
|
8
|
-
export function keyframesToViews(kfs, W, H, maxZoom = MAX_ZOOM) {
|
|
9
|
-
if (kfs.length === 0)
|
|
10
|
-
throw new ScreencastError("Give at least one keyframe.");
|
|
11
|
-
const sorted = [...kfs].sort((a, b) => a.t - b.t);
|
|
12
|
-
const views = sorted.map((k) => {
|
|
13
|
-
if (!Number.isFinite(k.t) || k.t < 0)
|
|
14
|
-
throw new ScreencastError("Keyframe t must be a non-negative number.");
|
|
15
|
-
if (k.full || k.width === undefined || k.height === undefined)
|
|
16
|
-
return { t: k.t, z: 1, cx: W / 2, cy: H / 2 };
|
|
17
|
-
if (!(k.width > 0) || !(k.height > 0))
|
|
18
|
-
throw new ScreencastError("Keyframe width and height must be positive.");
|
|
19
|
-
const z = Math.max(1, Math.min(maxZoom, W / k.width, H / k.height));
|
|
20
|
-
return { t: k.t, z, cx: (k.x ?? 0) + k.width / 2, cy: (k.y ?? 0) + k.height / 2 };
|
|
21
|
-
});
|
|
22
|
-
if (views[0] && views[0].t > 0)
|
|
23
|
-
views.unshift({ t: 0, z: 1, cx: W / 2, cy: H / 2 });
|
|
24
|
-
return views;
|
|
25
|
-
}
|
|
26
|
-
const n = (v) => Number(v.toFixed(4)).toString();
|
|
27
|
-
export function viewExpr(views, key, transition) {
|
|
28
|
-
const [first, ...rest] = views;
|
|
29
|
-
if (!first)
|
|
30
|
-
throw new ScreencastError("Give at least one keyframe.");
|
|
31
|
-
const terms = [n(first[key])];
|
|
32
|
-
let prev = first;
|
|
33
|
-
for (const next of rest) {
|
|
34
|
-
const a = prev[key];
|
|
35
|
-
const b = next[key];
|
|
36
|
-
const start = prev.t;
|
|
37
|
-
prev = next;
|
|
38
|
-
if (a === b)
|
|
39
|
-
continue;
|
|
40
|
-
const end = next.t;
|
|
41
|
-
const T = Math.max(0.001, Math.min(transition, end - start));
|
|
42
|
-
const s = `clip((it-${n(end - T)})/${n(T)},0,1)`;
|
|
43
|
-
terms.push(`(${n(b - a)})*${s}*${s}*(3-2*${s})`);
|
|
44
|
-
}
|
|
45
|
-
return sumExpr(terms);
|
|
46
|
-
}
|
|
47
|
-
export function zoomFilter(views, size, transition = DEFAULT_TRANSITION_SEC) {
|
|
48
|
-
const { width: W, height: H, fps } = size;
|
|
49
|
-
const up = W <= 1920 ? 2 : 1;
|
|
50
|
-
const z = viewExpr(views, "z", transition);
|
|
51
|
-
const cx = viewExpr(views, "cx", transition);
|
|
52
|
-
const cy = viewExpr(views, "cy", transition);
|
|
53
|
-
return (`fps=${n(fps)},scale=${W * up}:${H * up},` +
|
|
54
|
-
`zoompan=z='${z}':x='clip((${cx})*${up}-iw/zoom/2,0,iw-iw/zoom)':y='clip((${cy})*${up}-ih/zoom/2,0,ih-ih/zoom)'` +
|
|
55
|
-
`:d=1:s=${W}x${H}:fps=${n(fps)}`);
|
|
56
|
-
}
|
|
57
|
-
export function buildZoomArgs(input, output, views, size, transition = DEFAULT_TRANSITION_SEC, quality = "standard", rings) {
|
|
58
|
-
const { width: W, height: H, fps } = size;
|
|
59
|
-
const vf = zoomFilter(views, size, transition);
|
|
60
|
-
if (!rings || rings.clicks.length === 0) {
|
|
61
|
-
return ["-y", "-i", input, "-vf", vf, ...resolveQuality(quality), "-c:a", "copy", output];
|
|
62
|
-
}
|
|
63
|
-
const graph = [
|
|
64
|
-
"[0:v]null[in]",
|
|
65
|
-
...ringFilters(rings.clicks, W, H, fps, rings.color),
|
|
66
|
-
`[out]${vf}[v]`,
|
|
67
|
-
].join(";");
|
|
68
|
-
return [
|
|
69
|
-
"-y", "-i", input, "-filter_complex", graph,
|
|
70
|
-
"-map", "[v]", "-map", "0:a?", ...resolveQuality(quality), "-c:a", "copy", output,
|
|
71
|
-
];
|
|
72
|
-
}
|
|
73
|
-
export function planAutoZoom(frames, w, h, W, H, opts = {}) {
|
|
74
|
-
const planner = createAutoZoomPlanner(w, h, W, H, opts);
|
|
75
|
-
for (const f of frames)
|
|
76
|
-
planner.push(f);
|
|
77
|
-
return planner.finish();
|
|
78
|
-
}
|
|
79
|
-
export function createAutoZoomPlanner(w, h, W, H, opts = {}) {
|
|
80
|
-
const step = opts.step ?? 0.25;
|
|
81
|
-
const hold = opts.holdSec ?? 2;
|
|
82
|
-
const maxZoom = opts.maxZoom ?? DEFAULT_AUTO_MAX_ZOOM;
|
|
83
|
-
const globalFraction = opts.globalFraction ?? 0.3;
|
|
84
|
-
const T = opts.transition ?? DEFAULT_TRANSITION_SEC;
|
|
85
|
-
const scale = W / w;
|
|
86
|
-
const minW = W / maxZoom;
|
|
87
|
-
const minH = H / maxZoom;
|
|
88
|
-
const focuses = [];
|
|
89
|
-
let cur = null;
|
|
90
|
-
const close = () => {
|
|
91
|
-
if (cur)
|
|
92
|
-
focuses.push(cur);
|
|
93
|
-
cur = null;
|
|
94
|
-
};
|
|
95
|
-
let prev = null;
|
|
96
|
-
let i = 0;
|
|
97
|
-
const push = (frame) => {
|
|
98
|
-
const before = prev;
|
|
99
|
-
prev = frame;
|
|
100
|
-
if (!before) {
|
|
101
|
-
i = 1;
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
const t = i++ * step;
|
|
105
|
-
const d = diffFrames(before, frame, w, h, { scale });
|
|
106
|
-
if (d.regions.length === 0) {
|
|
107
|
-
if (cur && t - cur.last > hold)
|
|
108
|
-
close();
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
if (d.changedFraction > globalFraction) {
|
|
112
|
-
close();
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const box = unionRects(d.regions);
|
|
116
|
-
if (cur && t - cur.last <= hold && near(cur.box, box, W, H)) {
|
|
117
|
-
cur.box = unionRects([cur.box, box]);
|
|
118
|
-
cur.last = t;
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
close();
|
|
122
|
-
cur = { start: t, last: t, box };
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
const finish = () => {
|
|
126
|
-
close();
|
|
127
|
-
const kfs = [];
|
|
128
|
-
let lastT = 0;
|
|
129
|
-
for (const f of focuses) {
|
|
130
|
-
const view = fitView(f.box, W, H, minW, minH);
|
|
131
|
-
const inAt = Math.max(f.start, lastT + T);
|
|
132
|
-
const outAt = Math.max(f.last + hold, inAt + T);
|
|
133
|
-
kfs.push({ t: round(inAt), ...view }, { t: round(outAt), full: true });
|
|
134
|
-
lastT = outAt;
|
|
135
|
-
}
|
|
136
|
-
return kfs;
|
|
137
|
-
};
|
|
138
|
-
return { push, finish };
|
|
139
|
-
}
|
|
140
|
-
const round = (v) => Math.round(v * 100) / 100;
|
|
141
|
-
function unionRects(rs) {
|
|
142
|
-
const x0 = Math.min(...rs.map((r) => r.x));
|
|
143
|
-
const y0 = Math.min(...rs.map((r) => r.y));
|
|
144
|
-
const x1 = Math.max(...rs.map((r) => r.x + r.width));
|
|
145
|
-
const y1 = Math.max(...rs.map((r) => r.y + r.height));
|
|
146
|
-
return { x: x0, y: y0, width: x1 - x0, height: y1 - y0 };
|
|
147
|
-
}
|
|
148
|
-
function near(a, b, W, H) {
|
|
149
|
-
const u = unionRects([a, b]);
|
|
150
|
-
return u.width <= W / 2 && u.height <= H / 2;
|
|
151
|
-
}
|
|
152
|
-
export function fitView(box, W, H, minW, minH) {
|
|
153
|
-
let width = Math.max(box.width * 1.4, minW);
|
|
154
|
-
let height = Math.max(box.height * 1.4, minH);
|
|
155
|
-
const aspect = W / H;
|
|
156
|
-
if (width / height > aspect)
|
|
157
|
-
height = width / aspect;
|
|
158
|
-
else
|
|
159
|
-
width = height * aspect;
|
|
160
|
-
width = Math.min(width, W);
|
|
161
|
-
height = Math.min(height, H);
|
|
162
|
-
const cx = box.x + box.width / 2;
|
|
163
|
-
const cy = box.y + box.height / 2;
|
|
164
|
-
const x = Math.max(0, Math.min(W - width, cx - width / 2));
|
|
165
|
-
const y = Math.max(0, Math.min(H - height, cy - height / 2));
|
|
166
|
-
return { x: Math.round(x), y: Math.round(y), width: Math.round(width), height: Math.round(height) };
|
|
167
|
-
}
|
|
168
|
-
export function buildAnalysisArgs(input, size, step) {
|
|
169
|
-
return [
|
|
170
|
-
"-v", "error", "-i", input, "-an",
|
|
171
|
-
"-vf", `fps=${n(1 / step)},scale=${size.width}:${size.height}:flags=area,format=gray`,
|
|
172
|
-
"-f", "rawvideo", "-",
|
|
173
|
-
];
|
|
174
|
-
}
|
|
175
|
-
export function planClickZoom(clicks, W, H, opts = {}) {
|
|
176
|
-
const hold = opts.holdSec ?? 2;
|
|
177
|
-
const maxZoom = opts.maxZoom ?? DEFAULT_AUTO_MAX_ZOOM;
|
|
178
|
-
const T = opts.transition ?? DEFAULT_TRANSITION_SEC;
|
|
179
|
-
const minW = W / maxZoom;
|
|
180
|
-
const minH = H / maxZoom;
|
|
181
|
-
const pad = Math.min(W, H) * 0.05;
|
|
182
|
-
const sorted = [...clicks].sort((a, b) => a.t - b.t);
|
|
183
|
-
const kfs = [];
|
|
184
|
-
let lastT = 0;
|
|
185
|
-
let runEnd = -Infinity;
|
|
186
|
-
for (const c of sorted) {
|
|
187
|
-
const view = fitView({ x: c.x - pad, y: c.y - pad, width: 2 * pad, height: 2 * pad }, W, H, minW, minH);
|
|
188
|
-
const prev = kfs[kfs.length - 1];
|
|
189
|
-
if (prev && !prev.full && c.t - runEnd <= hold && insideView(prev, c)) {
|
|
190
|
-
runEnd = c.t;
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
if (c.t - runEnd > hold && kfs.length > 0) {
|
|
194
|
-
const outAt = Math.max(runEnd + hold, lastT + T);
|
|
195
|
-
kfs.push({ t: round(outAt), full: true });
|
|
196
|
-
lastT = outAt;
|
|
197
|
-
}
|
|
198
|
-
const at = Math.max(c.t, lastT + T);
|
|
199
|
-
kfs.push({ t: round(at), ...view });
|
|
200
|
-
lastT = at;
|
|
201
|
-
runEnd = c.t;
|
|
202
|
-
}
|
|
203
|
-
if (kfs.length > 0)
|
|
204
|
-
kfs.push({ t: round(Math.max(runEnd + hold, lastT + T)), full: true });
|
|
205
|
-
return kfs;
|
|
206
|
-
}
|
|
207
|
-
function insideView(v, p) {
|
|
208
|
-
const mx = v.width * 0.15;
|
|
209
|
-
const my = v.height * 0.15;
|
|
210
|
-
return p.x >= v.x + mx && p.x <= v.x + v.width - mx && p.y >= v.y + my && p.y <= v.y + v.height - my;
|
|
211
|
-
}
|
|
212
|
-
export const RING_SEC = 0.6;
|
|
213
|
-
export const DEFAULT_RING_COLOR = "#FF4545";
|
|
214
|
-
export function ringSize(W, H) {
|
|
215
|
-
return Math.max(40, 2 * Math.round(Math.min(W, H) * 0.045));
|
|
216
|
-
}
|
|
217
|
-
export function ringFilters(clicks, W, H, fps, color) {
|
|
218
|
-
const D = ringSize(W, H);
|
|
219
|
-
const c = D / 2;
|
|
220
|
-
const th = Math.max(3, Math.round(D / 10));
|
|
221
|
-
const r0 = c * 0.3;
|
|
222
|
-
const dr = c - th / 2 - r0;
|
|
223
|
-
const steps = [];
|
|
224
|
-
let cur = "[in]";
|
|
225
|
-
clicks.forEach((k, i) => {
|
|
226
|
-
const alpha = `if(lt(abs(hypot(X-${c},Y-${c})-(${n(r0)}+${n(dr)}*T/${RING_SEC})),${th / 2}),255*min(1,2-2*T/${RING_SEC}),0)`;
|
|
227
|
-
steps.push(`color=c=${color}:s=${D}x${D}:r=${n(fps)}:d=${RING_SEC},format=rgba,` +
|
|
228
|
-
`geq=r='r(X,Y)':g='g(X,Y)':b='b(X,Y)':a='${alpha}',setpts=PTS+${n(k.t)}/TB[ring${i}]`);
|
|
229
|
-
const out = i === clicks.length - 1 ? "[out]" : `[r${i}]`;
|
|
230
|
-
steps.push(`${cur}[ring${i}]overlay=x=${n(k.x - c)}:y=${n(k.y - c)}:eof_action=pass${out}`);
|
|
231
|
-
cur = `[r${i}]`;
|
|
232
|
-
});
|
|
233
|
-
return steps;
|
|
234
|
-
}
|