cuetake 0.3.0 → 0.5.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 +9 -7
- package/examples/tabs.mjs +88 -0
- package/helper/bin/cuetake-capture +0 -0
- package/package.json +6 -4
- package/src/app-capture.js +128 -0
- package/src/app-director.js +208 -0
- package/src/app-locators.js +223 -0
- package/src/auth.js +8 -1
- package/src/camera.js +80 -33
- package/src/cli.js +28 -7
- package/src/cursor.js +59 -3
- package/src/desktop.js +108 -0
- package/src/director.js +392 -32
- package/src/edit.js +87 -14
- package/src/environment.js +55 -7
- package/src/follow-tabs.js +64 -0
- package/src/frames.js +41 -0
- package/src/look.js +26 -8
- package/src/mac-keys.js +47 -0
- package/src/masks.js +140 -0
- package/src/motion.js +75 -0
- package/src/narration.js +146 -0
- package/src/pipeline.js +401 -46
- package/src/probe.js +338 -38
- package/src/recorder.js +45 -12
- package/src/render-page.js +702 -150
- package/src/render.js +70 -15
- package/src/shortcuts.js +73 -0
- package/src/shutter.js +42 -0
- package/src/styles/arrow.js +130 -10
- package/src/styles/browser.js +2 -1
- package/src/styles/dot.js +2 -1
- package/src/styles/fast-forward.js +22 -0
- package/src/styles/keycaps.js +38 -0
- package/src/styles/subtitles.js +17 -0
- package/src/styles.js +7 -3
- package/src/tab-capture.js +225 -77
- package/src/tabs.js +126 -0
- package/src/time-map.js +106 -0
- package/src/uninstall.js +62 -0
package/src/pipeline.js
CHANGED
|
@@ -1,29 +1,254 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
|
-
import { dirname, join, resolve } from 'node:path';
|
|
2
|
+
import { dirname, extname, join, resolve } from 'node:path';
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
4
|
import { doctor } from './environment.js';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { startRecording, getRecordingPage, beginCapture, stopRecording, cleanup } from './recorder.js';
|
|
7
|
-
import { renderFinal, inspectFinal, composePreview } from './render.js';
|
|
7
|
+
import { renderFinal, inspectFinal, composePreview, measureLines } from './render.js';
|
|
8
8
|
import { outputSize, atShortSide } from './stage.js';
|
|
9
9
|
import { resolveAuthProfile } from './auth.js';
|
|
10
10
|
import { createDirector } from './director.js';
|
|
11
|
+
import { createAppDirector } from './app-director.js';
|
|
12
|
+
import { appLocators } from './app-locators.js';
|
|
13
|
+
import { startDesktop } from './app-capture.js';
|
|
14
|
+
import { desktopWarnings } from './desktop.js';
|
|
11
15
|
import { collectTimeline } from './probe.js';
|
|
12
16
|
import { createEdit, evenSize, merge, withDefaults } from './edit.js';
|
|
13
17
|
import { loadLook, resolvedLook, applyLook, lookFromEdit, saveLook, summarize } from './look.js';
|
|
14
18
|
import { absolute, bundle, forRender } from './styles.js';
|
|
19
|
+
import { burnsIn, cuesFor, isCjk, lineProblems, toSrt, toVtt } from './narration.js';
|
|
20
|
+
import { linesInFinal, timeMap } from './time-map.js';
|
|
21
|
+
import { maskWarnings } from './masks.js';
|
|
15
22
|
import pkg from '../package.json' with { type: 'json' };
|
|
16
23
|
|
|
17
|
-
const SCHEMA_VERSION =
|
|
18
|
-
/**
|
|
24
|
+
const SCHEMA_VERSION = 5;
|
|
25
|
+
/**
|
|
26
|
+
* Scenario config: capture settings, validated, plus styling that seeds each Take's Edit, which is not
|
|
27
|
+
* (ADR 0005). A Scenario opens a start page (`url`) or starts Apps (`app`: one App, a `.app` path or
|
|
28
|
+
* bundle id with its arguments, or a list of them sharing one Desktop), never both (ADR 0009); for Apps,
|
|
29
|
+
* `viewport` is the Desktop's size in points.
|
|
30
|
+
*/
|
|
31
|
+
const appSchema = z.object({ path: z.string().min(1), args: z.array(z.string()).default([]) }).strict();
|
|
19
32
|
export const scenarioSchema = z.object({
|
|
20
33
|
name: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
|
|
21
|
-
url: z.string().url().refine(s => /^https?:/.test(s), 'Capture requires HTTP(S)'),
|
|
34
|
+
url: z.string().url().refine(s => /^https?:/.test(s), 'Capture requires HTTP(S)').optional(),
|
|
35
|
+
app: z.union([appSchema, z.array(appSchema).min(1)]).optional(),
|
|
22
36
|
viewport: z.object({ width: evenSize, height: evenSize }).default({ width: 1440, height: 900 }),
|
|
23
37
|
capture: z.object({ fps: z.union([z.literal(30), z.literal(60)]).default(60), resolutionScale: z.union([z.literal(1), z.literal(2)]).default(2) }).default({}),
|
|
24
|
-
}).
|
|
38
|
+
director: z.object({ speed: z.number().positive().default(1), seed: z.number().int().default(1) }).strict().default({}),
|
|
39
|
+
}).passthrough().refine(config => !config.url !== !config.app, { message: 'A Scenario names exactly one of url or app', path: ['url'] });
|
|
40
|
+
/**
|
|
41
|
+
* A Narration file: Lines in one language, each with its text, its audio (relative to the file) and
|
|
42
|
+
* optionally word timings from the speech tool and a start in seconds. Any duration it states is
|
|
43
|
+
* ignored: CueTake measures each Line from its audio.
|
|
44
|
+
*/
|
|
45
|
+
export const narrationSchema = z.object({
|
|
46
|
+
language: z.string().min(2),
|
|
47
|
+
lines: z.array(z.object({
|
|
48
|
+
id: z.string().regex(/^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/, 'Use a short Line id of letters, digits, dots, dashes and underscores'),
|
|
49
|
+
text: z.string().min(1),
|
|
50
|
+
audio: z.string().min(1),
|
|
51
|
+
start: z.number().min(0).optional(),
|
|
52
|
+
words: z.array(z.object({ text: z.string(), start: z.number().min(0), end: z.number().min(0) }).refine(word => word.end >= word.start, 'A word ends before it starts')).optional(),
|
|
53
|
+
})).min(1).refine(lines => new Set(lines.map(line => line.id)).size === lines.length, 'Line ids must be unique'),
|
|
54
|
+
});
|
|
55
|
+
const SUBTITLE_FILES = [['subtitles.srt', toSrt], ['subtitles.vtt', toVtt]];
|
|
25
56
|
const writeJson = (path, data) => fs.writeFile(path, JSON.stringify(data, null, 2) + '\n');
|
|
26
57
|
const readJson = async path => JSON.parse(await fs.readFile(path, 'utf8'));
|
|
58
|
+
const readIfPresent = path => readJson(path).catch(error => { if (error.code === 'ENOENT') return null; throw error; });
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Copies a Narration file and its audio into the Take's narration/ folder, replacing any earlier one,
|
|
62
|
+
* and measures each Line. The audio is renamed after its Line.
|
|
63
|
+
*/
|
|
64
|
+
async function intoTakeNarration(file, dir) {
|
|
65
|
+
const path = resolve(file), parsed = narrationSchema.safeParse(await readJson(path));
|
|
66
|
+
if (!parsed.success) throw new Error(`${path} is not a Narration file: ${parsed.error.issues.map(issue => `${issue.path.join('.') || 'file'}: ${issue.message}`).join('; ')}`);
|
|
67
|
+
// Read everything first: the file may already be the Take's own.
|
|
68
|
+
const lines = await Promise.all(parsed.data.lines.map(async line => {
|
|
69
|
+
const from = resolve(dirname(path), line.audio);
|
|
70
|
+
const bytes = await fs.readFile(from).catch(error => { throw error.code === 'ENOENT' ? new Error(`Line '${line.id}': no audio at ${from}`) : error; });
|
|
71
|
+
return { line: { ...line, audio: line.id + extname(from).toLowerCase() }, bytes };
|
|
72
|
+
}));
|
|
73
|
+
const folder = join(dir, 'narration');
|
|
74
|
+
await fs.rm(folder, { recursive: true, force: true });
|
|
75
|
+
await fs.mkdir(folder, { recursive: true });
|
|
76
|
+
for (const { line, bytes } of lines) await fs.writeFile(join(folder, line.audio), bytes);
|
|
77
|
+
const narration = { language: parsed.data.language, lines: lines.map(({ line }) => line) };
|
|
78
|
+
await writeJson(join(folder, 'narration.json'), narration);
|
|
79
|
+
return { narration, durations: await measureLines(narration.lines.map(line => ({ id: line.id, path: join(folder, line.audio) }))) };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The Edit with a Line added at its `start` for each Narration Line that has one and is not placed yet; also names the Lines left unplaced. */
|
|
83
|
+
function placeLines(edit, narration) {
|
|
84
|
+
const placed = new Set(edit.narration.lines.map(line => line.id));
|
|
85
|
+
const added = narration.lines.filter(line => !placed.has(line.id) && line.start !== undefined).map(line => ({ id: line.id, start: line.start }));
|
|
86
|
+
const lines = [...edit.narration.lines, ...added].sort((a, b) => a.start - b.start);
|
|
87
|
+
return { edit: { ...edit, narration: { ...edit.narration, lines } }, unplaced: narration.lines.filter(line => !placed.has(line.id) && line.start === undefined).map(line => line.id) };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The Edit's Lines joined with the Narration's text, audio and word timings, as Render takes them.
|
|
92
|
+
* A Line the Narration does not voice stops the Render.
|
|
93
|
+
*/
|
|
94
|
+
function voicedLines(edit, narration, dir) {
|
|
95
|
+
const byId = new Map(narration.lines.map(line => [line.id, line]));
|
|
96
|
+
return edit.narration.lines.map(line => {
|
|
97
|
+
const voiced = byId.get(line.id);
|
|
98
|
+
if (!voiced) throw new Error(`Line '${line.id}' has no audio in the Take's Narration; import one with cuetake narrate import ${dir} <narration.json>`);
|
|
99
|
+
return { ...line, text: voiced.text, words: voiced.words, path: join(dir, 'narration', voiced.audio) };
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The resolution scale Capture uses: the one the Scenario or Look chose, else 2, or 1 when doctor found
|
|
105
|
+
* Chromium drawing without a GPU, where scale 2 starves a busy page of frames.
|
|
106
|
+
*/
|
|
107
|
+
export function captureScale(chosen, gpu) {
|
|
108
|
+
if (chosen !== undefined) return { resolutionScale: chosen, lowered: false };
|
|
109
|
+
return gpu?.accelerated === false ? { resolutionScale: 1, lowered: true } : { resolutionScale: 2, lowered: false };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The Timeline from `take` (its url, viewport and scale), what Capture observed in each Tab (`observed`,
|
|
114
|
+
* the probe's by Tab id), what the Director noted and what the recorder saw: every input and page load carries the Tab it happened in,
|
|
115
|
+
* in that Tab's CSS pixels, and `front` events note which Tab is in front from when. Each element a
|
|
116
|
+
* Scenario masked is in `elements`, with its boxes over time, and each mask is a `mask` event.
|
|
117
|
+
*/
|
|
118
|
+
export function timelineOf(take, stopped, observed, notes, startedAtMs) {
|
|
119
|
+
const t = ms => Math.round(ms - startedAtMs) / 1000, inTab = (list, tab) => list.map(item => ({ ...item, tab }));
|
|
120
|
+
const pointer = [...[...observed].flatMap(([tab, seen]) => seen.pointer.map(sample => [...sample, tab])), ...notes.pointer.map(([ms, x, y, tab]) => [t(ms), x, y, tab])];
|
|
121
|
+
const shapes = [...observed.values()].flatMap(seen => seen.shapes).sort((a, b) => a[0] - b[0]);
|
|
122
|
+
const frameInput = { turned: [...observed.values()].flatMap(seen => seen.turned).sort((a, b) => a - b), unplaced: [...observed.values()].flatMap(seen => seen.unplaced).sort((a, b) => a - b) };
|
|
123
|
+
// Each element a mask follows, with the boxes the probe in its Tab saw it at.
|
|
124
|
+
const elements = (notes.elements ?? []).map(element => ({ ...element, boxes: observed.get(element.tab)?.watched?.find(watched => watched.id === element.id)?.boxes ?? [] }));
|
|
125
|
+
return {
|
|
126
|
+
schemaVersion: SCHEMA_VERSION, ...take, duration: stopped.durationSeconds,
|
|
127
|
+
tabs: stopped.tabs.map(({ id, opener, opened, closed, viewport, url, start }) => ({ id, opener, opened, closed, viewport, url, start })),
|
|
128
|
+
pointer: pointer.sort((a, b) => a[0] - b[0]), shapes, ...((frameInput.turned.length || frameInput.unplaced.length) && { frameInput }), ...(elements.length && { elements }),
|
|
129
|
+
events: [
|
|
130
|
+
...[...observed].flatMap(([tab, seen]) => inTab(seen.events, tab)),
|
|
131
|
+
...notes.focus.map(f => ({ type: 'focus', ...f })), ...notes.said.map(line => ({ type: 'say', ...line })), ...notes.forwarded.map(span => ({ type: 'fastForward', ...span })), ...(notes.masks ?? []).map(mask => ({ type: 'mask', ...mask })),
|
|
132
|
+
...(notes.scrolls ?? []).map(span => ({ type: 'scroll', ...span })),
|
|
133
|
+
...stopped.tabs.flatMap(tab => inTab(tab.navigations.map(load => ({ type: 'navigate', ...load })), tab.id)),
|
|
134
|
+
...stopped.fronts.filter(front => front.t > 0).map(front => ({ type: 'front', ...front })),
|
|
135
|
+
].sort((a, b) => a.t - b.t),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The Apps a Scenario starts, as a list: `config.app` names one or several. */
|
|
140
|
+
export const appsOf = config => [config.app].flat().filter(Boolean);
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* The Timeline of a Take of Apps (ADR 0009) from `take` (the Apps, the Desktop's size in points as the
|
|
144
|
+
* viewport, and its scale), what the helper saw (`stopped`: the duration, the Apps' windows over time,
|
|
145
|
+
* the system cursor's shapes, each element the App focused, as `focused` events the camera follows, and
|
|
146
|
+
* the frames of each masked element, `watched`) and what the Director noted: its pointer path and
|
|
147
|
+
* input, since the App shows none of its own, focus targets, Lines, fast-forwards and masks. Input the Director did not make never enters it. The Take has one
|
|
148
|
+
* Tab, its Desktop; positions are Desktop points.
|
|
149
|
+
*/
|
|
150
|
+
export function desktopTimelineOf({ apps, viewport, scale }, stopped, notes) {
|
|
151
|
+
// Each element a mask follows, with the boxes the helper read it at.
|
|
152
|
+
const elements = (notes.elements ?? []).map(element => ({ ...element, boxes: stopped.watched?.find(watched => watched.id === element.id)?.boxes ?? [] }));
|
|
153
|
+
return {
|
|
154
|
+
schemaVersion: SCHEMA_VERSION, apps, viewport, scale, duration: stopped.duration,
|
|
155
|
+
tabs: [{ id: 0, opener: null, opened: 0, closed: null, viewport, start: 0 }],
|
|
156
|
+
pointer: notes.pointer.map(([t, x, y]) => [t, x, y, 0]), shapes: stopped.shapes ?? [], windows: stopped.windows, ...(elements.length && { elements }),
|
|
157
|
+
events: [
|
|
158
|
+
...notes.focus.map(f => ({ type: 'focus', ...f })), ...notes.said.map(line => ({ type: 'say', ...line })), ...notes.forwarded.map(span => ({ type: 'fastForward', ...span })),
|
|
159
|
+
...notes.events.map(event => ({ ...event, tab: 0 })), ...(stopped.focused ?? []).map(f => ({ type: 'focused', ...f, tab: 0 })),
|
|
160
|
+
...(notes.masks ?? []).map(mask => ({ type: 'mask', ...mask })),
|
|
161
|
+
].sort((a, b) => a.t - b.t),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** The Source of each of a Take's Tabs, by Tab id. */
|
|
166
|
+
const sourcesOf = (dir, timeline) => Object.fromEntries(timeline.tabs.map(tab => [tab.id, join(dir, `source-${tab.id}.${timeline.windows ? 'mp4' : 'webm'}`)]));
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Refuses what does not apply to an App: an Auth profile, since the App runs with the user's own login
|
|
170
|
+
* and data; and a resolution scale, since the Desktop takes its display's (ADR 0009).
|
|
171
|
+
*/
|
|
172
|
+
function refuseForApp(given, options) {
|
|
173
|
+
if (options.authProfile) throw new Error('--auth-profile is for web pages: an App runs with the login and data it already has');
|
|
174
|
+
if (given.capture?.resolutionScale !== undefined) throw new Error('capture.resolutionScale does not apply to an App: the Desktop records at the scale of the display it sits on');
|
|
175
|
+
if (options.headed) throw new Error('--headed is for web pages: an App always shows on the screen');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Captures a start page: the Tabs' Sources, capture.json and poster.png in `dir`; returns the Timeline, the Director's notes and the evidence. */
|
|
179
|
+
async function capturePage(scenario, config, dir, { authState, headed, voiced }) {
|
|
180
|
+
try {
|
|
181
|
+
const session = await startRecording(config.url, {
|
|
182
|
+
...config.viewport, ...config.capture, outputDir: dir, deferCapture: true, storageState: authState, headed,
|
|
183
|
+
});
|
|
184
|
+
const page = getRecordingPage(session.sessionId);
|
|
185
|
+
if (scenario.prepare) await scenario.prepare(page);
|
|
186
|
+
await page.evaluate(() => document.fonts.ready);
|
|
187
|
+
const capture = await beginCapture(session.sessionId);
|
|
188
|
+
const startedAtMs = Date.parse(capture.startedAt);
|
|
189
|
+
const notes = { focus: [], wide: [], said: [], forwarded: [], pointer: [], elements: [], masks: [] };
|
|
190
|
+
const ran = new AbortController();
|
|
191
|
+
const director = createDirector(capture.tabs, { startedAt: startedAtMs, fps: config.capture.fps, voiced, ...config.director, signal: ran.signal }, notes);
|
|
192
|
+
const evidence = await scenario.run(director).finally(() => ran.abort());
|
|
193
|
+
await capture.tabs.started();
|
|
194
|
+
await capture.tabs.front.page.screenshot({ path: join(dir, 'poster.png') });
|
|
195
|
+
const observed = new Map();
|
|
196
|
+
for (const tab of capture.tabs.list()) if (tab.recorded) observed.set(tab.id, await collectTimeline(tab.page, startedAtMs));
|
|
197
|
+
const stopped = await stopRecording(session.sessionId);
|
|
198
|
+
for (const tab of stopped.tabs) await fs.rename(tab.webmPath, join(dir, `source-${tab.id}.webm`));
|
|
199
|
+
await writeJson(join(dir, 'capture.json'), { tabs: stopped.tabs.map(tab => ({ tab: tab.id, ...tab.stats })) });
|
|
200
|
+
const timeline = timelineOf({ url: capture.url, viewport: config.viewport, scale: config.capture.resolutionScale }, stopped, observed, notes, startedAtMs);
|
|
201
|
+
return { timeline, notes, evidence };
|
|
202
|
+
} finally { await cleanup(); }
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Captures a Desktop of the Apps (ADR 0009) through the helper: source-0.mp4, capture.json and
|
|
207
|
+
* poster.png in `dir`. The Desktop records at its display's scale, which `config.capture` then holds.
|
|
208
|
+
* `prepare(page, { app })` gets the first App's first window, and every App by `app(name)`, before
|
|
209
|
+
* Capture starts, to wait for what the demo needs and arrange the windows with `setFrame`.
|
|
210
|
+
* Returns the Timeline, the Director's notes, the evidence, and the Apps the helper could not quit.
|
|
211
|
+
*/
|
|
212
|
+
async function captureApp(scenario, config, dir, { voiced, useRunning }) {
|
|
213
|
+
const { fps } = config.capture, given = appsOf(config);
|
|
214
|
+
process.stderr.write(`CueTake ${useRunning ? 'records' : 'starts'} ${given.map(app => app.path).join(', ')}${useRunning ? ', as the user runs it where it is running' : ` and records ${given.length > 1 ? 'them' : 'it'}`}. Leave the Mac alone until the Take ends: the Scenario moves the real pointer and acts on the real ${given.length > 1 ? 'Apps' : 'App'} and their data.\n`);
|
|
215
|
+
const desktop = await startDesktop({ apps: given, desktop: config.viewport, fps, source: join(dir, 'source-0.mp4'), poster: join(dir, 'poster.png'), useRunning });
|
|
216
|
+
try {
|
|
217
|
+
config.capture.resolutionScale = desktop.ready.scale;
|
|
218
|
+
const apps = given.map((app, i) => ({ ...app, name: desktop.ready.apps[i].name, bundle: desktop.ready.apps[i].bundle }));
|
|
219
|
+
if (scenario.prepare) {
|
|
220
|
+
const arranged = appLocators(desktop, apps, { arrange: true });
|
|
221
|
+
await scenario.prepare(arranged.page('first'), { app: arranged.app });
|
|
222
|
+
}
|
|
223
|
+
// The pointer starts at the Desktop's top-left corner, where the Director's starts.
|
|
224
|
+
await desktop.request({ move: { x: 0, y: 0 } });
|
|
225
|
+
const startedAtMs = await desktop.start();
|
|
226
|
+
const notes = { focus: [], wide: [], said: [], forwarded: [], pointer: [], events: [], elements: [], masks: [] };
|
|
227
|
+
const ran = new AbortController();
|
|
228
|
+
const director = createAppDirector({ startedAt: startedAtMs, fps, voiced, ...config.director, helper: desktop, apps, signal: ran.signal }, notes);
|
|
229
|
+
const evidence = await scenario.run(director).finally(() => ran.abort());
|
|
230
|
+
const stopped = await desktop.stop();
|
|
231
|
+
const { width, height } = stopped.size;
|
|
232
|
+
await writeJson(join(dir, 'capture.json'), { tabs: [{
|
|
233
|
+
tab: 0, settings: { width, height, frameRate: fps }, duration: stopped.duration, dropped: stopped.dropped, otherInput: stopped.otherInput ?? [],
|
|
234
|
+
frames: stopped.frames.map(([t, scale]) => ({ timeMs: Math.round(t * 1e6) / 1000, scale })),
|
|
235
|
+
}] });
|
|
236
|
+
const timeline = desktopTimelineOf({ apps, viewport: config.viewport, scale: desktop.ready.scale }, stopped, notes);
|
|
237
|
+
return { timeline, notes, evidence, unquit: stopped.unquit ?? [], running: desktop.ready.apps.filter(app => app.running).map(app => app.name) };
|
|
238
|
+
} finally { desktop.kill(); }
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* What `record` reports of the Apps after a Take, or null when there is nothing to report: those it
|
|
243
|
+
* started that did not quit (`unquit`), and those the user runs that it recorded as they were (`running`).
|
|
244
|
+
*/
|
|
245
|
+
export function appReport({ unquit, running }) {
|
|
246
|
+
const notes = [];
|
|
247
|
+
if (unquit.length) notes.push(`${unquit.join(', ')} did not quit after the Take; ${unquit.length > 1 ? 'they' : 'it'} may be asking to save. Quit ${unquit.length > 1 ? 'them' : 'it'} before the next Take.`);
|
|
248
|
+
if (running.length) notes.push(`${running.join(', ')} ${running.length > 1 ? 'were' : 'was'} recorded as the user runs ${running.length > 1 ? 'them' : 'it'}: CueTake left ${running.length > 1 ? 'them' : 'it'} running and put ${running.length > 1 ? 'their' : 'its'} windows back.`);
|
|
249
|
+
if (!notes.length) return null;
|
|
250
|
+
return { ...(unquit.length && { quit: false, unquit }), ...(running.length && { running }), note: notes.join(' ') };
|
|
251
|
+
}
|
|
27
252
|
|
|
28
253
|
/** New take directories are exclusive: reruns never overwrite a previous take. */
|
|
29
254
|
export async function recordScenario(scenarioPath, outputDir, options = {}) {
|
|
@@ -31,49 +256,74 @@ export async function recordScenario(scenarioPath, outputDir, options = {}) {
|
|
|
31
256
|
// A Look sits under the Scenario: every field the config names wins over it. File refs resolve
|
|
32
257
|
// against the Look and the Scenario file, and the files are copied into the Take.
|
|
33
258
|
const look = options.look ? await loadLook(options.look) : null;
|
|
34
|
-
const
|
|
259
|
+
const given = merge(look ? resolvedLook(look) : {}, absolute(scenario.config, dirname(resolve(scenarioPath))));
|
|
260
|
+
const config = scenarioSchema.parse(given);
|
|
35
261
|
if (typeof scenario.run !== 'function') throw new Error('Scenario must export run(director)');
|
|
262
|
+
if (config.app) refuseForApp(given, options);
|
|
263
|
+
else if (options.useRunning) throw new Error('--use-running is for Apps: it records an App the user already runs, as it is');
|
|
264
|
+
// A relative .app path names an App beside the Scenario.
|
|
265
|
+
for (const app of appsOf(config)) if (app.path.includes('/')) app.path = resolve(dirname(resolve(scenarioPath)), app.path);
|
|
36
266
|
const authState = options.authProfile ? await resolveAuthProfile(options.authProfile) : undefined;
|
|
37
267
|
const ready = await doctor();
|
|
38
268
|
if (!ready.ok) throw new Error(JSON.stringify(ready));
|
|
269
|
+
if (config.app && !ready.apps?.ok) {
|
|
270
|
+
const missing = ready.apps ? ready.checks.filter(check => !check.ok).map(check => `${check.name}: ${check.fix}`) : ['Recording an App needs macOS'];
|
|
271
|
+
throw new Error(`This Mac cannot record an App yet. ${missing.join(' ')} Nothing was requested; run cuetake doctor after the change.`);
|
|
272
|
+
}
|
|
273
|
+
const gpu = ready.checks.find(check => check.name === 'gpu');
|
|
274
|
+
const { resolutionScale, lowered } = config.app ? { resolutionScale: config.capture.resolutionScale, lowered: false } : captureScale(given.capture?.resolutionScale, gpu);
|
|
275
|
+
config.capture.resolutionScale = resolutionScale;
|
|
39
276
|
const dir = resolve(outputDir || join('recordings', config.name, new Date().toISOString().replace(/[:.]/g, '-')));
|
|
40
277
|
await fs.mkdir(resolve(dir, '..'), { recursive: true });
|
|
41
278
|
await fs.mkdir(dir); // EEXIST is intentional, including for empty existing folders.
|
|
42
279
|
let project = { schemaVersion: SCHEMA_VERSION, tool: 'CueTake', version: pkg.version, createdAt: new Date().toISOString(), status: 'recording', authenticated: Boolean(authState), ...(look && { look: look.name }), config };
|
|
43
280
|
await writeJson(join(dir, 'project.json'), project);
|
|
44
281
|
await fs.copyFile(resolve(scenarioPath), join(dir, 'scenario.mjs'));
|
|
282
|
+
let unplaced = [], unvoiced = [], captured;
|
|
45
283
|
try {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
await page.evaluate(() => document.fonts.ready);
|
|
52
|
-
const capture = await beginCapture(session.sessionId);
|
|
53
|
-
const startedAtMs = Date.parse(capture.startedAt);
|
|
54
|
-
const focus = [], wide = [];
|
|
55
|
-
const director = createDirector(page, startedAtMs, config.capture.fps, focus, wide);
|
|
56
|
-
const evidence = await scenario.run(director);
|
|
57
|
-
await page.screenshot({ path: join(dir, 'poster.png') });
|
|
58
|
-
const observed = await collectTimeline(page, startedAtMs);
|
|
59
|
-
const stopped = await stopRecording(session.sessionId);
|
|
60
|
-
await fs.rename(stopped.webmPath, join(dir, 'source.webm'));
|
|
61
|
-
await fs.rename(stopped.webmPath.replace(/\.webm$/, '-capture.json'), join(dir, 'capture.json'));
|
|
62
|
-
const timeline = {
|
|
63
|
-
schemaVersion: SCHEMA_VERSION, viewport: config.viewport, scale: config.capture.resolutionScale, duration: stopped.durationSeconds,
|
|
64
|
-
pointer: observed.pointer, events: [...observed.events, ...focus.map(f => ({ type: 'focus', ...f }))].sort((a, b) => a.t - b.t),
|
|
65
|
-
};
|
|
284
|
+
// The Narration is voiced before Capture, so d.say can hold each Line for its audio (ADR 0006).
|
|
285
|
+
const imported = options.narration ? await intoTakeNarration(options.narration, dir) : null;
|
|
286
|
+
const voiced = imported && new Map(Object.entries(imported.durations));
|
|
287
|
+
captured = config.app ? await captureApp(scenario, config, dir, { voiced, useRunning: options.useRunning }) : await capturePage(scenario, config, dir, { authState, headed: options.headed, voiced });
|
|
288
|
+
const { timeline, notes: { focus, wide }, evidence } = captured;
|
|
66
289
|
await writeJson(join(dir, 'timeline.json'), timeline);
|
|
67
|
-
|
|
68
|
-
|
|
290
|
+
let edit = createEdit(config, timeline, focus, wide);
|
|
291
|
+
if (imported) ({ edit, unplaced } = placeLines(edit, imported.narration));
|
|
292
|
+
else unvoiced = edit.narration.lines.map(line => line.id);
|
|
293
|
+
await writeJson(join(dir, 'edit.json'), await intoTake(edit, dir));
|
|
294
|
+
project = { ...project, status: 'captured', duration: timeline.duration, evidence: evidence ?? null };
|
|
69
295
|
await writeJson(join(dir, 'project.json'), project);
|
|
70
296
|
} catch (error) {
|
|
71
297
|
await writeJson(join(dir, 'project.json'), { ...project, status: 'failed', error: error.message });
|
|
72
298
|
throw error;
|
|
73
|
-
}
|
|
299
|
+
}
|
|
74
300
|
await renderTake(dir);
|
|
75
301
|
const verification = await verifyTake(dir);
|
|
76
|
-
return { directory: dir, final: join(dir, 'final.mp4'), verification
|
|
302
|
+
return { directory: dir, final: join(dir, 'final.mp4'), verification,
|
|
303
|
+
...(lowered && { capture: { resolutionScale, note: `Chromium draws without a GPU here (${gpu.renderer}), so Capture used resolutionScale 1; set capture.resolutionScale to 2 in the Scenario to override` } }),
|
|
304
|
+
...(config.app && { capture: { resolutionScale: config.capture.resolutionScale, note: 'The Desktop records at the scale of the display it sits on' } }),
|
|
305
|
+
...(config.app && appReport(captured) && { app: appReport(captured) }),
|
|
306
|
+
...(unplaced.length && { unplaced: { lines: unplaced, note: 'These Lines were never said and have no start; add d.say or a start in edit.json' } }),
|
|
307
|
+
...(unvoiced.length && { unvoiced: { lines: unvoiced, note: `These Lines have no audio yet; voice them and run cuetake narrate import ${dir} <narration.json>` } }) };
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Imports a Narration into a recorded Take, replacing its earlier one. Lines keep their place in the
|
|
312
|
+
* Edit; a new Line is placed at its `start`, if the file gives one. Problems are reported here and
|
|
313
|
+
* stop the next Render.
|
|
314
|
+
*/
|
|
315
|
+
export async function importNarration(directory, file) {
|
|
316
|
+
const dir = resolve(directory);
|
|
317
|
+
const { timeline, edit } = await loadTake(dir);
|
|
318
|
+
const { narration, durations } = await intoTakeNarration(file, dir);
|
|
319
|
+
const { edit: next, unplaced } = placeLines(edit, narration);
|
|
320
|
+
await writeJson(join(dir, 'edit.json'), next);
|
|
321
|
+
const lines = next.narration.lines.filter(line => line.id in durations).map(line => ({ ...line, duration: durations[line.id] }));
|
|
322
|
+
const missing = next.narration.lines.filter(line => !(line.id in durations)).map(line => line.id);
|
|
323
|
+
const map = timeMap(next.fastForward, timeline.duration), end = Math.round(map.duration * next.output.fps) / next.output.fps;
|
|
324
|
+
const inFinal = linesInFinal(lines, map);
|
|
325
|
+
const problems = [...inFinal.problems, ...lineProblems(inFinal.lines, end), ...missing.map(id => `Line '${id}' is placed in edit.json but the Narration has no audio for it`)];
|
|
326
|
+
return { narration: join(dir, 'narration', 'narration.json'), lines, unplaced, problems, next: `cuetake render ${dir}` };
|
|
77
327
|
}
|
|
78
328
|
|
|
79
329
|
/** The Edit with every file it names copied into the Take's styles/ folder, so the Take stands alone (ADR 0002). */
|
|
@@ -83,22 +333,42 @@ const intoTake = (edit, dir) => bundle(edit, dir, join(dir, 'styles'), 'styles/'
|
|
|
83
333
|
async function loadTake(dir) {
|
|
84
334
|
const project = await readJson(join(dir, 'project.json'));
|
|
85
335
|
if (project.schemaVersion !== SCHEMA_VERSION) throw new Error(`${dir} was recorded by an older CueTake (schema ${project.schemaVersion ?? 1}); record it again`);
|
|
86
|
-
return {
|
|
336
|
+
return {
|
|
337
|
+
project, config: scenarioSchema.parse(project.config), timeline: await readJson(join(dir, 'timeline.json')),
|
|
338
|
+
edit: withDefaults(await readJson(join(dir, 'edit.json'))), narration: await readIfPresent(join(dir, 'narration', 'narration.json')),
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* The Narration as Render takes it, or null for a Take without Lines or without a Narration yet (a
|
|
344
|
+
* draft whose Lines `d.say` placed before any audio existed). Burned-in Chinese, Japanese or Korean
|
|
345
|
+
* Subtitles drawn by the built-in need a font: macOS has PingFang SC; elsewhere the Edit or Look names one.
|
|
346
|
+
*/
|
|
347
|
+
function narrationForRender(edit, narration, dir) {
|
|
348
|
+
if (!edit.narration.lines.length || !narration) return null;
|
|
349
|
+
const lines = voicedLines(edit, narration, dir), { subtitles } = edit;
|
|
350
|
+
const builtin = burnsIn(subtitles) && subtitles.draw === 'subtitles' && !subtitles.files?.font;
|
|
351
|
+
if (builtin && process.platform !== 'darwin' && lines.some(line => isCjk(line.text, narration.language))) {
|
|
352
|
+
throw new Error('Burned-in Subtitles in this language need a font outside macOS: add one to the Edit or Look as subtitles.files.font (a .woff2, .ttf or .otf file), or set subtitles.burn to false');
|
|
353
|
+
}
|
|
354
|
+
return { language: narration.language, volume: edit.narration.volume, lines };
|
|
87
355
|
}
|
|
88
356
|
|
|
89
357
|
/**
|
|
90
358
|
* Writes preview.png: the Take's current Edit beside each Look (names or JSON files), composed with a
|
|
91
|
-
* 1080-pixel short side in each output's own proportions.
|
|
359
|
+
* 1080-pixel short side in each output's own proportions. `at` is seconds of the Final; without it the
|
|
360
|
+
* Preview shows the last moment with the camera wide.
|
|
92
361
|
*/
|
|
93
362
|
export async function previewTake(directory, refs = [], { at } = {}) {
|
|
94
363
|
const dir = resolve(directory);
|
|
95
|
-
const { config, timeline, edit } = await loadTake(dir);
|
|
96
|
-
|
|
97
|
-
|
|
364
|
+
const { config, timeline, edit, narration } = await loadTake(dir);
|
|
365
|
+
const length = timeMap(edit.fastForward, timeline.duration).duration;
|
|
366
|
+
if (at !== undefined && !(at >= 0 && at <= length)) throw new Error(`--at must be between 0 and ${+length.toFixed(3)} seconds of the Final`);
|
|
367
|
+
const host = config.url && new URL(config.url).host;
|
|
98
368
|
const looks = await Promise.all(refs.map(ref => loadLook(ref)));
|
|
99
369
|
const tiles = [{ name: 'current', edit }, ...looks.map(look => ({ name: look.name, edit: applyLook(edit, resolvedLook(look), host) }))];
|
|
100
370
|
const files = {}, shown = tiles.map(({ name, edit }) => ({ name, edit: forRender(atShortSide(edit, 1080), dir, files).edit }));
|
|
101
|
-
const png = await composePreview({
|
|
371
|
+
const png = await composePreview({ sources: sourcesOf(dir, timeline), timeline, at, tiles: shown, files, narration: narrationForRender(edit, narration, dir) });
|
|
102
372
|
const preview = join(dir, 'preview.png');
|
|
103
373
|
await fs.writeFile(preview, png);
|
|
104
374
|
return { preview, at: at ?? 'end, camera wide', tiles: tiles.map(({ name, edit }) => ({ name, summary: summarize(lookFromEdit(edit)) })) };
|
|
@@ -109,7 +379,7 @@ export async function applyLookToTake(ref, directory) {
|
|
|
109
379
|
const dir = resolve(directory);
|
|
110
380
|
const { config, edit } = await loadTake(dir);
|
|
111
381
|
const look = await loadLook(ref);
|
|
112
|
-
const next = await intoTake(applyLook(edit, resolvedLook(look), new URL(config.url).host), dir);
|
|
382
|
+
const next = await intoTake(applyLook(edit, resolvedLook(look), config.url && new URL(config.url).host), dir);
|
|
113
383
|
await writeJson(join(dir, 'edit.json'), next);
|
|
114
384
|
return { look: look.name, edit: join(dir, 'edit.json'), summary: summarize(lookFromEdit(next)), next: `cuetake render ${dir}` };
|
|
115
385
|
}
|
|
@@ -120,14 +390,23 @@ export async function saveLookFromTake(name, directory, options) {
|
|
|
120
390
|
return saveLook(name, lookFromEdit(edit), { ...options, from: dir });
|
|
121
391
|
}
|
|
122
392
|
|
|
393
|
+
/** Writes subtitles.srt and subtitles.vtt for the cues Render drew from, or removes them for a Take without Lines. */
|
|
394
|
+
async function writeSubtitles(dir, cues) {
|
|
395
|
+
for (const [name, format] of SUBTITLE_FILES) {
|
|
396
|
+
if (cues) await fs.writeFile(join(dir, name), format(cues)); else await fs.rm(join(dir, name), { force: true });
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
123
400
|
export async function renderTake(directory) {
|
|
124
401
|
const dir = resolve(directory);
|
|
125
|
-
const { project,
|
|
402
|
+
const { project, timeline, edit, narration } = await loadTake(dir);
|
|
403
|
+
const spoken = narrationForRender(edit, narration, dir);
|
|
126
404
|
// Render to a temporary output; preserve the last complete final if encoding fails.
|
|
127
405
|
const temporary = join(dir, 'final.pending.mp4');
|
|
128
406
|
try {
|
|
129
|
-
const render = await renderFinal({
|
|
407
|
+
const render = await renderFinal({ sources: sourcesOf(dir, timeline), finalPath: temporary, timeline, ...forRender(edit, dir), narration: spoken });
|
|
130
408
|
await fs.rename(temporary, join(dir, 'final.mp4'));
|
|
409
|
+
await writeSubtitles(dir, render.subtitles?.map(({ frames, ...cue }) => cue) ?? null);
|
|
131
410
|
await writeJson(join(dir, 'render.json'), render);
|
|
132
411
|
await fs.rm(join(dir, 'verification.json'), { force: true });
|
|
133
412
|
await writeJson(join(dir, 'project.json'), { ...project, status: 'rendered' });
|
|
@@ -135,6 +414,37 @@ export async function renderTake(directory) {
|
|
|
135
414
|
return join(dir, 'final.mp4');
|
|
136
415
|
}
|
|
137
416
|
|
|
417
|
+
/**
|
|
418
|
+
* What stops the Final from playing the Narration as placed: a missing or undecodable audio track or
|
|
419
|
+
* Line, Lines that do not fit, subtitle files that do not match the Lines, and burned-in Subtitles
|
|
420
|
+
* Render did not draw for a Line.
|
|
421
|
+
*/
|
|
422
|
+
async function narrationProblems(dir, edit, narration, media, map, end) {
|
|
423
|
+
const problems = [], fps = edit.output.fps;
|
|
424
|
+
if (!media.audio) return ['no audio track, though the Edit places Lines'];
|
|
425
|
+
if (media.audio.error) problems.push(`the audio track does not decode: ${media.audio.error}`);
|
|
426
|
+
if (Math.abs(media.audio.duration - media.duration) > 0.1) problems.push(`audio lasts ${media.audio.duration.toFixed(3)} s, video ${media.duration.toFixed(3)} s`);
|
|
427
|
+
const measured = new Map(media.lines.map(line => [line.id, line]));
|
|
428
|
+
for (const line of media.lines) if (line.error) problems.push(line.error);
|
|
429
|
+
if (problems.length) return problems;
|
|
430
|
+
const inFinal = linesInFinal(narration.lines.map(line => ({ ...line, duration: measured.get(line.id).duration })), map), { lines } = inFinal;
|
|
431
|
+
problems.push(...inFinal.problems, ...lineProblems(lines, end));
|
|
432
|
+
if (problems.length) return problems;
|
|
433
|
+
const cues = cuesFor(lines, narration.language, edit.subtitles, end);
|
|
434
|
+
for (const [name, format] of SUBTITLE_FILES) {
|
|
435
|
+
const text = await fs.readFile(join(dir, name), 'utf8').catch(() => null);
|
|
436
|
+
if (text !== format(cues)) problems.push(`${name} ${text === null ? 'is missing' : 'does not match the Lines'}; render again`);
|
|
437
|
+
}
|
|
438
|
+
if (burnsIn(edit.subtitles)) {
|
|
439
|
+
const drawn = (await readIfPresent(join(dir, 'render.json')))?.subtitles ?? [];
|
|
440
|
+
for (const line of lines) {
|
|
441
|
+
const own = drawn.filter(cue => cue.id === line.id);
|
|
442
|
+
if (!own.length || own.some(cue => !cue.frames || cue.frames[0] > Math.ceil(cue.start * fps) + 1 || cue.frames[1] < Math.floor(cue.end * fps) - 2)) problems.push(`Subtitles for Line '${line.id}' were not drawn while it is spoken`);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return problems;
|
|
446
|
+
}
|
|
447
|
+
|
|
138
448
|
export function summarizeFrames(frames, duration) {
|
|
139
449
|
const intervals = frames.slice(1).map((f, i) => f.timeMs - frames[i].timeMs);
|
|
140
450
|
const sorted = intervals.toSorted((a, b) => a - b);
|
|
@@ -142,21 +452,66 @@ export function summarizeFrames(frames, duration) {
|
|
|
142
452
|
return { callbacks: frames.length, medianIntervalMs: sorted[Math.floor(sorted.length / 2)] ?? null, maxIntervalMs: sorted.at(-1) ?? null, perSecond: seconds, note: 'Source capture is variable frame rate. Static sections reduce cadence; callback counts are observations, not a guarantee of unique encoded frames. Final output uses constant frame rate without motion interpolation.' };
|
|
143
453
|
}
|
|
144
454
|
|
|
455
|
+
/** Animation frames per second below which the page in a Final visibly jumps. */
|
|
456
|
+
const SLOW_PAGE_FRAMES = 20;
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Warns when the browser fell behind during Capture: the page got fewer than SLOW_PAGE_FRAMES animation
|
|
460
|
+
* frames in at least two whole seconds. The Source's own frames cannot tell, since a still page sends few.
|
|
461
|
+
* A second that a navigation or reload touches is left out, since no document draws while one loads.
|
|
462
|
+
* At resolution scale 1 the Take cannot be helped by lowering it again. `tab`, the Timeline's Tab,
|
|
463
|
+
* is named in a Take with several Tabs.
|
|
464
|
+
*/
|
|
465
|
+
export function captureWarnings(capture, scale, tab = null) {
|
|
466
|
+
const loading = second => (capture.navigations ?? []).some(load => load.t < second + 1 && load.end >= second);
|
|
467
|
+
const whole = (capture.pageFrames ?? []).slice(0, Math.floor(capture.duration)).filter((_, second) => !loading(second));
|
|
468
|
+
const slow = whole.filter(n => n < SLOW_PAGE_FRAMES);
|
|
469
|
+
if (slow.length < 2) return [];
|
|
470
|
+
const fix = scale > 1
|
|
471
|
+
? 'Record again with capture: { resolutionScale: 1 } in the Scenario, or close other work'
|
|
472
|
+
: 'Capture already used resolutionScale 1: close other work, use a smaller viewport, or record on a machine with a GPU';
|
|
473
|
+
const lead = tab ? `In Tab ${tab.id}, opened at ${tab.opened.toFixed(2)} s, the browser` : 'The browser';
|
|
474
|
+
return [`${lead} fell behind during Capture: the page got fewer than ${SLOW_PAGE_FRAMES} frames per second for ${slow.length} of ${whole.length} s (lowest ${Math.min(...slow)}), so the page in the Final jumps while the Cursor moves smoothly. ${fix}.`];
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Warns when input landed inside an iframe Capture could not place exactly: one rotated, skewed or
|
|
479
|
+
* 3D-transformed, placed as if it were only scaled, or one it could not place at all, which the Cursor
|
|
480
|
+
* and camera do not follow.
|
|
481
|
+
*/
|
|
482
|
+
export function timelineWarnings(timeline) {
|
|
483
|
+
const { turned = [], unplaced = [] } = timeline.frameInput ?? {};
|
|
484
|
+
const at = times => times.slice(0, 5).map(t => `${t.toFixed(2)} s`).join(', ') + (times.length > 5 ? ` and ${times.length - 5} more` : '');
|
|
485
|
+
return [
|
|
486
|
+
turned.length && `Input at ${at(turned)} landed inside an iframe that is rotated, skewed or 3D-transformed, which Capture places as if it were only scaled, so the Cursor and camera there may sit off what the page shows. Check those moments with frame, and record again once the iframe is upright, after any opening animation.`,
|
|
487
|
+
unplaced.length && `Input at ${at(unplaced)} landed inside an iframe Capture could not place, so the Cursor and camera do not follow it there. Check those moments with frame.`,
|
|
488
|
+
].filter(Boolean);
|
|
489
|
+
}
|
|
490
|
+
|
|
145
491
|
export async function verifyTake(directory) {
|
|
146
492
|
const dir = resolve(directory);
|
|
147
|
-
const { project, config, timeline, edit } = await loadTake(dir);
|
|
148
|
-
const
|
|
149
|
-
const
|
|
150
|
-
const
|
|
493
|
+
const { project, config, timeline, edit, narration } = await loadTake(dir);
|
|
494
|
+
const spoken = narrationForRender(edit, narration, dir);
|
|
495
|
+
const media = await inspectFinal(join(dir, 'final.mp4'), spoken?.lines ?? []);
|
|
496
|
+
const { fps } = edit.output, map = timeMap(edit.fastForward, project.duration);
|
|
497
|
+
const expected = { ...outputSize(edit), fps, frames: Math.round(map.duration * fps) };
|
|
151
498
|
const problems = [
|
|
152
499
|
media.width !== expected.width || media.height !== expected.height ? `size ${media.width}×${media.height}, expected ${expected.width}×${expected.height}` : null,
|
|
153
500
|
Math.abs(media.fps - expected.fps) > 0.01 ? `${media.fps} fps, expected ${expected.fps}` : null,
|
|
154
501
|
media.packets !== expected.frames ? `${media.packets} frames, expected ${expected.frames}` : null,
|
|
155
502
|
media.decodedFrames !== media.packets ? `only ${media.decodedFrames} of ${media.packets} frames decoded` : null,
|
|
503
|
+
...(spoken ? await narrationProblems(dir, edit, spoken, media, map, expected.frames / fps) : []),
|
|
156
504
|
].filter(Boolean);
|
|
157
505
|
if (problems.length) throw new Error(`Final failed verification: ${problems.join('; ')}`);
|
|
158
|
-
const capture = await readJson(join(dir, 'capture.json'));
|
|
159
|
-
const
|
|
506
|
+
const capture = await readJson(join(dir, 'capture.json')), several = capture.tabs.length > 1;
|
|
507
|
+
const tabOf = id => timeline.tabs.find(tab => tab.id === id);
|
|
508
|
+
const { lines, ...final } = media;
|
|
509
|
+
const verification = {
|
|
510
|
+
passed: true, checkedAt: new Date().toISOString(), media: final,
|
|
511
|
+
warnings: [...capture.tabs.flatMap(stats => captureWarnings(stats, config.capture.resolutionScale, several ? tabOf(stats.tab) : null)), ...timelineWarnings(timeline), ...maskWarnings(edit.masks, timeline.elements), ...(timeline.windows ? desktopWarnings(timeline, capture.tabs[0]) : [])],
|
|
512
|
+
sources: capture.tabs.map(stats => ({ tab: stats.tab, settings: stats.settings, ...summarizeFrames(stats.frames, stats.duration), ...(stats.pageFrames && { pageFramesPerSecond: stats.pageFrames }) })), fullDecode: 'passed',
|
|
513
|
+
...(spoken && { narration: { lines: spoken.lines.map(({ id, start }) => ({ id, start, duration: lines.find(line => line.id === id).duration })), subtitles: SUBTITLE_FILES.map(([name]) => name), burned: burnsIn(edit.subtitles) } }),
|
|
514
|
+
};
|
|
160
515
|
await writeJson(join(dir, 'verification.json'), verification);
|
|
161
516
|
await writeJson(join(dir, 'project.json'), { ...project, status: 'verified' });
|
|
162
517
|
return verification;
|