@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
package/dist/utils/ocr.js
CHANGED
|
@@ -1,30 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
* On-screen text recognition with the OCR engine built into Windows
|
|
3
|
-
* (Windows.Media.Ocr), so no model or package is installed (#117).
|
|
4
|
-
*
|
|
5
|
-
* The engine misses small text and, notably, drops ALL_CAPS words joined by
|
|
6
|
-
* underscores (an env-var name like OPENAI_API_KEY, and anything glued to it
|
|
7
|
-
* with `=`) at ordinary sizes. Measured on 18 px UI text: missing at 1x-3x,
|
|
8
|
-
* recovered at 4x. So recognition runs two passes (2x and 4x upscales) in one
|
|
9
|
-
* PowerShell process and merges them, and matching tolerates the engine's
|
|
10
|
-
* usual confusions (`_` read as `-`, `I` as `l`).
|
|
11
|
-
*
|
|
12
|
-
* The PowerShell/WinRT call is impure; parsing, merging, and matching are pure.
|
|
13
|
-
*/
|
|
1
|
+
import { runInNewContext } from "node:vm";
|
|
14
2
|
import { ScreencastError } from "./errors.js";
|
|
15
3
|
import { runPowerShell, psTimeoutMs } from "./monitors.js";
|
|
16
|
-
/** Upscale factors for the two recognition passes. */
|
|
17
4
|
export const OCR_SCALES = [2, 4];
|
|
18
|
-
/** Windows.Media.Ocr refuses images larger than this on either side. */
|
|
19
5
|
export const OCR_MAX_DIMENSION = 10_000;
|
|
20
|
-
/** Recognise every image in `paths` (already upscaled by `scales[i]`) in one
|
|
21
|
-
* PowerShell run. Paths travel base64-encoded, so no quoting is involved. */
|
|
22
6
|
export async function recognize(paths, scales) {
|
|
23
7
|
if (process.platform !== "win32") {
|
|
24
8
|
throw new ScreencastError("find_text uses the Windows OCR engine and runs on Windows only.");
|
|
25
9
|
}
|
|
26
10
|
const list = Buffer.from(JSON.stringify(paths), "utf8").toString("base64");
|
|
27
|
-
// The limit grows with the image count, so a whole-clip scan gets the time it needs.
|
|
28
11
|
const stdout = await runPowerShell(PS_OCR.replace("__PATHS__", list), "text (OCR)", {
|
|
29
12
|
timeoutMs: psTimeoutMs(OCR_TIMEOUT_MS + Math.max(0, paths.length - 2) * OCR_PER_IMAGE_MS),
|
|
30
13
|
});
|
|
@@ -38,8 +21,6 @@ export async function recognize(paths, scales) {
|
|
|
38
21
|
const passes = Array.isArray(raw) ? raw : [raw];
|
|
39
22
|
return passes.map((p, i) => parseOcrPass(p, scales[i] ?? 1));
|
|
40
23
|
}
|
|
41
|
-
/** Turn one pass's JSON into lines in ORIGINAL image pixels (dividing out the
|
|
42
|
-
* upscale), each with a bounding box around its words. Pure. */
|
|
43
24
|
export function parseOcrPass(raw, scale) {
|
|
44
25
|
const pass = (raw ?? {});
|
|
45
26
|
if (pass.error) {
|
|
@@ -77,34 +58,62 @@ function overlapRatio(a, b) {
|
|
|
77
58
|
return 0;
|
|
78
59
|
return (w * h) / Math.min(a.width * a.height, b.width * b.height);
|
|
79
60
|
}
|
|
80
|
-
/** Merge recognition passes: start from the first, then add lines a later pass
|
|
81
|
-
* found that overlap nothing already kept; where they overlap, keep the
|
|
82
|
-
* longer reading. Result is in reading order. Pure. */
|
|
83
61
|
export function mergePasses(passes) {
|
|
84
62
|
const kept = [];
|
|
85
63
|
for (const pass of passes) {
|
|
86
64
|
for (const line of pass) {
|
|
87
65
|
const i = kept.findIndex((k) => overlapRatio(k, line) > 0.5);
|
|
88
|
-
|
|
66
|
+
const match = kept[i];
|
|
67
|
+
if (!match)
|
|
89
68
|
kept.push(line);
|
|
90
|
-
else if (line.text.length >
|
|
69
|
+
else if (line.text.length > match.text.length)
|
|
91
70
|
kept[i] = line;
|
|
92
71
|
}
|
|
93
72
|
}
|
|
94
73
|
return kept.sort((a, b) => a.y - b.y || a.x - b.x);
|
|
95
74
|
}
|
|
96
|
-
/** Fold the engine's usual confusions so a query still matches a misread:
|
|
97
|
-
* case, `-`/`_`/space, `l`/`I`/`1`/`|`, and `O`/`0`. Pure. */
|
|
98
75
|
export function normalizeForMatch(s) {
|
|
99
76
|
return s.toLowerCase().replace(/[-_\s]+/g, "_").replace(/[l1|]/g, "i").replace(/0/g, "o");
|
|
100
77
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
78
|
+
export const MAX_QUERY_LENGTH = 500;
|
|
79
|
+
export const REGEX_BUDGET_MS = 1_000;
|
|
80
|
+
const REGEX_SCAN = `JSON.stringify(texts.map((text) => {
|
|
81
|
+
const re = new RegExp(query, "gi");
|
|
82
|
+
const seen = new Set();
|
|
83
|
+
const ranges = [];
|
|
84
|
+
for (const variant of [text, text.replace(/-/g, "_"), text.replace(/_/g, "-")]) {
|
|
85
|
+
for (const m of variant.matchAll(re)) {
|
|
86
|
+
const key = m.index + ":" + m[0].length;
|
|
87
|
+
if (m[0].length > 0 && !seen.has(key)) {
|
|
88
|
+
seen.add(key);
|
|
89
|
+
ranges.push([m.index, m.index + m[0].length]);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return ranges;
|
|
94
|
+
}))`;
|
|
95
|
+
export function regexRanges(texts, query, budgetMs = REGEX_BUDGET_MS) {
|
|
96
|
+
try {
|
|
97
|
+
new RegExp(query, "gi");
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
throw new ScreencastError(`Invalid regex: ${err.message}`);
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
return JSON.parse(runInNewContext(REGEX_SCAN, { texts, query }, { timeout: budgetMs }));
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
if (err.code === "ERR_SCRIPT_EXECUTION_TIMEOUT") {
|
|
107
|
+
throw new ScreencastError(`The regex took longer than ${budgetMs / 1000} s to run and was stopped.`, "Simplify it: nested quantifiers such as (a+)+ backtrack catastrophically.");
|
|
108
|
+
}
|
|
109
|
+
throw err;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
104
112
|
export function findMatches(lines, query, regex = false) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
113
|
+
if (query.length > MAX_QUERY_LENGTH) {
|
|
114
|
+
throw new ScreencastError(`The query is ${query.length} characters; at most ${MAX_QUERY_LENGTH} are allowed.`);
|
|
115
|
+
}
|
|
116
|
+
const rebuilt = lines.map((line) => {
|
|
108
117
|
const spans = [];
|
|
109
118
|
let text = "";
|
|
110
119
|
for (const w of line.words) {
|
|
@@ -113,35 +122,19 @@ export function findMatches(lines, query, regex = false) {
|
|
|
113
122
|
spans.push({ start: text.length, end: text.length + w.text.length, word: w });
|
|
114
123
|
text += w.text;
|
|
115
124
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
// Also try the text with `_` and `-` swapped either way: the engine
|
|
126
|
-
// often reads one as the other, and a secret pattern like `ghp_` must
|
|
127
|
-
// still match `ghp-` (#236). Same length, so offsets map to words as is.
|
|
128
|
-
const seen = new Set();
|
|
129
|
-
for (const variant of [text, text.replace(/-/g, "_"), text.replace(/_/g, "-")]) {
|
|
130
|
-
for (const m of variant.matchAll(re)) {
|
|
131
|
-
const key = `${m.index}:${m[0].length}`;
|
|
132
|
-
if (m[0].length > 0 && !seen.has(key)) {
|
|
133
|
-
seen.add(key);
|
|
134
|
-
ranges.push([m.index, m.index + m[0].length]);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
125
|
+
return { line, spans, text };
|
|
126
|
+
});
|
|
127
|
+
const regexHits = regex ? regexRanges(rebuilt.map((r) => r.text), query) : null;
|
|
128
|
+
const out = [];
|
|
129
|
+
rebuilt.forEach(({ line, spans }, i) => {
|
|
130
|
+
let ranges = [];
|
|
131
|
+
if (regexHits) {
|
|
132
|
+
ranges = regexHits[i] ?? [];
|
|
138
133
|
}
|
|
139
134
|
else {
|
|
140
|
-
// normalizeForMatch keeps string length except for collapsing runs of
|
|
141
|
-
// separators, so search the normalized text and map back word by word.
|
|
142
135
|
const needle = normalizeForMatch(query);
|
|
143
136
|
if (!needle)
|
|
144
|
-
|
|
137
|
+
return;
|
|
145
138
|
const hay = spans.map((s) => normalizeForMatch(s.word.text)).join("_");
|
|
146
139
|
let from = 0;
|
|
147
140
|
for (let at = hay.indexOf(needle, from); at !== -1; at = hay.indexOf(needle, from)) {
|
|
@@ -157,11 +150,9 @@ export function findMatches(lines, query, regex = false) {
|
|
|
157
150
|
words.forEach((w) => boxed.add(w));
|
|
158
151
|
out.push({ text: words.map((w) => w.text).join(" "), line: line.text, ...unionRect(words) });
|
|
159
152
|
}
|
|
160
|
-
}
|
|
153
|
+
});
|
|
161
154
|
return out;
|
|
162
155
|
}
|
|
163
|
-
/** Map a range in the `_`-joined normalized word string back to a range in
|
|
164
|
-
* the space-joined text (both join words with one character). */
|
|
165
156
|
function normalizedRangeToText(spans, start, end) {
|
|
166
157
|
let pos = 0;
|
|
167
158
|
let textStart = -1;
|
|
@@ -176,9 +167,8 @@ function normalizedRangeToText(spans, start, end) {
|
|
|
176
167
|
}
|
|
177
168
|
pos += len + 1;
|
|
178
169
|
}
|
|
179
|
-
return [textStart === -1 ? 0 : textStart, textEnd === -1 ? spans
|
|
170
|
+
return [textStart === -1 ? 0 : textStart, textEnd === -1 ? (spans.at(-1)?.end ?? 0) : textEnd];
|
|
180
171
|
}
|
|
181
|
-
/** Padded rectangles for redact_region, clamped to the frame. Pure. */
|
|
182
172
|
export function redactionRects(matches, frame, pad = 4) {
|
|
183
173
|
return matches.map((m) => {
|
|
184
174
|
const x = Math.max(0, m.x - pad);
|
|
@@ -191,21 +181,14 @@ export function redactionRects(matches, frame, pad = 4) {
|
|
|
191
181
|
};
|
|
192
182
|
});
|
|
193
183
|
}
|
|
194
|
-
/** The scales actually used for an image of this size: each OCR_SCALES entry,
|
|
195
|
-
* capped so the upscaled image stays within the engine's limit. Pure. */
|
|
196
184
|
export function passScales(width, height) {
|
|
197
185
|
const cap = OCR_MAX_DIMENSION / Math.max(width, height);
|
|
198
186
|
const scales = OCR_SCALES.map((s) => Math.min(s, Math.floor(cap * 100) / 100)).filter((s) => s >= 1);
|
|
199
187
|
return [...new Set(scales.length ? scales : [Math.min(1, cap)])];
|
|
200
188
|
}
|
|
201
|
-
/** Limit for one OCR run (all passes of all images) (#183). */
|
|
202
189
|
export const OCR_TIMEOUT_MS = 60_000;
|
|
203
|
-
/** Extra time per image beyond the first two (a whole-clip scan, #204). */
|
|
204
190
|
export const OCR_PER_IMAGE_MS = 5_000;
|
|
205
|
-
/** Limit for one WinRT call inside it (open, decode, recognise). */
|
|
206
191
|
export const OCR_STEP_TIMEOUT_MS = 20_000;
|
|
207
|
-
// Windows PowerShell 5.1 + WinRT: decode each image, recognise it with the
|
|
208
|
-
// user's profile languages, and print one JSON object per image.
|
|
209
192
|
const PS_OCR = `
|
|
210
193
|
$ErrorActionPreference = 'Stop'
|
|
211
194
|
Add-Type -AssemblyName System.Runtime.WindowsRuntime
|
|
@@ -232,4 +215,3 @@ $out = foreach ($p in $paths) {
|
|
|
232
215
|
}
|
|
233
216
|
ConvertTo-Json -InputObject @($out) -Depth 6 -Compress
|
|
234
217
|
`;
|
|
235
|
-
//# sourceMappingURL=ocr.js.map
|
package/dist/utils/paths.js
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Output location and filename helpers.
|
|
3
|
-
*
|
|
4
|
-
* By default everything the server writes lands under SCREENCAST_HOME
|
|
5
|
-
* (default: <homedir>/.screencast-mcp), NOT the current working directory, so
|
|
6
|
-
* captures never accidentally land inside a checked-out repo. Callers may still
|
|
7
|
-
* pass an absolute `output` path per call. The repo .gitignore is a second line
|
|
8
|
-
* of defence for the case where output is pointed back into the project.
|
|
9
|
-
*/
|
|
10
1
|
import { homedir, tmpdir } from "node:os";
|
|
11
|
-
import { join, isAbsolute, resolve } from "node:path";
|
|
12
|
-
import { mkdirSync, existsSync } from "node:fs";
|
|
2
|
+
import { basename, delimiter, dirname, join, isAbsolute, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { mkdirSync, existsSync, realpathSync } from "node:fs";
|
|
13
4
|
import { ScreencastError } from "./errors.js";
|
|
14
5
|
export function homeRoot() {
|
|
15
6
|
const override = process.env.SCREENCAST_HOME;
|
|
@@ -22,50 +13,90 @@ export function subdir(name) {
|
|
|
22
13
|
mkdirSync(dir, { recursive: true });
|
|
23
14
|
return dir;
|
|
24
15
|
}
|
|
25
|
-
/** The on-disk session registry path. */
|
|
26
16
|
export function registryPath() {
|
|
27
17
|
const dir = homeRoot();
|
|
28
18
|
mkdirSync(dir, { recursive: true });
|
|
29
19
|
return join(dir, "sessions.json");
|
|
30
20
|
}
|
|
31
|
-
/** A compact UTC timestamp like 20260615-192430-880. */
|
|
32
21
|
export function stamp(date = new Date()) {
|
|
33
22
|
const iso = date.toISOString().replace(/[-:T]/g, "").replace(/\..+/, "");
|
|
34
23
|
const ms = String(date.getMilliseconds()).padStart(3, "0");
|
|
35
24
|
return `${iso.slice(0, 8)}-${iso.slice(8, 14)}-${ms}`;
|
|
36
25
|
}
|
|
37
|
-
/** Short random suffix to make ids/filenames unique within the same ms. */
|
|
38
26
|
export function rand(n = 4) {
|
|
39
27
|
return Math.random().toString(36).slice(2, 2 + n);
|
|
40
28
|
}
|
|
41
|
-
/** An ffmpeg image-sequence pattern (`name` holds the `%0Nd`) inside `dir`. A
|
|
42
|
-
* `%` in the directory itself is escaped as `%%` so ffmpeg reads it literally
|
|
43
|
-
* (#238). */
|
|
44
29
|
export function sequencePattern(dir, name) {
|
|
45
30
|
return join(dir.replace(/%/g, "%%"), name);
|
|
46
31
|
}
|
|
47
32
|
const STILL_IMAGE = /\.(png|jpe?g|bmp|tiff?)$/i;
|
|
48
|
-
/** The output args for a single still image. ffmpeg's image2 muxer reads a `%`
|
|
49
|
-
* in the file name as a sequence pattern (`b%dx.png` becomes `b1x.png`), so
|
|
50
|
-
* `-update 1` keeps the name literal and the returned path real (#238). */
|
|
51
33
|
export function stillOutput(output) {
|
|
52
34
|
return STILL_IMAGE.test(output) ? ["-update", "1", output] : [output];
|
|
53
35
|
}
|
|
54
|
-
/** A unique scratch path in the OS temp dir for short-lived working files (a
|
|
55
|
-
* concat list, a drawtext textfile). Kept out of SCREENCAST_HOME/edits so a hard
|
|
56
|
-
* crash before cleanup leaves it where the OS reaps it, not next to outputs. */
|
|
57
36
|
export function tempPath(suffix = "") {
|
|
58
37
|
return join(tmpdir(), `screencast-${stamp()}-${rand()}${suffix}`);
|
|
59
38
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
39
|
+
export const ALLOWED_DIRS_ENV = "SCREENCAST_ALLOWED_DIRS";
|
|
40
|
+
export function envAllowedDirs(env = process.env) {
|
|
41
|
+
const raw = env[ALLOWED_DIRS_ENV];
|
|
42
|
+
if (!raw)
|
|
43
|
+
return [];
|
|
44
|
+
return raw
|
|
45
|
+
.split(delimiter)
|
|
46
|
+
.map((d) => d.trim())
|
|
47
|
+
.filter((d) => d.length > 0)
|
|
48
|
+
.map((d) => resolve(d));
|
|
49
|
+
}
|
|
50
|
+
let clientRoots = null;
|
|
51
|
+
export function setClientRoots(dirs) {
|
|
52
|
+
clientRoots = dirs === null || dirs === "pending" ? dirs : dirs.map((d) => resolve(d));
|
|
53
|
+
}
|
|
54
|
+
export function getClientRoots() {
|
|
55
|
+
return Array.isArray(clientRoots) ? clientRoots : null;
|
|
56
|
+
}
|
|
57
|
+
export function allowedOutputDirs(env = process.env) {
|
|
58
|
+
const fromEnv = envAllowedDirs(env);
|
|
59
|
+
if (clientRoots === null && fromEnv.length === 0)
|
|
60
|
+
return null;
|
|
61
|
+
const roots = Array.isArray(clientRoots) ? clientRoots : [];
|
|
62
|
+
return [resolve(homeRoot()), ...fromEnv, ...roots];
|
|
63
|
+
}
|
|
64
|
+
function realish(path) {
|
|
65
|
+
const tail = [];
|
|
66
|
+
let cur = resolve(path);
|
|
67
|
+
for (;;) {
|
|
68
|
+
try {
|
|
69
|
+
return join(realpathSync.native(cur), ...tail.reverse());
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
const parent = dirname(cur);
|
|
73
|
+
if (parent === cur)
|
|
74
|
+
return resolve(path);
|
|
75
|
+
tail.push(basename(cur));
|
|
76
|
+
cur = parent;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export function isWithin(path, dir) {
|
|
81
|
+
const rel = relative(realish(dir), realish(path));
|
|
82
|
+
return rel === "" || (rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel));
|
|
83
|
+
}
|
|
84
|
+
export function assertOutputAllowed(path) {
|
|
85
|
+
if (clientRoots === "pending" && envAllowedDirs().length === 0 && !isWithin(path, homeRoot())) {
|
|
86
|
+
throw new ScreencastError(`Output ${path} is outside SCREENCAST_HOME and the client's workspace roots have not loaded yet. ` +
|
|
87
|
+
"Retry the call in a moment, or omit the path to write under SCREENCAST_HOME.");
|
|
88
|
+
}
|
|
89
|
+
const allowed = allowedOutputDirs();
|
|
90
|
+
if (allowed === null || allowed.some((dir) => isWithin(path, dir)))
|
|
91
|
+
return;
|
|
92
|
+
throw new ScreencastError(`Output ${path} is outside the allowed directories: ${allowed.join(", ")}. ` +
|
|
93
|
+
`Write under one of them (a relative path lands in SCREENCAST_HOME), or add the folder to ` +
|
|
94
|
+
`${ALLOWED_DIRS_ENV} or the client's workspace roots.`);
|
|
95
|
+
}
|
|
66
96
|
export function resolveOutput(provided, defaultDir, defaultName, overwrite = false) {
|
|
67
97
|
if (provided && provided.trim().length > 0) {
|
|
68
|
-
const path =
|
|
98
|
+
const path = resolve(defaultDir, provided);
|
|
99
|
+
assertOutputAllowed(path);
|
|
69
100
|
if (!overwrite && existsSync(path)) {
|
|
70
101
|
throw new ScreencastError(`Output already exists: ${path}. Pass overwrite: true to replace it, ` +
|
|
71
102
|
`or choose a different path.`);
|
|
@@ -74,4 +105,10 @@ export function resolveOutput(provided, defaultDir, defaultName, overwrite = fal
|
|
|
74
105
|
}
|
|
75
106
|
return join(defaultDir, defaultName);
|
|
76
107
|
}
|
|
77
|
-
|
|
108
|
+
export function resolveOutputDir(provided, defaultParent) {
|
|
109
|
+
if (!provided || provided.trim().length === 0)
|
|
110
|
+
return undefined;
|
|
111
|
+
const dir = resolve(defaultParent, provided);
|
|
112
|
+
assertOutputAllowed(dir);
|
|
113
|
+
return dir;
|
|
114
|
+
}
|
package/dist/utils/pipeline.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* pipeline (#125): run a chain of edits as ONE ffmpeg process instead of one
|
|
3
|
-
* re-encode (and one intermediate file) per tool call.
|
|
4
|
-
*
|
|
5
|
-
* Each step contributes filter-graph steps over the current video label, built
|
|
6
|
-
* by the same helpers as the standalone tools, so a pipeline step behaves like
|
|
7
|
-
* its tool. Frame size, fps, and duration are tracked through the chain so each
|
|
8
|
-
* step is validated against the frame it actually receives, and times inside a
|
|
9
|
-
* step (callout from/to, redact start/end, zoom keyframes) are on the timeline
|
|
10
|
-
* as it is at that step (after an earlier trim or speed change).
|
|
11
|
-
*
|
|
12
|
-
* A leading trim becomes an input seek, the cheapest form. export_preset and
|
|
13
|
-
* export_gif can only be the last step: export_preset sets the encoder; an
|
|
14
|
-
* export_gif tail renders the chain to a temporary high-quality mp4 first and
|
|
15
|
-
* then runs the size-budget ladder, so it is two stages. All of this is pure.
|
|
16
|
-
*/
|
|
17
1
|
import { ScreencastError } from "./errors.js";
|
|
18
2
|
import { atempoChain, cropFilter, redactSteps, scaleFilter, scaledSize } from "./media.js";
|
|
19
3
|
import { calloutSteps } from "./callout.js";
|
|
@@ -22,7 +6,6 @@ import { keyframesToViews, zoomFilter, DEFAULT_TRANSITION_SEC } from "./zoom.js"
|
|
|
22
6
|
import { resolveQuality } from "./targets.js";
|
|
23
7
|
export const MAX_PIPELINE_STEPS = 30;
|
|
24
8
|
const r3 = (v) => Math.round(v * 1000) / 1000;
|
|
25
|
-
/** Plan the fused command. `assets[i]` holds the files callout step i needs. */
|
|
26
9
|
export function planPipeline(input, output, steps, src, assets = {}, quality = "standard") {
|
|
27
10
|
if (steps.length === 0)
|
|
28
11
|
throw new ScreencastError("Give at least one step.");
|
|
@@ -33,8 +16,6 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
|
|
|
33
16
|
throw new ScreencastError(`${s.op} must be the last step (it is step ${i + 1} of ${steps.length}).`);
|
|
34
17
|
}
|
|
35
18
|
});
|
|
36
|
-
// A zoom moves the content within the frame over time, so a fixed redact
|
|
37
|
-
// box after it would slide off the secret (#204).
|
|
38
19
|
const zoomAt = steps.findIndex((s) => s.op === "zoom");
|
|
39
20
|
const lateRedact = zoomAt === -1 ? -1 : steps.findIndex((s, i) => i > zoomAt && s.op === "redact");
|
|
40
21
|
if (lateRedact !== -1) {
|
|
@@ -184,14 +165,11 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
|
|
|
184
165
|
}
|
|
185
166
|
if (src.hasAudio)
|
|
186
167
|
args.push("-map", audio.length > 0 && graph.length > 0 ? "[aout]" : "0:a");
|
|
187
|
-
// Assigned inside the forEach above, which TypeScript does not track.
|
|
188
168
|
const finalEncode = encode;
|
|
189
169
|
if (finalEncode) {
|
|
190
170
|
args.push(...finalEncode);
|
|
191
171
|
}
|
|
192
172
|
else {
|
|
193
|
-
// An export_gif tail reads this file once, so give it more quality; a
|
|
194
|
-
// redaction gets it too, like redact_region, so its edges stay crisp (#204).
|
|
195
173
|
args.push(...resolveQuality(gif || redacts ? "high" : quality));
|
|
196
174
|
if (src.hasAudio)
|
|
197
175
|
args.push(...(audioReencode ? ["-c:a", "aac", "-b:a", "160k"] : ["-c:a", "copy"]));
|
|
@@ -200,4 +178,3 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
|
|
|
200
178
|
args.push(output);
|
|
201
179
|
return { args, width: W, height: H, fps, durationSec: dur === null ? null : r3(dur), gif, summary };
|
|
202
180
|
}
|
|
203
|
-
//# sourceMappingURL=pipeline.js.map
|
package/dist/utils/player.js
CHANGED
|
@@ -1,47 +1,71 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The review player (#128): an MCP Apps view (a sandboxed HTML page the host
|
|
3
|
-
* shows inline) where a person scrubs a recording, sets trim handles, and
|
|
4
|
-
* draws redaction boxes; their choices come back as a pipeline call.
|
|
5
|
-
*
|
|
6
|
-
* The page gets the video as JPEG frames (data: images work under the strict
|
|
7
|
-
* CSP hosts apply to apps, unlike a local file or HTTP server, and keep
|
|
8
|
-
* "output stays local"). These helpers plan and split those frames. Pure.
|
|
9
|
-
*/
|
|
10
1
|
import { ScreencastError } from "./errors.js";
|
|
11
|
-
|
|
2
|
+
import { escapeFilterPath } from "./fonts.js";
|
|
12
3
|
export const PLAYER_URI = "ui://screencast/player";
|
|
13
4
|
export const MCP_APP_MIME = "text/html;profile=mcp-app";
|
|
14
|
-
/** Tool _meta that tells an Apps host to render the player for a tool's
|
|
15
|
-
* result. Both the current and the legacy key, as the spec asks hosts to read. */
|
|
16
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
|
+
}
|
|
17
14
|
export const DEFAULT_PLAYER_FRAMES = 120;
|
|
18
15
|
export const MAX_PLAYER_FRAMES = 300;
|
|
19
16
|
export const PLAYER_FPS = 4;
|
|
20
17
|
export const DEFAULT_PLAYER_WIDTH = 640;
|
|
21
|
-
|
|
22
|
-
* PLAYER_FPS per second, at most `maxFrames`, spread evenly. */
|
|
18
|
+
export const PLAYER_SCENE_THRESHOLD = 0.01;
|
|
23
19
|
export function playerFramePlan(durationSec, maxFrames = DEFAULT_PLAYER_FRAMES) {
|
|
24
20
|
if (!(durationSec > 0))
|
|
25
21
|
throw new ScreencastError("The video has no duration to review.");
|
|
26
22
|
const count = Math.max(1, Math.min(maxFrames, Math.ceil(durationSec * PLAYER_FPS)));
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
/** Each frame's time: the middle of its slice of the video. */
|
|
30
|
-
export function playerFrameTimes(durationSec, count) {
|
|
31
|
-
return Array.from({ length: count }, (_, i) => Math.round(((i + 0.5) * durationSec * 1000) / count) / 1000);
|
|
23
|
+
const intervalSec = Number((durationSec / count).toFixed(6));
|
|
24
|
+
return { count, intervalSec, sceneGapSec: Number(Math.max(0.25, intervalSec / 4).toFixed(6)) };
|
|
32
25
|
}
|
|
33
|
-
|
|
34
|
-
|
|
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}))`;
|
|
35
30
|
return [
|
|
36
31
|
"-v", "error", "-i", input, "-an",
|
|
37
|
-
"-vf",
|
|
38
|
-
|
|
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",
|
|
39
38
|
"-q:v", "6", "-f", "image2pipe", "-c:v", "mjpeg", "-",
|
|
40
39
|
];
|
|
41
40
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
+
}
|
|
45
69
|
export function splitJpegs(buf) {
|
|
46
70
|
const out = [];
|
|
47
71
|
let start = -1;
|
|
@@ -59,4 +83,3 @@ export function splitJpegs(buf) {
|
|
|
59
83
|
}
|
|
60
84
|
return out;
|
|
61
85
|
}
|
|
62
|
-
//# sourceMappingURL=player.js.map
|