@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.
Files changed (133) 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 -89
  16. package/dist/tools/bugReport.js +0 -266
  17. package/dist/tools/burnSubtitles.js +0 -56
  18. package/dist/tools/callout.js +0 -103
  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 -135
  24. package/dist/tools/convert.js +0 -46
  25. package/dist/tools/crop.js +0 -43
  26. package/dist/tools/cursor.js +0 -87
  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 -196
  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 -131
  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 -60
  47. package/dist/tools/overlay.js +0 -62
  48. package/dist/tools/pauseRecording.js +0 -44
  49. package/dist/tools/pipeline.js +0 -400
  50. package/dist/tools/readEvents.js +0 -98
  51. package/dist/tools/redactRegion.js +0 -70
  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 -250
  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 -128
  69. package/dist/tools/xfadeTransition.js +0 -58
  70. package/dist/tools/zoom.js +0 -149
  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 -113
  75. package/dist/utils/audioDevices.js +0 -107
  76. package/dist/utils/backdrop.js +0 -151
  77. package/dist/utils/bugReport.js +0 -172
  78. package/dist/utils/callout.js +0 -90
  79. package/dist/utils/calloutAssets.js +0 -42
  80. package/dist/utils/capabilities.js +0 -96
  81. package/dist/utils/captions.js +0 -103
  82. package/dist/utils/chapters.js +0 -227
  83. package/dist/utils/consent.js +0 -29
  84. package/dist/utils/cursor.js +0 -317
  85. package/dist/utils/diff.js +0 -184
  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/gpu.js +0 -219
  93. package/dist/utils/idle.js +0 -91
  94. package/dist/utils/images.js +0 -38
  95. package/dist/utils/jobs.js +0 -129
  96. package/dist/utils/keystrokes.js +0 -155
  97. package/dist/utils/lifecycle.js +0 -233
  98. package/dist/utils/logging.js +0 -75
  99. package/dist/utils/media.js +0 -574
  100. package/dist/utils/monitors.js +0 -124
  101. package/dist/utils/narrate.js +0 -233
  102. package/dist/utils/ocr.js +0 -222
  103. package/dist/utils/ocrScan.js +0 -91
  104. package/dist/utils/paths.js +0 -155
  105. package/dist/utils/pause.js +0 -190
  106. package/dist/utils/pipeline.js +0 -361
  107. package/dist/utils/player.js +0 -85
  108. package/dist/utils/pool.js +0 -29
  109. package/dist/utils/produce.js +0 -298
  110. package/dist/utils/recipes.js +0 -71
  111. package/dist/utils/recorder.js +0 -173
  112. package/dist/utils/recordingFiles.js +0 -32
  113. package/dist/utils/recordingIndex.js +0 -312
  114. package/dist/utils/replay.js +0 -283
  115. package/dist/utils/resolveTarget.js +0 -25
  116. package/dist/utils/retention.js +0 -48
  117. package/dist/utils/roots.js +0 -43
  118. package/dist/utils/sessions.js +0 -499
  119. package/dist/utils/sheet.js +0 -59
  120. package/dist/utils/stepGuide.js +0 -231
  121. package/dist/utils/steps.js +0 -88
  122. package/dist/utils/still.js +0 -38
  123. package/dist/utils/targetList.js +0 -64
  124. package/dist/utils/targets.js +0 -265
  125. package/dist/utils/timeline.js +0 -85
  126. package/dist/utils/toolSpec.js +0 -31
  127. package/dist/utils/toolsets.js +0 -134
  128. package/dist/utils/transcriptCut.js +0 -149
  129. package/dist/utils/validate.js +0 -23
  130. package/dist/utils/waitLoop.js +0 -50
  131. package/dist/utils/wgc.js +0 -84
  132. package/dist/utils/windows.js +0 -192
  133. package/dist/utils/zoom.js +0 -234
