@tmhs/screencast-mcp 0.39.0 → 0.44.2
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 +58 -14
- package/assets/icon.png +0 -0
- package/assets/ui/player.html +38 -302
- package/assets/ui/player.js +382 -0
- package/dist/context.js +0 -5
- package/dist/index.js +5 -21
- package/dist/prompts.js +0 -7
- package/dist/resources.js +2 -14
- package/dist/server.js +37 -11
- package/dist/tools/assembleHighlights.js +12 -7
- package/dist/tools/burnSubtitles.js +12 -6
- package/dist/tools/callout.js +32 -16
- package/dist/tools/clip.js +12 -9
- package/dist/tools/compress.js +10 -5
- package/dist/tools/concat.js +16 -15
- package/dist/tools/contactSheet.js +26 -22
- package/dist/tools/convert.js +12 -6
- package/dist/tools/crop.js +12 -7
- package/dist/tools/cutIdle.js +15 -9
- package/dist/tools/denoise.js +12 -6
- package/dist/tools/doctor.js +133 -0
- package/dist/tools/exportGif.js +14 -10
- package/dist/tools/exportPreset.js +11 -8
- package/dist/tools/extractAudio.js +10 -8
- package/dist/tools/findText.js +69 -65
- package/dist/tools/getMediaInfo.js +17 -3
- package/dist/tools/getSession.js +15 -3
- package/dist/tools/listAudioDevices.js +14 -7
- package/dist/tools/listSessions.js +13 -3
- package/dist/tools/listTargets.js +76 -0
- package/dist/tools/musicBed.js +14 -10
- package/dist/tools/normalizeAudio.js +12 -8
- package/dist/tools/overlay.js +16 -12
- package/dist/tools/pipeline.js +31 -22
- package/dist/tools/readEvents.js +21 -12
- package/dist/tools/redactRegion.js +19 -17
- package/dist/tools/reframe.js +9 -5
- package/dist/tools/reviewRecording.js +63 -22
- package/dist/tools/sampleFrames.js +33 -40
- package/dist/tools/scale.js +9 -3
- package/dist/tools/screenDiff.js +23 -17
- package/dist/tools/screenshot.js +21 -17
- package/dist/tools/speed.js +15 -4
- package/dist/tools/startRecording.js +48 -52
- package/dist/tools/stopRecording.js +10 -9
- package/dist/tools/titleCard.js +19 -11
- package/dist/tools/transcribe.js +13 -7
- package/dist/tools/trim.js +11 -10
- package/dist/tools/waitForChange.js +37 -22
- package/dist/tools/xfadeTransition.js +12 -8
- package/dist/tools/zoom.js +26 -29
- package/dist/utils/anim.js +1 -21
- package/dist/utils/animExport.js +5 -10
- package/dist/utils/audio.js +4 -33
- package/dist/utils/audioDevices.js +1 -48
- package/dist/utils/callout.js +1 -19
- package/dist/utils/calloutAssets.js +21 -11
- package/dist/utils/capabilities.js +95 -0
- package/dist/utils/captions.js +9 -26
- package/dist/utils/consent.js +29 -0
- package/dist/utils/diff.js +0 -46
- package/dist/utils/errors.js +5 -13
- package/dist/utils/events.js +21 -77
- package/dist/utils/expr.js +11 -0
- package/dist/utils/ffmpeg.js +119 -48
- package/dist/utils/fontCoverage.js +177 -0
- package/dist/utils/fonts.js +139 -23
- package/dist/utils/idle.js +12 -24
- package/dist/utils/images.js +0 -17
- package/dist/utils/jobs.js +42 -41
- package/dist/utils/lifecycle.js +0 -29
- package/dist/utils/logging.js +75 -0
- package/dist/utils/media.js +11 -122
- package/dist/utils/monitors.js +7 -43
- package/dist/utils/ocr.js +53 -71
- package/dist/utils/paths.js +68 -31
- package/dist/utils/pipeline.js +0 -23
- package/dist/utils/player.js +50 -27
- package/dist/utils/produce.js +6 -66
- package/dist/utils/resolveTarget.js +0 -19
- package/dist/utils/retention.js +1 -15
- package/dist/utils/roots.js +42 -0
- package/dist/utils/sessions.js +195 -160
- package/dist/utils/sheet.js +0 -19
- package/dist/utils/still.js +0 -15
- package/dist/utils/targetList.js +63 -0
- package/dist/utils/targets.js +5 -70
- package/dist/utils/toolSpec.js +25 -0
- package/dist/utils/toolsets.js +102 -0
- package/dist/utils/validate.js +0 -22
- package/dist/utils/wgc.js +0 -46
- package/dist/utils/windows.js +5 -50
- package/dist/utils/zoom.js +55 -85
- package/dist/wgcRecorder.js +1 -30
- package/package.json +7 -3
- package/dist/context.d.ts +0 -9
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/prompts.d.ts +0 -10
- package/dist/prompts.d.ts.map +0 -1
- package/dist/prompts.js.map +0 -1
- package/dist/resources.d.ts +0 -3
- package/dist/resources.d.ts.map +0 -1
- package/dist/resources.js.map +0 -1
- package/dist/server.d.ts +0 -3
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/tools/assembleHighlights.d.ts +0 -3
- package/dist/tools/assembleHighlights.d.ts.map +0 -1
- package/dist/tools/assembleHighlights.js.map +0 -1
- package/dist/tools/burnSubtitles.d.ts +0 -3
- package/dist/tools/burnSubtitles.d.ts.map +0 -1
- package/dist/tools/burnSubtitles.js.map +0 -1
- package/dist/tools/callout.d.ts +0 -37
- package/dist/tools/callout.d.ts.map +0 -1
- package/dist/tools/callout.js.map +0 -1
- package/dist/tools/clip.d.ts +0 -3
- package/dist/tools/clip.d.ts.map +0 -1
- package/dist/tools/clip.js.map +0 -1
- package/dist/tools/compress.d.ts +0 -3
- package/dist/tools/compress.d.ts.map +0 -1
- package/dist/tools/compress.js.map +0 -1
- package/dist/tools/concat.d.ts +0 -3
- package/dist/tools/concat.d.ts.map +0 -1
- package/dist/tools/concat.js.map +0 -1
- package/dist/tools/contactSheet.d.ts +0 -3
- package/dist/tools/contactSheet.d.ts.map +0 -1
- package/dist/tools/contactSheet.js.map +0 -1
- package/dist/tools/convert.d.ts +0 -3
- package/dist/tools/convert.d.ts.map +0 -1
- package/dist/tools/convert.js.map +0 -1
- package/dist/tools/crop.d.ts +0 -3
- package/dist/tools/crop.d.ts.map +0 -1
- package/dist/tools/crop.js.map +0 -1
- package/dist/tools/cutIdle.d.ts +0 -3
- package/dist/tools/cutIdle.d.ts.map +0 -1
- package/dist/tools/cutIdle.js.map +0 -1
- package/dist/tools/denoise.d.ts +0 -3
- package/dist/tools/denoise.d.ts.map +0 -1
- package/dist/tools/denoise.js.map +0 -1
- package/dist/tools/exportGif.d.ts +0 -3
- package/dist/tools/exportGif.d.ts.map +0 -1
- package/dist/tools/exportGif.js.map +0 -1
- package/dist/tools/exportPreset.d.ts +0 -3
- package/dist/tools/exportPreset.d.ts.map +0 -1
- package/dist/tools/exportPreset.js.map +0 -1
- package/dist/tools/extractAudio.d.ts +0 -3
- package/dist/tools/extractAudio.d.ts.map +0 -1
- package/dist/tools/extractAudio.js.map +0 -1
- package/dist/tools/findText.d.ts +0 -6
- package/dist/tools/findText.d.ts.map +0 -1
- package/dist/tools/findText.js.map +0 -1
- package/dist/tools/getMediaInfo.d.ts +0 -3
- package/dist/tools/getMediaInfo.d.ts.map +0 -1
- package/dist/tools/getMediaInfo.js.map +0 -1
- package/dist/tools/getSession.d.ts +0 -3
- package/dist/tools/getSession.d.ts.map +0 -1
- package/dist/tools/getSession.js.map +0 -1
- package/dist/tools/listAudioDevices.d.ts +0 -3
- package/dist/tools/listAudioDevices.d.ts.map +0 -1
- package/dist/tools/listAudioDevices.js.map +0 -1
- package/dist/tools/listSessions.d.ts +0 -3
- package/dist/tools/listSessions.d.ts.map +0 -1
- package/dist/tools/listSessions.js.map +0 -1
- package/dist/tools/musicBed.d.ts +0 -3
- package/dist/tools/musicBed.d.ts.map +0 -1
- package/dist/tools/musicBed.js.map +0 -1
- package/dist/tools/normalizeAudio.d.ts +0 -3
- package/dist/tools/normalizeAudio.d.ts.map +0 -1
- package/dist/tools/normalizeAudio.js.map +0 -1
- package/dist/tools/overlay.d.ts +0 -3
- package/dist/tools/overlay.d.ts.map +0 -1
- package/dist/tools/overlay.js.map +0 -1
- package/dist/tools/pipeline.d.ts +0 -3
- package/dist/tools/pipeline.d.ts.map +0 -1
- package/dist/tools/pipeline.js.map +0 -1
- package/dist/tools/readEvents.d.ts +0 -6
- package/dist/tools/readEvents.d.ts.map +0 -1
- package/dist/tools/readEvents.js.map +0 -1
- package/dist/tools/redactRegion.d.ts +0 -13
- package/dist/tools/redactRegion.d.ts.map +0 -1
- package/dist/tools/redactRegion.js.map +0 -1
- package/dist/tools/reframe.d.ts +0 -3
- package/dist/tools/reframe.d.ts.map +0 -1
- package/dist/tools/reframe.js.map +0 -1
- package/dist/tools/reviewRecording.d.ts +0 -5
- package/dist/tools/reviewRecording.d.ts.map +0 -1
- package/dist/tools/reviewRecording.js.map +0 -1
- package/dist/tools/sampleFrames.d.ts +0 -3
- package/dist/tools/sampleFrames.d.ts.map +0 -1
- package/dist/tools/sampleFrames.js.map +0 -1
- package/dist/tools/scale.d.ts +0 -3
- package/dist/tools/scale.d.ts.map +0 -1
- package/dist/tools/scale.js.map +0 -1
- package/dist/tools/screenDiff.d.ts +0 -3
- package/dist/tools/screenDiff.d.ts.map +0 -1
- package/dist/tools/screenDiff.js.map +0 -1
- package/dist/tools/screenshot.d.ts +0 -3
- package/dist/tools/screenshot.d.ts.map +0 -1
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/speed.d.ts +0 -3
- package/dist/tools/speed.d.ts.map +0 -1
- package/dist/tools/speed.js.map +0 -1
- package/dist/tools/startRecording.d.ts +0 -3
- package/dist/tools/startRecording.d.ts.map +0 -1
- package/dist/tools/startRecording.js.map +0 -1
- package/dist/tools/stopRecording.d.ts +0 -3
- package/dist/tools/stopRecording.d.ts.map +0 -1
- package/dist/tools/stopRecording.js.map +0 -1
- package/dist/tools/titleCard.d.ts +0 -3
- package/dist/tools/titleCard.d.ts.map +0 -1
- package/dist/tools/titleCard.js.map +0 -1
- package/dist/tools/transcribe.d.ts +0 -3
- package/dist/tools/transcribe.d.ts.map +0 -1
- package/dist/tools/transcribe.js.map +0 -1
- package/dist/tools/trim.d.ts +0 -3
- package/dist/tools/trim.d.ts.map +0 -1
- package/dist/tools/trim.js.map +0 -1
- package/dist/tools/waitForChange.d.ts +0 -3
- package/dist/tools/waitForChange.d.ts.map +0 -1
- package/dist/tools/waitForChange.js.map +0 -1
- package/dist/tools/xfadeTransition.d.ts +0 -3
- package/dist/tools/xfadeTransition.d.ts.map +0 -1
- package/dist/tools/xfadeTransition.js.map +0 -1
- package/dist/tools/zoom.d.ts +0 -15
- package/dist/tools/zoom.d.ts.map +0 -1
- package/dist/tools/zoom.js.map +0 -1
- package/dist/utils/anim.d.ts +0 -33
- package/dist/utils/anim.d.ts.map +0 -1
- package/dist/utils/anim.js.map +0 -1
- package/dist/utils/animExport.d.ts +0 -27
- package/dist/utils/animExport.d.ts.map +0 -1
- package/dist/utils/animExport.js.map +0 -1
- package/dist/utils/audio.d.ts +0 -49
- package/dist/utils/audio.d.ts.map +0 -1
- package/dist/utils/audio.js.map +0 -1
- package/dist/utils/audioDevices.d.ts +0 -33
- package/dist/utils/audioDevices.d.ts.map +0 -1
- package/dist/utils/audioDevices.js.map +0 -1
- package/dist/utils/callout.d.ts +0 -72
- package/dist/utils/callout.d.ts.map +0 -1
- package/dist/utils/callout.js.map +0 -1
- package/dist/utils/calloutAssets.d.ts +0 -3
- package/dist/utils/calloutAssets.d.ts.map +0 -1
- package/dist/utils/calloutAssets.js.map +0 -1
- package/dist/utils/captions.d.ts +0 -26
- package/dist/utils/captions.d.ts.map +0 -1
- package/dist/utils/captions.js.map +0 -1
- package/dist/utils/diff.d.ts +0 -112
- package/dist/utils/diff.d.ts.map +0 -1
- package/dist/utils/diff.js.map +0 -1
- package/dist/utils/errors.d.ts +0 -33
- package/dist/utils/errors.d.ts.map +0 -1
- package/dist/utils/errors.js.map +0 -1
- package/dist/utils/events.d.ts +0 -143
- package/dist/utils/events.d.ts.map +0 -1
- package/dist/utils/events.js.map +0 -1
- package/dist/utils/ffmpeg.d.ts +0 -50
- package/dist/utils/ffmpeg.d.ts.map +0 -1
- package/dist/utils/ffmpeg.js.map +0 -1
- package/dist/utils/fonts.d.ts +0 -17
- package/dist/utils/fonts.d.ts.map +0 -1
- package/dist/utils/fonts.js.map +0 -1
- package/dist/utils/idle.d.ts +0 -23
- package/dist/utils/idle.d.ts.map +0 -1
- package/dist/utils/idle.js.map +0 -1
- package/dist/utils/images.d.ts +0 -21
- package/dist/utils/images.d.ts.map +0 -1
- package/dist/utils/images.js.map +0 -1
- package/dist/utils/jobs.d.ts +0 -44
- package/dist/utils/jobs.d.ts.map +0 -1
- package/dist/utils/jobs.js.map +0 -1
- package/dist/utils/lifecycle.d.ts +0 -29
- package/dist/utils/lifecycle.d.ts.map +0 -1
- package/dist/utils/lifecycle.js.map +0 -1
- package/dist/utils/media.d.ts +0 -272
- package/dist/utils/media.d.ts.map +0 -1
- package/dist/utils/media.js.map +0 -1
- package/dist/utils/monitors.d.ts +0 -47
- package/dist/utils/monitors.d.ts.map +0 -1
- package/dist/utils/monitors.js.map +0 -1
- package/dist/utils/ocr.d.ts +0 -50
- package/dist/utils/ocr.d.ts.map +0 -1
- package/dist/utils/ocr.js.map +0 -1
- package/dist/utils/paths.d.ts +0 -28
- package/dist/utils/paths.d.ts.map +0 -1
- package/dist/utils/paths.js.map +0 -1
- package/dist/utils/pipeline.d.ts +0 -69
- package/dist/utils/pipeline.d.ts.map +0 -1
- package/dist/utils/pipeline.js.map +0 -1
- package/dist/utils/player.d.ts +0 -30
- package/dist/utils/player.d.ts.map +0 -1
- package/dist/utils/player.js.map +0 -1
- package/dist/utils/produce.d.ts +0 -126
- package/dist/utils/produce.d.ts.map +0 -1
- package/dist/utils/produce.js.map +0 -1
- package/dist/utils/resolveTarget.d.ts +0 -32
- package/dist/utils/resolveTarget.d.ts.map +0 -1
- package/dist/utils/resolveTarget.js.map +0 -1
- package/dist/utils/retention.d.ts +0 -10
- package/dist/utils/retention.d.ts.map +0 -1
- package/dist/utils/retention.js.map +0 -1
- package/dist/utils/sessions.d.ts +0 -154
- package/dist/utils/sessions.d.ts.map +0 -1
- package/dist/utils/sessions.js.map +0 -1
- package/dist/utils/sheet.d.ts +0 -26
- package/dist/utils/sheet.d.ts.map +0 -1
- package/dist/utils/sheet.js.map +0 -1
- package/dist/utils/still.d.ts +0 -7
- package/dist/utils/still.d.ts.map +0 -1
- package/dist/utils/still.js.map +0 -1
- package/dist/utils/targets.d.ts +0 -113
- package/dist/utils/targets.d.ts.map +0 -1
- package/dist/utils/targets.js.map +0 -1
- package/dist/utils/validate.d.ts +0 -15
- package/dist/utils/validate.d.ts.map +0 -1
- package/dist/utils/validate.js.map +0 -1
- package/dist/utils/wgc.d.ts +0 -46
- package/dist/utils/wgc.d.ts.map +0 -1
- package/dist/utils/wgc.js.map +0 -1
- package/dist/utils/windows.d.ts +0 -94
- package/dist/utils/windows.d.ts.map +0 -1
- package/dist/utils/windows.js.map +0 -1
- package/dist/utils/zoom.d.ts +0 -95
- package/dist/utils/zoom.d.ts.map +0 -1
- package/dist/utils/zoom.js.map +0 -1
- package/dist/wgcRecorder.d.ts +0 -2
- package/dist/wgcRecorder.d.ts.map +0 -1
- package/dist/wgcRecorder.js.map +0 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { virtualDesktopBounds } from "./targets.js";
|
|
2
|
+
import { parseWindowSelector, selectWindow } from "./windows.js";
|
|
3
|
+
function windowTarget(w) {
|
|
4
|
+
return w.hwnd !== undefined ? `window:hwnd=${w.hwnd}` : `window:${w.title}`;
|
|
5
|
+
}
|
|
6
|
+
function firstSentence(message) {
|
|
7
|
+
const m = /^.*?[.!?](?=\s|$)/.exec(message);
|
|
8
|
+
return m ? m[0] : message;
|
|
9
|
+
}
|
|
10
|
+
function resolves(query, w, allowCloaked) {
|
|
11
|
+
try {
|
|
12
|
+
selectWindow(query, windowTarget(w).slice("window:".length), { allowCloaked, exactOnly: true });
|
|
13
|
+
return { ok: true };
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
return { ok: false, reason: firstSentence(err.message) };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function buildTargetList(monitors, query, opts) {
|
|
20
|
+
const filter = opts.filter ?? {};
|
|
21
|
+
const exe = filter.exe ? parseWindowSelector(`exe=${filter.exe}`) : null;
|
|
22
|
+
const wantedExe = exe?.kind === "exe" ? exe.exe : null;
|
|
23
|
+
const needle = filter.titleContains?.trim().toLowerCase() || null;
|
|
24
|
+
const v = virtualDesktopBounds(monitors);
|
|
25
|
+
const desktop = monitors.length > 0 ? v : query.virtual;
|
|
26
|
+
const windows = [];
|
|
27
|
+
for (const w of Array.isArray(query.windows) ? query.windows : []) {
|
|
28
|
+
if (wantedExe !== null && (w.exe ?? "").toLowerCase().replace(/\.exe$/, "") !== wantedExe)
|
|
29
|
+
continue;
|
|
30
|
+
if (needle !== null && !w.title.toLowerCase().includes(needle))
|
|
31
|
+
continue;
|
|
32
|
+
const gdi = resolves(query, w, false);
|
|
33
|
+
const wgc = opts.wgcAvailable && w.hwnd !== undefined ? resolves(query, w, true) : { ok: false };
|
|
34
|
+
if (filter.capturableOnly && !gdi.ok && !wgc.ok)
|
|
35
|
+
continue;
|
|
36
|
+
windows.push({
|
|
37
|
+
target: windowTarget(w),
|
|
38
|
+
title: w.title,
|
|
39
|
+
exe: w.exe || null,
|
|
40
|
+
pid: typeof w.pid === "number" ? w.pid : null,
|
|
41
|
+
hwnd: w.hwnd ?? null,
|
|
42
|
+
bounds: { x: w.left, y: w.top, width: w.right - w.left, height: w.bottom - w.top },
|
|
43
|
+
minimized: Boolean(w.minimized),
|
|
44
|
+
cloaked: Boolean(w.cloaked),
|
|
45
|
+
capturable: gdi.ok,
|
|
46
|
+
wgcCapturable: wgc.ok,
|
|
47
|
+
...(gdi.ok ? {} : { reason: gdi.reason }),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
full: { target: "full", bounds: { x: desktop.x, y: desktop.y, width: desktop.w, height: desktop.h } },
|
|
52
|
+
monitors: monitors.map((m) => ({
|
|
53
|
+
target: `monitor:${m.index}`,
|
|
54
|
+
index: m.index,
|
|
55
|
+
primary: m.primary,
|
|
56
|
+
bounds: { x: m.x, y: m.y, width: m.width, height: m.height },
|
|
57
|
+
dpi: m.dpi ?? null,
|
|
58
|
+
scale: m.dpi ? Math.round((m.dpi / 96) * 100) / 100 : null,
|
|
59
|
+
})),
|
|
60
|
+
windows,
|
|
61
|
+
wgcAvailable: opts.wgcAvailable,
|
|
62
|
+
};
|
|
63
|
+
}
|
package/dist/utils/targets.js
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Capture target parsing and gdigrab argument construction.
|
|
3
|
-
*
|
|
4
|
-
* Target grammar (a single string so an agent never has to juggle quoting):
|
|
5
|
-
* full - the whole virtual desktop
|
|
6
|
-
* monitor:<index> - one display; 0 is primary (see monitors.ts)
|
|
7
|
-
* window:<title> - a window by exact title (everything after the colon)
|
|
8
|
-
* region:<x>,<y>,<w>,<h> - an absolute pixel rectangle on the virtual desktop
|
|
9
|
-
*
|
|
10
|
-
* Everything here is pure (the monitor list is passed in), so the offset math
|
|
11
|
-
* that makes monitor:1 grab the second display is unit-tested without Windows.
|
|
12
|
-
*/
|
|
13
1
|
import { ScreencastError } from "./errors.js";
|
|
14
2
|
import { stillOutput } from "./paths.js";
|
|
15
3
|
export const QUALITY_PRESETS = {
|
|
@@ -19,14 +7,9 @@ export const QUALITY_PRESETS = {
|
|
|
19
7
|
};
|
|
20
8
|
export const DEFAULT_FPS = 30;
|
|
21
9
|
export const DEFAULT_QUALITY = "standard";
|
|
22
|
-
// gdigrab is video-only, so system audio comes from a separate dshow input.
|
|
23
|
-
// Device resolution (enumeration + loopback selection) lives in
|
|
24
|
-
// utils/audioDevices.ts; this stays pure and just takes the resolved name.
|
|
25
10
|
export function buildAudioInputArgs(audio) {
|
|
26
11
|
if (!audio || audio.device.trim().length === 0)
|
|
27
12
|
return [];
|
|
28
|
-
// No surrounding quotes: passed as a single argv element, ffmpeg reads the
|
|
29
|
-
// whole value (spaces included) as the device spec.
|
|
30
13
|
return ["-f", "dshow", "-i", `audio=${audio.device}`];
|
|
31
14
|
}
|
|
32
15
|
function parseIntStrict(value, label) {
|
|
@@ -35,7 +18,6 @@ function parseIntStrict(value, label) {
|
|
|
35
18
|
}
|
|
36
19
|
return parseInt(value, 10);
|
|
37
20
|
}
|
|
38
|
-
/** Parse a target spec string into a structured Target. */
|
|
39
21
|
export function parseTarget(spec) {
|
|
40
22
|
const raw = spec.trim();
|
|
41
23
|
if (raw === "" || raw.toLowerCase() === "full")
|
|
@@ -64,11 +46,12 @@ export function parseTarget(spec) {
|
|
|
64
46
|
if (parts.length !== 4) {
|
|
65
47
|
throw new ScreencastError(`region must be x,y,w,h (4 integers), got "${rest}".`);
|
|
66
48
|
}
|
|
49
|
+
const [px = "", py = "", pw = "", ph = ""] = parts;
|
|
67
50
|
const [x, y, w, h] = [
|
|
68
|
-
parseIntStrict(
|
|
69
|
-
parseIntStrict(
|
|
70
|
-
parseIntStrict(
|
|
71
|
-
parseIntStrict(
|
|
51
|
+
parseIntStrict(px, "region x"),
|
|
52
|
+
parseIntStrict(py, "region y"),
|
|
53
|
+
parseIntStrict(pw, "region w"),
|
|
54
|
+
parseIntStrict(ph, "region h"),
|
|
72
55
|
];
|
|
73
56
|
if (w <= 0 || h <= 0) {
|
|
74
57
|
throw new ScreencastError("region width and height must be positive.");
|
|
@@ -77,7 +60,6 @@ export function parseTarget(spec) {
|
|
|
77
60
|
}
|
|
78
61
|
throw new ScreencastError(`Unknown target kind "${kind}". Use full | monitor | window | region.`);
|
|
79
62
|
}
|
|
80
|
-
/** Resolve a monitor index to its pixel bounds using the supplied monitor list. */
|
|
81
63
|
export function resolveMonitor(index, monitors) {
|
|
82
64
|
const m = monitors.find((mon) => mon.index === index);
|
|
83
65
|
if (!m) {
|
|
@@ -86,9 +68,6 @@ export function resolveMonitor(index, monitors) {
|
|
|
86
68
|
}
|
|
87
69
|
return m;
|
|
88
70
|
}
|
|
89
|
-
/** The virtual desktop = the bounding box of every monitor. gdigrab captures
|
|
90
|
-
* this rectangle, so a region must fit inside it. Returns a zero-size box when
|
|
91
|
-
* no monitors are supplied (the caller then skips bounds validation). */
|
|
92
71
|
export function virtualDesktopBounds(monitors) {
|
|
93
72
|
if (monitors.length === 0)
|
|
94
73
|
return { x: 0, y: 0, w: 0, h: 0 };
|
|
@@ -98,15 +77,6 @@ export function virtualDesktopBounds(monitors) {
|
|
|
98
77
|
const maxY = Math.max(...monitors.map((m) => m.y + m.height));
|
|
99
78
|
return { x: minX, y: minY, w: maxX - minX, h: maxY - minY };
|
|
100
79
|
}
|
|
101
|
-
/**
|
|
102
|
-
* Reject a region rectangle that is not fully inside the virtual desktop.
|
|
103
|
-
* gdigrab passes the offset/size straight through, so an off-desktop rectangle
|
|
104
|
-
* (a negative offset before the leftmost monitor, or one running past the
|
|
105
|
-
* right/bottom edge) otherwise fails with a cryptic libav error. Negative
|
|
106
|
-
* offsets are legitimate when a monitor sits left of / above the primary, so
|
|
107
|
-
* the rectangle is checked against the real desktop origin, not a blanket >= 0.
|
|
108
|
-
* With no monitor geometry the check is skipped (cannot validate).
|
|
109
|
-
*/
|
|
110
80
|
export function validateRegionOnDesktop(region, monitors) {
|
|
111
81
|
if (monitors.length === 0)
|
|
112
82
|
return;
|
|
@@ -122,7 +92,6 @@ export function validateRegionOnDesktop(region, monitors) {
|
|
|
122
92
|
`offset/size, or use monitor:<index> to capture a whole display.`);
|
|
123
93
|
}
|
|
124
94
|
}
|
|
125
|
-
/** Encoder args for a quality preset (libx264, web-safe pixel format). */
|
|
126
95
|
export function resolveQuality(quality) {
|
|
127
96
|
const q = QUALITY_PRESETS[quality];
|
|
128
97
|
if (!q)
|
|
@@ -130,16 +99,12 @@ export function resolveQuality(quality) {
|
|
|
130
99
|
return ["-c:v", "libx264", "-preset", q.preset, "-crf", String(q.crf),
|
|
131
100
|
"-pix_fmt", "yuv420p"];
|
|
132
101
|
}
|
|
133
|
-
/** Largest even integer <= n. libx264 + yuv420p requires even W/H. */
|
|
134
102
|
function evenDown(n) {
|
|
135
103
|
return n - (n % 2);
|
|
136
104
|
}
|
|
137
|
-
/** The gdigrab input args (offset/size/input) for a target. */
|
|
138
105
|
export function targetInputArgs(target, monitors, opts = {}) {
|
|
139
106
|
switch (target.kind) {
|
|
140
107
|
case "full": {
|
|
141
|
-
// An odd-sized virtual desktop (offset monitors) fails libx264 + yuv420p,
|
|
142
|
-
// so the recording path grabs it as an even-sized region instead (#226).
|
|
143
108
|
const v = virtualDesktopBounds(monitors);
|
|
144
109
|
if (opts.evenSize && monitors.length > 0 && (v.w % 2 !== 0 || v.h % 2 !== 0)) {
|
|
145
110
|
return [
|
|
@@ -152,9 +117,6 @@ export function targetInputArgs(target, monitors, opts = {}) {
|
|
|
152
117
|
return ["-i", "desktop"];
|
|
153
118
|
}
|
|
154
119
|
case "window":
|
|
155
|
-
// A window target must be resolved to its on-screen rectangle first (see
|
|
156
|
-
// resolveCaptureTarget). gdigrab `title=` grabs a blank surface for
|
|
157
|
-
// GPU-composited windows, so it is never used.
|
|
158
120
|
throw new ScreencastError("Internal: a window target must be resolved to a region before " +
|
|
159
121
|
"building capture args. Call resolveCaptureTarget().");
|
|
160
122
|
case "region": {
|
|
@@ -188,13 +150,7 @@ export function targetInputArgs(target, monitors, opts = {}) {
|
|
|
188
150
|
}
|
|
189
151
|
}
|
|
190
152
|
}
|
|
191
|
-
/** Default recording cap when start_recording is given none (#82): one hour. */
|
|
192
153
|
export const DEFAULT_MAX_RECORDING_SEC = 3600;
|
|
193
|
-
/**
|
|
194
|
-
* Resolve the effective recording cap: an explicit per-call value, else
|
|
195
|
-
* SCREENCAST_MAX_RECORDING_SEC, else DEFAULT_MAX_RECORDING_SEC. 0 means no cap.
|
|
196
|
-
* Pure (env is passed in) so the precedence is unit-tested.
|
|
197
|
-
*/
|
|
198
154
|
export function resolveMaxDuration(explicit, env = process.env) {
|
|
199
155
|
if (explicit !== undefined)
|
|
200
156
|
return validateMaxDuration(explicit);
|
|
@@ -208,7 +164,6 @@ export function resolveMaxDuration(explicit, env = process.env) {
|
|
|
208
164
|
}
|
|
209
165
|
return DEFAULT_MAX_RECORDING_SEC;
|
|
210
166
|
}
|
|
211
|
-
/** The largest accepted cap: 7 days. Use 0 for no cap at all (#184). */
|
|
212
167
|
export const MAX_RECORDING_CAP_SEC = 7 * 24 * 3600;
|
|
213
168
|
function validateMaxDuration(n) {
|
|
214
169
|
if (!Number.isInteger(n) || n < 0 || n > MAX_RECORDING_CAP_SEC) {
|
|
@@ -222,13 +177,9 @@ function validateFps(fps) {
|
|
|
222
177
|
}
|
|
223
178
|
return fps;
|
|
224
179
|
}
|
|
225
|
-
/** A keyframe every 2 s of capture. x264's default (250 frames) is 25 s at 10
|
|
226
|
-
* fps, so a stream-copy cut snaps far from the cut point and hides that much
|
|
227
|
-
* content behind an edit list (#203). */
|
|
228
180
|
export function captureKeyframeArgs(fps) {
|
|
229
181
|
return ["-g", String(Math.max(1, Math.round(fps * 2)))];
|
|
230
182
|
}
|
|
231
|
-
/** Build the full ffmpeg argument vector for a recording (gdigrab -> mp4). */
|
|
232
183
|
export function buildCaptureArgs(target, opts) {
|
|
233
184
|
const fps = validateFps(opts.fps ?? DEFAULT_FPS);
|
|
234
185
|
const quality = opts.quality ?? DEFAULT_QUALITY;
|
|
@@ -240,29 +191,18 @@ export function buildCaptureArgs(target, opts) {
|
|
|
240
191
|
"-framerate", String(fps),
|
|
241
192
|
...targetInputArgs(target, monitors, { evenSize: true }),
|
|
242
193
|
...buildAudioInputArgs(opts.audio),
|
|
243
|
-
// Without monitor geometry `full` cannot be sized up front, so crop it to
|
|
244
|
-
// even dimensions in the filter graph instead (#226).
|
|
245
194
|
...(target.kind === "full" && monitors.length === 0
|
|
246
195
|
? ["-vf", "crop=trunc(iw/2)*2:trunc(ih/2)*2"]
|
|
247
196
|
: []),
|
|
248
197
|
...resolveQuality(quality),
|
|
249
198
|
...captureKeyframeArgs(fps),
|
|
250
199
|
...(opts.audio ? ["-c:a", "aac", "-b:a", "160k"] : []),
|
|
251
|
-
// Fragmented mp4: keeps the file playable even if the process is killed
|
|
252
|
-
// before the trailing moov atom would normally be written.
|
|
253
200
|
"-movflags", "+frag_keyframe+empty_moov+default_base_moof",
|
|
254
|
-
// Output-side -t: ffmpeg stops and finalizes the file cleanly at the cap.
|
|
255
201
|
...(cap > 0 ? ["-t", String(cap)] : []),
|
|
256
202
|
opts.output,
|
|
257
203
|
];
|
|
258
204
|
}
|
|
259
|
-
/** gdigrab rate for a still. gdigrab paces grabs at the input rate, so at 1
|
|
260
|
-
* fps ffmpeg waits about two frame intervals (~2 s) before writing a single
|
|
261
|
-
* frame; at 30 fps the same still takes ~0.2 s and is pixel-identical (#88). */
|
|
262
205
|
export const SCREENSHOT_GRAB_FPS = 30;
|
|
263
|
-
/** A still of one window's own surface through Windows Graphics Capture
|
|
264
|
-
* (FFmpeg 8's gfxcapture), selected by handle (#113). Unlike gdigrab, it
|
|
265
|
-
* captures the window even when other windows cover it. */
|
|
266
206
|
export function buildWgcScreenshotArgs(hwnd, output) {
|
|
267
207
|
if (!Number.isSafeInteger(hwnd) || hwnd <= 0)
|
|
268
208
|
throw new ScreencastError("Invalid window handle.");
|
|
@@ -273,7 +213,6 @@ export function buildWgcScreenshotArgs(hwnd, output) {
|
|
|
273
213
|
...stillOutput(output),
|
|
274
214
|
];
|
|
275
215
|
}
|
|
276
|
-
/** Build ffmpeg args for a single-frame screenshot (gdigrab -> png). */
|
|
277
216
|
export function buildScreenshotArgs(target, output, monitors = []) {
|
|
278
217
|
return [
|
|
279
218
|
"-y",
|
|
@@ -284,9 +223,6 @@ export function buildScreenshotArgs(target, output, monitors = []) {
|
|
|
284
223
|
...stillOutput(output),
|
|
285
224
|
];
|
|
286
225
|
}
|
|
287
|
-
/** Where the recorded video sits on the desktop, and its size: the offset that
|
|
288
|
-
* maps desktop coordinates (input events, #118) to video pixels. `full` needs
|
|
289
|
-
* the monitor list for the virtual desktop's origin, which can be negative. */
|
|
290
226
|
export function captureFrame(target, monitors) {
|
|
291
227
|
switch (target.kind) {
|
|
292
228
|
case "region":
|
|
@@ -303,4 +239,3 @@ export function captureFrame(target, monitors) {
|
|
|
303
239
|
throw new ScreencastError("Internal: resolve a window target to a region first.");
|
|
304
240
|
}
|
|
305
241
|
}
|
|
306
|
-
//# sourceMappingURL=targets.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const READ_ONLY = {
|
|
3
|
+
readOnlyHint: true,
|
|
4
|
+
destructiveHint: false,
|
|
5
|
+
idempotentHint: true,
|
|
6
|
+
openWorldHint: false,
|
|
7
|
+
};
|
|
8
|
+
export const WRITES_FILE = {
|
|
9
|
+
readOnlyHint: false,
|
|
10
|
+
destructiveHint: true,
|
|
11
|
+
idempotentHint: false,
|
|
12
|
+
openWorldHint: false,
|
|
13
|
+
};
|
|
14
|
+
export const STOPS_SESSION = {
|
|
15
|
+
readOnlyHint: false,
|
|
16
|
+
destructiveHint: false,
|
|
17
|
+
idempotentHint: true,
|
|
18
|
+
openWorldHint: false,
|
|
19
|
+
};
|
|
20
|
+
export function looseOutput(shape) {
|
|
21
|
+
return z.looseObject(shape);
|
|
22
|
+
}
|
|
23
|
+
export const OUTPUT_PATH = looseOutput({
|
|
24
|
+
outputPath: z.string().describe("Path of the file written."),
|
|
25
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export const TOOLSETS = {
|
|
2
|
+
core: ["doctor", "get_media_info"],
|
|
3
|
+
capture: [
|
|
4
|
+
"start_recording",
|
|
5
|
+
"stop_recording",
|
|
6
|
+
"list_sessions",
|
|
7
|
+
"get_session",
|
|
8
|
+
"read_events",
|
|
9
|
+
"screenshot",
|
|
10
|
+
"list_targets",
|
|
11
|
+
"list_audio_devices",
|
|
12
|
+
],
|
|
13
|
+
watch: [
|
|
14
|
+
"sample_frames",
|
|
15
|
+
"contact_sheet",
|
|
16
|
+
"screen_diff",
|
|
17
|
+
"wait_for_change",
|
|
18
|
+
"find_text",
|
|
19
|
+
"review_recording",
|
|
20
|
+
"player_frames",
|
|
21
|
+
],
|
|
22
|
+
edit: [
|
|
23
|
+
"pipeline",
|
|
24
|
+
"trim",
|
|
25
|
+
"clip",
|
|
26
|
+
"concat",
|
|
27
|
+
"convert",
|
|
28
|
+
"export_gif",
|
|
29
|
+
"crop",
|
|
30
|
+
"scale",
|
|
31
|
+
"speed",
|
|
32
|
+
"compress",
|
|
33
|
+
"redact_region",
|
|
34
|
+
"cut_idle",
|
|
35
|
+
],
|
|
36
|
+
produce: [
|
|
37
|
+
"callout",
|
|
38
|
+
"overlay",
|
|
39
|
+
"zoom",
|
|
40
|
+
"reframe",
|
|
41
|
+
"title_card",
|
|
42
|
+
"xfade_transition",
|
|
43
|
+
"assemble_highlights",
|
|
44
|
+
"export_preset",
|
|
45
|
+
"burn_subtitles",
|
|
46
|
+
],
|
|
47
|
+
audio: ["extract_audio", "normalize_audio", "denoise", "transcribe", "music_bed"],
|
|
48
|
+
};
|
|
49
|
+
export const SELECTABLE_TOOLSETS = Object.keys(TOOLSETS).filter((t) => t !== "core");
|
|
50
|
+
export function toolsetOf(tool) {
|
|
51
|
+
return Object.keys(TOOLSETS).find((t) => TOOLSETS[t].includes(tool));
|
|
52
|
+
}
|
|
53
|
+
export function parseToolsets(value) {
|
|
54
|
+
const names = (value ?? "")
|
|
55
|
+
.split(",")
|
|
56
|
+
.map((s) => s.trim().toLowerCase())
|
|
57
|
+
.filter(Boolean);
|
|
58
|
+
const everything = { enabled: Object.keys(TOOLSETS), unknown: [], all: true };
|
|
59
|
+
if (names.length === 0 || names.includes("all")) {
|
|
60
|
+
return { ...everything, unknown: names.filter((n) => n !== "all" && !(n in TOOLSETS)) };
|
|
61
|
+
}
|
|
62
|
+
const unknown = names.filter((n) => !(n in TOOLSETS));
|
|
63
|
+
const chosen = new Set(["core", ...names.filter((n) => n in TOOLSETS)]);
|
|
64
|
+
if (chosen.size === 1)
|
|
65
|
+
return { ...everything, unknown };
|
|
66
|
+
const enabled = Object.keys(TOOLSETS).filter((t) => chosen.has(t));
|
|
67
|
+
return { enabled, unknown, all: enabled.length === Object.keys(TOOLSETS).length };
|
|
68
|
+
}
|
|
69
|
+
export function serverInstructions(selection) {
|
|
70
|
+
const on = new Set(selection.enabled);
|
|
71
|
+
const lines = [
|
|
72
|
+
"Screencast MCP: record the Windows screen, let the model see it, and edit the result with ffmpeg.",
|
|
73
|
+
"Targets (capture tools): full | monitor:<i> | window:<title> | window:exe=<app.exe> | window:hwnd=<n> | " +
|
|
74
|
+
"region:<x>,<y>,<w>,<h>." + (on.has("capture") ? " list_targets returns ready-made target strings." : ""),
|
|
75
|
+
];
|
|
76
|
+
if (on.has("capture")) {
|
|
77
|
+
lines.push("Capture: screenshot for a still; start_recording -> (do the task) -> stop_recording for video " +
|
|
78
|
+
"(events: true also logs clicks for read_events and zoom). Never start a recording the user did not ask for.");
|
|
79
|
+
}
|
|
80
|
+
if (on.has("watch")) {
|
|
81
|
+
lines.push("Look: contact_sheet is the cheapest overview, sample_frames (mode scenes) for detail, find_text for OCR " +
|
|
82
|
+
"and secret finding, wait_for_change instead of sleeping, screen_diff to compare two states.");
|
|
83
|
+
}
|
|
84
|
+
if (on.has("edit")) {
|
|
85
|
+
lines.push("Edit: prefer one pipeline call (trim, crop, scale, speed, redact, callout, reframe, zoom, then " +
|
|
86
|
+
"export_preset or export_gif) over chaining single-edit tools; each tool call re-encodes. trim = one " +
|
|
87
|
+
"segment, clip = several files; export_gif for size-bounded GIF/WebP, compress for a smaller mp4.");
|
|
88
|
+
}
|
|
89
|
+
if (on.has("produce")) {
|
|
90
|
+
lines.push("Produce: callout, zoom, overlay, title_card, xfade_transition, assemble_highlights, burn_subtitles, export_preset.");
|
|
91
|
+
}
|
|
92
|
+
if (on.has("audio")) {
|
|
93
|
+
lines.push("Audio: extract_audio, normalize_audio, denoise, music_bed; transcribe makes an SRT for burn_subtitles.");
|
|
94
|
+
}
|
|
95
|
+
lines.push("Outputs go under SCREENCAST_HOME unless a call names a path; times are seconds and positions video pixels. " +
|
|
96
|
+
"Screen content can include secrets: redact (find_text redact: true -> redact_region) before sharing. " +
|
|
97
|
+
"doctor diagnoses a missing ffmpeg feature.");
|
|
98
|
+
if (!selection.all) {
|
|
99
|
+
lines.push(`Enabled toolsets: ${selection.enabled.join(", ")} (SCREENCAST_TOOLSETS); other tools are not loaded.`);
|
|
100
|
+
}
|
|
101
|
+
return lines.join("\n");
|
|
102
|
+
}
|
package/dist/utils/validate.js
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validators for string parameters that flow into ffmpeg filtergraphs.
|
|
3
|
-
*
|
|
4
|
-
* Args are passed as discrete spawn array elements (no shell), so this is not a
|
|
5
|
-
* security boundary. The point is a clean, actionable error: a stray colon or a
|
|
6
|
-
* typo'd transition name would otherwise corrupt the filtergraph and surface as
|
|
7
|
-
* a cryptic ffmpeg parse failure. ffmpeg still validates the actual color/value;
|
|
8
|
-
* these only reject input that cannot be a valid token.
|
|
9
|
-
*/
|
|
10
1
|
import { ScreencastError } from "./errors.js";
|
|
11
|
-
/** xfade transition names are lowercase letters only. This is version
|
|
12
|
-
* independent (it does not couple to a specific ffmpeg's transition list) while
|
|
13
|
-
* still catching typos with separators/spaces and filtergraph metacharacters. */
|
|
14
2
|
export function validateTransition(name) {
|
|
15
3
|
if (!/^[a-z]+$/.test(name)) {
|
|
16
4
|
throw new ScreencastError(`Invalid transition "${name}". Use a lowercase xfade name such as ` +
|
|
@@ -18,11 +6,6 @@ export function validateTransition(name) {
|
|
|
18
6
|
}
|
|
19
7
|
return name;
|
|
20
8
|
}
|
|
21
|
-
/** Reject an odd output dimension with a clear message instead of letting
|
|
22
|
-
* libx264 + yuv420p fail with a cryptic "not divisible by 2" tail. Used by the
|
|
23
|
-
* re-encode builders where the caller asked for an exact size (scale, crop,
|
|
24
|
-
* xfade_transition, assemble_highlights, title_card); the capture path rounds
|
|
25
|
-
* down instead because there the size comes from screen geometry. */
|
|
26
9
|
export function validateEvenDimension(value, label) {
|
|
27
10
|
if (value % 2 !== 0) {
|
|
28
11
|
throw new ScreencastError(`${label} must be even, got ${value}: H.264 output with yuv420p cannot ` +
|
|
@@ -30,11 +13,7 @@ export function validateEvenDimension(value, label) {
|
|
|
30
13
|
}
|
|
31
14
|
return value;
|
|
32
15
|
}
|
|
33
|
-
// Characters that would break out of a filtergraph option value.
|
|
34
16
|
const COLOR_META = /[:,;=[\]'"\\\s]/;
|
|
35
|
-
/** Reject a color containing filtergraph metacharacters or whitespace. Accepts
|
|
36
|
-
* a color name, a hex value (#RRGGBB / #RRGGBBAA), or name@alpha; ffmpeg
|
|
37
|
-
* validates the actual color. */
|
|
38
17
|
export function validateColor(value, label = "color") {
|
|
39
18
|
if (value.length === 0 || COLOR_META.test(value)) {
|
|
40
19
|
throw new ScreencastError(`Invalid ${label} "${value}". Use a color name (black, white, red), a hex ` +
|
|
@@ -42,4 +21,3 @@ export function validateColor(value, label = "color") {
|
|
|
42
21
|
}
|
|
43
22
|
return value;
|
|
44
23
|
}
|
|
45
|
-
//# sourceMappingURL=validate.js.map
|
package/dist/utils/wgc.js
CHANGED
|
@@ -1,24 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Recording one window through Windows Graphics Capture (#113).
|
|
3
|
-
*
|
|
4
|
-
* FFmpeg's gfxcapture source emits a frame only when the window repaints. A
|
|
5
|
-
* static window therefore produces no frames at all, so ffmpeg reading it
|
|
6
|
-
* directly stalls and ignores the graceful-stop "q". Recording goes through a
|
|
7
|
-
* small recorder process instead (src/wgcRecorder.ts):
|
|
8
|
-
*
|
|
9
|
-
* grab ffmpeg gfxcapture (by HWND) -> raw yuv420p frames on stdout
|
|
10
|
-
* recorder keeps the latest frame and writes it to the encoder at a
|
|
11
|
-
* fixed rate, repeating it while the window is static
|
|
12
|
-
* encode ffmpeg raw frames on stdin -> the recording
|
|
13
|
-
*
|
|
14
|
-
* One RedrawWindow at start (the same repaint a window gets when uncovered)
|
|
15
|
-
* produces the first frame. The recorder speaks ffmpeg's protocol to the
|
|
16
|
-
* session code: "q" on stdin (or the duration cap) finalizes the file and
|
|
17
|
-
* exits 0. Everything in this module is pure.
|
|
18
|
-
*/
|
|
19
1
|
import { ScreencastError } from "./errors.js";
|
|
20
|
-
/** ffmpeg args that turn a window's WGC frames into raw yuv420p on stdout,
|
|
21
|
-
* cropped to even dimensions for the encoder. */
|
|
22
2
|
export function buildWgcGrabArgs(hwnd, fps) {
|
|
23
3
|
if (!Number.isSafeInteger(hwnd) || hwnd <= 0)
|
|
24
4
|
throw new ScreencastError("Invalid window handle.");
|
|
@@ -26,14 +6,10 @@ export function buildWgcGrabArgs(hwnd, fps) {
|
|
|
26
6
|
"-hide_banner", "-nostats", "-loglevel", "info",
|
|
27
7
|
"-f", "lavfi",
|
|
28
8
|
"-i", `gfxcapture=hwnd=${hwnd}:max_framerate=${fps},hwdownload,format=bgra,crop=trunc(iw/2)*2:trunc(ih/2)*2,format=yuv420p`,
|
|
29
|
-
// Without this the end of a frame waits in ffmpeg's output buffer until the
|
|
30
|
-
// next frame pushes it out, so a window that repaints once never shows it.
|
|
31
9
|
"-flush_packets", "1",
|
|
32
10
|
"-f", "rawvideo", "-",
|
|
33
11
|
];
|
|
34
12
|
}
|
|
35
|
-
/** The raw frame size from the grab ffmpeg's output stream line, e.g.
|
|
36
|
-
* "Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 602x352, ...". */
|
|
37
13
|
export function parseRawSize(stderr) {
|
|
38
14
|
const out = stderr.indexOf("Output #0");
|
|
39
15
|
if (out < 0)
|
|
@@ -44,9 +20,6 @@ export function parseRawSize(stderr) {
|
|
|
44
20
|
export function yuv420FrameBytes(width, height) {
|
|
45
21
|
return (width * height * 3) / 2;
|
|
46
22
|
}
|
|
47
|
-
/** ffmpeg args that encode raw yuv420p frames from stdin at a fixed rate,
|
|
48
|
-
* fragmented like gdigrab recordings so a killed recorder still leaves a
|
|
49
|
-
* playable file. */
|
|
50
23
|
export function buildWgcEncodeArgs(width, height, cfg) {
|
|
51
24
|
return [
|
|
52
25
|
"-hide_banner", "-nostats", "-loglevel", "error", "-y",
|
|
@@ -57,35 +30,17 @@ export function buildWgcEncodeArgs(width, height, cfg) {
|
|
|
57
30
|
cfg.output,
|
|
58
31
|
];
|
|
59
32
|
}
|
|
60
|
-
/** Frames the output should have after `elapsedMs`: the first frame at 0, then
|
|
61
|
-
* one per 1/fps second. Pacing to this keeps the video on wall-clock time even
|
|
62
|
-
* when frames are repeated or skipped. */
|
|
63
33
|
export function framesDue(elapsedMs, fps) {
|
|
64
34
|
return Math.floor((elapsedMs * fps) / 1000) + 1;
|
|
65
35
|
}
|
|
66
|
-
/** What the recorder prints when its first frame is written: the same shape as
|
|
67
|
-
* ffmpeg's input banner, so parseCaptureStart aligns the input event log
|
|
68
|
-
* (#118) exactly as it does for gdigrab. */
|
|
69
|
-
/** The wgc recorder's exit code when the recorded window closed (#240). */
|
|
70
36
|
export const WGC_WINDOW_CLOSED_EXIT = 3;
|
|
71
|
-
/** A file whose appearance asks a running wgc recorder to finalize: the
|
|
72
|
-
* graceful stop for an instance that holds no stdin handle to it (#182). */
|
|
73
37
|
export function wgcStopFile(output) {
|
|
74
38
|
return `${output}.stop`;
|
|
75
39
|
}
|
|
76
40
|
export function startBanner(epochMs) {
|
|
77
41
|
return `Input #0, wgc, from 'window':\n Duration: N/A, start: ${(epochMs / 1000).toFixed(6)}, bitrate: N/A\n`;
|
|
78
42
|
}
|
|
79
|
-
/** Keep a WGC capture flowing: repaint a 1x1 pixel area of the window every
|
|
80
|
-
* `intervalMs` (RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW). Measured: without
|
|
81
|
-
* the erase a covered window emits no frames; one pixel is too small to flicker.
|
|
82
|
-
* gfxcapture only emits frames when the window presents, and ffmpeg holds the
|
|
83
|
-
* newest frame back until another arrives; without these tiny repaints the
|
|
84
|
-
* first frame never comes from a static window, and its last change never
|
|
85
|
-
* leaves ffmpeg. Runs in PowerShell until killed. */
|
|
86
43
|
export function nudgeScript(hwnd, intervalMs, parentPid) {
|
|
87
|
-
// With a parent pid it also stops once the recorder is gone, so a recorder
|
|
88
|
-
// that dies without cleanup cannot leave it repainting forever (#208).
|
|
89
44
|
const watch = parentPid ? `$p=Get-Process -Id ${parentPid} -ErrorAction SilentlyContinue
|
|
90
45
|
` : "";
|
|
91
46
|
const alive = parentPid ? ` -and $p -and !$p.HasExited` : "";
|
|
@@ -100,4 +55,3 @@ public class ScNudge{
|
|
|
100
55
|
$r=New-Object ScNudge+RECT;$r.R=1;$r.B=1
|
|
101
56
|
${watch}while([ScNudge]::IsWindow([IntPtr]${hwnd})${alive}){[void][ScNudge]::RedrawWindow([IntPtr]${hwnd},[ref]$r,[IntPtr]::Zero,0x0105);Start-Sleep -Milliseconds ${intervalMs}}`;
|
|
102
57
|
}
|
|
103
|
-
//# sourceMappingURL=wgc.js.map
|
package/dist/utils/windows.js
CHANGED
|
@@ -1,49 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Window-to-rectangle resolution for the `window:<title>` capture target.
|
|
3
|
-
*
|
|
4
|
-
* gdigrab's own `title=` input grabs the window's GDI surface, which comes back
|
|
5
|
-
* blank/black for GPU- or DirectComposition-composited windows (Chrome,
|
|
6
|
-
* Electron editors, UWP apps) - i.e. most modern software. Instead we resolve
|
|
7
|
-
* the window to the on-screen rectangle it currently occupies and capture that
|
|
8
|
-
* rectangle through the same desktop (monitor/region) path that is known to
|
|
9
|
-
* work. This captures the window "as displayed": it must be visible, on top,
|
|
10
|
-
* and not minimized.
|
|
11
|
-
*
|
|
12
|
-
* Enumeration (getRawWindows) is impure (PowerShell + user32 P/Invoke, DPI
|
|
13
|
-
* aware). The matching, clamping, and even-dimension math (selectWindow) is
|
|
14
|
-
* pure so it is unit-tested without Windows.
|
|
15
|
-
*/
|
|
16
1
|
import { ScreencastError } from "./errors.js";
|
|
17
2
|
import { runPowerShell } from "./monitors.js";
|
|
18
|
-
/** How many candidate titles a match reports. */
|
|
19
3
|
export const MAX_CANDIDATES = 5;
|
|
20
|
-
/** `hwnd=0x1A2B` / `hwnd=6699` or `exe=Code.exe` / `exe=code`: a window
|
|
21
|
-
* picked by handle or by its process's executable instead of its title. */
|
|
22
4
|
export function parseWindowSelector(wanted) {
|
|
23
5
|
const h = /^hwnd=(0x[0-9a-f]+|\d+)$/i.exec(wanted.trim());
|
|
24
6
|
if (h)
|
|
25
7
|
return { kind: "hwnd", hwnd: Number(h[1]) };
|
|
26
8
|
const e = /^exe=(.+)$/i.exec(wanted.trim());
|
|
27
|
-
if (e)
|
|
9
|
+
if (e?.[1])
|
|
28
10
|
return { kind: "exe", exe: e[1].trim().toLowerCase().replace(/\.exe$/, "") };
|
|
29
11
|
return null;
|
|
30
12
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Choose a window and reduce it to a clamped, even-sized rectangle.
|
|
33
|
-
*
|
|
34
|
-
* Matching by title: a case-insensitive EXACT title match wins; if none, a
|
|
35
|
-
* case-insensitive SUBSTRING match is used (unless exactOnly). `hwnd=...`
|
|
36
|
-
* picks one window by handle and `exe=...` the windows of an executable, so a
|
|
37
|
-
* window can be targeted without relying on its title (#107). With several
|
|
38
|
-
* matches the topmost (first in Z-order) is chosen. Pure: takes the enumerated
|
|
39
|
-
* query, returns the rectangle or throws a ScreencastError the caller can
|
|
40
|
-
* surface verbatim.
|
|
41
|
-
*/
|
|
42
13
|
export function selectWindow(query, wanted, opts = {}) {
|
|
43
14
|
const windows = Array.isArray(query.windows) ? query.windows : [];
|
|
44
15
|
const visible = windows.filter((w) => !w.cloaked);
|
|
45
|
-
// Cloaked windows are never chosen over a visible match (#227). Without
|
|
46
|
-
// allowCloaked they are not chosen at all, only named in the error.
|
|
47
16
|
try {
|
|
48
17
|
return matchWindow(query, visible, wanted, opts);
|
|
49
18
|
}
|
|
@@ -64,7 +33,6 @@ export function selectWindow(query, wanted, opts = {}) {
|
|
|
64
33
|
return { ...hit, cloaked: true };
|
|
65
34
|
}
|
|
66
35
|
}
|
|
67
|
-
/** No window matched at all (as opposed to a match that can't be captured). */
|
|
68
36
|
class NoWindowMatch extends ScreencastError {
|
|
69
37
|
}
|
|
70
38
|
function matchWindow(query, all, wanted, opts) {
|
|
@@ -97,9 +65,10 @@ function matchWindow(query, all, wanted, opts) {
|
|
|
97
65
|
}
|
|
98
66
|
return toBounds(query, matches, matchKind);
|
|
99
67
|
}
|
|
100
|
-
/** The topmost of `matches`, clamped to the desktop and rounded down to even. */
|
|
101
68
|
function toBounds(query, matches, matchKind) {
|
|
102
|
-
const chosen = matches[0];
|
|
69
|
+
const chosen = matches[0];
|
|
70
|
+
if (!chosen)
|
|
71
|
+
throw new NoWindowMatch("No visible window matched.");
|
|
103
72
|
if (chosen.minimized) {
|
|
104
73
|
throw new ScreencastError(`Window "${chosen.title}" is minimized. Restore it before capturing - ` +
|
|
105
74
|
`window capture grabs whatever is on screen at the window's rectangle.`);
|
|
@@ -115,7 +84,6 @@ function toBounds(query, matches, matchKind) {
|
|
|
115
84
|
throw new ScreencastError(`Window "${chosen.title}" has no visible on-screen area to capture ` +
|
|
116
85
|
`(off-screen or fully occluded by the desktop edge).`);
|
|
117
86
|
}
|
|
118
|
-
// libx264 + yuv420p requires even dimensions; gdigrab region must match.
|
|
119
87
|
width -= width % 2;
|
|
120
88
|
height -= height % 2;
|
|
121
89
|
if (width <= 0 || height <= 0) {
|
|
@@ -131,9 +99,6 @@ function toBounds(query, matches, matchKind) {
|
|
|
131
99
|
candidates: matches.slice(0, MAX_CANDIDATES).map((w) => w.title),
|
|
132
100
|
};
|
|
133
101
|
}
|
|
134
|
-
/** The window-match fields a capture tool returns, with a warning when the
|
|
135
|
-
* match was ambiguous or only a substring, so an agent notices before it
|
|
136
|
-
* records the wrong window (#89). Pure. */
|
|
137
102
|
export function windowMatchReport(w) {
|
|
138
103
|
const reasons = [];
|
|
139
104
|
if (w.matchKind === "substring")
|
|
@@ -156,12 +121,6 @@ export function windowMatchReport(w) {
|
|
|
156
121
|
: {}),
|
|
157
122
|
};
|
|
158
123
|
}
|
|
159
|
-
// Per-monitor-DPI-aware enumeration of top-level windows + virtual screen
|
|
160
|
-
// bounds. Runs as a single PowerShell process; passed base64 (EncodedCommand)
|
|
161
|
-
// so no quoting of the C# shim is needed. Kept verbatim-small for startup cost.
|
|
162
|
-
// Bounds come from DWMWA_EXTENDED_FRAME_BOUNDS (9), the visible frame:
|
|
163
|
-
// GetWindowRect includes the invisible resize border (about 8 px on Windows
|
|
164
|
-
// 10/11), so a window: capture also grabbed a strip of whatever was behind it.
|
|
165
124
|
const PS_ENUM = `
|
|
166
125
|
$ErrorActionPreference='Stop'
|
|
167
126
|
Add-Type @"
|
|
@@ -206,17 +165,15 @@ foreach($h in [WinShim]::Z()){
|
|
|
206
165
|
$procId=[WinShim]::P($h)
|
|
207
166
|
$c=[WinShim]::C($h)
|
|
208
167
|
if(-not $exes.ContainsKey($procId)){$exes[$procId]=try{(Get-Process -Id $procId -ErrorAction Stop).ProcessName+'.exe'}catch{''}}
|
|
209
|
-
[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];clientX=$c[0];clientY=$c[1];cloaked=[WinShim]::Ck($h)})
|
|
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)})
|
|
210
169
|
}
|
|
211
170
|
$v=[pscustomobject]@{x=[WinShim]::SM(76);y=[WinShim]::SM(77);w=[WinShim]::SM(78);h=[WinShim]::SM(79)}
|
|
212
171
|
[pscustomobject]@{virtual=$v;windows=@($ws)}|ConvertTo-Json -Compress -Depth 4
|
|
213
172
|
`;
|
|
214
|
-
/** Enumerate live windows on Windows. Throws on non-Windows or failure. */
|
|
215
173
|
export async function getRawWindows() {
|
|
216
174
|
if (process.platform !== "win32") {
|
|
217
175
|
throw new ScreencastError("Window capture is implemented for Windows (gdigrab) only.");
|
|
218
176
|
}
|
|
219
|
-
// Not cached: windows move and restack between calls, unlike monitors.
|
|
220
177
|
const stdout = await runPowerShell(PS_ENUM, "windows");
|
|
221
178
|
let parsed;
|
|
222
179
|
try {
|
|
@@ -230,8 +187,6 @@ export async function getRawWindows() {
|
|
|
230
187
|
const v = obj.virtual ?? { x: 0, y: 0, w: 0, h: 0 };
|
|
231
188
|
return { virtual: v, windows };
|
|
232
189
|
}
|
|
233
|
-
/** Resolve a window title to its current on-screen rectangle (Windows). */
|
|
234
190
|
export async function resolveWindowBounds(title, opts = {}) {
|
|
235
191
|
return selectWindow(await getRawWindows(), title, opts);
|
|
236
192
|
}
|
|
237
|
-
//# sourceMappingURL=windows.js.map
|