@tmhs/screencast-mcp 0.49.1 → 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.
Files changed (134) hide show
  1. package/README.md +13 -8
  2. package/dist/index.js +550 -106
  3. package/dist/wgcRecorder.js +15 -139
  4. package/package.json +8 -4
  5. package/assets/.gitkeep +0 -0
  6. package/assets/icon.png +0 -0
  7. package/dist/cli.js +0 -516
  8. package/dist/context.js +0 -50
  9. package/dist/prompts.js +0 -95
  10. package/dist/resources.js +0 -93
  11. package/dist/server.js +0 -174
  12. package/dist/setup.js +0 -438
  13. package/dist/tools/addMarker.js +0 -93
  14. package/dist/tools/assembleHighlights.js +0 -69
  15. package/dist/tools/backdrop.js +0 -79
  16. package/dist/tools/bugReport.js +0 -243
  17. package/dist/tools/burnSubtitles.js +0 -56
  18. package/dist/tools/callout.js +0 -62
  19. package/dist/tools/chapters.js +0 -156
  20. package/dist/tools/clip.js +0 -52
  21. package/dist/tools/compress.js +0 -51
  22. package/dist/tools/concat.js +0 -67
  23. package/dist/tools/contactSheet.js +0 -113
  24. package/dist/tools/convert.js +0 -46
  25. package/dist/tools/crop.js +0 -43
  26. package/dist/tools/cursor.js +0 -67
  27. package/dist/tools/cutByTranscript.js +0 -86
  28. package/dist/tools/cutIdle.js +0 -84
  29. package/dist/tools/deleteRecording.js +0 -119
  30. package/dist/tools/denoise.js +0 -60
  31. package/dist/tools/doctor.js +0 -146
  32. package/dist/tools/exportGif.js +0 -57
  33. package/dist/tools/exportPreset.js +0 -48
  34. package/dist/tools/extractAudio.js +0 -65
  35. package/dist/tools/findText.js +0 -194
  36. package/dist/tools/getMediaInfo.js +0 -36
  37. package/dist/tools/getSession.js +0 -40
  38. package/dist/tools/indexRecording.js +0 -195
  39. package/dist/tools/keystrokeOverlay.js +0 -90
  40. package/dist/tools/listAudioDevices.js +0 -35
  41. package/dist/tools/listSessions.js +0 -28
  42. package/dist/tools/listTargets.js +0 -76
  43. package/dist/tools/listVideoDevices.js +0 -26
  44. package/dist/tools/musicBed.js +0 -55
  45. package/dist/tools/narrate.js +0 -86
  46. package/dist/tools/normalizeAudio.js +0 -59
  47. package/dist/tools/overlay.js +0 -62
  48. package/dist/tools/pauseRecording.js +0 -44
  49. package/dist/tools/pipeline.js +0 -397
  50. package/dist/tools/readEvents.js +0 -98
  51. package/dist/tools/redactRegion.js +0 -62
  52. package/dist/tools/reframe.js +0 -46
  53. package/dist/tools/resumeRecording.js +0 -46
  54. package/dist/tools/reviewRecording.js +0 -163
  55. package/dist/tools/sampleFrames.js +0 -200
  56. package/dist/tools/saveReplay.js +0 -90
  57. package/dist/tools/scale.js +0 -44
  58. package/dist/tools/screenDiff.js +0 -86
  59. package/dist/tools/screenshot.js +0 -76
  60. package/dist/tools/searchRecording.js +0 -79
  61. package/dist/tools/speed.js +0 -46
  62. package/dist/tools/startRecording.js +0 -398
  63. package/dist/tools/stepGuide.js +0 -249
  64. package/dist/tools/stopRecording.js +0 -132
  65. package/dist/tools/titleCard.js +0 -67
  66. package/dist/tools/transcribe.js +0 -66
  67. package/dist/tools/trim.js +0 -57
  68. package/dist/tools/waitForChange.js +0 -142
  69. package/dist/tools/xfadeTransition.js +0 -58
  70. package/dist/tools/zoom.js +0 -134
  71. package/dist/utils/anim.js +0 -54
  72. package/dist/utils/animExport.js +0 -56
  73. package/dist/utils/argPaths.js +0 -39
  74. package/dist/utils/audio.js +0 -117
  75. package/dist/utils/audioDevices.js +0 -107
  76. package/dist/utils/backdrop.js +0 -162
  77. package/dist/utils/bugReport.js +0 -195
  78. package/dist/utils/callout.js +0 -132
  79. package/dist/utils/calloutAssets.js +0 -42
  80. package/dist/utils/capabilities.js +0 -96
  81. package/dist/utils/captions.js +0 -104
  82. package/dist/utils/chapters.js +0 -227
  83. package/dist/utils/consent.js +0 -29
  84. package/dist/utils/cursor.js +0 -338
  85. package/dist/utils/diff.js +0 -186
  86. package/dist/utils/errors.js +0 -29
  87. package/dist/utils/events.js +0 -403
  88. package/dist/utils/expr.js +0 -11
  89. package/dist/utils/ffmpeg.js +0 -285
  90. package/dist/utils/fontCoverage.js +0 -177
  91. package/dist/utils/fonts.js +0 -154
  92. package/dist/utils/frameQueue.js +0 -50
  93. package/dist/utils/gpu.js +0 -219
  94. package/dist/utils/idle.js +0 -91
  95. package/dist/utils/images.js +0 -38
  96. package/dist/utils/jobs.js +0 -129
  97. package/dist/utils/keystrokes.js +0 -198
  98. package/dist/utils/lifecycle.js +0 -233
  99. package/dist/utils/logging.js +0 -75
  100. package/dist/utils/media.js +0 -584
  101. package/dist/utils/monitors.js +0 -124
  102. package/dist/utils/narrate.js +0 -233
  103. package/dist/utils/ocr.js +0 -222
  104. package/dist/utils/ocrScan.js +0 -93
  105. package/dist/utils/paths.js +0 -155
  106. package/dist/utils/pause.js +0 -190
  107. package/dist/utils/pipeline.js +0 -361
  108. package/dist/utils/player.js +0 -85
  109. package/dist/utils/pool.js +0 -29
  110. package/dist/utils/produce.js +0 -300
  111. package/dist/utils/recipes.js +0 -71
  112. package/dist/utils/recorder.js +0 -173
  113. package/dist/utils/recordingFiles.js +0 -32
  114. package/dist/utils/recordingIndex.js +0 -312
  115. package/dist/utils/replay.js +0 -283
  116. package/dist/utils/resolveTarget.js +0 -25
  117. package/dist/utils/retention.js +0 -48
  118. package/dist/utils/roots.js +0 -43
  119. package/dist/utils/sessions.js +0 -499
  120. package/dist/utils/sheet.js +0 -82
  121. package/dist/utils/stepGuide.js +0 -231
  122. package/dist/utils/steps.js +0 -88
  123. package/dist/utils/still.js +0 -38
  124. package/dist/utils/targetList.js +0 -64
  125. package/dist/utils/targets.js +0 -265
  126. package/dist/utils/timeline.js +0 -85
  127. package/dist/utils/toolSpec.js +0 -31
  128. package/dist/utils/toolsets.js +0 -134
  129. package/dist/utils/transcriptCut.js +0 -149
  130. package/dist/utils/validate.js +0 -23
  131. package/dist/utils/waitLoop.js +0 -50
  132. package/dist/utils/wgc.js +0 -84
  133. package/dist/utils/windows.js +0 -192
  134. package/dist/utils/zoom.js +0 -252
