@tmhs/screencast-mcp 0.46.0 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +127 -303
- package/assets/cursor/arrow.png +0 -0
- package/assets/fonts/Inter-Bold.ttf +0 -0
- package/assets/fonts/Inter-Regular.ttf +0 -0
- package/dist/cli.js +515 -0
- package/dist/index.js +10 -2
- package/dist/server.js +23 -0
- package/dist/setup.js +437 -0
- package/dist/tools/addMarker.js +6 -2
- package/dist/tools/bugReport.js +1 -1
- package/dist/tools/chapters.js +1 -1
- package/dist/tools/cursor.js +87 -0
- package/dist/tools/cutByTranscript.js +3 -3
- package/dist/tools/doctor.js +14 -1
- package/dist/tools/indexRecording.js +37 -15
- package/dist/tools/listVideoDevices.js +26 -0
- package/dist/tools/narrate.js +86 -0
- package/dist/tools/overlay.js +2 -0
- package/dist/tools/pauseRecording.js +44 -0
- package/dist/tools/pipeline.js +37 -13
- package/dist/tools/readEvents.js +1 -1
- package/dist/tools/resumeRecording.js +46 -0
- package/dist/tools/reviewRecording.js +1 -1
- package/dist/tools/searchRecording.js +9 -3
- package/dist/tools/startRecording.js +155 -86
- package/dist/tools/stepGuide.js +57 -4
- package/dist/tools/stopRecording.js +38 -3
- package/dist/utils/argPaths.js +39 -0
- package/dist/utils/audioDevices.js +34 -4
- package/dist/utils/captions.js +5 -3
- package/dist/utils/cursor.js +317 -0
- package/dist/utils/events.js +62 -12
- package/dist/utils/gpu.js +219 -0
- package/dist/utils/lifecycle.js +136 -13
- package/dist/utils/media.js +7 -2
- package/dist/utils/monitors.js +39 -5
- package/dist/utils/narrate.js +233 -0
- package/dist/utils/ocr.js +8 -3
- package/dist/utils/paths.js +41 -3
- package/dist/utils/pause.js +190 -0
- package/dist/utils/pipeline.js +29 -2
- package/dist/utils/recipes.js +7 -3
- package/dist/utils/recorder.js +172 -0
- package/dist/utils/recordingIndex.js +55 -9
- package/dist/utils/replay.js +20 -2
- package/dist/utils/retention.js +4 -1
- package/dist/utils/roots.js +1 -1
- package/dist/utils/sessions.js +32 -6
- package/dist/utils/stepGuide.js +26 -0
- package/dist/utils/targets.js +31 -7
- package/dist/utils/toolsets.js +8 -3
- package/dist/utils/transcriptCut.js +20 -5
- package/dist/utils/wgc.js +2 -2
- package/dist/wgcRecorder.js +1 -1
- package/package.json +5 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync } from "node:fs";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
5
5
|
import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
6
6
|
import { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
|
|
@@ -12,7 +12,7 @@ import { ocrStatus } from "../utils/capabilities.js";
|
|
|
12
12
|
import { parseEventsJsonl } from "../utils/events.js";
|
|
13
13
|
import { resolveWhisperModel, buildTranscribeArgs, parseSrt, normalizeCues } from "../utils/captions.js";
|
|
14
14
|
import { subdir, tempPath } from "../utils/paths.js";
|
|
15
|
-
import { DEFAULT_INDEX_FRAMES, DEFAULT_INDEX_THRESHOLD, INDEX_VERSION, MAX_INDEX_FRAMES, attach, cueTexts, eventTexts, fingerprintFile, findIndex, indexWritePath, keyframeTime, markerTexts, mergeSegments, planKeyframes, readIndex, resolveRecording,
|
|
15
|
+
import { DEFAULT_INDEX_FRAMES, DEFAULT_INDEX_THRESHOLD, INDEX_VERSION, MAX_INDEX_FRAMES, attach, canReuseIndex, cueTexts, defaultTranscriptPath, eventTexts, fingerprintFile, findIndex, indexMatchesVideo, indexWritePath, keyframeTime, legacyIndexSidecarPath, markerTexts, maskSegmentText, mergeSegments, planKeyframes, readIndex, resolveRecording, segmentsFrom, writeIndex, } from "../utils/recordingIndex.js";
|
|
16
16
|
const OCR_BATCH = 8;
|
|
17
17
|
const inputSchema = {
|
|
18
18
|
input: z.string().optional().describe("Recording path."),
|
|
@@ -47,12 +47,16 @@ export function register(server) {
|
|
|
47
47
|
const fingerprint = fingerprintFile(source.path);
|
|
48
48
|
const report = progressReporter(extra);
|
|
49
49
|
const notes = [];
|
|
50
|
-
const existingPath = args.force ? null : findIndex(source.path, edits);
|
|
50
|
+
const existingPath = args.force ? null : findIndex(source.path, edits, fingerprint);
|
|
51
51
|
const prior = existingPath ? readIndex(existingPath) : null;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
let ocrNow = null;
|
|
53
|
+
const ocrAvailable = async () => (ocrNow ??= process.platform === "win32" && (await ocrStatus()).available);
|
|
54
|
+
const cached = canReuseIndex(prior, {
|
|
55
|
+
fingerprint,
|
|
56
|
+
sceneThreshold: threshold,
|
|
57
|
+
maxFrames,
|
|
58
|
+
ocrAvailable: prior !== null && !prior.ocr ? await ocrAvailable() : false,
|
|
59
|
+
});
|
|
56
60
|
let segments;
|
|
57
61
|
let framesRead = 0;
|
|
58
62
|
let ocr = false;
|
|
@@ -70,7 +74,7 @@ export function register(server) {
|
|
|
70
74
|
report?.(0.1);
|
|
71
75
|
const spans = segmentsFrom(planKeyframes(parseSceneScan(scan.stdout), duration, maxFrames), duration);
|
|
72
76
|
const texts = spans.map(() => []);
|
|
73
|
-
ocr =
|
|
77
|
+
ocr = await ocrAvailable();
|
|
74
78
|
if (ocr) {
|
|
75
79
|
for (let b = 0; b < spans.length; b += OCR_BATCH) {
|
|
76
80
|
extra.signal.throwIfAborted();
|
|
@@ -94,13 +98,14 @@ export function register(server) {
|
|
|
94
98
|
const read = spans.map((s, i) => ({ ...s, ocr: texts[i] ?? [] }));
|
|
95
99
|
segments = ocr ? mergeSegments(read) : read;
|
|
96
100
|
}
|
|
101
|
+
segments = maskSegmentText(segments);
|
|
97
102
|
const events = source.eventsPath ? eventTexts(parseEventsJsonl(readFileSync(source.eventsPath, "utf8"))) : [];
|
|
98
103
|
segments = attach(segments, events, "events");
|
|
99
104
|
segments = attach(segments, markerTexts(source.markers), "markers");
|
|
100
105
|
const cues = await transcriptCues(args.transcript, source.path, info.audioCodec !== null, duration, extra.signal, notes);
|
|
101
106
|
if (cues !== null)
|
|
102
107
|
segments = attach(segments, cueTexts(cues), "transcript");
|
|
103
|
-
else if (cached) {
|
|
108
|
+
else if (cached && prior) {
|
|
104
109
|
const kept = prior.segments.flatMap((s) => s.transcript ?? []);
|
|
105
110
|
segments = attach(segments, kept, "transcript");
|
|
106
111
|
}
|
|
@@ -118,6 +123,12 @@ export function register(server) {
|
|
|
118
123
|
};
|
|
119
124
|
mkdirSync(join(outPath, ".."), { recursive: true });
|
|
120
125
|
writeIndex(outPath, index);
|
|
126
|
+
const legacy = legacyIndexSidecarPath(source.path);
|
|
127
|
+
if (legacy !== outPath && existsSync(legacy)) {
|
|
128
|
+
const old = readIndex(legacy);
|
|
129
|
+
if (old && indexMatchesVideo(old, source.path, fingerprint))
|
|
130
|
+
rmSync(legacy, { force: true });
|
|
131
|
+
}
|
|
121
132
|
report?.(1);
|
|
122
133
|
const count = (f) => segments.reduce((n, s) => n + (s[f]?.length ?? 0), 0);
|
|
123
134
|
return okResponse({
|
|
@@ -133,7 +144,8 @@ export function register(server) {
|
|
|
133
144
|
transcriptCues: count("transcript"),
|
|
134
145
|
},
|
|
135
146
|
...(notes.length > 0 ? { note: notes.join(" ") } : {}),
|
|
136
|
-
next: "search_recording { query } returns timecoded hits
|
|
147
|
+
next: "search_recording { query } returns timecoded hits. Secret-shaped screen text is stored masked; the rest " +
|
|
148
|
+
"of the index is plain text, so treat it like the video.",
|
|
137
149
|
});
|
|
138
150
|
}
|
|
139
151
|
catch (error) {
|
|
@@ -163,11 +175,21 @@ async function transcriptCues(arg, video, hasAudio, duration, signal, notes) {
|
|
|
163
175
|
rmSync(raw, { force: true });
|
|
164
176
|
}
|
|
165
177
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (arg !== undefined)
|
|
178
|
+
if (arg !== undefined) {
|
|
179
|
+
if (!existsSync(arg))
|
|
169
180
|
throw new ScreencastError(`Transcript not found: ${arg}`);
|
|
181
|
+
return normalizeCues(parseSrt(readFileSync(arg, "utf8")));
|
|
182
|
+
}
|
|
183
|
+
let siblings;
|
|
184
|
+
try {
|
|
185
|
+
siblings = readdirSync(dirname(video));
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
170
188
|
return null;
|
|
171
189
|
}
|
|
172
|
-
|
|
190
|
+
const found = defaultTranscriptPath(video, siblings);
|
|
191
|
+
if (found.ambiguous) {
|
|
192
|
+
notes.push("Another video in the folder shares this one's base name, so its .srt was not attached; pass transcript.");
|
|
193
|
+
}
|
|
194
|
+
return found.path ? normalizeCues(parseSrt(readFileSync(found.path, "utf8"))) : null;
|
|
173
195
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { errorResponse, okResponse } from "../utils/errors.js";
|
|
3
|
+
import { READ_ONLY, looseOutput } from "../utils/toolSpec.js";
|
|
4
|
+
import { requireFfmpeg } from "../utils/ffmpeg.js";
|
|
5
|
+
import { listDshowVideoDevices } from "../utils/audioDevices.js";
|
|
6
|
+
export function register(server) {
|
|
7
|
+
server.registerTool("list_video_devices", {
|
|
8
|
+
title: "List Video Devices",
|
|
9
|
+
description: "List DirectShow cameras for start_recording's webcam.device.",
|
|
10
|
+
inputSchema: {},
|
|
11
|
+
outputSchema: looseOutput({ devices: z.array(z.string()) }),
|
|
12
|
+
annotations: READ_ONLY,
|
|
13
|
+
}, async () => {
|
|
14
|
+
try {
|
|
15
|
+
requireFfmpeg();
|
|
16
|
+
const devices = await listDshowVideoDevices(true);
|
|
17
|
+
return okResponse({
|
|
18
|
+
devices,
|
|
19
|
+
note: devices.length ? `start_recording { webcam: { device: "${devices[0]}" } } records it.` : "No camera found.",
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
return errorResponse(error);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
6
|
+
import { OUTPUT_PATH, WRITES_FILE } from "../utils/toolSpec.js";
|
|
7
|
+
import { requireFfmpeg, probeMedia } from "../utils/ffmpeg.js";
|
|
8
|
+
import { runEditJob } from "../utils/jobs.js";
|
|
9
|
+
import { editOutputExt, assertEditContainer } from "../utils/media.js";
|
|
10
|
+
import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
|
|
11
|
+
import { markersOrChapters, readMarkers, writeMarkers } from "../utils/chapters.js";
|
|
12
|
+
import { formatSrt } from "../utils/captions.js";
|
|
13
|
+
import { buildNarrateArgs, narrationCues, placementWarnings, resolveLines, synthesize, wavDurationSec, MAX_RATE, MIN_RATE, } from "../utils/narrate.js";
|
|
14
|
+
const inputSchema = {
|
|
15
|
+
video: z.string().min(1).describe("Path to the video."),
|
|
16
|
+
lines: z
|
|
17
|
+
.array(z.object({
|
|
18
|
+
t: z.number().nonnegative().optional().describe("Seconds."),
|
|
19
|
+
marker: z.string().optional().describe("Or a marker label."),
|
|
20
|
+
text: z.string().min(1),
|
|
21
|
+
}))
|
|
22
|
+
.min(1),
|
|
23
|
+
voice: z.string().optional().describe("Voice name or part (doctor lists them)."),
|
|
24
|
+
rate: z.number().min(MIN_RATE).max(MAX_RATE).optional().describe("Default 1."),
|
|
25
|
+
duck: z.boolean().optional().describe("Duck the original audio (default true)."),
|
|
26
|
+
output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
|
|
27
|
+
overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
|
|
28
|
+
};
|
|
29
|
+
export function register(server) {
|
|
30
|
+
server.registerTool("narrate", {
|
|
31
|
+
title: "Narrate",
|
|
32
|
+
description: "Offline voiceover with the built-in Windows voices: speaks each line at its time or marker " +
|
|
33
|
+
"over the audio, plus an SRT.",
|
|
34
|
+
inputSchema,
|
|
35
|
+
outputSchema: OUTPUT_PATH,
|
|
36
|
+
annotations: WRITES_FILE,
|
|
37
|
+
}, async (args, extra) => {
|
|
38
|
+
let work = null;
|
|
39
|
+
try {
|
|
40
|
+
requireFfmpeg();
|
|
41
|
+
if (!existsSync(args.video))
|
|
42
|
+
throw new ScreencastError(`Input file not found: ${args.video}`);
|
|
43
|
+
const info = await probeMedia(args.video);
|
|
44
|
+
if (info.durationSec === null)
|
|
45
|
+
throw new ScreencastError(`Could not read duration of ${args.video}.`);
|
|
46
|
+
const needsMarkers = args.lines.some((l) => l.marker !== undefined);
|
|
47
|
+
const markers = needsMarkers ? (await markersOrChapters(args.video, extra.signal)).markers : [];
|
|
48
|
+
const lines = resolveLines(args.lines, markers);
|
|
49
|
+
assertEditContainer(args.output);
|
|
50
|
+
const output = resolveOutput(args.output, subdir("edits"), `narrated-${stamp()}-${rand()}${editOutputExt(args.video)}`, args.overwrite);
|
|
51
|
+
const srtPath = output.replace(/\.[^./\\]+$/, "") + ".srt";
|
|
52
|
+
if (!args.overwrite && existsSync(srtPath))
|
|
53
|
+
throw new ScreencastError(`Output already exists: ${srtPath}. Pass overwrite: true to replace it.`);
|
|
54
|
+
work = mkdtempSync(join(tmpdir(), "screencast-tts-"));
|
|
55
|
+
const wavs = lines.map((_, i) => join(work, `line-${i}.wav`));
|
|
56
|
+
const voice = await synthesize(lines.map((l, i) => ({ text: l.text, path: wavs[i] })), { voice: args.voice, rate: args.rate, signal: extra.signal });
|
|
57
|
+
const placed = lines.map((l, i) => ({ ...l, durationSec: wavDurationSec(readFileSync(wavs[i])) }));
|
|
58
|
+
const warnings = placementWarnings(placed, info.durationSec);
|
|
59
|
+
const ffArgs = buildNarrateArgs(args.video, wavs, output, placed, info.durationSec, {
|
|
60
|
+
hasAudio: info.audioCodec !== null,
|
|
61
|
+
channels: info.channels,
|
|
62
|
+
duck: args.duck,
|
|
63
|
+
});
|
|
64
|
+
await runEditJob(ffArgs, { output, durationSec: info.durationSec, extra });
|
|
65
|
+
writeFileSync(srtPath, formatSrt(narrationCues(placed, info.durationSec)));
|
|
66
|
+
const inputMarkers = readMarkers(args.video);
|
|
67
|
+
if (inputMarkers.length > 0)
|
|
68
|
+
writeMarkers(output, inputMarkers);
|
|
69
|
+
return okResponse({
|
|
70
|
+
outputPath: output,
|
|
71
|
+
srtPath,
|
|
72
|
+
voice,
|
|
73
|
+
lines: placed.map((p) => ({ t: p.t, durationSec: Math.round(p.durationSec * 100) / 100 })),
|
|
74
|
+
mixedWithOriginal: info.audioCodec !== null,
|
|
75
|
+
...(warnings.length ? { warnings } : {}),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
return errorResponse(error);
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
if (work)
|
|
83
|
+
rmSync(work, { recursive: true, force: true });
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
package/dist/tools/overlay.js
CHANGED
|
@@ -15,6 +15,7 @@ const inputSchema = {
|
|
|
15
15
|
height: z.number().int().positive().optional().describe("Scale to this height."),
|
|
16
16
|
start: z.number().nonnegative().optional().describe("Show from this second."),
|
|
17
17
|
end: z.number().positive().optional().describe("Hide after this second."),
|
|
18
|
+
shape: z.enum(["rect", "circle"]).optional().describe("circle: centre square masked round (webcam)."),
|
|
18
19
|
output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
|
|
19
20
|
overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
|
|
20
21
|
};
|
|
@@ -48,6 +49,7 @@ export function register(server) {
|
|
|
48
49
|
start: args.start,
|
|
49
50
|
end: args.end,
|
|
50
51
|
scale,
|
|
52
|
+
shape: args.shape,
|
|
51
53
|
durationSec,
|
|
52
54
|
});
|
|
53
55
|
await runEditJob(ffArgs, { output, durationSec, extra });
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
3
|
+
import { STOPS_SESSION, looseOutput } from "../utils/toolSpec.js";
|
|
4
|
+
import { requireFfmpeg } from "../utils/ffmpeg.js";
|
|
5
|
+
import { pauseSession, probeDuration } from "../utils/lifecycle.js";
|
|
6
|
+
import { recordedSec } from "../utils/pause.js";
|
|
7
|
+
import { getStore } from "../context.js";
|
|
8
|
+
const r3 = (n) => Math.round(n * 1000) / 1000;
|
|
9
|
+
export function register(server) {
|
|
10
|
+
server.registerTool("pause_recording", {
|
|
11
|
+
title: "Pause Recording",
|
|
12
|
+
description: "Pause a recording; until resume_recording nothing is captured, and the gap is left out of the file, events, and markers.",
|
|
13
|
+
inputSchema: { sessionId: z.string().min(1).describe("From start_recording.") },
|
|
14
|
+
outputSchema: looseOutput({ sessionId: z.string(), status: z.string(), recordedSec: z.number() }),
|
|
15
|
+
annotations: STOPS_SESSION,
|
|
16
|
+
}, async (args) => {
|
|
17
|
+
try {
|
|
18
|
+
const store = getStore();
|
|
19
|
+
const record = store.get(args.sessionId);
|
|
20
|
+
if (!record)
|
|
21
|
+
throw new ScreencastError(`No session with id "${args.sessionId}".`);
|
|
22
|
+
if (record.status === "paused") {
|
|
23
|
+
return okResponse({
|
|
24
|
+
sessionId: record.id,
|
|
25
|
+
status: "paused",
|
|
26
|
+
recordedSec: r3(recordedSec(record.segments?.parts ?? [])),
|
|
27
|
+
note: "Already paused.",
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const { ffprobe } = requireFfmpeg();
|
|
31
|
+
const res = await pauseSession(store, record, { probe: (p) => probeDuration(ffprobe, p) });
|
|
32
|
+
return okResponse({
|
|
33
|
+
sessionId: record.id,
|
|
34
|
+
status: "paused",
|
|
35
|
+
recordedSec: r3(res.recordedSec),
|
|
36
|
+
segments: res.record?.segments?.parts.length ?? 0,
|
|
37
|
+
note: "Nothing is captured until resume_recording; stop_recording joins what was recorded.",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
return errorResponse(error);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
package/dist/tools/pipeline.js
CHANGED
|
@@ -6,7 +6,7 @@ import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
|
6
6
|
import { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
|
|
7
7
|
import { requireFfmpeg, probeMedia, hasFilter, runCapture, runFfmpeg, scriptLongFilters } from "../utils/ffmpeg.js";
|
|
8
8
|
import { jobTimeoutMs, runEditJob } from "../utils/jobs.js";
|
|
9
|
-
import { planPipeline, probeArgs, MAX_PIPELINE_STEPS } from "../utils/pipeline.js";
|
|
9
|
+
import { planPipeline, probeArgs, sidecarCues, MAX_PIPELINE_STEPS } from "../utils/pipeline.js";
|
|
10
10
|
import { calloutFonts, prepareCalloutAssets } from "../utils/calloutAssets.js";
|
|
11
11
|
import { exportAnimation } from "../utils/animExport.js";
|
|
12
12
|
import { calloutItemSchema, fontFileSchema } from "./callout.js";
|
|
@@ -15,6 +15,8 @@ import { redactRegionSchema } from "./redactRegion.js";
|
|
|
15
15
|
import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
|
|
16
16
|
import { PLATFORMS } from "../utils/produce.js";
|
|
17
17
|
import { buildChapters, ffmetadata, markerPoints, markersOrChapters, retimeMarkers, writeMarkers } from "../utils/chapters.js";
|
|
18
|
+
import { cursorOptionsSchema, loadCursor } from "./cursor.js";
|
|
19
|
+
import { cursorSpritePath } from "../utils/cursor.js";
|
|
18
20
|
import { backdropOptionsSchema } from "./backdrop.js";
|
|
19
21
|
import { keystrokeOptionsSchema, loadBadges, prepareKeystrokeAssets } from "./keystrokeOverlay.js";
|
|
20
22
|
import { MAX_ZOOM } from "../utils/zoom.js";
|
|
@@ -85,6 +87,7 @@ const step = z.discriminatedUnion("op", [
|
|
|
85
87
|
}),
|
|
86
88
|
z.object({ op: z.literal("backdrop"), ...backdropOptionsSchema }),
|
|
87
89
|
z.object({ op: z.literal("keystroke_overlay"), ...keystrokeOptionsSchema }),
|
|
90
|
+
z.object({ op: z.literal("cursor"), ...cursorOptionsSchema }),
|
|
88
91
|
z.object({ op: z.literal("export_preset"), platform: z.enum(PLATFORMS), fit }),
|
|
89
92
|
z.object({
|
|
90
93
|
op: z.literal("export_gif"),
|
|
@@ -107,7 +110,8 @@ const inputSchema = {
|
|
|
107
110
|
.enum(RECIPES)
|
|
108
111
|
.optional()
|
|
109
112
|
.describe("Polish preset expanded to steps (see dryRun): pr_demo = cut_idle, click zoom, GIF <=10 MB; tutorial = " +
|
|
110
|
-
"+ audio, captions, 1080p mp4; social_reel = 9:16, big captions. Given steps replace its same-op step
|
|
113
|
+
"+ audio, captions, 1080p mp4; social_reel = 9:16, big captions. Given steps replace its same-op step; " +
|
|
114
|
+
"trim, redact, crop and cursor go first (source pixels and time)."),
|
|
111
115
|
quality: z.enum(["draft", "standard", "high"]).optional().describe("Encoder preset for an mp4 result (default standard)."),
|
|
112
116
|
dryRun: z.boolean().optional().describe("Return the plan (ffmpeg command, output size) without running it."),
|
|
113
117
|
output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
|
|
@@ -120,7 +124,7 @@ const inputSchema = {
|
|
|
120
124
|
export function register(server) {
|
|
121
125
|
server.registerTool("pipeline", {
|
|
122
126
|
title: "Edit Pipeline",
|
|
123
|
-
description: "Run several edits (trim, crop, scale, speed, cut_idle, redact, callout, keystroke_overlay, reframe, zoom, backdrop, " +
|
|
127
|
+
description: "Run several edits (trim, crop, scale, speed, cut_idle, redact, callout, keystroke_overlay, cursor, reframe, zoom, backdrop, " +
|
|
124
128
|
"audio, burn_subtitles, then optionally export_preset or export_gif) in one ffmpeg pass: one re-encode, no " +
|
|
125
129
|
"intermediate files. Prefer it over chaining edit tools; a recipe does the usual polish in one call.",
|
|
126
130
|
inputSchema,
|
|
@@ -159,6 +163,16 @@ export function register(server) {
|
|
|
159
163
|
hasAudio,
|
|
160
164
|
};
|
|
161
165
|
const timeout = jobTimeoutMs(info.durationSec);
|
|
166
|
+
const last = steps.at(-1);
|
|
167
|
+
if (!last)
|
|
168
|
+
throw new ScreencastError("Provide at least one step.");
|
|
169
|
+
const ext = last.op === "export_gif" ? `.${last.format ?? "gif"}` : ".mp4";
|
|
170
|
+
const output = resolveOutput(args.output, subdir("edits"), `pipeline-${stamp()}-${rand()}${ext}`, args.overwrite);
|
|
171
|
+
const transcribes = last.op !== "export_gif" && steps.some((s) => s.op === "burn_subtitles" && s.transcribe);
|
|
172
|
+
const sidecar = output.replace(/\.[^./\\]+$/, "") + ".srt";
|
|
173
|
+
if (transcribes && !args.overwrite && existsSync(sidecar)) {
|
|
174
|
+
throw new ScreencastError(`Output already exists: ${sidecar}. Pass overwrite: true to replace it.`);
|
|
175
|
+
}
|
|
162
176
|
for (const [i, s] of steps.entries()) {
|
|
163
177
|
if (s.op !== "burn_subtitles")
|
|
164
178
|
continue;
|
|
@@ -200,11 +214,6 @@ export function register(server) {
|
|
|
200
214
|
const freezes = parseFreezes(scan.stderr, total);
|
|
201
215
|
idle = useAudio ? intersect(freezes, parseSilences(scan.stderr, total)) : freezes;
|
|
202
216
|
}
|
|
203
|
-
const last = steps.at(-1);
|
|
204
|
-
if (!last)
|
|
205
|
-
throw new ScreencastError("Provide at least one step.");
|
|
206
|
-
const ext = last.op === "export_gif" ? `.${last.format ?? "gif"}` : ".mp4";
|
|
207
|
-
const output = resolveOutput(args.output, subdir("edits"), `pipeline-${stamp()}-${rand()}${ext}`, args.overwrite);
|
|
208
217
|
const work = mkdtempSync(join(tmpdir(), "screencast-pipeline-"));
|
|
209
218
|
try {
|
|
210
219
|
const assets = {};
|
|
@@ -232,12 +241,22 @@ export function register(server) {
|
|
|
232
241
|
keystrokes[i] = { badges, fontFile: k.fontFile, textFiles: k.textFiles };
|
|
233
242
|
warnings.push(...k.warnings.map((w) => `Step ${i}, ${w.charAt(0).toLowerCase()}${w.slice(1)}`));
|
|
234
243
|
}
|
|
244
|
+
const cursor = {};
|
|
245
|
+
for (const [i, s] of steps.entries()) {
|
|
246
|
+
if (s.op !== "cursor")
|
|
247
|
+
continue;
|
|
248
|
+
cursor[i] = {
|
|
249
|
+
plan: loadCursor(args.input, s.events, s, info.durationSec),
|
|
250
|
+
sprite: cursorSpritePath(),
|
|
251
|
+
commandsFile: args.dryRun ? `<cursor ${i}.cmd>` : join(work, `s${i}_cursor.cmd`),
|
|
252
|
+
};
|
|
253
|
+
}
|
|
235
254
|
const target = last.op === "export_gif" ? (args.dryRun ? "<temporary stage1.mp4>" : join(work, "stage1.mp4")) : output;
|
|
236
255
|
const audioM = {};
|
|
237
256
|
const subtitles = {};
|
|
238
257
|
const fontsDir = dirname(bundledFontPath("regular"));
|
|
239
258
|
const planWith = (chaptersFile) => planPipeline(args.input, target, steps, src, assets, args.quality ?? "standard", {
|
|
240
|
-
keystrokes, idle, clicks, audio: audioM, subtitles, fontsDir, chaptersFile,
|
|
259
|
+
keystrokes, cursor, idle, clicks, audio: audioM, subtitles, fontsDir, chaptersFile,
|
|
241
260
|
});
|
|
242
261
|
let plan = planWith();
|
|
243
262
|
let transcript;
|
|
@@ -279,8 +298,8 @@ export function register(server) {
|
|
|
279
298
|
const cues = existsSync(raw) ? normalizeCues(parseSrt(readFileSync(raw, "utf8"))) : [];
|
|
280
299
|
subtitles[p.step] = cues.length > 0 ? join(work, `s${p.step}.srt`) : "";
|
|
281
300
|
if (cues.length > 0) {
|
|
282
|
-
transcript =
|
|
283
|
-
writeFileSync(subtitles[p.step],
|
|
301
|
+
transcript = { cues, opsBefore: p.ops.length };
|
|
302
|
+
writeFileSync(subtitles[p.step], formatSrt(cues));
|
|
284
303
|
}
|
|
285
304
|
else
|
|
286
305
|
warnings.push(`Step ${p.step + 1}: no speech was recognised; no captions.`);
|
|
@@ -337,6 +356,8 @@ export function register(server) {
|
|
|
337
356
|
};
|
|
338
357
|
if (args.dryRun)
|
|
339
358
|
return okResponse({ dryRun: true, ...result, ffmpegArgs: plan.args });
|
|
359
|
+
for (const f of plan.files)
|
|
360
|
+
writeFileSync(f.path, f.content);
|
|
340
361
|
await runEditJob(plan.args, { output: target, durationSec: plan.durationSec, inputDurationSec: info.durationSec, extra });
|
|
341
362
|
if (plan.gif) {
|
|
342
363
|
const anim = await exportAnimation(target, output, plan.gif, extra);
|
|
@@ -345,8 +366,11 @@ export function register(server) {
|
|
|
345
366
|
let subtitlesPath;
|
|
346
367
|
if (transcript) {
|
|
347
368
|
try {
|
|
348
|
-
|
|
349
|
-
|
|
369
|
+
const cues = sidecarCues(transcript.cues, plan.timeOps, transcript.opsBefore);
|
|
370
|
+
if (cues.length > 0) {
|
|
371
|
+
writeFileSync(sidecar, formatSrt(cues));
|
|
372
|
+
subtitlesPath = sidecar;
|
|
373
|
+
}
|
|
350
374
|
}
|
|
351
375
|
catch {
|
|
352
376
|
subtitlesPath = undefined;
|
package/dist/tools/readEvents.js
CHANGED
|
@@ -53,7 +53,7 @@ export function register(server) {
|
|
|
53
53
|
throw new ScreencastError(`Session "${args.sessionId}" was recorded without an event log. ` +
|
|
54
54
|
"Start the recording with events: true.");
|
|
55
55
|
}
|
|
56
|
-
if (record.status === "recording") {
|
|
56
|
+
if (record.status === "recording" || record.status === "paused") {
|
|
57
57
|
throw new ScreencastError("The recording is still running; its event log is written when it stops.");
|
|
58
58
|
}
|
|
59
59
|
path = record.events.path;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
3
|
+
import { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
|
|
4
|
+
import { requireFfmpeg } from "../utils/ffmpeg.js";
|
|
5
|
+
import { resumeSession } from "../utils/recorder.js";
|
|
6
|
+
import { logMessage } from "../utils/logging.js";
|
|
7
|
+
import { recordedSec } from "../utils/pause.js";
|
|
8
|
+
import { getStore } from "../context.js";
|
|
9
|
+
const r3 = (n) => Math.round(n * 1000) / 1000;
|
|
10
|
+
export function register(server) {
|
|
11
|
+
server.registerTool("resume_recording", {
|
|
12
|
+
title: "Resume Recording",
|
|
13
|
+
description: "Resume a paused recording (same target and settings).",
|
|
14
|
+
inputSchema: { sessionId: z.string().min(1).describe("From start_recording.") },
|
|
15
|
+
outputSchema: looseOutput({ sessionId: z.string(), status: z.string(), recordedSec: z.number() }),
|
|
16
|
+
annotations: WRITES_FILE,
|
|
17
|
+
}, async (args) => {
|
|
18
|
+
try {
|
|
19
|
+
const store = getStore();
|
|
20
|
+
const record = store.get(args.sessionId);
|
|
21
|
+
if (!record)
|
|
22
|
+
throw new ScreencastError(`No session with id "${args.sessionId}".`);
|
|
23
|
+
if (record.status === "recording") {
|
|
24
|
+
return okResponse({
|
|
25
|
+
sessionId: record.id,
|
|
26
|
+
status: "recording",
|
|
27
|
+
recordedSec: r3(recordedSec(record.segments?.parts ?? [])),
|
|
28
|
+
note: "Already recording.",
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const { ffmpeg } = requireFfmpeg();
|
|
32
|
+
const res = await resumeSession(store, record, ffmpeg);
|
|
33
|
+
logMessage("notice", `Recording ${record.id} resumed.`, { sessionId: record.id });
|
|
34
|
+
return okResponse({
|
|
35
|
+
sessionId: record.id,
|
|
36
|
+
status: "recording",
|
|
37
|
+
recordedSec: r3(res.recordedSec),
|
|
38
|
+
pid: res.record.pid,
|
|
39
|
+
...(res.capSec > 0 ? { remainingSec: res.capSec } : {}),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
return errorResponse(error);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -21,7 +21,7 @@ function resolveInput(args) {
|
|
|
21
21
|
const record = getStore().get(args.sessionId);
|
|
22
22
|
if (!record)
|
|
23
23
|
throw new ScreencastError(`No session with id "${args.sessionId}".`);
|
|
24
|
-
if (record.status === "recording")
|
|
24
|
+
if (record.status === "recording" || record.status === "paused")
|
|
25
25
|
throw new ScreencastError("The recording is still running; stop it first.");
|
|
26
26
|
return record.outputPath;
|
|
27
27
|
}
|
|
@@ -29,13 +29,19 @@ export function register(server) {
|
|
|
29
29
|
}, async (args, extra) => {
|
|
30
30
|
try {
|
|
31
31
|
const source = await resolveRecording(args);
|
|
32
|
-
const
|
|
32
|
+
const fingerprint = fingerprintFile(source.path);
|
|
33
|
+
const indexPath = findIndex(source.path, subdir("edits"), fingerprint);
|
|
33
34
|
const index = indexPath ? readIndex(indexPath) : null;
|
|
34
35
|
if (!indexPath || !index) {
|
|
35
36
|
throw new ScreencastError(`No index for ${source.path}.`, "Run index_recording on it first.");
|
|
36
37
|
}
|
|
37
|
-
const stale = !sameFingerprint(index.fingerprint,
|
|
38
|
-
const { hits, total } = searchIndex(index, args.query, {
|
|
38
|
+
const stale = !sameFingerprint(index.fingerprint, fingerprint);
|
|
39
|
+
const { hits, total } = searchIndex(index, args.query, {
|
|
40
|
+
regex: args.regex === true,
|
|
41
|
+
limit: args.limit,
|
|
42
|
+
video: source.path,
|
|
43
|
+
fingerprint,
|
|
44
|
+
});
|
|
39
45
|
const want = Math.min(clampInlineCount(args.images ?? 0), hits.length);
|
|
40
46
|
let images = [];
|
|
41
47
|
if (want > 0) {
|