@tmhs/screencast-mcp 0.2.1
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/LICENSE +34 -0
- package/README.md +212 -0
- package/dist/context.d.ts +5 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +13 -0
- package/dist/context.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/concat.d.ts +3 -0
- package/dist/tools/concat.d.ts.map +1 -0
- package/dist/tools/concat.js +42 -0
- package/dist/tools/concat.js.map +1 -0
- package/dist/tools/convert.d.ts +3 -0
- package/dist/tools/convert.d.ts.map +1 -0
- package/dist/tools/convert.js +38 -0
- package/dist/tools/convert.js.map +1 -0
- package/dist/tools/getMediaInfo.d.ts +3 -0
- package/dist/tools/getMediaInfo.d.ts.map +1 -0
- package/dist/tools/getMediaInfo.js +28 -0
- package/dist/tools/getMediaInfo.js.map +1 -0
- package/dist/tools/getSession.d.ts +3 -0
- package/dist/tools/getSession.d.ts.map +1 -0
- package/dist/tools/getSession.js +28 -0
- package/dist/tools/getSession.js.map +1 -0
- package/dist/tools/listSessions.d.ts +3 -0
- package/dist/tools/listSessions.d.ts.map +1 -0
- package/dist/tools/listSessions.js +18 -0
- package/dist/tools/listSessions.js.map +1 -0
- package/dist/tools/sampleFrames.d.ts +3 -0
- package/dist/tools/sampleFrames.d.ts.map +1 -0
- package/dist/tools/sampleFrames.js +69 -0
- package/dist/tools/sampleFrames.js.map +1 -0
- package/dist/tools/screenshot.d.ts +3 -0
- package/dist/tools/screenshot.d.ts.map +1 -0
- package/dist/tools/screenshot.js +39 -0
- package/dist/tools/screenshot.js.map +1 -0
- package/dist/tools/startRecording.d.ts +3 -0
- package/dist/tools/startRecording.d.ts.map +1 -0
- package/dist/tools/startRecording.js +107 -0
- package/dist/tools/startRecording.js.map +1 -0
- package/dist/tools/stopRecording.d.ts +3 -0
- package/dist/tools/stopRecording.d.ts.map +1 -0
- package/dist/tools/stopRecording.js +100 -0
- package/dist/tools/stopRecording.js.map +1 -0
- package/dist/tools/trim.d.ts +3 -0
- package/dist/tools/trim.d.ts.map +1 -0
- package/dist/tools/trim.js +38 -0
- package/dist/tools/trim.js.map +1 -0
- package/dist/utils/errors.d.ts +25 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +36 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/ffmpeg.d.ts +24 -0
- package/dist/utils/ffmpeg.d.ts.map +1 -0
- package/dist/utils/ffmpeg.js +88 -0
- package/dist/utils/ffmpeg.js.map +1 -0
- package/dist/utils/media.d.ts +53 -0
- package/dist/utils/media.d.ts.map +1 -0
- package/dist/utils/media.js +133 -0
- package/dist/utils/media.js.map +1 -0
- package/dist/utils/monitors.d.ts +14 -0
- package/dist/utils/monitors.d.ts.map +1 -0
- package/dist/utils/monitors.js +55 -0
- package/dist/utils/monitors.js.map +1 -0
- package/dist/utils/paths.d.ts +11 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +47 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/resolveTarget.d.ts +24 -0
- package/dist/utils/resolveTarget.d.ts.map +1 -0
- package/dist/utils/resolveTarget.js +32 -0
- package/dist/utils/resolveTarget.js.map +1 -0
- package/dist/utils/sessions.d.ts +51 -0
- package/dist/utils/sessions.d.ts.map +1 -0
- package/dist/utils/sessions.js +144 -0
- package/dist/utils/sessions.js.map +1 -0
- package/dist/utils/targets.d.ts +43 -0
- package/dist/utils/targets.d.ts.map +1 -0
- package/dist/utils/targets.js +156 -0
- package/dist/utils/targets.js.map +1 -0
- package/dist/utils/windows.d.ts +43 -0
- package/dist/utils/windows.d.ts.map +1 -0
- package/dist/utils/windows.js +127 -0
- package/dist/utils/windows.js.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { mkdirSync, readdirSync, existsSync } from "node:fs";
|
|
4
|
+
import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
5
|
+
import { requireFfmpeg, runFfmpeg } from "../utils/ffmpeg.js";
|
|
6
|
+
import { buildSampleByFpsArgs, buildSampleAtTimestampArgs, } from "../utils/media.js";
|
|
7
|
+
import { subdir, stamp, rand } from "../utils/paths.js";
|
|
8
|
+
const inputSchema = {
|
|
9
|
+
input: z.string().min(1).describe("Path to the source video file."),
|
|
10
|
+
fps: z
|
|
11
|
+
.number()
|
|
12
|
+
.positive()
|
|
13
|
+
.optional()
|
|
14
|
+
.describe("Sample this many frames per second. Mutually exclusive with timestamps."),
|
|
15
|
+
timestamps: z
|
|
16
|
+
.array(z.number().nonnegative())
|
|
17
|
+
.optional()
|
|
18
|
+
.describe("Explicit second offsets to grab one frame at each. Mutually exclusive with fps."),
|
|
19
|
+
outputDir: z
|
|
20
|
+
.string()
|
|
21
|
+
.optional()
|
|
22
|
+
.describe("Optional folder for the frames. Defaults to SCREENCAST_HOME/frames/<id>."),
|
|
23
|
+
};
|
|
24
|
+
export function register(server) {
|
|
25
|
+
server.tool("sample_frames", "Sample frames from a video so the agent can actually view what happened: " +
|
|
26
|
+
"either at a fixed rate (fps) or at explicit timestamps. Writes PNG frames " +
|
|
27
|
+
"to a folder and returns their paths.", inputSchema, async (args) => {
|
|
28
|
+
try {
|
|
29
|
+
requireFfmpeg();
|
|
30
|
+
if (!existsSync(args.input)) {
|
|
31
|
+
throw new ScreencastError(`Input file not found: ${args.input}`);
|
|
32
|
+
}
|
|
33
|
+
const hasFps = args.fps !== undefined;
|
|
34
|
+
const hasTs = args.timestamps !== undefined && args.timestamps.length > 0;
|
|
35
|
+
if (hasFps === hasTs) {
|
|
36
|
+
throw new ScreencastError("Provide exactly one of: fps (fixed rate) or timestamps (explicit offsets).");
|
|
37
|
+
}
|
|
38
|
+
const dir = args.outputDir ?? join(subdir("frames"), `sample-${stamp()}-${rand()}`);
|
|
39
|
+
mkdirSync(dir, { recursive: true });
|
|
40
|
+
let frames = [];
|
|
41
|
+
if (hasFps) {
|
|
42
|
+
const pattern = join(dir, "frame_%05d.png");
|
|
43
|
+
await runFfmpeg(buildSampleByFpsArgs(args.input, args.fps, pattern), 5 * 60_000);
|
|
44
|
+
frames = readdirSync(dir)
|
|
45
|
+
.filter((f) => f.endsWith(".png"))
|
|
46
|
+
.sort()
|
|
47
|
+
.map((f) => join(dir, f));
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const ts = args.timestamps;
|
|
51
|
+
for (let i = 0; i < ts.length; i++) {
|
|
52
|
+
const out = join(dir, `frame_${String(i).padStart(3, "0")}_${ts[i]}s.png`);
|
|
53
|
+
await runFfmpeg(buildSampleAtTimestampArgs(args.input, ts[i], out), 60_000);
|
|
54
|
+
frames.push(out);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return okResponse({
|
|
58
|
+
frameDir: dir,
|
|
59
|
+
frameCount: frames.length,
|
|
60
|
+
frames,
|
|
61
|
+
mode: hasFps ? `fps=${args.fps}` : `timestamps=[${args.timestamps.join(", ")}]`,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
return errorResponse(error);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=sampleFrames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sampleFrames.js","sourceRoot":"","sources":["../../src/tools/sampleFrames.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE7D,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EA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CAAC,0BAA0B,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;oBAC5E,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACnB,CAAC;YACH,CAAC;YAED,OAAO,UAAU,CAAC;gBAChB,QAAQ,EAAE,GAAG;gBACb,UAAU,EAAE,MAAM,CAAC,MAAM;gBACzB,MAAM;gBACN,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,eAAe,IAAI,CAAC,UAAW,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;aACjF,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screenshot.d.ts","sourceRoot":"","sources":["../../src/tools/screenshot.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAyBzE,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA0BhD"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { errorResponse, okResponse } from "../utils/errors.js";
|
|
3
|
+
import { requireFfmpeg, runFfmpeg } from "../utils/ffmpeg.js";
|
|
4
|
+
import { buildScreenshotArgs } from "../utils/targets.js";
|
|
5
|
+
import { resolveCaptureTarget } from "../utils/resolveTarget.js";
|
|
6
|
+
import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
|
|
7
|
+
const inputSchema = {
|
|
8
|
+
target: z
|
|
9
|
+
.string()
|
|
10
|
+
.describe("Capture target: 'full' | 'monitor:<index>' | 'window:<title>' | " +
|
|
11
|
+
"'region:<x>,<y>,<w>,<h>'. window: captures the on-screen rectangle the " +
|
|
12
|
+
"window occupies as currently displayed - it must be visible, on top, " +
|
|
13
|
+
"and not minimized (case-insensitive exact title, else substring; " +
|
|
14
|
+
"topmost match wins)."),
|
|
15
|
+
output: z
|
|
16
|
+
.string()
|
|
17
|
+
.optional()
|
|
18
|
+
.describe("Optional output .png path. Defaults to a file under SCREENCAST_HOME/screenshots."),
|
|
19
|
+
};
|
|
20
|
+
export function register(server) {
|
|
21
|
+
server.tool("screenshot", "Capture a single still frame (PNG) of a target (full screen, a monitor, a " +
|
|
22
|
+
"window by title, or a region). Returns the image path.", inputSchema, async (args) => {
|
|
23
|
+
try {
|
|
24
|
+
requireFfmpeg();
|
|
25
|
+
const { target, monitors, window } = resolveCaptureTarget(args.target);
|
|
26
|
+
const output = resolveOutput(args.output, subdir("screenshots"), `shot-${stamp()}-${rand()}.png`);
|
|
27
|
+
await runFfmpeg(buildScreenshotArgs(target, output, monitors), 60_000);
|
|
28
|
+
return okResponse({
|
|
29
|
+
outputPath: output,
|
|
30
|
+
target: args.target,
|
|
31
|
+
...(window ? { matchedWindow: window.matchedTitle, region: window } : {}),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
return errorResponse(error);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=screenshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screenshot.js","sourceRoot":"","sources":["../../src/tools/screenshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,oBAA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AC,CAAC;QAC9B,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"startRecording.d.ts","sourceRoot":"","sources":["../../src/tools/startRecording.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AA2CzE,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAwFhD"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
4
|
+
import { requireFfmpeg } from "../utils/ffmpeg.js";
|
|
5
|
+
import { buildCaptureArgs, DEFAULT_FPS, DEFAULT_QUALITY, } from "../utils/targets.js";
|
|
6
|
+
import { resolveCaptureTarget } from "../utils/resolveTarget.js";
|
|
7
|
+
import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
|
|
8
|
+
import { getStore } from "../context.js";
|
|
9
|
+
const inputSchema = {
|
|
10
|
+
target: z
|
|
11
|
+
.string()
|
|
12
|
+
.describe("Capture target: 'full' | 'monitor:<index>' (0 = primary) | " +
|
|
13
|
+
"'window:<title>' | 'region:<x>,<y>,<w>,<h>' (absolute pixels). " +
|
|
14
|
+
"window: records the on-screen rectangle the window occupies, resolved " +
|
|
15
|
+
"ONCE at start (it must be visible, on top, not minimized); it does not " +
|
|
16
|
+
"follow a window moved or resized mid-recording."),
|
|
17
|
+
fps: z
|
|
18
|
+
.number()
|
|
19
|
+
.int()
|
|
20
|
+
.min(1)
|
|
21
|
+
.max(120)
|
|
22
|
+
.optional()
|
|
23
|
+
.describe(`Frames per second (default ${DEFAULT_FPS}).`),
|
|
24
|
+
quality: z
|
|
25
|
+
.enum(["draft", "standard", "high"])
|
|
26
|
+
.optional()
|
|
27
|
+
.describe(`Encoder preset (default ${DEFAULT_QUALITY}).`),
|
|
28
|
+
output: z
|
|
29
|
+
.string()
|
|
30
|
+
.optional()
|
|
31
|
+
.describe("Optional output .mp4 path. Defaults to a file under SCREENCAST_HOME/recordings."),
|
|
32
|
+
};
|
|
33
|
+
export function register(server) {
|
|
34
|
+
server.tool("start_recording", "Start a screen recording (Windows gdigrab) as a background ffmpeg process. " +
|
|
35
|
+
"Returns a session id and output path. Recording is explicit and never " +
|
|
36
|
+
"auto-starts. Use stop_recording with the id to finalize the file. " +
|
|
37
|
+
"Audio is not captured in Phase 1 (video only).", inputSchema, async (args) => {
|
|
38
|
+
try {
|
|
39
|
+
const { ffmpeg } = requireFfmpeg();
|
|
40
|
+
const { target, monitors } = resolveCaptureTarget(args.target);
|
|
41
|
+
const fps = args.fps ?? DEFAULT_FPS;
|
|
42
|
+
const quality = args.quality ?? DEFAULT_QUALITY;
|
|
43
|
+
const output = resolveOutput(args.output, subdir("recordings"), `rec-${stamp()}-${rand()}.mp4`);
|
|
44
|
+
const ffArgs = buildCaptureArgs(target, { fps, quality, output, monitors });
|
|
45
|
+
const child = spawn(ffmpeg, ffArgs, {
|
|
46
|
+
stdio: ["pipe", "ignore", "pipe"],
|
|
47
|
+
windowsHide: true,
|
|
48
|
+
});
|
|
49
|
+
// Detect an immediate failure (bad window title, busy device, etc.).
|
|
50
|
+
let stderrTail = "";
|
|
51
|
+
child.stderr?.on("data", (d) => {
|
|
52
|
+
stderrTail = (stderrTail + d.toString()).slice(-2000);
|
|
53
|
+
});
|
|
54
|
+
const settled = await new Promise((resolve) => {
|
|
55
|
+
const timer = setTimeout(() => resolve("running"), 1200);
|
|
56
|
+
child.on("error", (err) => {
|
|
57
|
+
clearTimeout(timer);
|
|
58
|
+
stderrTail += `\n${err.message}`;
|
|
59
|
+
resolve("exited");
|
|
60
|
+
});
|
|
61
|
+
child.on("exit", () => {
|
|
62
|
+
clearTimeout(timer);
|
|
63
|
+
resolve("exited");
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
const id = `rec-${stamp()}-${rand(6)}`;
|
|
67
|
+
if (settled === "exited") {
|
|
68
|
+
const tail = stderrTail.trim().split("\n").slice(-6).join("\n");
|
|
69
|
+
throw new ScreencastError(`Recording failed to start (ffmpeg exited immediately):\n${tail}`);
|
|
70
|
+
}
|
|
71
|
+
const record = {
|
|
72
|
+
id,
|
|
73
|
+
target: args.target,
|
|
74
|
+
outputPath: output,
|
|
75
|
+
fps,
|
|
76
|
+
quality,
|
|
77
|
+
pid: child.pid ?? null,
|
|
78
|
+
status: "recording",
|
|
79
|
+
startedAt: new Date().toISOString(),
|
|
80
|
+
};
|
|
81
|
+
const store = getStore();
|
|
82
|
+
store.create(record);
|
|
83
|
+
store.attachChild(id, child);
|
|
84
|
+
// Keep the on-disk record consistent if the child dies on its own.
|
|
85
|
+
child.on("exit", () => {
|
|
86
|
+
const cur = store.get(id);
|
|
87
|
+
if (cur && cur.status === "recording") {
|
|
88
|
+
store.update(id, { status: "stopped", stoppedAt: new Date().toISOString() });
|
|
89
|
+
}
|
|
90
|
+
store.detachChild(id);
|
|
91
|
+
});
|
|
92
|
+
return okResponse({
|
|
93
|
+
sessionId: id,
|
|
94
|
+
status: "recording",
|
|
95
|
+
outputPath: output,
|
|
96
|
+
pid: record.pid,
|
|
97
|
+
fps,
|
|
98
|
+
quality,
|
|
99
|
+
note: "Call stop_recording with this sessionId to finalize the file.",
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
return errorResponse(error);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=startRecording.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"startRecording.js","sourceRoot":"","sources":["../../src/tools/startRecording.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,aAAa,EA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M,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;gBAC/E,CAAC;gBACD,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;YACxB,CAAC,CAAC,CAAC;YAEH,OAAO,UAAU,CAAC;gBAChB,SAAS,EAAE,EAAE;gBACb,MAAM,EAAE,WAAW;gBACnB,UAAU,EAAE,MAAM;gBAClB,GAAG,EAAE,MAAM,CAAC,GAAG;gBACf,GAAG;gBACH,OAAO;gBACP,IAAI,EAAE,+DAA+D;aACtE,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stopRecording.d.ts","sourceRoot":"","sources":["../../src/tools/stopRecording.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAkCzE,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAqEhD"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
4
|
+
import { requireFfmpeg, runCapture } from "../utils/ffmpeg.js";
|
|
5
|
+
import { buildProbeArgs, parseMediaInfo } from "../utils/media.js";
|
|
6
|
+
import { isAlive, isFfmpegProcess, killPid } from "../utils/sessions.js";
|
|
7
|
+
import { getStore } from "../context.js";
|
|
8
|
+
const inputSchema = {
|
|
9
|
+
sessionId: z.string().min(1).describe("Session id returned by start_recording."),
|
|
10
|
+
};
|
|
11
|
+
/** Wait up to ms for a child to exit; resolve true if it did. */
|
|
12
|
+
function waitForExit(child, ms) {
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
15
|
+
return resolve(true);
|
|
16
|
+
const timer = setTimeout(() => resolve(false), ms);
|
|
17
|
+
child.once("exit", () => {
|
|
18
|
+
clearTimeout(timer);
|
|
19
|
+
resolve(true);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
async function probeDuration(ffprobe, path) {
|
|
24
|
+
if (!existsSync(path))
|
|
25
|
+
return null;
|
|
26
|
+
try {
|
|
27
|
+
const res = await runCapture(ffprobe, buildProbeArgs(path), 30_000);
|
|
28
|
+
if (res.code !== 0)
|
|
29
|
+
return null;
|
|
30
|
+
return parseMediaInfo(JSON.parse(res.stdout)).durationSec;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function register(server) {
|
|
37
|
+
server.tool("stop_recording", "Stop a recording by session id. Sends ffmpeg a graceful quit so the file " +
|
|
38
|
+
"is finalized rather than truncated, then returns the final path and " +
|
|
39
|
+
"duration. Falls back to terminating the process by pid if the live " +
|
|
40
|
+
"handle was lost (for example after a server restart).", inputSchema, async (args) => {
|
|
41
|
+
try {
|
|
42
|
+
const store = getStore();
|
|
43
|
+
const record = store.get(args.sessionId);
|
|
44
|
+
if (!record) {
|
|
45
|
+
throw new ScreencastError(`No session with id "${args.sessionId}".`);
|
|
46
|
+
}
|
|
47
|
+
if (record.status !== "recording") {
|
|
48
|
+
return okResponse({
|
|
49
|
+
sessionId: record.id,
|
|
50
|
+
status: record.status,
|
|
51
|
+
outputPath: record.outputPath,
|
|
52
|
+
durationSec: record.durationSec ?? null,
|
|
53
|
+
note: "Session was not active; returning its recorded final state.",
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const { ffprobe } = requireFfmpeg();
|
|
57
|
+
let graceful = false;
|
|
58
|
+
const child = store.getChild(record.id);
|
|
59
|
+
if (child && child.stdin && child.stdin.writable) {
|
|
60
|
+
// ffmpeg quits cleanly (and writes the moov atom) on 'q'.
|
|
61
|
+
child.stdin.write("q\n");
|
|
62
|
+
child.stdin.end();
|
|
63
|
+
graceful = await waitForExit(child, 8000);
|
|
64
|
+
if (!graceful && record.pid !== null)
|
|
65
|
+
killPid(record.pid);
|
|
66
|
+
}
|
|
67
|
+
else if (record.pid !== null && isAlive(record.pid)) {
|
|
68
|
+
// Cross-restart stop: no stdin handle. Terminate by pid. The
|
|
69
|
+
// fragmented-mp4 muxing keeps the partial file playable.
|
|
70
|
+
if (isFfmpegProcess(record.pid))
|
|
71
|
+
killPid(record.pid);
|
|
72
|
+
}
|
|
73
|
+
store.detachChild(record.id);
|
|
74
|
+
// Give the muxer a moment to flush the trailer.
|
|
75
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
76
|
+
const durationSec = await probeDuration(ffprobe, record.outputPath);
|
|
77
|
+
const updated = store.update(record.id, {
|
|
78
|
+
status: "stopped",
|
|
79
|
+
stoppedAt: new Date().toISOString(),
|
|
80
|
+
durationSec: durationSec ?? undefined,
|
|
81
|
+
});
|
|
82
|
+
return okResponse({
|
|
83
|
+
sessionId: record.id,
|
|
84
|
+
status: "stopped",
|
|
85
|
+
outputPath: record.outputPath,
|
|
86
|
+
durationSec: durationSec ?? null,
|
|
87
|
+
finalizedGracefully: graceful,
|
|
88
|
+
fileExists: existsSync(record.outputPath),
|
|
89
|
+
note: graceful
|
|
90
|
+
? "ffmpeg quit cleanly; file finalized."
|
|
91
|
+
: "Process terminated by pid; fragmented mp4 keeps the file playable.",
|
|
92
|
+
record: updated,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
return errorResponse(error);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=stopRecording.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stopRecording.js","source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AC,EAAE;gBACpB,MAAM,EAAE,SAAS;gBACjB,UAAU,EAAE,MAAM,CAAC,UAAU;gBAC7B,WAAW,EAAE,WAAW,IAAI,IAAI;gBAChC,mBAAmB,EAAE,QAAQ;gBAC7B,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC;gBACzC,IAAI,EAAE,QAAQ;oBACZ,CAAC,CAAC,sCAAsC;oBACxC,CAAC,CAAC,oEAAoE;gBACxE,MAAM,EAAE,OAAO;aAChB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trim.d.ts","sourceRoot":"","sources":["../../src/tools/trim.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAczE,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA8BhD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { extname } from "node:path";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
5
|
+
import { requireFfmpeg, runFfmpeg } from "../utils/ffmpeg.js";
|
|
6
|
+
import { buildTrimArgs } from "../utils/media.js";
|
|
7
|
+
import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
|
|
8
|
+
const inputSchema = {
|
|
9
|
+
input: z.string().min(1).describe("Path to the source video."),
|
|
10
|
+
start: z.number().nonnegative().describe("Start time in seconds."),
|
|
11
|
+
end: z.number().positive().optional().describe("End time in seconds. Use end OR duration."),
|
|
12
|
+
duration: z.number().positive().optional().describe("Clip length in seconds. Use end OR duration."),
|
|
13
|
+
output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
|
|
14
|
+
};
|
|
15
|
+
export function register(server) {
|
|
16
|
+
server.tool("trim", "Trim a video to a sub-clip by start + (end or duration). Uses stream copy " +
|
|
17
|
+
"for speed; cut points snap to the nearest keyframe.", inputSchema, async (args) => {
|
|
18
|
+
try {
|
|
19
|
+
requireFfmpeg();
|
|
20
|
+
if (!existsSync(args.input)) {
|
|
21
|
+
throw new ScreencastError(`Input file not found: ${args.input}`);
|
|
22
|
+
}
|
|
23
|
+
const ext = extname(args.input) || ".mp4";
|
|
24
|
+
const output = resolveOutput(args.output, subdir("edits"), `trim-${stamp()}-${rand()}${ext}`);
|
|
25
|
+
const ffArgs = buildTrimArgs(args.input, output, {
|
|
26
|
+
start: args.start,
|
|
27
|
+
end: args.end,
|
|
28
|
+
duration: args.duration,
|
|
29
|
+
});
|
|
30
|
+
await runFfmpeg(ffArgs, 5 * 60_000);
|
|
31
|
+
return okResponse({ outputPath: output });
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
return errorResponse(error);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=trim.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trim.js","sourceRoot":"","sources":["../../src/tools/trim.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBA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,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,GAAG,EAAE,IAAI,CAAC,GAAG;gBACb,QAAQ,EAAE,IAAI,CAAC,QAAQ;aACxB,CAAC,CAAC;YACH,MAAM,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC;YACpC,OAAO,UAAU,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;QAC5C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared error type and MCP response helpers.
|
|
3
|
+
*
|
|
4
|
+
* Every tool returns the same content shape: a single text block. Errors are
|
|
5
|
+
* surfaced as `isError: true` so an agent sees an actionable message instead of
|
|
6
|
+
* a transport-level failure.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ScreencastError extends Error {
|
|
9
|
+
/** Optional remediation hint shown to the caller (e.g. an install command). */
|
|
10
|
+
readonly hint?: string;
|
|
11
|
+
constructor(message: string, hint?: string);
|
|
12
|
+
}
|
|
13
|
+
export interface ToolResult {
|
|
14
|
+
content: Array<{
|
|
15
|
+
type: "text";
|
|
16
|
+
text: string;
|
|
17
|
+
}>;
|
|
18
|
+
isError?: true;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
/** Wrap a JSON-serializable value as a successful tool result. */
|
|
22
|
+
export declare function okResponse(value: unknown): ToolResult;
|
|
23
|
+
/** Wrap any thrown value as an error tool result, appending a hint if present. */
|
|
24
|
+
export declare function errorResponse(error: unknown): ToolResult;
|
|
25
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,+EAA+E;IAC/E,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;gBAEX,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;CAK3C;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,OAAO,CAAC,EAAE,IAAI,CAAC;IAGf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,kEAAkE;AAClE,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAIrD;AAED,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAUxD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared error type and MCP response helpers.
|
|
3
|
+
*
|
|
4
|
+
* Every tool returns the same content shape: a single text block. Errors are
|
|
5
|
+
* surfaced as `isError: true` so an agent sees an actionable message instead of
|
|
6
|
+
* a transport-level failure.
|
|
7
|
+
*/
|
|
8
|
+
export class ScreencastError extends Error {
|
|
9
|
+
/** Optional remediation hint shown to the caller (e.g. an install command). */
|
|
10
|
+
hint;
|
|
11
|
+
constructor(message, hint) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "ScreencastError";
|
|
14
|
+
this.hint = hint;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Wrap a JSON-serializable value as a successful tool result. */
|
|
18
|
+
export function okResponse(value) {
|
|
19
|
+
const text = typeof value === "string" ? value : JSON.stringify(value, null, 2);
|
|
20
|
+
return { content: [{ type: "text", text }] };
|
|
21
|
+
}
|
|
22
|
+
/** Wrap any thrown value as an error tool result, appending a hint if present. */
|
|
23
|
+
export function errorResponse(error) {
|
|
24
|
+
let message;
|
|
25
|
+
if (error instanceof ScreencastError) {
|
|
26
|
+
message = error.hint ? `${error.message}\n\n${error.hint}` : error.message;
|
|
27
|
+
}
|
|
28
|
+
else if (error instanceof Error) {
|
|
29
|
+
message = error.message;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
message = String(error);
|
|
33
|
+
}
|
|
34
|
+
return { content: [{ type: "text", text: message }], isError: true };
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,+EAA+E;IACtE,IAAI,CAAU;IAEvB,YAAY,OAAe,EAAE,IAAa;QACxC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAUD,kEAAkE;AAClE,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,MAAM,IAAI,GACR,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACrE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;AAC/C,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IAAI,OAAe,CAAC;IACpB,IAAI,KAAK,YAAY,eAAe,EAAE,CAAC;QACrC,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;IAC7E,CAAC;SAAM,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAClC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;IAC1B,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface FfmpegTools {
|
|
2
|
+
ffmpeg: string;
|
|
3
|
+
ffprobe: string;
|
|
4
|
+
}
|
|
5
|
+
/** Return true if `bin -version` runs and exits 0. */
|
|
6
|
+
export declare function binaryWorks(bin: string): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Detect ffmpeg + ffprobe. Returns the resolved binary names/paths, or throws a
|
|
9
|
+
* ScreencastError with an install hint naming whichever binary is missing.
|
|
10
|
+
*/
|
|
11
|
+
export declare function detectFfmpeg(): FfmpegTools;
|
|
12
|
+
/** Cached variant for per-call guards. Re-detects only after a failure. */
|
|
13
|
+
export declare function requireFfmpeg(): FfmpegTools;
|
|
14
|
+
export interface RunResult {
|
|
15
|
+
code: number | null;
|
|
16
|
+
stdout: string;
|
|
17
|
+
stderr: string;
|
|
18
|
+
}
|
|
19
|
+
/** Run a binary to completion, capturing stdout/stderr. Used for ffprobe and
|
|
20
|
+
* short ffmpeg edit jobs (not for long-running captures). */
|
|
21
|
+
export declare function runCapture(bin: string, args: string[], timeoutMs?: number): Promise<RunResult>;
|
|
22
|
+
/** Run an ffmpeg edit job and reject with the tail of stderr on non-zero exit. */
|
|
23
|
+
export declare function runFfmpeg(args: string[], timeoutMs?: number): Promise<void>;
|
|
24
|
+
//# sourceMappingURL=ffmpeg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ffmpeg.d.ts","sourceRoot":"","sources":["../../src/utils/ffmpeg.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAOD,sDAAsD;AACtD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAUhD;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,WAAW,CAa1C;AAID,2EAA2E;AAC3E,wBAAgB,aAAa,IAAI,WAAW,CAI3C;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;6DAC6D;AAC7D,wBAAgB,UAAU,CACxB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EAAE,EACd,SAAS,SAAgB,GACxB,OAAO,CAAC,SAAS,CAAC,CAwBpB;AAED,kFAAkF;AAClF,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,EAAE,EACd,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAOf"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ffmpeg / ffprobe discovery and invocation.
|
|
3
|
+
*
|
|
4
|
+
* ffmpeg and ffprobe are EXTERNAL dependencies. They are detected on PATH (or
|
|
5
|
+
* via the FFMPEG_PATH / FFPROBE_PATH env overrides) and a missing binary
|
|
6
|
+
* produces a clear ScreencastError with an install hint, rather than a cryptic
|
|
7
|
+
* spawn failure deep inside a tool call.
|
|
8
|
+
*/
|
|
9
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
10
|
+
import { ScreencastError } from "./errors.js";
|
|
11
|
+
const INSTALL_HINT = "ffmpeg and ffprobe must be installed and on PATH (or set FFMPEG_PATH / " +
|
|
12
|
+
"FFPROBE_PATH). Windows: `winget install Gyan.FFmpeg` or `choco install " +
|
|
13
|
+
"ffmpeg`. macOS: `brew install ffmpeg`. Linux: `apt install ffmpeg`.";
|
|
14
|
+
function resolveBinary(envVar, fallback) {
|
|
15
|
+
const override = process.env[envVar];
|
|
16
|
+
return override && override.trim().length > 0 ? override : fallback;
|
|
17
|
+
}
|
|
18
|
+
/** Return true if `bin -version` runs and exits 0. */
|
|
19
|
+
export function binaryWorks(bin) {
|
|
20
|
+
try {
|
|
21
|
+
const res = spawnSync(bin, ["-version"], {
|
|
22
|
+
stdio: "ignore",
|
|
23
|
+
windowsHide: true,
|
|
24
|
+
});
|
|
25
|
+
return res.status === 0;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Detect ffmpeg + ffprobe. Returns the resolved binary names/paths, or throws a
|
|
33
|
+
* ScreencastError with an install hint naming whichever binary is missing.
|
|
34
|
+
*/
|
|
35
|
+
export function detectFfmpeg() {
|
|
36
|
+
const ffmpeg = resolveBinary("FFMPEG_PATH", "ffmpeg");
|
|
37
|
+
const ffprobe = resolveBinary("FFPROBE_PATH", "ffprobe");
|
|
38
|
+
const missing = [];
|
|
39
|
+
if (!binaryWorks(ffmpeg))
|
|
40
|
+
missing.push("ffmpeg");
|
|
41
|
+
if (!binaryWorks(ffprobe))
|
|
42
|
+
missing.push("ffprobe");
|
|
43
|
+
if (missing.length > 0) {
|
|
44
|
+
throw new ScreencastError(`Required ${missing.join(" and ")} not found on PATH.`, INSTALL_HINT);
|
|
45
|
+
}
|
|
46
|
+
return { ffmpeg, ffprobe };
|
|
47
|
+
}
|
|
48
|
+
let cached = null;
|
|
49
|
+
/** Cached variant for per-call guards. Re-detects only after a failure. */
|
|
50
|
+
export function requireFfmpeg() {
|
|
51
|
+
if (cached)
|
|
52
|
+
return cached;
|
|
53
|
+
cached = detectFfmpeg();
|
|
54
|
+
return cached;
|
|
55
|
+
}
|
|
56
|
+
/** Run a binary to completion, capturing stdout/stderr. Used for ffprobe and
|
|
57
|
+
* short ffmpeg edit jobs (not for long-running captures). */
|
|
58
|
+
export function runCapture(bin, args, timeoutMs = 5 * 60 * 1000) {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
const child = spawn(bin, args, { windowsHide: true });
|
|
61
|
+
let stdout = "";
|
|
62
|
+
let stderr = "";
|
|
63
|
+
const timer = setTimeout(() => {
|
|
64
|
+
child.kill("SIGKILL");
|
|
65
|
+
reject(new ScreencastError(`${bin} timed out after ${Math.round(timeoutMs / 1000)}s.`));
|
|
66
|
+
}, timeoutMs);
|
|
67
|
+
child.stdout?.on("data", (d) => (stdout += d.toString()));
|
|
68
|
+
child.stderr?.on("data", (d) => (stderr += d.toString()));
|
|
69
|
+
child.on("error", (err) => {
|
|
70
|
+
clearTimeout(timer);
|
|
71
|
+
reject(err);
|
|
72
|
+
});
|
|
73
|
+
child.on("close", (code) => {
|
|
74
|
+
clearTimeout(timer);
|
|
75
|
+
resolve({ code, stdout, stderr });
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/** Run an ffmpeg edit job and reject with the tail of stderr on non-zero exit. */
|
|
80
|
+
export async function runFfmpeg(args, timeoutMs) {
|
|
81
|
+
const { ffmpeg } = requireFfmpeg();
|
|
82
|
+
const res = await runCapture(ffmpeg, args, timeoutMs);
|
|
83
|
+
if (res.code !== 0) {
|
|
84
|
+
const tail = res.stderr.trim().split("\n").slice(-6).join("\n");
|
|
85
|
+
throw new ScreencastError(`ffmpeg failed (exit ${res.code}):\n${tail}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=ffmpeg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ffmpeg.js","sourceRoot":"","sources":["../../src/utils/ffmpeg.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACt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