@@ -1,195 +0,0 @@
1
- import { ScreencastError } from "./errors.js";
2
- import { findMatches, normalizeForMatch, regexRanges } from "./ocr.js";
3
- import { formatTimecode } from "./sheet.js";
4
- import { existsSync } from "node:fs";
5
- import { eventPaths, whenFinalized } from "./events.js";
6
- import { getStore } from "../context.js";
7
- export const DEFAULT_CLIP_SEC = 30;
8
- export const MAX_CLIP_SEC = 600;
9
- export const DEFAULT_SCAN_EVERY_SEC = 1;
10
- export const MAX_STEPS = 100;
11
- export const MAX_ERROR_LINES = 20;
12
- export const DEFAULT_SECRET_PATTERN = [
13
- "\\b(?:sk|pk|rk)-[a-z0-9_-]{8,}",
14
- "\\bgh[pousr]_[a-z0-9]{10,}",
15
- "\\bgithub_pat_[a-z0-9_]{10,}",
16
- "\\bxox[abprs]-[a-z0-9-]{8,}",
17
- "\\bAKIA[0-9A-Z]{12,}",
18
- "\\bAIza[0-9a-z_-]{20,}",
19
- "\\beyJ[a-z0-9_-]{8,}\\.[a-z0-9_-]{8,}",
20
- "(?:api.?key|secret|token|passw(?:or)?d|bearer|authorization)\\s*[:=]?\\s*\\S+",
21
- ].join("|");
22
- export const DEFAULT_ERROR_PATTERN = "error|exception|fail(?:ed|ure)?|fatal|crash|denied|refused|not found|cannot|can't|unable|invalid|" +
23
- "timed? ?out|traceback|panic|unhandled|warning";
24
- export const REPORT_FILES = {
25
- markdown: "report.md",
26
- json: "report.json",
27
- clip: "clip.mp4",
28
- contactSheet: "contact-sheet.png",
29
- gif: (format) => `repro.${format}`,
30
- };
31
- const r3 = (n) => Math.round(n * 1000) / 1000;
32
- export function clipWindow(durationSec, opts = {}) {
33
- if (!(durationSec > 0))
34
- throw new ScreencastError("Could not read the recording's duration.");
35
- const end = Math.min(opts.end ?? durationSec, durationSec);
36
- const clipSec = opts.clipSec ?? DEFAULT_CLIP_SEC;
37
- const start = opts.start ?? Math.max(0, end - clipSec);
38
- if (start >= durationSec) {
39
- throw new ScreencastError(`start ${start}s is past the end of the ${r3(durationSec)}s recording.`);
40
- }
41
- if (!(end > start))
42
- throw new ScreencastError("end must be after start.");
43
- if (end - start > MAX_CLIP_SEC) {
44
- throw new ScreencastError(`The clip would be ${r3(end - start)}s; at most ${MAX_CLIP_SEC}s. Narrow start/end.`);
45
- }
46
- return { start: r3(start), end: r3(end) };
47
- }
48
- export { reconstructSteps } from "./steps.js";
49
- function mostlyOverlap(a, b) {
50
- const w = Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x);
51
- const h = Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y);
52
- if (w <= 0 || h <= 0)
53
- return false;
54
- return w * h >= 0.5 * Math.min(a.width * a.height, b.width * b.height);
55
- }
56
- export function mergeRedactions(regions) {
57
- const out = [];
58
- for (const r of [...regions].sort((a, b) => a.start - b.start)) {
59
- const into = out.find((o) => r.start <= o.end && mostlyOverlap(o, r));
60
- if (!into) {
61
- out.push({ ...r });
62
- continue;
63
- }
64
- const x = Math.min(into.x, r.x);
65
- const y = Math.min(into.y, r.y);
66
- into.width = Math.max(into.x + into.width, r.x + r.width) - x;
67
- into.height = Math.max(into.y + into.height, r.y + r.height) - y;
68
- into.x = x;
69
- into.y = y;
70
- into.start = Math.min(into.start, r.start);
71
- into.end = Math.max(into.end, r.end);
72
- }
73
- return out;
74
- }
75
- export const MASK = "[REDACTED]";
76
- export function maskSecrets(texts, pattern) {
77
- if (texts.length === 0)
78
- return [];
79
- const ranges = regexRanges(texts, pattern);
80
- return texts.map((text, i) => {
81
- const spans = [...(ranges[i] ?? [])].sort((a, b) => a[0] - b[0]);
82
- let out = "";
83
- let at = 0;
84
- for (const [s, e] of spans) {
85
- if (e <= at)
86
- continue;
87
- out += text.slice(at, Math.max(at, s)) + (s >= at ? MASK : "");
88
- at = e;
89
- }
90
- return out + text.slice(at);
91
- });
92
- }
93
- export function errorFindings(frames, errorPattern, secretPattern) {
94
- const found = new Map();
95
- for (const frame of frames) {
96
- const hitLines = new Set(findMatches(frame.lines, errorPattern, true).map((m) => m.line));
97
- for (const line of hitLines) {
98
- const key = normalizeForMatch(line);
99
- const seen = found.get(key);
100
- if (seen)
101
- seen.lastSeen = frame.t;
102
- else
103
- found.set(key, { text: line, firstSeen: frame.t, lastSeen: frame.t });
104
- }
105
- }
106
- const lastT = frames.at(-1)?.t;
107
- const list = [...found.values()].sort((a, b) => Number(b.lastSeen === lastT) - Number(a.lastSeen === lastT) || a.firstSeen - b.firstSeen).slice(0, MAX_ERROR_LINES);
108
- if (!secretPattern)
109
- return list;
110
- const masked = maskSecrets(list.map((f) => f.text), secretPattern);
111
- return list.map((f, i) => ({ ...f, text: masked[i] ?? f.text }));
112
- }
113
- const code = (s) => `\`${s.replace(/`/g, "'").replace(/\s+/g, " ").trim()}\``;
114
- const cell = (s) => s.replace(/\|/g, "\\|").replace(/\s*\n\s*/g, " ");
115
- export function buildReportMarkdown(r) {
116
- const out = [`# ${r.title.replace(/\s*\n\s*/g, " ")}`, ""];
117
- const span = `${formatTimecode(r.clip.start)}-${formatTimecode(r.clip.end)}`;
118
- out.push(`Recorded repro: ${r.clip.width}x${r.clip.height}, clip ${span} of a ${formatTimecode(r.clip.recordingDurationSec)} recording.`, "");
119
- if (r.actual || r.expected) {
120
- if (r.actual)
121
- out.push("**Actual:** " + r.actual.trim(), "");
122
- if (r.expected)
123
- out.push("**Expected:** " + r.expected.trim(), "");
124
- }
125
- out.push("## Steps to reproduce", "");
126
- if (r.steps.length === 0) {
127
- out.push(`_${r.stepsNote ?? "No input events in the recording."} Add the steps by hand._`, "");
128
- }
129
- else {
130
- out.push("From the recording's input event log; times are on the recording's clock, positions in video pixels.", "");
131
- r.steps.forEach((s, i) => out.push(`${i + 1}. \`${formatTimecode(s.t)}\` ${s.text}`));
132
- if (r.stepsOmitted)
133
- out.push("", `_${r.stepsOmitted} more steps not shown (see report.json)._`);
134
- out.push("");
135
- }
136
- out.push("## Error text on screen", "");
137
- if (r.ocr !== "read") {
138
- out.push("_Not read: Windows OCR is unavailable here._", "");
139
- }
140
- else if (r.errors.length === 0) {
141
- out.push("_None found by OCR in the clip._", "");
142
- }
143
- else {
144
- out.push("Read by OCR (best-effort, may contain misreads); times from the clip start.", "");
145
- for (const e of r.errors) {
146
- const when = e.firstSeen === e.lastSeen ? formatTimecode(e.firstSeen) : `${formatTimecode(e.firstSeen)}-${formatTimecode(e.lastSeen)}`;
147
- out.push(`- \`${when}\` ${code(e.text)}`);
148
- }
149
- out.push("");
150
- }
151
- out.push("## Recording", "");
152
- if (r.files.gif) {
153
- out.push("<!-- GitHub does not upload local files from --body-file: drag the GIF and clip into the issue, " +
154
- "or replace these links with the uploaded URLs. -->", `![Repro](${r.files.gif})`, "");
155
- }
156
- out.push(`- Clip: [${r.files.clip}](${r.files.clip}) (${r3(r.clip.end - r.clip.start)} s)`);
157
- if (r.files.gif && r.gif) {
158
- const mb = (r.gif.sizeBytes / 1_000_000).toFixed(1);
159
- out.push(`- ${r.gif.format === "gif" ? "GIF" : "WebP"}: [${r.files.gif}](${r.files.gif}) (${mb} MB${r.gif.withinBudget ? "" : ", over the size budget"})`);
160
- }
161
- if (r.files.contactSheet)
162
- out.push(`- Contact sheet: [${r.files.contactSheet}](${r.files.contactSheet})`);
163
- out.push("");
164
- out.push("## Environment", "", "| | |", "|---|---|");
165
- for (const [k, v] of r.environment)
166
- out.push(`| ${cell(k)} | ${cell(v)} |`);
167
- out.push("");
168
- const red = r.redaction;
169
- const boxes = red.found + red.manual;
170
- out.push("<sub>", red.scanned
171
- ? `Secret scan: OCR every ${red.everySec} s over ${red.framesScanned} frames; ${boxes} region${boxes === 1 ? "" : "s"} boxed out of the media. ` +
172
- "OCR is best-effort: review the clip before posting."
173
- : `Not scanned for secrets${red.manual > 0 ? ` (${red.manual} region${red.manual === 1 ? "" : "s"} boxed out by hand)` : ""}: review the clip before posting.`, `Generated by screencast-mcp bug_report, ${r.createdAt}.`, "</sub>", "");
174
- return out.join("\n");
175
- }
176
- export async function resolveSource(args) {
177
- if (args.sessionId !== undefined) {
178
- const record = getStore().get(args.sessionId);
179
- if (!record)
180
- throw new ScreencastError(`No session with id "${args.sessionId}".`);
181
- if (record.status === "recording" || record.status === "paused") {
182
- throw new ScreencastError("The recording is still running; stop_recording it first.");
183
- }
184
- await whenFinalized(record.id);
185
- if (!existsSync(record.outputPath))
186
- throw new ScreencastError(`The session's recording is missing: ${record.outputPath}`);
187
- const events = record.events?.path;
188
- return { path: record.outputPath, eventsPath: events && existsSync(events) ? events : null, record };
189
- }
190
- const path = args.input;
191
- if (!existsSync(path))
192
- throw new ScreencastError(`Input file not found: ${path}`);
193
- const { jsonl } = eventPaths(path);
194
- return { path, eventsPath: existsSync(jsonl) ? jsonl : null };
195
- }
@@ -1,132 +0,0 @@
1
- import { ScreencastError } from "./errors.js";
2
- import { escapeFilterPath } from "./fonts.js";
3
- import { enableExpr } from "./media.js";
4
- import { resolveQuality } from "./targets.js";
5
- import { validateColor } from "./validate.js";
6
- import { stillOutput } from "./paths.js";
7
- import { z } from "zod";
8
- const nonNeg = (v, label) => {
9
- if (!Number.isFinite(v) || v < 0)
10
- throw new ScreencastError(`${label} must be a non-negative number.`);
11
- return Math.round(v);
12
- };
13
- function enable(c) {
14
- const e = enableExpr(c.from, c.to);
15
- return e ? `:enable='${e}'` : "";
16
- }
17
- export function arrowGeometry(a) {
18
- const dx = a.x2 - a.x1;
19
- const dy = a.y2 - a.y1;
20
- const length = Math.round(Math.hypot(dx, dy));
21
- const thickness = Math.max(2, Math.round(a.thickness ?? 8));
22
- if (length < thickness * 3)
23
- throw new ScreencastError("An arrow must be at least three times as long as it is thick.");
24
- return { length, thickness, angle: Math.atan2(dy, dx), cx: (a.x1 + a.x2) / 2, cy: (a.y1 + a.y2) / 2 };
25
- }
26
- export function buildArrowImageArgs(a, output) {
27
- const { length, thickness, angle } = arrowGeometry(a);
28
- const color = validateColor(a.color ?? "red");
29
- const head = thickness * 3;
30
- const ang = angle.toFixed(6);
31
- const alpha = `if(lt(X,W-H),if(lt(abs(Y-H/2),${thickness}/2),255,0),if(lt(abs(Y-H/2),(W-X)/2),255,0))`;
32
- return [
33
- "-y", "-v", "error",
34
- "-f", "lavfi", "-i", `color=c=${color}:s=${length}x${head}`,
35
- "-vf", `format=rgba,geq=r='r(X,Y)':g='g(X,Y)':b='b(X,Y)':a='${alpha}',rotate=a=${ang}:ow=rotw(${ang}):oh=roth(${ang}):c=none`,
36
- "-frames:v", "1",
37
- ...stillOutput(output),
38
- ];
39
- }
40
- export function calloutSteps(items, assets, input, firstInput, tag) {
41
- if (items.length === 0)
42
- throw new ScreencastError("Give at least one callout.");
43
- const extraInputs = [];
44
- const steps = [];
45
- let cur = input;
46
- items.forEach((c, i) => {
47
- const out = `[${tag}c${i}]`;
48
- if (c.type === "box") {
49
- const color = validateColor(c.color ?? "red");
50
- const t = c.fill ? "fill" : String(Math.max(1, Math.round(c.thickness ?? 4)));
51
- steps.push(`${cur}drawbox=x=${nonNeg(c.x, "x")}:y=${nonNeg(c.y, "y")}:w=${nonNeg(c.width, "width")}:h=${nonNeg(c.height, "height")}` +
52
- `:color=${color}:t=${t}${enable(c)}${out}`);
53
- }
54
- else if (c.type === "text") {
55
- const file = assets.textFiles[i];
56
- if (!file)
57
- throw new ScreencastError("Internal: missing text file for a text callout.");
58
- const color = validateColor(c.color ?? "white");
59
- const size = Math.max(8, Math.round(c.size ?? 32));
60
- const panel = c.background === false ? "" : `:box=1:boxcolor=black@0.6:boxborderw=${Math.round(size / 3)}`;
61
- steps.push(`${cur}drawtext=fontfile=${escapeFilterPath(assets.fontFiles?.[i] ?? assets.fontFile)}:textfile=${escapeFilterPath(file)}:expansion=none` +
62
- `:x=${nonNeg(c.x, "x")}:y=${nonNeg(c.y, "y")}:fontsize=${size}:fontcolor=${color}${panel}${enable(c)}${out}`);
63
- }
64
- else {
65
- const file = assets.arrowFiles[i];
66
- if (!file)
67
- throw new ScreencastError("Internal: missing image for an arrow callout.");
68
- const { cx, cy } = arrowGeometry(c);
69
- const n = firstInput + extraInputs.length / 4;
70
- extraInputs.push("-loop", "1", "-i", file);
71
- steps.push(`${cur}[${n}:v]overlay=x=${cx.toFixed(1)}-w/2:y=${cy.toFixed(1)}-h/2:shortest=1${enable(c)}${out}`);
72
- }
73
- cur = out;
74
- });
75
- return { steps, out: cur, extraInputs };
76
- }
77
- export function buildCalloutArgs(input, output, items, assets, quality = "standard", still = false) {
78
- const drawn = still ? items.map(({ from: _f, to: _t, ...c }) => c) : items;
79
- const { steps, out, extraInputs } = calloutSteps(drawn, assets, "[0:v]", 1, "");
80
- if (still) {
81
- return ["-y", "-i", input, ...extraInputs, "-filter_complex", steps.join(";"), "-map", out, "-frames:v", "1", ...stillOutput(output)];
82
- }
83
- return [
84
- "-y", "-i", input, ...extraInputs,
85
- "-filter_complex", steps.join(";"),
86
- "-map", out, "-map", "0:a?",
87
- ...resolveQuality(quality),
88
- "-c:a", "copy",
89
- output,
90
- ];
91
- }
92
- const timing = {
93
- from: z.number().nonnegative().optional(),
94
- to: z.number().positive().optional(),
95
- color: z.string().optional(),
96
- };
97
- export const fontFileSchema = z
98
- .string()
99
- .min(1)
100
- .optional()
101
- .describe("Font: a .ttf/.otf/.ttc path or a C:\\Windows\\Fonts file name. Default: bundled Inter, with a " +
102
- "covering system font for scripts it lacks (CJK, emoji, Arabic, ...).");
103
- export const calloutItemSchema = z.discriminatedUnion("type", [
104
- z.object({
105
- type: z.literal("box"),
106
- x: z.number(),
107
- y: z.number(),
108
- width: z.number().positive(),
109
- height: z.number().positive(),
110
- thickness: z.number().positive().optional().describe("Outline px (default 4)."),
111
- fill: z.boolean().optional().describe("Fill instead of outline."),
112
- ...timing,
113
- }),
114
- z.object({
115
- type: z.literal("text"),
116
- x: z.number(),
117
- y: z.number(),
118
- text: z.string().min(1),
119
- size: z.number().positive().optional().describe("Font size px (default 32)."),
120
- background: z.boolean().optional().describe("Dark panel behind the text (default true)."),
121
- ...timing,
122
- }),
123
- z.object({
124
- type: z.literal("arrow"),
125
- x1: z.number(),
126
- y1: z.number(),
127
- x2: z.number().describe("Head (x2,y2) is the point the arrow points at."),
128
- y2: z.number(),
129
- thickness: z.number().positive().optional().describe("Shaft px (default 8)."),
130
- ...timing,
131
- }),
132
- ]);
@@ -1,42 +0,0 @@
1
- import { join } from "node:path";
2
- import { writeFileSync } from "node:fs";
3
- import { runFfmpeg } from "./ffmpeg.js";
4
- import { buildArrowImageArgs } from "./callout.js";
5
- import { bundledFontPath, resolveTextFont } from "./fonts.js";
6
- export function calloutFonts(items, fontFile) {
7
- const out = { fontFiles: [], fallbackFonts: [], warnings: [] };
8
- items.forEach((c, i) => {
9
- if (c.type !== "text") {
10
- out.fontFiles.push(null);
11
- return;
12
- }
13
- const font = resolveTextFont(c.text, { weight: "bold", fontFile });
14
- out.fontFiles.push(font.fontFile);
15
- if (font.fallback)
16
- out.fallbackFonts.push({ item: i, fontFile: font.fontFile });
17
- if (font.warning)
18
- out.warnings.push(`Item ${i}: ${font.warning}`);
19
- });
20
- return out;
21
- }
22
- export async function prepareCalloutAssets(items, workDir, tag = "", fontFile) {
23
- const fonts = calloutFonts(items, fontFile);
24
- const textFiles = items.map((c, i) => {
25
- if (c.type !== "text")
26
- return null;
27
- const f = join(workDir, `${tag}text_${i}.txt`);
28
- writeFileSync(f, c.text);
29
- return f;
30
- });
31
- const arrowFiles = [];
32
- for (const [i, c] of items.entries()) {
33
- if (c.type !== "arrow") {
34
- arrowFiles.push(null);
35
- continue;
36
- }
37
- const f = join(workDir, `${tag}arrow_${i}.png`);
38
- await runFfmpeg(buildArrowImageArgs(c, f), 30_000);
39
- arrowFiles.push(f);
40
- }
41
- return { fontFile: bundledFontPath("bold"), textFiles, arrowFiles, ...fonts };
42
- }
@@ -1,96 +0,0 @@
1
- import { spawnSync } from "node:child_process";
2
- import { isAbsolute } from "node:path";
3
- import { runPowerShell, psTimeoutMs } from "./monitors.js";
4
- import { errorMessage } from "./errors.js";
5
- export const FFMPEG_FEATURE_MAJOR = 8;
6
- export function parseFfmpegVersion(text) {
7
- const version = /^ff(?:mpeg|probe) version (\S+)/m.exec(text)?.[1] ?? null;
8
- const release = version ? /^n?(\d+)\.\d+/.exec(version) : null;
9
- if (release)
10
- return { version, major: Number(release[1]), inferred: false };
11
- const avutil = /^\s*libavutil\s+(\d+)\./m.exec(text);
12
- if (avutil && Number(avutil[1]) >= 56)
13
- return { version, major: Number(avutil[1]) - 52, inferred: true };
14
- return { version, major: null, inferred: false };
15
- }
16
- export function parseDevices(text) {
17
- const out = new Set();
18
- const body = text.split(/^\s*---\s*$/m).slice(1).join("\n") || text;
19
- for (const line of body.split(/\r?\n/)) {
20
- const m = /^\s{0,2}[D ][E ]\s?[d ]?\s+([a-z0-9_,]+)\s/i.exec(line);
21
- if (m?.[1])
22
- for (const name of m[1].split(","))
23
- out.add(name);
24
- }
25
- return [...out];
26
- }
27
- function run(bin, args) {
28
- try {
29
- const res = spawnSync(bin, args, { encoding: "utf8", windowsHide: true, timeout: 10_000 });
30
- if (res.status !== 0)
31
- return null;
32
- return `${res.stdout ?? ""}${res.stderr ?? ""}`;
33
- }
34
- catch {
35
- return null;
36
- }
37
- }
38
- export function versionText(bin) {
39
- return run(bin, ["-version"]);
40
- }
41
- export function devicesText(ffmpeg) {
42
- return run(ffmpeg, ["-hide_banner", "-devices"]);
43
- }
44
- export function locate(bin) {
45
- if (isAbsolute(bin))
46
- return bin;
47
- const out = run(process.platform === "win32" ? "where" : "which", [bin]);
48
- return out?.split(/\r?\n/).map((l) => l.trim()).find((l) => l.length > 0) ?? null;
49
- }
50
- const PS_OCR_STATUS = `
51
- $ErrorActionPreference = 'Stop'
52
- $null = [Windows.Media.Ocr.OcrEngine, Windows.Foundation, ContentType = WindowsRuntime]
53
- $e = [Windows.Media.Ocr.OcrEngine]::TryCreateFromUserProfileLanguages()
54
- [pscustomobject]@{ available = ($null -ne $e); language = $(if ($e) { $e.RecognizerLanguage.LanguageTag } else { $null }); languages = @([Windows.Media.Ocr.OcrEngine]::AvailableRecognizerLanguages | ForEach-Object { $_.LanguageTag }) } | ConvertTo-Json -Compress
55
- `;
56
- export async function ocrStatus() {
57
- if (process.platform !== "win32") {
58
- return { available: false, language: null, languages: [], error: "The Windows OCR engine is available on Windows only." };
59
- }
60
- try {
61
- const raw = JSON.parse(await runPowerShell(PS_OCR_STATUS, "OCR languages", { timeoutMs: psTimeoutMs(15_000) }));
62
- const languages = Array.isArray(raw.languages) ? raw.languages : raw.languages ? [raw.languages] : [];
63
- return { available: raw.available === true, language: raw.language ?? null, languages };
64
- }
65
- catch (err) {
66
- return { available: false, language: null, languages: [], error: errorMessage(err) };
67
- }
68
- }
69
- export const ENV_SETTINGS = [
70
- "SCREENCAST_HOME",
71
- "SCREENCAST_ALLOWED_DIRS",
72
- "FFMPEG_PATH",
73
- "FFPROBE_PATH",
74
- "SCREENCAST_WHISPER_MODEL",
75
- "SCREENCAST_MAX_RECORDING_SEC",
76
- "SCREENCAST_JOB_TIMEOUT_MS",
77
- "SCREENCAST_PS_TIMEOUT_MS",
78
- "SCREENCAST_RETENTION_DAYS",
79
- "SCREENCAST_CONFIRM_CAPTURE",
80
- "SCREENCAST_TOOLSETS",
81
- ];
82
- export function envSettings(env = process.env) {
83
- return Object.fromEntries(ENV_SETTINGS.map((name) => {
84
- const value = env[name];
85
- return [name, value && value.trim().length > 0 ? value : null];
86
- }));
87
- }
88
- export const KEY_FILTERS = [
89
- { filter: "whisper", tools: "transcribe", why: `FFmpeg ${FFMPEG_FEATURE_MAJOR}+ built with whisper.cpp` },
90
- { filter: "gfxcapture", tools: 'backend: "wgc" (screenshot, start_recording, find_text)', why: `FFmpeg ${FFMPEG_FEATURE_MAJOR}+ on Windows` },
91
- { filter: "subtitles", tools: "burn_subtitles", why: "libass" },
92
- { filter: "drawtext", tools: "title_card, callout, contact_sheet labels, produce", why: "libfreetype" },
93
- { filter: "afftdn", tools: "denoise", why: "a standard build" },
94
- { filter: "loudnorm", tools: "normalize_audio", why: "a standard build" },
95
- { filter: "xfade", tools: "xfade_transition, assemble_highlights", why: "FFmpeg 4.3+" },
96
- ];
@@ -1,104 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { ScreencastError } from "./errors.js";
3
- import { escapeFilterPath } from "./fonts.js";
4
- import { resolveQuality } from "./targets.js";
5
- export const WHISPER_MODEL_ENV = "SCREENCAST_WHISPER_MODEL";
6
- const MODEL_HINT = `Download a whisper.cpp model (ggml-base.en.bin is a good start; ggml-tiny.en.bin is fastest) from ` +
7
- `https://huggingface.co/ggerganov/whisper.cpp and pass its path as model, or set ${WHISPER_MODEL_ENV}.`;
8
- export function resolveWhisperModel(arg, env = process.env) {
9
- const model = arg ?? env[WHISPER_MODEL_ENV];
10
- if (!model || model.trim().length === 0) {
11
- throw new ScreencastError("No whisper model given.", MODEL_HINT);
12
- }
13
- if (!existsSync(model))
14
- throw new ScreencastError(`Whisper model not found: ${model}`, MODEL_HINT);
15
- return model;
16
- }
17
- export function buildTranscribeArgs(input, model, srtOut, language = "auto", words = false) {
18
- if (!/^[a-z]{2,3}$|^auto$/.test(language)) {
19
- throw new ScreencastError(`language must be a code like "en" or "auto", got "${language}".`);
20
- }
21
- return [
22
- "-y", "-v", "error", "-i", input, "-vn",
23
- "-af",
24
- `aresample=16000,whisper=model=${escapeFilterPath(model)}:language=${language}:format=srt:` +
25
- `destination=${escapeFilterPath(srtOut)}:use_gpu=false` + (words ? ":max_len=1" : ""),
26
- "-f", "null", "-",
27
- ];
28
- }
29
- export function mergePunctuation(cues) {
30
- const out = [];
31
- for (const c of cues) {
32
- const prev = out[out.length - 1];
33
- if (prev && !/[\p{L}\p{N}]/u.test(c.text))
34
- prev.text += c.text.trim();
35
- else
36
- out.push({ ...c });
37
- }
38
- return out;
39
- }
40
- const TIME = /(\d+):(\d{2}):(\d{2})[,.](\d{3})/;
41
- const toSec = (m) => Number(m[1]) * 3600 + Number(m[2]) * 60 + Number(m[3]) + Number(m[4]) / 1000;
42
- function fmt(sec) {
43
- const ms = Math.round(sec * 1000);
44
- const h = Math.floor(ms / 3_600_000);
45
- const m = Math.floor((ms % 3_600_000) / 60_000);
46
- const s = Math.floor((ms % 60_000) / 1000);
47
- const pad = (n, w = 2) => String(n).padStart(w, "0");
48
- return `${pad(h)}:${pad(m)}:${pad(s)},${pad(ms % 1000, 3)}`;
49
- }
50
- export function parseSrt(srt, opts = {}) {
51
- const cues = [];
52
- for (const block of srt.replace(/\r\n/g, "\n").split(/\n\s*\n/)) {
53
- const lines = block.split("\n").map((l) => l.trim()).filter((l) => l.length > 0);
54
- const i = lines.findIndex((l) => l.includes("-->"));
55
- const header = lines[i];
56
- if (header === undefined)
57
- continue;
58
- const [a, b] = header.split("-->");
59
- const sa = a?.match(TIME);
60
- const sb = b?.match(TIME);
61
- if (!sa || !sb)
62
- continue;
63
- const text = lines.slice(i + 1).join("\n");
64
- if (!text)
65
- continue;
66
- const n = opts.index && i > 0 && /^\d+$/.test(lines[i - 1]) ? Number(lines[i - 1]) : undefined;
67
- cues.push({ start: toSec(sa), end: toSec(sb), text, ...(n !== undefined && { index: n }) });
68
- }
69
- return cues;
70
- }
71
- export function normalizeCues(cues) {
72
- const sorted = [...cues].sort((p, q) => p.start - q.start);
73
- return sorted
74
- .map((c, i) => {
75
- const next = sorted[i + 1];
76
- const end = next ? Math.min(c.end, next.start) : c.end;
77
- return { ...c, end };
78
- })
79
- .filter((c) => c.end > c.start);
80
- }
81
- export function formatSrt(cues) {
82
- return cues.map((c, i) => `${i + 1}\n${fmt(c.start)} --> ${fmt(c.end)}\n${c.text}\n`).join("\n");
83
- }
84
- export const CAPTION_STYLE_NAMES = ["clean", "social"];
85
- export const CAPTION_STYLES = {
86
- clean: "FontName=Inter,FontSize=16,PrimaryColour=&H00FFFFFF,OutlineColour=&H00000000,BorderStyle=1,Outline=1.5,Shadow=0,MarginV=16",
87
- social: "FontName=Inter,Bold=1,FontSize=22,PrimaryColour=&H00FFFFFF,BackColour=&H99000000,BorderStyle=3,Outline=6,Shadow=0,MarginV=40",
88
- };
89
- export function subtitlesFilter(subtitles, fontsDir, style = "clean") {
90
- const force = style === null ? null : CAPTION_STYLES[style];
91
- if (force === undefined)
92
- throw new ScreencastError(`Unknown caption style "${style}".`);
93
- return (`subtitles=filename=${escapeFilterPath(subtitles)}:fontsdir=${escapeFilterPath(fontsDir)}` +
94
- (force ? `:force_style='${force}'` : ""));
95
- }
96
- export function buildBurnSubtitlesArgs(input, subtitles, output, fontsDir, style = "clean", quality = "standard") {
97
- return [
98
- "-y", "-i", input,
99
- "-vf", subtitlesFilter(subtitles, fontsDir, style),
100
- ...resolveQuality(quality),
101
- "-c:a", "copy",
102
- output,
103
- ];
104
- }