@@ -1,361 +0,0 @@
1
- import { ScreencastError } from "./errors.js";
2
- import { atempoChain, cropFilter, redactSteps, scaleFilter, scaledSize } from "./media.js";
3
- import { calloutSteps } from "./callout.js";
4
- import { ASPECT_DIMS, exportPresetParts, reframeFilter } from "./produce.js";
5
- import { keyframesToViews, planClickZoom, zoomFilter, DEFAULT_TRANSITION_SEC } from "./zoom.js";
6
- import { resolveQuality } from "./targets.js";
7
- import { backdropSteps } from "./backdrop.js";
8
- import { groupBadges, keystrokeSteps, retimeBadges } from "./keystrokes.js";
9
- import { cutFilters, cutsFor, DEFAULT_KEEP_SEC, DEFAULT_MIN_IDLE_SEC } from "./idle.js";
10
- import { denoiseFilter, loudnessTarget, loudnormFilter } from "./audio.js";
11
- import { subtitlesFilter } from "./captions.js";
12
- import { mapSpans, mapTime, retimeCues } from "./timeline.js";
13
- import { cursorSteps, transformCursor } from "./cursor.js";
14
- export const MAX_PIPELINE_STEPS = 30;
15
- const r3 = (v) => Math.round(v * 1000) / 1000;
16
- export function probeArgs(args, p) {
17
- const out = [...args];
18
- const af = out.indexOf("-af");
19
- if (af !== -1 && p.audio.length > 0)
20
- out[af + 1] = `${p.audio.join(",")},${out[af + 1]}`;
21
- out.splice(out.indexOf("-i"), 0, ...p.seek);
22
- return out;
23
- }
24
- export function sidecarCues(cues, timeOps, opsBefore) {
25
- const later = timeOps.slice(opsBefore);
26
- return later.length > 0 ? retimeCues(cues, later) : [...cues];
27
- }
28
- export function planPipeline(input, output, steps, src, assets = {}, quality = "standard", opts = {}) {
29
- if (steps.length === 0)
30
- throw new ScreencastError("Give at least one step.");
31
- if (steps.length > MAX_PIPELINE_STEPS)
32
- throw new ScreencastError(`At most ${MAX_PIPELINE_STEPS} steps.`);
33
- steps.forEach((s, i) => {
34
- if ((s.op === "export_preset" || s.op === "export_gif") && i !== steps.length - 1) {
35
- throw new ScreencastError(`${s.op} must be the last step (it is step ${i + 1} of ${steps.length}).`);
36
- }
37
- });
38
- const zoomAt = steps.findIndex((s) => s.op === "zoom");
39
- const lateRedact = zoomAt === -1 ? -1 : steps.findIndex((s, i) => i > zoomAt && s.op === "redact");
40
- if (lateRedact !== -1) {
41
- throw new ScreencastError(`step ${lateRedact + 1}: redact comes after zoom (step ${zoomAt + 1}), which moves the content under a fixed box. ` +
42
- "Put redact before zoom, in the source's coordinates.");
43
- }
44
- const redacts = steps.some((s) => s.op === "redact");
45
- if (steps.filter((s) => s.op === "cut_idle").length > 1)
46
- throw new ScreencastError("Use at most one cut_idle step.");
47
- let W = src.width;
48
- let H = src.height;
49
- let fps = src.fps;
50
- let dur = src.durationSec;
51
- const inputArgs = [];
52
- const extraInputs = [];
53
- let nextInput = 1;
54
- const graph = [];
55
- const audio = [];
56
- let audioReencode = false;
57
- let cur = "[0:v]";
58
- let encode = null;
59
- let gif;
60
- const summary = [];
61
- const timeOps = [];
62
- const pending = [];
63
- const files = [];
64
- let geo = { sx: 1, sy: 1, ox: 0, oy: 0 };
65
- const trimRange = (s, at) => {
66
- if (!Number.isFinite(s.start) || s.start < 0)
67
- throw new ScreencastError(`step ${at}: trim start must be a non-negative number.`);
68
- if ((s.end === undefined) === (s.duration === undefined)) {
69
- throw new ScreencastError(`step ${at}: trim takes end OR duration.`);
70
- }
71
- const end = s.end ?? s.start + s.duration;
72
- if (!(end > s.start))
73
- throw new ScreencastError(`step ${at}: trim end must be after start.`);
74
- if (dur !== null && s.start >= dur) {
75
- throw new ScreencastError(`step ${at}: trim starts at ${s.start}s, but the video is ${r3(dur)}s long at that point.`);
76
- }
77
- return { start: s.start, end: dur !== null ? Math.min(end, dur) : end };
78
- };
79
- steps.forEach((s, i) => {
80
- const at = i + 1;
81
- const tag = `p${i}`;
82
- const out = `[${tag}]`;
83
- const chain = (filter) => {
84
- graph.push(`${cur}${filter}${out}`);
85
- cur = out;
86
- };
87
- const pend = (kind) => pending.push({ step: i, kind, seek: [...inputArgs], audio: [...audio], ops: [...timeOps] });
88
- switch (s.op) {
89
- case "trim": {
90
- const { start, end } = trimRange(s, at);
91
- if (i === 0) {
92
- inputArgs.push("-ss", String(start), "-t", String(r3(end - start)));
93
- summary.push(`trim ${start}-${r3(end)}s: input seek`);
94
- }
95
- else {
96
- chain(`trim=start=${start}:end=${r3(end)},setpts=PTS-STARTPTS`);
97
- audio.push(`atrim=start=${start}:end=${r3(end)},asetpts=PTS-STARTPTS`);
98
- summary.push(`trim ${start}-${r3(end)}s: trim filter`);
99
- }
100
- audioReencode = true;
101
- dur = end - start;
102
- timeOps.push({ op: "trim", start, end });
103
- break;
104
- }
105
- case "crop":
106
- chain(cropFilter(s, { width: W, height: H }));
107
- if (geo)
108
- geo = { ...geo, ox: geo.ox - s.x, oy: geo.oy - s.y };
109
- W = s.width;
110
- H = s.height;
111
- summary.push(`crop to ${W}x${H}`);
112
- break;
113
- case "scale": {
114
- const f = scaleFilter(s);
115
- const [w0, h0] = [W, H];
116
- ({ width: W, height: H } = scaledSize(W, H, s));
117
- if (geo)
118
- geo = { sx: (geo.sx * W) / w0, sy: (geo.sy * H) / h0, ox: (geo.ox * W) / w0, oy: (geo.oy * H) / h0 };
119
- chain(f);
120
- summary.push(`scale to ${W}x${H}`);
121
- break;
122
- }
123
- case "speed":
124
- if (!Number.isFinite(s.factor) || s.factor <= 0)
125
- throw new ScreencastError(`step ${at}: speed factor must be positive.`);
126
- chain(`setpts=PTS/${s.factor}`);
127
- audio.push(atempoChain(s.factor));
128
- audioReencode = true;
129
- if (dur !== null)
130
- dur /= s.factor;
131
- timeOps.push({ op: "speed", factor: s.factor });
132
- summary.push(`speed x${s.factor}`);
133
- break;
134
- case "redact": {
135
- const { steps: st, out: o } = redactSteps(s.regions, s, { width: W, height: H }, cur, tag);
136
- graph.push(...st);
137
- cur = o;
138
- summary.push(`redact ${s.regions.length} region(s), ${s.style ?? "box"}`);
139
- break;
140
- }
141
- case "callout": {
142
- const a = assets[i];
143
- if (!a)
144
- throw new ScreencastError(`Internal: missing callout assets for step ${at}.`);
145
- const { steps: st, out: o, extraInputs: ex } = calloutSteps(s.items, a, cur, nextInput, tag);
146
- graph.push(...st);
147
- extraInputs.push(...ex);
148
- nextInput += ex.length / 4;
149
- cur = o;
150
- summary.push(`callout ${s.items.length} item(s)`);
151
- break;
152
- }
153
- case "reframe": {
154
- const dim = ASPECT_DIMS[s.aspect];
155
- if (!dim)
156
- throw new ScreencastError(`step ${at}: unknown aspect "${s.aspect}".`);
157
- chain(`${reframeFilter(dim.w, dim.h, s.fit ?? "pad")},format=yuv420p`);
158
- geo = null;
159
- W = dim.w;
160
- H = dim.h;
161
- summary.push(`reframe to ${s.aspect} (${s.fit ?? "pad"})`);
162
- break;
163
- }
164
- case "zoom": {
165
- const transition = s.transitionSec ?? DEFAULT_TRANSITION_SEC;
166
- let kfs = s.keyframes;
167
- let from = "";
168
- if (s.follow === "clicks") {
169
- if (kfs)
170
- throw new ScreencastError(`step ${at}: zoom takes keyframes or follow, not both.`);
171
- if (!geo) {
172
- throw new ScreencastError(`step ${at}: zoom follow "clicks" must come before reframe, backdrop or another zoom; the logged click positions no longer match the frame.`);
173
- }
174
- const g = geo;
175
- const logged = opts.clicks?.[i];
176
- if (!logged)
177
- throw new ScreencastError(`Internal: missing clicks for step ${at}.`);
178
- const clicks = logged.flatMap((c) => {
179
- const t = mapTime(c.t, timeOps);
180
- const x = c.x * g.sx + g.ox;
181
- const y = c.y * g.sy + g.oy;
182
- return t !== null && x >= 0 && x < W && y >= 0 && y < H ? [{ t, x, y }] : [];
183
- });
184
- kfs = planClickZoom(clicks, W, H, { holdSec: s.holdSec, maxZoom: s.maxZoom, transition });
185
- from = ` from ${clicks.length} click(s)`;
186
- }
187
- else if (!kfs || kfs.length === 0) {
188
- throw new ScreencastError(`step ${at}: zoom needs keyframes, or follow: "clicks".`);
189
- }
190
- if (kfs.length === 0) {
191
- summary.push("zoom: no clicks in this part of the video; skipped");
192
- break;
193
- }
194
- chain(zoomFilter(keyframesToViews(kfs, W, H), { width: W, height: H, fps }, transition));
195
- geo = null;
196
- summary.push(`zoom ${kfs.length} keyframe(s)${from}`);
197
- break;
198
- }
199
- case "cut_idle": {
200
- if (!opts.idle)
201
- throw new ScreencastError(`Internal: missing idle scan for step ${at}.`);
202
- const cuts = cutsFor(mapSpans(opts.idle, timeOps), s.minIdleSec ?? DEFAULT_MIN_IDLE_SEC, s.keepSec ?? DEFAULT_KEEP_SEC);
203
- if (cuts.length === 0) {
204
- summary.push("cut_idle: no idle stretches here; nothing cut");
205
- break;
206
- }
207
- const f = cutFilters(cuts);
208
- chain(f.video);
209
- audio.push(f.audio);
210
- audioReencode = true;
211
- const removed = cuts.reduce((sum, c) => sum + (c.end - c.start), 0);
212
- if (dur !== null)
213
- dur -= removed;
214
- timeOps.push({ op: "cut", spans: cuts });
215
- summary.push(`cut_idle ${cuts.length} stretch(es), ${r3(removed)}s removed`);
216
- break;
217
- }
218
- case "audio": {
219
- if (s.normalize === undefined && s.denoise === undefined)
220
- throw new ScreencastError(`step ${at}: audio needs normalize and/or denoise.`);
221
- if (!src.hasAudio) {
222
- summary.push("audio: the input has no audio; skipped");
223
- break;
224
- }
225
- const m = opts.audio?.[i];
226
- const did = [];
227
- if (s.denoise !== undefined) {
228
- if (m?.floorDb === undefined)
229
- pend("noisefloor");
230
- audio.push(denoiseFilter(s.denoise, m?.floorDb ?? null));
231
- did.push(`denoise ${s.denoise}`);
232
- }
233
- if (s.normalize !== undefined && m?.silent)
234
- did.push("silent, not normalized");
235
- else if (s.normalize !== undefined) {
236
- const t = loudnessTarget(s.normalize);
237
- if (!m?.loudness)
238
- pend("loudness");
239
- audio.push(loudnormFilter(t, m?.loudness), "aresample=48000");
240
- did.push(`normalize to ${t.i} LUFS${m?.loudness ? ` (measured ${m.loudness.input_i})` : ""}`);
241
- }
242
- audioReencode = true;
243
- summary.push(`audio: ${did.join(", ")}`);
244
- break;
245
- }
246
- case "burn_subtitles": {
247
- if (!s.subtitles === !s.transcribe)
248
- throw new ScreencastError(`step ${at}: burn_subtitles takes subtitles (a path) or transcribe: true.`);
249
- if (s.transcribe && !src.hasAudio)
250
- throw new ScreencastError(`step ${at}: transcribe needs audio, and the input has none.`);
251
- const file = opts.subtitles?.[i];
252
- if (file === "") {
253
- summary.push("burn_subtitles: no cues in this part of the video; skipped");
254
- break;
255
- }
256
- if (file === undefined)
257
- pend(s.transcribe ? "transcribe" : "subtitles");
258
- const ass = !!s.subtitles && /\.(ass|ssa)$/i.test(s.subtitles);
259
- const style = s.style ?? (ass ? null : "clean");
260
- chain(subtitlesFilter(file ?? "<subtitles.srt>", opts.fontsDir ?? "<fonts>", style));
261
- summary.push(`burn_subtitles ${s.transcribe ? "from a transcript" : "from a file"}, ${style ?? "file"} style`);
262
- break;
263
- }
264
- case "backdrop": {
265
- const { op: _op, ...bo } = s;
266
- const { steps: st, out: o, extraInputs: ex, layout } = backdropSteps(bo, { width: W, height: H }, cur, nextInput, tag);
267
- geo = null;
268
- graph.push(...st);
269
- extraInputs.push(...ex);
270
- nextInput += ex.length / 2;
271
- cur = o;
272
- W = layout.canvasW;
273
- H = layout.canvasH;
274
- summary.push(`backdrop to ${W}x${H}`);
275
- break;
276
- }
277
- case "keystroke_overlay": {
278
- const k = opts.keystrokes?.[i];
279
- if (!k)
280
- throw new ScreencastError(`Internal: missing keystroke badges for step ${at}.`);
281
- const badges = retimeBadges(k.badges, timeOps);
282
- if (badges.length === 0) {
283
- summary.push("keystroke_overlay: no badges in this part of the video");
284
- break;
285
- }
286
- const { steps: st, out: o } = keystrokeSteps(groupBadges(badges), k, s, { height: H }, cur, tag);
287
- graph.push(...st);
288
- cur = o;
289
- summary.push(`keystroke_overlay ${badges.length} badge(s)`);
290
- break;
291
- }
292
- case "cursor": {
293
- if (!geo) {
294
- throw new ScreencastError(`step ${at}: cursor must come before zoom, reframe or backdrop; the logged positions no longer match the frame after them.`);
295
- }
296
- const c = opts.cursor?.[i];
297
- if (!c)
298
- throw new ScreencastError(`Internal: missing cursor plan for step ${at}.`);
299
- const moved = transformCursor(c.plan, timeOps, geo);
300
- if (moved.path.length === 0 || moved.visible.length === 0) {
301
- summary.push("cursor: no cursor movement in this part of the video");
302
- break;
303
- }
304
- const { steps: st, out: o, extraInputs: ex, commands } = cursorSteps(moved, s, { width: W, height: H }, cur, nextInput, tag, c.sprite, c.commandsFile);
305
- graph.push(...st);
306
- extraInputs.push(...ex);
307
- nextInput += ex.length / 2;
308
- cur = o;
309
- files.push({ path: c.commandsFile, content: commands });
310
- summary.push(`cursor ${moved.path.length} segment(s), ${moved.clicks.length} click(s)${s.spotlight ? ", spotlight" : ""}`);
311
- break;
312
- }
313
- case "export_preset": {
314
- const p = exportPresetParts(s.platform, s.fit ?? "pad", tag);
315
- geo = null;
316
- chain(p.vf);
317
- if (p.af)
318
- audio.push(p.af);
319
- encode = p.encode;
320
- W = p.width;
321
- H = p.height;
322
- fps = 30;
323
- audioReencode = true;
324
- summary.push(`export_preset ${s.platform}`);
325
- break;
326
- }
327
- case "export_gif": {
328
- const { op: _op, ...opts } = s;
329
- gif = opts;
330
- summary.push(`export_gif (${opts.format ?? "gif"}): second stage, size-budget ladder`);
331
- break;
332
- }
333
- }
334
- });
335
- const args = ["-y", ...inputArgs, "-i", input, ...extraInputs];
336
- const chaptersInput = opts.chaptersFile ? args.filter((a) => a === "-i").length : -1;
337
- if (opts.chaptersFile)
338
- args.push("-f", "ffmetadata", "-i", opts.chaptersFile);
339
- const audioGraph = src.hasAudio && audio.length > 0;
340
- if (audioGraph)
341
- graph.push(`[0:a]${audio.join(",")}[aout]`);
342
- if (graph.length > 0)
343
- args.push("-filter_complex", graph.join(";"));
344
- args.push("-map", cur === "[0:v]" ? "0:v" : cur);
345
- if (src.hasAudio)
346
- args.push("-map", audioGraph ? "[aout]" : "0:a");
347
- const finalEncode = encode;
348
- if (finalEncode) {
349
- args.push(...finalEncode);
350
- }
351
- else {
352
- args.push(...resolveQuality(gif || redacts ? "high" : quality));
353
- if (src.hasAudio)
354
- args.push(...(audioReencode ? ["-c:a", "aac", "-b:a", "160k"] : ["-c:a", "copy"]));
355
- args.push("-movflags", "+faststart");
356
- }
357
- if (chaptersInput !== -1)
358
- args.push("-map_chapters", String(chaptersInput));
359
- args.push(output);
360
- return { args, width: W, height: H, fps, durationSec: dur === null ? null : r3(dur), gif, summary, timeOps, pending, files };
361
- }
@@ -1,85 +0,0 @@
1
- import { ScreencastError } from "./errors.js";
2
- import { escapeFilterPath } from "./fonts.js";
3
- export const PLAYER_URI = "ui://screencast/player";
4
- export const MCP_APP_MIME = "text/html;profile=mcp-app";
5
- export const PLAYER_TOOL_META = { ui: { resourceUri: PLAYER_URI }, "ui/resourceUri": PLAYER_URI };
6
- export const MCP_APPS_EXTENSION = "io.modelcontextprotocol/ui";
7
- export function clientSupportsApps(caps) {
8
- const c = caps;
9
- const ext = (c?.extensions?.[MCP_APPS_EXTENSION] ?? c?.experimental?.[MCP_APPS_EXTENSION]);
10
- if (!ext || typeof ext !== "object")
11
- return false;
12
- return !Array.isArray(ext.mimeTypes) || ext.mimeTypes.includes(MCP_APP_MIME);
13
- }
14
- export const DEFAULT_PLAYER_FRAMES = 120;
15
- export const MAX_PLAYER_FRAMES = 300;
16
- export const PLAYER_FPS = 4;
17
- export const DEFAULT_PLAYER_WIDTH = 640;
18
- export const PLAYER_SCENE_THRESHOLD = 0.01;
19
- export function playerFramePlan(durationSec, maxFrames = DEFAULT_PLAYER_FRAMES) {
20
- if (!(durationSec > 0))
21
- throw new ScreencastError("The video has no duration to review.");
22
- const count = Math.max(1, Math.min(maxFrames, Math.ceil(durationSec * PLAYER_FPS)));
23
- const intervalSec = Number((durationSec / count).toFixed(6));
24
- return { count, intervalSec, sceneGapSec: Number(Math.max(0.25, intervalSec / 4).toFixed(6)) };
25
- }
26
- export function buildPlayerFramesArgs(input, plan, width, logFile, threshold = PLAYER_SCENE_THRESHOLD) {
27
- const i = plan.intervalSec;
28
- const grid = `isnan(prev_t)+gt(floor((t-start_t)/${i})\\,floor((prev_t-start_t)/${i}))`;
29
- const scene = `gt(scene\\,${threshold})*not(${grid})*(isnan(prev_selected_t)+gte(t-prev_selected_t\\,${plan.sceneGapSec}))`;
30
- return [
31
- "-v", "error", "-i", input, "-an",
32
- "-vf",
33
- `scale='min(${width},iw)':-2,split[g][s];` +
34
- `[g]select='${grid}',metadata=add:key=kind:value=grid[g1];` +
35
- `[s]select='${scene}',metadata=add:key=kind:value=scene[s1];` +
36
- `[g1][s1]interleave,metadata=print:file=${escapeFilterPath(logFile)}`,
37
- "-fps_mode", "passthrough",
38
- "-q:v", "6", "-f", "image2pipe", "-c:v", "mjpeg", "-",
39
- ];
40
- }
41
- export function parsePlayerFrameLog(text) {
42
- const out = [];
43
- for (const line of text.split(/\r?\n/)) {
44
- const t = line.match(/pts_time:\s*(-?[\d.]+)/);
45
- if (t) {
46
- out.push({ timeSec: Number(t[1]), scene: false, score: 0 });
47
- continue;
48
- }
49
- const last = out.at(-1);
50
- if (!last)
51
- continue;
52
- if (line === "kind=scene")
53
- last.scene = true;
54
- const s = line.match(/^lavfi\.scene_score=([\d.]+)/);
55
- if (s)
56
- last.score = Number(s[1]);
57
- }
58
- return out;
59
- }
60
- export function pickPlayerFrames(frames, maxScene) {
61
- const scene = frames
62
- .map((f, i) => ({ f, i }))
63
- .filter((x) => x.f.scene)
64
- .sort((a, b) => b.f.score - a.f.score)
65
- .slice(0, Math.max(0, maxScene));
66
- const keep = new Set(scene.map((x) => x.i));
67
- return frames.flatMap((f, i) => (!f.scene || keep.has(i) ? [i] : []));
68
- }
69
- export function splitJpegs(buf) {
70
- const out = [];
71
- let start = -1;
72
- for (let i = 0; i + 1 < buf.length; i++) {
73
- if (buf[i] !== 0xff)
74
- continue;
75
- const m = buf[i + 1];
76
- if (m === 0xd8 && start < 0)
77
- start = i;
78
- else if (m === 0xd9 && start >= 0) {
79
- out.push(buf.subarray(start, i + 2));
80
- start = -1;
81
- i++;
82
- }
83
- }
84
- return out;
85
- }
@@ -1,29 +0,0 @@
1
- import { availableParallelism } from "node:os";
2
- export function frameConcurrency(cores = availableParallelism()) {
3
- return Math.min(4, Math.max(2, Math.floor(cores / 4)));
4
- }
5
- export async function mapPool(items, fn, limit = frameConcurrency()) {
6
- const results = new Array(items.length);
7
- let next = 0;
8
- let failed = false;
9
- let error;
10
- const worker = async () => {
11
- while (!failed && next < items.length) {
12
- const i = next++;
13
- try {
14
- results[i] = await fn(items[i], i);
15
- }
16
- catch (err) {
17
- if (!failed) {
18
- failed = true;
19
- error = err;
20
- }
21
- }
22
- }
23
- };
24
- const n = Math.max(1, Math.min(Math.floor(limit), items.length));
25
- await Promise.all(Array.from({ length: n }, worker));
26
- if (failed)
27
- throw error;
28
- return results;
29
- }