Skip to content

Commit f550c2b

Browse files
committed
feat(mcp): export with the Export dialog's options, record the webcam and the system cursor
exportVideo takes fps (24, 30, 60), gifFrameRate, gifSize and gifLoop, with the dialog's defaults; an option of the other format is refused. The CLI contract and runner gain the MP4 frame rate and the GIF loop, and a GIF is sized from the source size as in the dialog. startRecording takes camera and cursor on both servers: the record runner turns the webcam on, listSources lists the cameras, and the in-app recorder maps them onto the recording bar's prefs. The CLI gains --fps, --gif-loop, --camera and --camera-device. Part of #1180
1 parent e896d77 commit f550c2b

16 files changed

Lines changed: 580 additions & 109 deletions

‎electron/cli/args.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,22 @@ describe("parseCliArgs", () => {
108108
windowTitle: null,
109109
mic: false,
110110
systemAudio: false,
111+
camera: false,
112+
cameraDevice: null,
111113
cursorMode: "editable-overlay",
112114
durationMs: null,
113115
});
114116
});
115117

118+
it("parses the camera: --camera for the default one, --camera-device for one by name", () => {
119+
expect(parse(["record", "--camera"])).toMatchObject({ camera: true, cameraDevice: null });
120+
expect(parse(["record", "--camera-device", "BRIO"])).toMatchObject({
121+
camera: true,
122+
cameraDevice: "BRIO",
123+
});
124+
expect(parse(["record", "--camera-device"])).toMatchObject({ kind: "error" });
125+
});
126+
116127
it("parses record options", () => {
117128
const cmd = parse([
118129
"record",
@@ -143,6 +154,20 @@ describe("parseCliArgs", () => {
143154
expect(parse(["record", "--project", "demo.json"])).toMatchObject({ kind: "error" });
144155
});
145156

157+
it("parses the Export dialog's frame rates, GIF sizes and GIF loop", () => {
158+
expect(parse(["export", "a.openscreen"])).toMatchObject({ mp4FrameRate: 60, gifLoop: null });
159+
expect(parse(["export", "a.openscreen", "--fps", "24"])).toMatchObject({ mp4FrameRate: 24 });
160+
expect(parse(["export", "a.openscreen", "--fps", "25"])).toMatchObject({ kind: "error" });
161+
expect(parse(["export", "a.openscreen", "--gif-size", "small"])).toMatchObject({
162+
gifSizePreset: "small",
163+
});
164+
expect(parse(["export", "a.openscreen", "--gif-size", "toString"])).toMatchObject({
165+
kind: "error",
166+
});
167+
expect(parse(["export", "a.openscreen", "--no-gif-loop"])).toMatchObject({ gifLoop: false });
168+
expect(parse(["export", "a.openscreen", "--gif-loop"])).toMatchObject({ gifLoop: true });
169+
});
170+
146171
it("parses --auto-zoom", () => {
147172
expect(parse(["export", "a.openscreen", "--auto-zoom"])).toMatchObject({
148173
kind: "export",

‎electron/cli/args.ts‎

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import {
77
CAPTION_WORDS_PER_LINE_MIN,
88
} from "../../src/lib/ai-edition/captions/wordsPerLine";
99
import type { CliExportRequest, CliRecordRequest, CliRequest } from "../../src/lib/cliContracts";
10+
import {
11+
GIF_SIZE_PRESETS,
12+
type GifSizePreset,
13+
MP4_FRAME_RATES,
14+
} from "../../src/lib/exporter/types";
1015

1116
export interface CliInfoCommand {
1217
kind: "info";
@@ -77,7 +82,7 @@ export const CLI_USAGE = `OpenScreen CLI
7782
Usage:
7883
openscreen export <project.openscreen> [options] Render a project to MP4/GIF
7984
openscreen record [options] Record the screen headlessly
80-
openscreen sources [--json] [-o <file>] List displays, windows and microphones
85+
openscreen sources [--json] [-o <file>] List displays, windows, microphones and cameras
8186
openscreen pack <project.openscreen> --out <dir> Copy project + media into one portable folder
8287
openscreen captions <project.openscreen> Add auto-captions (on-device Whisper) to a project
8388
[--min-words <1-12>] [--max-words <1-12>]
@@ -90,9 +95,11 @@ Export options:
9095
--format <mp4|gif> Override the format stored in the project
9196
--quality <medium|good|source>
9297
MP4 quality (default: from project)
98+
--fps <24|30|60> MP4 frame rate (default 60)
9399
--gif-fps <15|20|25|30> GIF frame rate (default: from project)
94-
--gif-size <medium|large|original>
100+
--gif-size <small|medium|large|original>
95101
GIF size preset (default: from project)
102+
--gif-loop, --no-gif-loop GIF loops forever, or plays once (default: from project)
96103
--auto-zoom Add automatic zooms from cursor telemetry (editor's magic wand)
97104
--audio <file> Mix a voiceover audio file into the MP4 (mp3/wav/m4a)
98105
--audio-mode <mix|replace>
@@ -106,6 +113,8 @@ Record options (recording is saved into the app's recordings directory):
106113
--mic Capture the default microphone
107114
--mic-device <name> Microphone device name (implies --mic)
108115
--system-audio Capture system audio
116+
--camera Record the default webcam beside the screen
117+
--camera-device <name> Camera device name (implies --camera)
109118
--cursor <editable-overlay|system>
110119
Cursor capture mode (default editable-overlay)
111120
--duration <seconds> Stop automatically after this long
@@ -190,8 +199,10 @@ function parseExport(args: string[], cwd: string): CliCommand {
190199
outPath: null,
191200
format: null,
192201
quality: null,
202+
mp4FrameRate: 60,
193203
gifFrameRate: null,
194204
gifSizePreset: null,
205+
gifLoop: null,
195206
autoZoom: false,
196207
audioPath: null,
197208
audioMode: "mix",
@@ -226,6 +237,16 @@ function parseExport(args: string[], cwd: string): CliCommand {
226237
i = next;
227238
break;
228239
}
240+
case "--fps": {
241+
const [value, next] = takeValue(args, i, arg);
242+
const fps = MP4_FRAME_RATES.find((rate) => rate === Number(value));
243+
if (fps === undefined) {
244+
throw new Error(`--fps must be ${MP4_FRAME_RATES.join(", ")}, got "${value}"`);
245+
}
246+
request.mp4FrameRate = fps;
247+
i = next;
248+
break;
249+
}
229250
case "--gif-fps": {
230251
const [value, next] = takeValue(args, i, arg);
231252
const fps = Number(value);
@@ -238,13 +259,18 @@ function parseExport(args: string[], cwd: string): CliCommand {
238259
}
239260
case "--gif-size": {
240261
const [value, next] = takeValue(args, i, arg);
241-
if (value !== "medium" && value !== "large" && value !== "original") {
242-
throw new Error(`--gif-size must be medium, large or original, got "${value}"`);
262+
const size = (Object.keys(GIF_SIZE_PRESETS) as GifSizePreset[]).find((s) => s === value);
263+
if (size === undefined) {
264+
throw new Error(`--gif-size must be small, medium, large or original, got "${value}"`);
243265
}
244-
request.gifSizePreset = value;
266+
request.gifSizePreset = size;
245267
i = next;
246268
break;
247269
}
270+
case "--gif-loop":
271+
case "--no-gif-loop":
272+
request.gifLoop = arg === "--gif-loop";
273+
break;
248274
case "--auto-zoom":
249275
request.autoZoom = true;
250276
break;
@@ -312,6 +338,8 @@ function parseRecord(args: string[], cwd: string): CliCommand {
312338
mic: false,
313339
micDevice: null,
314340
systemAudio: false,
341+
camera: false,
342+
cameraDevice: null,
315343
cursorMode: "editable-overlay",
316344
durationMs: null,
317345
projectOut: null,
@@ -349,6 +377,16 @@ function parseRecord(args: string[], cwd: string): CliCommand {
349377
case "--system-audio":
350378
request.systemAudio = true;
351379
break;
380+
case "--camera":
381+
request.camera = true;
382+
break;
383+
case "--camera-device": {
384+
const [value, next] = takeValue(args, i, arg);
385+
request.camera = true;
386+
request.cameraDevice = value;
387+
i = next;
388+
break;
389+
}
352390
case "--cursor": {
353391
const [value, next] = takeValue(args, i, arg);
354392
if (value !== "editable-overlay" && value !== "system") {

‎electron/cli/cliMain.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@ function printSources(output: CliOutput, sources: CliSourcesResult): void {
167167
for (const mic of sources.microphones) {
168168
lines.push(` - ${mic.label}`);
169169
}
170+
lines.push("Cameras:");
171+
if (sources.cameraLabelsUnavailable) {
172+
lines.push(" (labels unavailable — grant camera permission to see device names)");
173+
} else if (sources.cameras.length === 0) {
174+
lines.push(" (none)");
175+
}
176+
for (const camera of sources.cameras) {
177+
lines.push(` - ${camera.label}`);
178+
}
170179
output.info(lines.join("\n"));
171180
}
172181

‎electron/ipc/handlers.ts‎

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
isAxcutDocumentFile,
2525
parseDocumentFile,
2626
} from "../../src/lib/ai-edition/schema";
27+
import type { CliSourcesResult } from "../../src/lib/cliContracts";
2728
import { pickRecordingSource } from "../../src/lib/cliSourcePick";
2829
import {
2930
type NativeLinuxRecordingRequest,
@@ -79,7 +80,7 @@ import {
7980
RECORDINGS_DIR,
8081
setRecordingsDir,
8182
} from "../main";
82-
import { createAppRecorder } from "../mcp/app-recorder";
83+
import { createAppRecorder, pickTakePrefs, takePrefs } from "../mcp/app-recorder";
8384
import { EditorDocumentHost } from "../mcp/editor-document-host";
8485
import { openVideoInHiddenWindow } from "../mcp/hidden-video";
8586
import { McpController } from "../mcp/mcp-controller";
@@ -5081,26 +5082,14 @@ export function registerIpcHandlers(
50815082
* user's own source and settings are what their next take starts from.
50825083
*/
50835084
async function pointHudAtTake(request: RecordRequest): Promise<() => void> {
5084-
// The microphone first: finding it changes nothing, so a miss leaves all as it was.
5085-
let microphone: Pick<RecordingPrefs, "micDeviceId" | "micDeviceName"> = {
5086-
micDeviceId: null,
5087-
micDeviceName: null,
5088-
};
5089-
if (request.mic && request.micDevice) {
5090-
// Its id as well as its name, both of which the HUD records with: a renderer's to read.
5085+
// The devices first: finding them changes nothing, so a miss leaves all as it was.
5086+
let listed: CliSourcesResult | null = null;
5087+
if ((request.mic && request.micDevice) || (request.camera && request.cameraDevice)) {
5088+
// Their ids as well as their names, both of which the HUD records with: a renderer's to read.
50915089
const run = mcpRunners.start({ kind: "sources" });
5092-
const listed = await run.done.finally(() => run.close());
5093-
const needle = request.micDevice.toLowerCase();
5094-
const match = listed.sources?.microphones.find((mic) =>
5095-
mic.label.toLowerCase().includes(needle),
5096-
);
5097-
if (!match) {
5098-
throw new Error(
5099-
`No microphone's name contains "${request.micDevice}". Call listSources for their names.`,
5100-
);
5101-
}
5102-
microphone = { micDeviceId: match.deviceId ?? null, micDeviceName: match.label };
5090+
listed = (await run.done.finally(() => run.close())).sources ?? null;
51035091
}
5092+
const next = takePrefs(request, listed);
51045093

51055094
const before = { source: selectedSource, live: selectedDesktopSource };
51065095
const restoreSource = () => {
@@ -5133,24 +5122,13 @@ export function registerIpcHandlers(
51335122
}
51345123
}
51355124

5136-
const prefs = recordingPrefs.get();
5137-
recordingPrefs.set({
5138-
micEnabled: request.mic,
5139-
...microphone,
5140-
systemAudioEnabled: request.systemAudio,
5141-
cursorCaptureMode: "editable-overlay",
5142-
});
5125+
const userPrefs = pickTakePrefs(recordingPrefs.get());
5126+
recordingPrefs.set(next);
51435127
// The prefs are saved to disk: a quit mid-take must not leave the client's for the next
51445128
// launch. ponytail: a crash still does; keep them in memory only if that bites.
51455129
const restore = () => {
51465130
app.off("will-quit", restore);
5147-
recordingPrefs.set({
5148-
micEnabled: prefs.micEnabled,
5149-
micDeviceId: prefs.micDeviceId,
5150-
micDeviceName: prefs.micDeviceName,
5151-
systemAudioEnabled: prefs.systemAudioEnabled,
5152-
cursorCaptureMode: prefs.cursorCaptureMode,
5153-
});
5131+
recordingPrefs.set(userPrefs);
51545132
restoreSource();
51555133
};
51565134
app.once("will-quit", restore);

‎electron/mcp/app-recorder.test.ts‎

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import {
88
createEmptyDocument,
99
documentSchema,
1010
} from "../../src/lib/ai-edition/schema";
11-
import { type AppRecorderDeps, createAppRecorder } from "./app-recorder";
11+
import {
12+
type AppRecorderDeps,
13+
createAppRecorder,
14+
pickTakePrefs,
15+
type TakePrefs,
16+
takePrefs,
17+
} from "./app-recorder";
1218
import type { McpApplyResult } from "./openscreen-mcp-server";
1319

1420
const VIDEO = path.resolve("recordings", "take.webm");
@@ -19,6 +25,9 @@ const REQUEST = {
1925
mic: false,
2026
micDevice: null,
2127
systemAudio: false,
28+
camera: false,
29+
cameraDevice: null,
30+
cursorMode: "editable-overlay" as const,
2231
};
2332

2433
/** The editor's project for the take: `clipEndSec` 60 is the placeholder it starts with. */
@@ -186,3 +195,53 @@ describe("an MCP take in the app", () => {
186195
await expect(started(recorder, calls)).resolves.toBeDefined();
187196
});
188197
});
198+
199+
describe("the recording bar's settings for a client's take", () => {
200+
const listed = {
201+
displays: [],
202+
windows: [],
203+
microphones: [{ label: "USB Mic", deviceId: "mic-1" }],
204+
microphoneLabelsUnavailable: false,
205+
cameras: [{ label: "Logitech BRIO", deviceId: "cam-1" }],
206+
cameraLabelsUnavailable: false,
207+
};
208+
209+
it("records the camera and the cursor mode asked for, a named device by its id and name", () => {
210+
expect(
211+
takePrefs(
212+
{ ...REQUEST, mic: true, camera: true, cameraDevice: "brio", cursorMode: "system" },
213+
listed,
214+
),
215+
).toEqual({
216+
micEnabled: true,
217+
micDeviceId: null,
218+
micDeviceName: null,
219+
camEnabled: true,
220+
camDeviceId: "cam-1",
221+
camDeviceName: "Logitech BRIO",
222+
systemAudioEnabled: false,
223+
cursorCaptureMode: "system",
224+
});
225+
});
226+
227+
it("turns off what the request leaves out, the user's camera included", () => {
228+
expect(takePrefs(REQUEST, null)).toMatchObject({ micEnabled: false, camEnabled: false });
229+
});
230+
231+
it("refuses a device no listed name contains", () => {
232+
expect(() => takePrefs({ ...REQUEST, camera: true, cameraDevice: "Facetime" }, listed)).toThrow(
233+
`No camera's name contains "Facetime"`,
234+
);
235+
expect(() => takePrefs({ ...REQUEST, mic: true, micDevice: "Yeti" }, null)).toThrow(
236+
"No microphone's name",
237+
);
238+
});
239+
240+
it("puts back exactly the settings a take changes", () => {
241+
const user: TakePrefs & { hideDesktopIcons: boolean } = {
242+
...takePrefs({ ...REQUEST, camera: true }, null),
243+
hideDesktopIcons: true,
244+
};
245+
expect(pickTakePrefs(user)).toEqual(takePrefs({ ...REQUEST, camera: true }, null));
246+
});
247+
});

0 commit comments

Comments
 (0)