cuetake 0.4.0 → 0.6.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 +5 -5
- package/examples/tabs.mjs +88 -0
- package/helper/bin/cuetake-capture +0 -0
- package/package.json +5 -3
- 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 +3 -2
- package/src/camera.js +80 -33
- package/src/cli.js +29 -13
- package/src/cursor.js +24 -4
- package/src/desktop.js +108 -0
- package/src/director.js +340 -35
- package/src/edit.js +74 -16
- package/src/environment.js +34 -2
- package/src/follow-tabs.js +64 -0
- package/src/frames.js +41 -0
- package/src/home.js +23 -0
- package/src/look.js +36 -31
- package/src/mac-keys.js +47 -0
- package/src/masks.js +140 -0
- package/src/motion.js +13 -4
- package/src/pipeline.js +253 -48
- package/src/probe.js +315 -73
- package/src/recorder.js +46 -13
- package/src/render-page.js +545 -151
- package/src/render.js +38 -14
- package/src/shutter.js +42 -0
- package/src/styles/browser.js +2 -1
- package/src/styles/fast-forward.js +22 -0
- package/src/styles.js +3 -2
- package/src/tab-capture.js +225 -77
- package/src/tabs.js +126 -0
- package/src/time-map.js +106 -0
- package/src/uninstall.js +22 -9
package/src/masks.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Masks, shared by Node and the render page. Pure functions, no imports.
|
|
3
|
+
*
|
|
4
|
+
* A Mask hides or points at a region of a Tab's page for a span of the Take: `blur` blurs it past
|
|
5
|
+
* reading, `cover` fills it with a solid color, and `spotlight` dims everything outside it. A mask
|
|
6
|
+
* names either a fixed `box` in its Tab's CSS pixels, or an `element`: one of the Timeline's
|
|
7
|
+
* `elements`, whose boxes Capture recorded over time. Its `start` and `end` are Source seconds; without
|
|
8
|
+
* them it runs from the start or to the end of the Take. Masks sit on the page under the camera.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Each effect's parameters: `padding`, `radius` (corner), `blur` and `feather` (how far the light
|
|
13
|
+
* falls off across the region's edge) in CSS px; `color` as '#rrggbb'; `dim`, the share of light taken
|
|
14
|
+
* from the rest of the frame; `ease` in Final seconds.
|
|
15
|
+
*/
|
|
16
|
+
export const MASK_EFFECTS = {
|
|
17
|
+
blur: { blur: 16, padding: 4, radius: 6 },
|
|
18
|
+
cover: { color: '#000000', padding: 4, radius: 6 },
|
|
19
|
+
spotlight: { dim: 0.6, padding: 8, radius: 10, feather: 16, ease: 0.3 },
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** The effects, as messages list them: "blur, cover or spotlight". */
|
|
23
|
+
export const EFFECT_NAMES = Object.keys(MASK_EFFECTS).join(', ').replace(/, (\w+)$/, ' or $1');
|
|
24
|
+
|
|
25
|
+
// Seconds before and after a moment whose boxes a blur or cover also hides. Tab capture shows a
|
|
26
|
+
// change tens of milliseconds after the page made it, more on a busy machine, so the Source can still
|
|
27
|
+
// show an element where it was after its box has moved. Capture sees an element the page replaced
|
|
28
|
+
// elsewhere, or one in a new document, only when the Director next watches it (director.js).
|
|
29
|
+
const SLACK = { before: 0.2, after: 0.25 };
|
|
30
|
+
|
|
31
|
+
/** Below this many CSS px, a blur leaves body text readable. */
|
|
32
|
+
const LEAST_BLUR = 8;
|
|
33
|
+
|
|
34
|
+
const isColor = value => typeof value === 'string' && /^#[0-9a-f]{6}$/i.test(value);
|
|
35
|
+
const isBox = box => box && ['x', 'y', 'width', 'height'].every(key => typeof box[key] === 'number' && Number.isFinite(box[key])) && box.width > 0 && box.height > 0;
|
|
36
|
+
|
|
37
|
+
/** A mask as messages name it, such as "Mask 2 (blur from 1.20 s)". */
|
|
38
|
+
const nameOf = (mask, i) => `Mask ${i} (${mask.effect}${typeof mask.start === 'number' ? ` from ${mask.start.toFixed(2)} s` : ''})`;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* What stops Render from masking as the Edit asks, each naming its mask: an unknown effect, a mask
|
|
42
|
+
* with neither or both of a box and an element the Timeline recorded (`elements`), a box on a Tab the
|
|
43
|
+
* Take does not show (`tabs`, their ids, when given), an empty span, a color that is not '#rrggbb', or
|
|
44
|
+
* a blur too weak to hide text. A mask Render cannot draw would show what it hides, so any of these stops it.
|
|
45
|
+
*/
|
|
46
|
+
export function maskProblems(masks = [], elements = [], tabs = null) {
|
|
47
|
+
if (!Array.isArray(masks)) return ['masks must be a list of masks'];
|
|
48
|
+
const ids = new Set(elements.map(element => element.id));
|
|
49
|
+
return masks.flatMap((mask, i) => {
|
|
50
|
+
if (!(mask?.effect in MASK_EFFECTS)) return [`Mask ${i} has effect '${mask?.effect}'; use ${EFFECT_NAMES}`];
|
|
51
|
+
const name = nameOf(mask, i), problems = [];
|
|
52
|
+
if (mask.element !== undefined && mask.box !== undefined) problems.push(`${name} names both a box and an element; keep one`);
|
|
53
|
+
else if (mask.element !== undefined) { if (!ids.has(mask.element)) problems.push(`${name} follows element ${mask.element}, which the Timeline does not record`); }
|
|
54
|
+
else if (!isBox(mask.box)) problems.push(`${name} needs a box { x, y, width, height } in CSS pixels, or the element a Scenario masked`);
|
|
55
|
+
else if (tabs && !tabs.includes(mask.tab ?? 0)) problems.push(`${name} is on Tab ${mask.tab}, which the Take does not show; its Tabs are ${tabs.join(', ')}`);
|
|
56
|
+
if (mask.color !== undefined && !isColor(mask.color)) problems.push(`${name} has color '${mask.color}'; use '#rrggbb'`);
|
|
57
|
+
const { start = 0, end = Infinity } = mask;
|
|
58
|
+
if (!(typeof start === 'number' && typeof end === 'number' && end > start)) problems.push(`${name} needs a start before its end, in seconds`);
|
|
59
|
+
const blur = mask.blur ?? MASK_EFFECTS.blur.blur;
|
|
60
|
+
if (mask.effect === 'blur' && !(blur >= LEAST_BLUR)) problems.push(`${name} blurs ${blur} CSS px, too little to hide text; use at least ${LEAST_BLUR}`);
|
|
61
|
+
return problems;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const padded = ({ x, y, width, height }, p) => ({ x: x - p, y: y - p, width: width + 2 * p, height: height + 2 * p });
|
|
66
|
+
const rectOf = ([x, y, width, height]) => ({ x, y, width, height });
|
|
67
|
+
|
|
68
|
+
/** The index of the last sample at or before Source time `s`, or the first: a box holds until the next one, and back to the start. */
|
|
69
|
+
function heldAt(boxes, s) {
|
|
70
|
+
let low = 0, high = boxes.length - 1, found = 0;
|
|
71
|
+
while (low <= high) { const mid = (low + high) >> 1; if (boxes[mid][0] <= s) { found = mid; low = mid + 1; } else high = mid - 1; }
|
|
72
|
+
return found;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* An element's boxes at Source time `s`, as rects: those it held then, or with `slack`, every box it
|
|
77
|
+
* held from `slack.before` seconds before to `slack.after` after. A sample `[t, ...boxes]` lists each
|
|
78
|
+
* element the locator matched, as [x, y, width, height]; one without boxes means none showed.
|
|
79
|
+
*/
|
|
80
|
+
export function elementBoxesAt(boxes, s, slack = { before: 0, after: 0 }) {
|
|
81
|
+
if (!boxes?.length) return [];
|
|
82
|
+
const from = heldAt(boxes, s - slack.before), to = heldAt(boxes, s + slack.after), seen = new Set(), rects = [];
|
|
83
|
+
for (const sample of boxes.slice(from, to + 1)) for (const box of sample.slice(1)) {
|
|
84
|
+
const key = box.join();
|
|
85
|
+
if (!seen.has(key)) { seen.add(key); rects.push(rectOf(box)); }
|
|
86
|
+
}
|
|
87
|
+
return rects;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The masks through the Final: `at(t)` lists those showing at Final time `t`, each with its index in
|
|
92
|
+
* `masks`, its Tab, its effect and parameters, its `opacity` and its `rects`, padded, in its Tab's CSS
|
|
93
|
+
* pixels. `map` is the Take's time map (time-map.js).
|
|
94
|
+
*/
|
|
95
|
+
export function maskTrack(masks = [], elements = [], map) {
|
|
96
|
+
const byId = new Map(elements.map(element => [element.id, element]));
|
|
97
|
+
const placed = masks.map((mask, index) => {
|
|
98
|
+
const { effect, box, element: id, start = 0, end = Infinity, tab = 0, ...rest } = mask;
|
|
99
|
+
const params = { ...MASK_EFFECTS[effect], ...rest }, element = byId.get(id), slack = effect === 'spotlight' ? undefined : SLACK;
|
|
100
|
+
const rects = element ? s => elementBoxesAt(element.boxes, s, slack) : () => [box];
|
|
101
|
+
return { index, tab: element ? element.tab : tab, effect, params, from: map.outputAt(start), until: end === Infinity ? map.duration : map.outputAt(end), rects };
|
|
102
|
+
});
|
|
103
|
+
return {
|
|
104
|
+
at(t) {
|
|
105
|
+
const s = map.sourceAt(t);
|
|
106
|
+
// A spotlight eases in after its start and out before its end, in Final time; a blur or cover is whole at once.
|
|
107
|
+
const opacity = ({ effect, params: { ease }, from, until }) => effect !== 'spotlight' || !(ease > 0) ? 1 : Math.max(0, Math.min(1, (t - from) / ease, (until - t) / ease));
|
|
108
|
+
return placed.filter(mask => t >= mask.from && t < mask.until).map(({ index, tab, effect, params, rects, ...mask }) => ({
|
|
109
|
+
index, tab, effect, opacity: opacity({ effect, params, ...mask }), rects: rects(s).map(r => padded(r, params.padding)), ...params,
|
|
110
|
+
})).filter(mask => mask.rects.length);
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* At most `n` of `items` (each `{ rect, ... }`), the rest merged: past `n`, they become one item, the
|
|
117
|
+
* first of them with a rect around them all, so a box that does not fit one pass is hidden more widely, never shown.
|
|
118
|
+
*/
|
|
119
|
+
export function mergedPast(items, n) {
|
|
120
|
+
if (items.length <= n) return items;
|
|
121
|
+
const rest = items.slice(n - 1);
|
|
122
|
+
const left = Math.min(...rest.map(({ rect }) => rect.x)), top = Math.min(...rest.map(({ rect }) => rect.y));
|
|
123
|
+
const right = Math.max(...rest.map(({ rect }) => rect.x + rect.width)), bottom = Math.max(...rest.map(({ rect }) => rect.y + rect.height));
|
|
124
|
+
return [...items.slice(0, n - 1), { ...rest[0], rect: { x: left, y: top, width: right - left, height: bottom - top } }];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Warnings for masks that drew nothing: each that follows an element its locator never matched on the
|
|
129
|
+
* page during its span, which usually means a locator that misses or a span before the element shows.
|
|
130
|
+
*/
|
|
131
|
+
export function maskWarnings(masks = [], elements = []) {
|
|
132
|
+
const byId = new Map(elements.map(element => [element.id, element]));
|
|
133
|
+
return masks.flatMap((mask, i) => {
|
|
134
|
+
const element = byId.get(mask.element);
|
|
135
|
+
if (!element) return [];
|
|
136
|
+
const { start = 0, end = Infinity } = mask, { boxes } = element;
|
|
137
|
+
const seen = boxes.length && (boxes[heldAt(boxes, start)].length > 1 || boxes.some(([t, ...shown]) => t > start && t < end && shown.length));
|
|
138
|
+
return seen ? [] : [`${nameOf(mask, i)} found no ${element.name} on the page during its span, so it drew nothing; check the locator, or when the element shows`];
|
|
139
|
+
});
|
|
140
|
+
}
|
package/src/motion.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* How the Director's hand moves: durations from Fitts's law, a quick start and a long settle, a
|
|
3
|
-
* slight arc, pauses around presses and Shortcuts, a held click or key
|
|
3
|
+
* slight arc, pauses around presses and Shortcuts, a held click or key, uneven typing and scrolls that
|
|
4
|
+
* flick quickly and settle long. Pure and
|
|
4
5
|
* seeded, so a Scenario moves the same way on every recording. CSS pixels and milliseconds throughout.
|
|
5
6
|
*/
|
|
6
7
|
|
|
@@ -10,7 +11,9 @@ const DRAG_SLOWDOWN = 1.5; // a held button makes people slower
|
|
|
10
11
|
const POINT_SIZE = 24; // target size for moves to a bare point
|
|
11
12
|
const BEND = 0.1, MAX_BEND = 80; // the arc's sideways offset, as a share of the distance and in CSS px
|
|
12
13
|
const LANDING = 0.15, MAX_LANDING = 8; // a click lands at most this share of its box's size, and CSS px, from the center
|
|
13
|
-
const
|
|
14
|
+
const SCROLL_MS = 300, SCROLL_MS_PER_BIT = 300, SCROLL_UNIT = 300; // a scroll takes SCROLL_MS + SCROLL_MS_PER_BIT * log2(distance / SCROLL_UNIT + 1)
|
|
15
|
+
const MAX_SCROLL_SPEED = 3000; // CSS px/s on average: a quick flick of a wheel or trackpad
|
|
16
|
+
const PAUSES = { beforePress: 120, press: 100, afterRelease: 150, afterGrab: 100, beforeDrop: 100, beforeKey: 150, afterKey: 250, afterScroll: 200 }; // press: how long a click or key is held
|
|
14
17
|
const PAUSE_JITTER = 0.25, TYPING_JITTER = 0.4, WORD_BREAK = 1.5;
|
|
15
18
|
|
|
16
19
|
/** A deterministic source of numbers in [0, 1) (mulberry32). */
|
|
@@ -31,8 +34,14 @@ export function reachMs(distance, size = POINT_SIZE, { speed = 1, drag = false }
|
|
|
31
34
|
return Math.max(fitts, distance / MAX_AVERAGE_SPEED * 1000) * (drag ? DRAG_SLOWDOWN : 1) / speed;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
/**
|
|
35
|
-
|
|
37
|
+
/** How long a person takes to scroll `distance` CSS px: longer the farther, but a long scroll flicks fast. */
|
|
38
|
+
export function scrollMs(distance, { speed = 1 } = {}) {
|
|
39
|
+
if (distance < 1) return 0;
|
|
40
|
+
return Math.max(SCROLL_MS + SCROLL_MS_PER_BIT * Math.log2(distance / SCROLL_UNIT + 1), distance / MAX_SCROLL_SPEED * 1000) / speed;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Progress along a move or scroll at time share `t`: minimum-jerk, warped so it peaks early and settles long. */
|
|
44
|
+
export const ease = t => { const u = t ** 0.75; return u * u * u * (10 - 15 * u + 6 * u * u); };
|
|
36
45
|
|
|
37
46
|
/** A move from `from` to `to`: its duration and its point at time share `t`, along a slight arc. */
|
|
38
47
|
export function reach(from, to, { size, duration, speed, drag, rand }) {
|
package/src/pipeline.js
CHANGED
|
@@ -8,22 +8,36 @@ import { renderFinal, inspectFinal, composePreview, measureLines } from './rende
|
|
|
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';
|
|
18
|
+
import { ensureHome } from './home.js';
|
|
14
19
|
import { absolute, bundle, forRender } from './styles.js';
|
|
15
20
|
import { burnsIn, cuesFor, isCjk, lineProblems, toSrt, toVtt } from './narration.js';
|
|
21
|
+
import { linesInFinal, timeMap } from './time-map.js';
|
|
22
|
+
import { maskWarnings } from './masks.js';
|
|
16
23
|
import pkg from '../package.json' with { type: 'json' };
|
|
17
24
|
|
|
18
|
-
const SCHEMA_VERSION =
|
|
19
|
-
/**
|
|
25
|
+
const SCHEMA_VERSION = 5;
|
|
26
|
+
/**
|
|
27
|
+
* Scenario config: capture settings, validated, plus styling that seeds each Take's Edit, which is not
|
|
28
|
+
* (ADR 0005). A Scenario opens a start page (`url`) or starts Apps (`app`: one App, a `.app` path or
|
|
29
|
+
* bundle id with its arguments, or a list of them sharing one Desktop), never both (ADR 0009); for Apps,
|
|
30
|
+
* `viewport` is the Desktop's size in points.
|
|
31
|
+
*/
|
|
32
|
+
const appSchema = z.object({ path: z.string().min(1), args: z.array(z.string()).default([]) }).strict();
|
|
20
33
|
export const scenarioSchema = z.object({
|
|
21
34
|
name: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
|
|
22
|
-
url: z.string().url().refine(s => /^https?:/.test(s), 'Capture requires HTTP(S)'),
|
|
35
|
+
url: z.string().url().refine(s => /^https?:/.test(s), 'Capture requires HTTP(S)').optional(),
|
|
36
|
+
app: z.union([appSchema, z.array(appSchema).min(1)]).optional(),
|
|
23
37
|
viewport: z.object({ width: evenSize, height: evenSize }).default({ width: 1440, height: 900 }),
|
|
24
38
|
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({}),
|
|
25
39
|
director: z.object({ speed: z.number().positive().default(1), seed: z.number().int().default(1) }).strict().default({}),
|
|
26
|
-
}).passthrough();
|
|
40
|
+
}).passthrough().refine(config => !config.url !== !config.app, { message: 'A Scenario names exactly one of url or app', path: ['url'] });
|
|
27
41
|
/**
|
|
28
42
|
* A Narration file: Lines in one language, each with its text, its audio (relative to the file) and
|
|
29
43
|
* optionally word timings from the speech tool and a start in seconds. Any duration it states is
|
|
@@ -87,61 +101,210 @@ function voicedLines(edit, narration, dir) {
|
|
|
87
101
|
});
|
|
88
102
|
}
|
|
89
103
|
|
|
104
|
+
/**
|
|
105
|
+
* The resolution scale Capture uses: the one the Scenario or Look chose, else 2, or 1 when doctor found
|
|
106
|
+
* Chromium drawing without a GPU, where scale 2 starves a busy page of frames.
|
|
107
|
+
*/
|
|
108
|
+
export function captureScale(chosen, gpu) {
|
|
109
|
+
if (chosen !== undefined) return { resolutionScale: chosen, lowered: false };
|
|
110
|
+
return gpu?.accelerated === false ? { resolutionScale: 1, lowered: true } : { resolutionScale: 2, lowered: false };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The Timeline from `take` (its url, viewport and scale), what Capture observed in each Tab (`observed`,
|
|
115
|
+
* 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,
|
|
116
|
+
* in that Tab's CSS pixels, and `front` events note which Tab is in front from when. Each element a
|
|
117
|
+
* Scenario masked is in `elements`, with its boxes over time, and each mask is a `mask` event.
|
|
118
|
+
*/
|
|
119
|
+
export function timelineOf(take, stopped, observed, notes, startedAtMs) {
|
|
120
|
+
const t = ms => Math.round(ms - startedAtMs) / 1000, inTab = (list, tab) => list.map(item => ({ ...item, tab }));
|
|
121
|
+
const pointer = [...[...observed].flatMap(([tab, seen]) => seen.pointer.map(sample => [...sample, tab])), ...notes.pointer.map(([ms, x, y, tab]) => [t(ms), x, y, tab])];
|
|
122
|
+
const shapes = [...observed.values()].flatMap(seen => seen.shapes).sort((a, b) => a[0] - b[0]);
|
|
123
|
+
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) };
|
|
124
|
+
// Each element a mask follows, with the boxes the probe in its Tab saw it at.
|
|
125
|
+
const elements = (notes.elements ?? []).map(element => ({ ...element, boxes: observed.get(element.tab)?.watched?.find(watched => watched.id === element.id)?.boxes ?? [] }));
|
|
126
|
+
return {
|
|
127
|
+
schemaVersion: SCHEMA_VERSION, ...take, duration: stopped.durationSeconds,
|
|
128
|
+
tabs: stopped.tabs.map(({ id, opener, opened, closed, viewport, url, start }) => ({ id, opener, opened, closed, viewport, url, start })),
|
|
129
|
+
pointer: pointer.sort((a, b) => a[0] - b[0]), shapes, ...((frameInput.turned.length || frameInput.unplaced.length) && { frameInput }), ...(elements.length && { elements }),
|
|
130
|
+
events: [
|
|
131
|
+
...[...observed].flatMap(([tab, seen]) => inTab(seen.events, tab)),
|
|
132
|
+
...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 })),
|
|
133
|
+
...(notes.scrolls ?? []).map(span => ({ type: 'scroll', ...span })),
|
|
134
|
+
...stopped.tabs.flatMap(tab => inTab(tab.navigations.map(load => ({ type: 'navigate', ...load })), tab.id)),
|
|
135
|
+
...stopped.fronts.filter(front => front.t > 0).map(front => ({ type: 'front', ...front })),
|
|
136
|
+
].sort((a, b) => a.t - b.t),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** The Apps a Scenario starts, as a list: `config.app` names one or several. */
|
|
141
|
+
export const appsOf = config => [config.app].flat().filter(Boolean);
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* The Timeline of a Take of Apps (ADR 0009) from `take` (the Apps, the Desktop's size in points as the
|
|
145
|
+
* viewport, and its scale), what the helper saw (`stopped`: the duration, the Apps' windows over time,
|
|
146
|
+
* the system cursor's shapes, each element the App focused, as `focused` events the camera follows, and
|
|
147
|
+
* the frames of each masked element, `watched`) and what the Director noted: its pointer path and
|
|
148
|
+
* 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
|
|
149
|
+
* Tab, its Desktop; positions are Desktop points.
|
|
150
|
+
*/
|
|
151
|
+
export function desktopTimelineOf({ apps, viewport, scale }, stopped, notes) {
|
|
152
|
+
// Each element a mask follows, with the boxes the helper read it at.
|
|
153
|
+
const elements = (notes.elements ?? []).map(element => ({ ...element, boxes: stopped.watched?.find(watched => watched.id === element.id)?.boxes ?? [] }));
|
|
154
|
+
return {
|
|
155
|
+
schemaVersion: SCHEMA_VERSION, apps, viewport, scale, duration: stopped.duration,
|
|
156
|
+
tabs: [{ id: 0, opener: null, opened: 0, closed: null, viewport, start: 0 }],
|
|
157
|
+
pointer: notes.pointer.map(([t, x, y]) => [t, x, y, 0]), shapes: stopped.shapes ?? [], windows: stopped.windows, ...(elements.length && { elements }),
|
|
158
|
+
events: [
|
|
159
|
+
...notes.focus.map(f => ({ type: 'focus', ...f })), ...notes.said.map(line => ({ type: 'say', ...line })), ...notes.forwarded.map(span => ({ type: 'fastForward', ...span })),
|
|
160
|
+
...notes.events.map(event => ({ ...event, tab: 0 })), ...(stopped.focused ?? []).map(f => ({ type: 'focused', ...f, tab: 0 })),
|
|
161
|
+
...(notes.masks ?? []).map(mask => ({ type: 'mask', ...mask })),
|
|
162
|
+
].sort((a, b) => a.t - b.t),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** The Source of each of a Take's Tabs, by Tab id. */
|
|
167
|
+
const sourcesOf = (dir, timeline) => Object.fromEntries(timeline.tabs.map(tab => [tab.id, join(dir, `source-${tab.id}.${timeline.windows ? 'mp4' : 'webm'}`)]));
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Refuses what does not apply to an App: an Auth profile, since the App runs with the user's own login
|
|
171
|
+
* and data; and a resolution scale, since the Desktop takes its display's (ADR 0009).
|
|
172
|
+
*/
|
|
173
|
+
function refuseForApp(given, options) {
|
|
174
|
+
if (options.authProfile) throw new Error('--auth-profile is for web pages: an App runs with the login and data it already has');
|
|
175
|
+
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');
|
|
176
|
+
if (options.headed) throw new Error('--headed is for web pages: an App always shows on the screen');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Captures a start page: the Tabs' Sources, capture.json and poster.png in `dir`; returns the Timeline, the Director's notes and the evidence. */
|
|
180
|
+
async function capturePage(scenario, config, dir, { authState, headed, voiced }) {
|
|
181
|
+
try {
|
|
182
|
+
const session = await startRecording(config.url, {
|
|
183
|
+
...config.viewport, ...config.capture, outputDir: dir, deferCapture: true, storageState: authState, headed,
|
|
184
|
+
});
|
|
185
|
+
const page = getRecordingPage(session.sessionId);
|
|
186
|
+
if (scenario.prepare) await scenario.prepare(page);
|
|
187
|
+
await page.evaluate(() => document.fonts.ready);
|
|
188
|
+
const capture = await beginCapture(session.sessionId);
|
|
189
|
+
const startedAtMs = Date.parse(capture.startedAt);
|
|
190
|
+
const notes = { focus: [], wide: [], said: [], forwarded: [], pointer: [], elements: [], masks: [] };
|
|
191
|
+
const ran = new AbortController();
|
|
192
|
+
const director = createDirector(capture.tabs, { startedAt: startedAtMs, fps: config.capture.fps, voiced, ...config.director, signal: ran.signal }, notes);
|
|
193
|
+
const evidence = await scenario.run(director).finally(() => ran.abort());
|
|
194
|
+
await capture.tabs.started();
|
|
195
|
+
await capture.tabs.front.page.screenshot({ path: join(dir, 'poster.png') });
|
|
196
|
+
const observed = new Map();
|
|
197
|
+
for (const tab of capture.tabs.list()) if (tab.recorded) observed.set(tab.id, await collectTimeline(tab.page, startedAtMs));
|
|
198
|
+
const stopped = await stopRecording(session.sessionId);
|
|
199
|
+
for (const tab of stopped.tabs) await fs.rename(tab.webmPath, join(dir, `source-${tab.id}.webm`));
|
|
200
|
+
await writeJson(join(dir, 'capture.json'), { tabs: stopped.tabs.map(tab => ({ tab: tab.id, ...tab.stats })) });
|
|
201
|
+
const timeline = timelineOf({ url: capture.url, viewport: config.viewport, scale: config.capture.resolutionScale }, stopped, observed, notes, startedAtMs);
|
|
202
|
+
return { timeline, notes, evidence };
|
|
203
|
+
} finally { await cleanup(); }
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Captures a Desktop of the Apps (ADR 0009) through the helper: source-0.mp4, capture.json and
|
|
208
|
+
* poster.png in `dir`. The Desktop records at its display's scale, which `config.capture` then holds.
|
|
209
|
+
* `prepare(page, { app })` gets the first App's first window, and every App by `app(name)`, before
|
|
210
|
+
* Capture starts, to wait for what the demo needs and arrange the windows with `setFrame`.
|
|
211
|
+
* Returns the Timeline, the Director's notes, the evidence, and the Apps the helper could not quit.
|
|
212
|
+
*/
|
|
213
|
+
async function captureApp(scenario, config, dir, { voiced, useRunning }) {
|
|
214
|
+
const { fps } = config.capture, given = appsOf(config);
|
|
215
|
+
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`);
|
|
216
|
+
const desktop = await startDesktop({ apps: given, desktop: config.viewport, fps, source: join(dir, 'source-0.mp4'), poster: join(dir, 'poster.png'), useRunning });
|
|
217
|
+
try {
|
|
218
|
+
config.capture.resolutionScale = desktop.ready.scale;
|
|
219
|
+
const apps = given.map((app, i) => ({ ...app, name: desktop.ready.apps[i].name, bundle: desktop.ready.apps[i].bundle }));
|
|
220
|
+
if (scenario.prepare) {
|
|
221
|
+
const arranged = appLocators(desktop, apps, { arrange: true });
|
|
222
|
+
await scenario.prepare(arranged.page('first'), { app: arranged.app });
|
|
223
|
+
}
|
|
224
|
+
// The pointer starts at the Desktop's top-left corner, where the Director's starts.
|
|
225
|
+
await desktop.request({ move: { x: 0, y: 0 } });
|
|
226
|
+
const startedAtMs = await desktop.start();
|
|
227
|
+
const notes = { focus: [], wide: [], said: [], forwarded: [], pointer: [], events: [], elements: [], masks: [] };
|
|
228
|
+
const ran = new AbortController();
|
|
229
|
+
const director = createAppDirector({ startedAt: startedAtMs, fps, voiced, ...config.director, helper: desktop, apps, signal: ran.signal }, notes);
|
|
230
|
+
const evidence = await scenario.run(director).finally(() => ran.abort());
|
|
231
|
+
const stopped = await desktop.stop();
|
|
232
|
+
const { width, height } = stopped.size;
|
|
233
|
+
await writeJson(join(dir, 'capture.json'), { tabs: [{
|
|
234
|
+
tab: 0, settings: { width, height, frameRate: fps }, duration: stopped.duration, dropped: stopped.dropped, otherInput: stopped.otherInput ?? [],
|
|
235
|
+
frames: stopped.frames.map(([t, scale]) => ({ timeMs: Math.round(t * 1e6) / 1000, scale })),
|
|
236
|
+
}] });
|
|
237
|
+
const timeline = desktopTimelineOf({ apps, viewport: config.viewport, scale: desktop.ready.scale }, stopped, notes);
|
|
238
|
+
return { timeline, notes, evidence, unquit: stopped.unquit ?? [], running: desktop.ready.apps.filter(app => app.running).map(app => app.name) };
|
|
239
|
+
} finally { desktop.kill(); }
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* What `record` reports of the Apps after a Take, or null when there is nothing to report: those it
|
|
244
|
+
* started that did not quit (`unquit`), and those the user runs that it recorded as they were (`running`).
|
|
245
|
+
*/
|
|
246
|
+
export function appReport({ unquit, running }) {
|
|
247
|
+
const notes = [];
|
|
248
|
+
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.`);
|
|
249
|
+
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.`);
|
|
250
|
+
if (!notes.length) return null;
|
|
251
|
+
return { ...(unquit.length && { quit: false, unquit }), ...(running.length && { running }), note: notes.join(' ') };
|
|
252
|
+
}
|
|
253
|
+
|
|
90
254
|
/** New take directories are exclusive: reruns never overwrite a previous take. */
|
|
91
255
|
export async function recordScenario(scenarioPath, outputDir, options = {}) {
|
|
92
256
|
const scenario = await import(pathToFileURL(resolve(scenarioPath)).href);
|
|
93
257
|
// A Look sits under the Scenario: every field the config names wins over it. File refs resolve
|
|
94
258
|
// against the Look and the Scenario file, and the files are copied into the Take.
|
|
95
259
|
const look = options.look ? await loadLook(options.look) : null;
|
|
96
|
-
const
|
|
260
|
+
const given = merge(look ? resolvedLook(look) : {}, absolute(scenario.config, dirname(resolve(scenarioPath))));
|
|
261
|
+
const config = scenarioSchema.parse(given);
|
|
97
262
|
if (typeof scenario.run !== 'function') throw new Error('Scenario must export run(director)');
|
|
263
|
+
if (config.app) refuseForApp(given, options);
|
|
264
|
+
else if (options.useRunning) throw new Error('--use-running is for Apps: it records an App the user already runs, as it is');
|
|
265
|
+
// A relative .app path names an App beside the Scenario.
|
|
266
|
+
for (const app of appsOf(config)) if (app.path.includes('/')) app.path = resolve(dirname(resolve(scenarioPath)), app.path);
|
|
98
267
|
const authState = options.authProfile ? await resolveAuthProfile(options.authProfile) : undefined;
|
|
99
268
|
const ready = await doctor();
|
|
100
269
|
if (!ready.ok) throw new Error(JSON.stringify(ready));
|
|
101
|
-
|
|
270
|
+
if (config.app && !ready.apps?.ok) {
|
|
271
|
+
const missing = ready.apps ? ready.checks.filter(check => !check.ok).map(check => `${check.name}: ${check.fix}`) : ['Recording an App needs macOS'];
|
|
272
|
+
throw new Error(`This Mac cannot record an App yet. ${missing.join(' ')} Nothing was requested; run cuetake doctor after the change.`);
|
|
273
|
+
}
|
|
274
|
+
const gpu = ready.checks.find(check => check.name === 'gpu');
|
|
275
|
+
const { resolutionScale, lowered } = config.app ? { resolutionScale: config.capture.resolutionScale, lowered: false } : captureScale(given.capture?.resolutionScale, gpu);
|
|
276
|
+
config.capture.resolutionScale = resolutionScale;
|
|
277
|
+
const dir = resolve(outputDir || join(await ensureHome(), 'takes', config.name, new Date().toISOString().replace(/[:.]/g, '-')));
|
|
102
278
|
await fs.mkdir(resolve(dir, '..'), { recursive: true });
|
|
103
279
|
await fs.mkdir(dir); // EEXIST is intentional, including for empty existing folders.
|
|
104
280
|
let project = { schemaVersion: SCHEMA_VERSION, tool: 'CueTake', version: pkg.version, createdAt: new Date().toISOString(), status: 'recording', authenticated: Boolean(authState), ...(look && { look: look.name }), config };
|
|
105
281
|
await writeJson(join(dir, 'project.json'), project);
|
|
106
282
|
await fs.copyFile(resolve(scenarioPath), join(dir, 'scenario.mjs'));
|
|
107
|
-
let unplaced = [], unvoiced = [];
|
|
283
|
+
let unplaced = [], unvoiced = [], captured;
|
|
108
284
|
try {
|
|
109
285
|
// The Narration is voiced before Capture, so d.say can hold each Line for its audio (ADR 0006).
|
|
110
286
|
const imported = options.narration ? await intoTakeNarration(options.narration, dir) : null;
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
const page = getRecordingPage(session.sessionId);
|
|
115
|
-
if (scenario.prepare) await scenario.prepare(page);
|
|
116
|
-
await page.evaluate(() => document.fonts.ready);
|
|
117
|
-
const capture = await beginCapture(session.sessionId);
|
|
118
|
-
const startedAtMs = Date.parse(capture.startedAt);
|
|
119
|
-
const focus = [], wide = [], said = [];
|
|
120
|
-
const director = createDirector(page, startedAtMs, config.capture.fps, focus, wide, said, imported && new Map(Object.entries(imported.durations)), config.director);
|
|
121
|
-
const evidence = await scenario.run(director);
|
|
122
|
-
await page.screenshot({ path: join(dir, 'poster.png') });
|
|
123
|
-
const observed = await collectTimeline(page, startedAtMs);
|
|
124
|
-
const stopped = await stopRecording(session.sessionId);
|
|
125
|
-
await fs.rename(stopped.webmPath, join(dir, 'source.webm'));
|
|
126
|
-
await fs.rename(stopped.webmPath.replace(/\.webm$/, '-capture.json'), join(dir, 'capture.json'));
|
|
127
|
-
const timeline = {
|
|
128
|
-
schemaVersion: SCHEMA_VERSION, viewport: config.viewport, scale: config.capture.resolutionScale, duration: stopped.durationSeconds,
|
|
129
|
-
pointer: observed.pointer, shapes: observed.shapes, events: [...observed.events, ...focus.map(f => ({ type: 'focus', ...f })), ...said.map(line => ({ type: 'say', ...line }))].sort((a, b) => a.t - b.t),
|
|
130
|
-
};
|
|
287
|
+
const voiced = imported && new Map(Object.entries(imported.durations));
|
|
288
|
+
captured = config.app ? await captureApp(scenario, config, dir, { voiced, useRunning: options.useRunning }) : await capturePage(scenario, config, dir, { authState, headed: options.headed, voiced });
|
|
289
|
+
const { timeline, notes: { focus, wide }, evidence } = captured;
|
|
131
290
|
await writeJson(join(dir, 'timeline.json'), timeline);
|
|
132
291
|
let edit = createEdit(config, timeline, focus, wide);
|
|
133
292
|
if (imported) ({ edit, unplaced } = placeLines(edit, imported.narration));
|
|
134
293
|
else unvoiced = edit.narration.lines.map(line => line.id);
|
|
135
294
|
await writeJson(join(dir, 'edit.json'), await intoTake(edit, dir));
|
|
136
|
-
project = { ...project, status: 'captured', duration:
|
|
295
|
+
project = { ...project, status: 'captured', duration: timeline.duration, evidence: evidence ?? null };
|
|
137
296
|
await writeJson(join(dir, 'project.json'), project);
|
|
138
297
|
} catch (error) {
|
|
139
298
|
await writeJson(join(dir, 'project.json'), { ...project, status: 'failed', error: error.message });
|
|
140
299
|
throw error;
|
|
141
|
-
}
|
|
300
|
+
}
|
|
142
301
|
await renderTake(dir);
|
|
143
302
|
const verification = await verifyTake(dir);
|
|
144
|
-
return { directory: dir, final: join(dir, 'final.mp4'), verification,
|
|
303
|
+
return { directory: dir, final: join(dir, 'final.mp4'), verification,
|
|
304
|
+
...(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` } }),
|
|
305
|
+
...(config.app && { capture: { resolutionScale: config.capture.resolutionScale, note: 'The Desktop records at the scale of the display it sits on' } }),
|
|
306
|
+
...(config.app && appReport(captured) && { app: appReport(captured) }),
|
|
307
|
+
...(unplaced.length && { unplaced: { lines: unplaced, note: 'These Lines were never said and have no start; add d.say or a start in edit.json' } }),
|
|
145
308
|
...(unvoiced.length && { unvoiced: { lines: unvoiced, note: `These Lines have no audio yet; voice them and run cuetake narrate import ${dir} <narration.json>` } }) };
|
|
146
309
|
}
|
|
147
310
|
|
|
@@ -154,12 +317,13 @@ export async function importNarration(directory, file) {
|
|
|
154
317
|
const dir = resolve(directory);
|
|
155
318
|
const { timeline, edit } = await loadTake(dir);
|
|
156
319
|
const { narration, durations } = await intoTakeNarration(file, dir);
|
|
157
|
-
const end = Math.round(timeline.duration * edit.output.fps) / edit.output.fps;
|
|
158
320
|
const { edit: next, unplaced } = placeLines(edit, narration);
|
|
159
321
|
await writeJson(join(dir, 'edit.json'), next);
|
|
160
322
|
const lines = next.narration.lines.filter(line => line.id in durations).map(line => ({ ...line, duration: durations[line.id] }));
|
|
161
323
|
const missing = next.narration.lines.filter(line => !(line.id in durations)).map(line => line.id);
|
|
162
|
-
const
|
|
324
|
+
const map = timeMap(next.fastForward, timeline.duration), end = Math.round(map.duration * next.output.fps) / next.output.fps;
|
|
325
|
+
const inFinal = linesInFinal(lines, map);
|
|
326
|
+
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`)];
|
|
163
327
|
return { narration: join(dir, 'narration', 'narration.json'), lines, unplaced, problems, next: `cuetake render ${dir}` };
|
|
164
328
|
}
|
|
165
329
|
|
|
@@ -193,17 +357,19 @@ function narrationForRender(edit, narration, dir) {
|
|
|
193
357
|
|
|
194
358
|
/**
|
|
195
359
|
* Writes preview.png: the Take's current Edit beside each Look (names or JSON files), composed with a
|
|
196
|
-
* 1080-pixel short side in each output's own proportions.
|
|
360
|
+
* 1080-pixel short side in each output's own proportions. `at` is seconds of the Final; without it the
|
|
361
|
+
* Preview shows the last moment with the camera wide.
|
|
197
362
|
*/
|
|
198
363
|
export async function previewTake(directory, refs = [], { at } = {}) {
|
|
199
364
|
const dir = resolve(directory);
|
|
200
365
|
const { config, timeline, edit, narration } = await loadTake(dir);
|
|
201
|
-
|
|
202
|
-
|
|
366
|
+
const length = timeMap(edit.fastForward, timeline.duration).duration;
|
|
367
|
+
if (at !== undefined && !(at >= 0 && at <= length)) throw new Error(`--at must be between 0 and ${+length.toFixed(3)} seconds of the Final`);
|
|
368
|
+
const host = config.url && new URL(config.url).host;
|
|
203
369
|
const looks = await Promise.all(refs.map(ref => loadLook(ref)));
|
|
204
370
|
const tiles = [{ name: 'current', edit }, ...looks.map(look => ({ name: look.name, edit: applyLook(edit, resolvedLook(look), host) }))];
|
|
205
371
|
const files = {}, shown = tiles.map(({ name, edit }) => ({ name, edit: forRender(atShortSide(edit, 1080), dir, files).edit }));
|
|
206
|
-
const png = await composePreview({
|
|
372
|
+
const png = await composePreview({ sources: sourcesOf(dir, timeline), timeline, at, tiles: shown, files, narration: narrationForRender(edit, narration, dir) });
|
|
207
373
|
const preview = join(dir, 'preview.png');
|
|
208
374
|
await fs.writeFile(preview, png);
|
|
209
375
|
return { preview, at: at ?? 'end, camera wide', tiles: tiles.map(({ name, edit }) => ({ name, summary: summarize(lookFromEdit(edit)) })) };
|
|
@@ -214,12 +380,12 @@ export async function applyLookToTake(ref, directory) {
|
|
|
214
380
|
const dir = resolve(directory);
|
|
215
381
|
const { config, edit } = await loadTake(dir);
|
|
216
382
|
const look = await loadLook(ref);
|
|
217
|
-
const next = await intoTake(applyLook(edit, resolvedLook(look), new URL(config.url).host), dir);
|
|
383
|
+
const next = await intoTake(applyLook(edit, resolvedLook(look), config.url && new URL(config.url).host), dir);
|
|
218
384
|
await writeJson(join(dir, 'edit.json'), next);
|
|
219
385
|
return { look: look.name, edit: join(dir, 'edit.json'), summary: summarize(lookFromEdit(next)), next: `cuetake render ${dir}` };
|
|
220
386
|
}
|
|
221
387
|
|
|
222
|
-
/** Saves the Take's styling as a Look,
|
|
388
|
+
/** Saves the Take's styling as a Look in the Home, or the user Home when `global`. */
|
|
223
389
|
export async function saveLookFromTake(name, directory, options) {
|
|
224
390
|
const dir = resolve(directory), { edit } = await loadTake(dir);
|
|
225
391
|
return saveLook(name, lookFromEdit(edit), { ...options, from: dir });
|
|
@@ -239,7 +405,7 @@ export async function renderTake(directory) {
|
|
|
239
405
|
// Render to a temporary output; preserve the last complete final if encoding fails.
|
|
240
406
|
const temporary = join(dir, 'final.pending.mp4');
|
|
241
407
|
try {
|
|
242
|
-
const render = await renderFinal({
|
|
408
|
+
const render = await renderFinal({ sources: sourcesOf(dir, timeline), finalPath: temporary, timeline, ...forRender(edit, dir), narration: spoken });
|
|
243
409
|
await fs.rename(temporary, join(dir, 'final.mp4'));
|
|
244
410
|
await writeSubtitles(dir, render.subtitles?.map(({ frames, ...cue }) => cue) ?? null);
|
|
245
411
|
await writeJson(join(dir, 'render.json'), render);
|
|
@@ -254,7 +420,7 @@ export async function renderTake(directory) {
|
|
|
254
420
|
* Line, Lines that do not fit, subtitle files that do not match the Lines, and burned-in Subtitles
|
|
255
421
|
* Render did not draw for a Line.
|
|
256
422
|
*/
|
|
257
|
-
async function narrationProblems(dir, edit, narration, media, end) {
|
|
423
|
+
async function narrationProblems(dir, edit, narration, media, map, end) {
|
|
258
424
|
const problems = [], fps = edit.output.fps;
|
|
259
425
|
if (!media.audio) return ['no audio track, though the Edit places Lines'];
|
|
260
426
|
if (media.audio.error) problems.push(`the audio track does not decode: ${media.audio.error}`);
|
|
@@ -262,8 +428,8 @@ async function narrationProblems(dir, edit, narration, media, end) {
|
|
|
262
428
|
const measured = new Map(media.lines.map(line => [line.id, line]));
|
|
263
429
|
for (const line of media.lines) if (line.error) problems.push(line.error);
|
|
264
430
|
if (problems.length) return problems;
|
|
265
|
-
const
|
|
266
|
-
problems.push(...lineProblems(lines, end));
|
|
431
|
+
const inFinal = linesInFinal(narration.lines.map(line => ({ ...line, duration: measured.get(line.id).duration })), map), { lines } = inFinal;
|
|
432
|
+
problems.push(...inFinal.problems, ...lineProblems(lines, end));
|
|
267
433
|
if (problems.length) return problems;
|
|
268
434
|
const cues = cuesFor(lines, narration.language, edit.subtitles, end);
|
|
269
435
|
for (const [name, format] of SUBTITLE_FILES) {
|
|
@@ -287,25 +453,64 @@ export function summarizeFrames(frames, duration) {
|
|
|
287
453
|
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.' };
|
|
288
454
|
}
|
|
289
455
|
|
|
456
|
+
/** Animation frames per second below which the page in a Final visibly jumps. */
|
|
457
|
+
const SLOW_PAGE_FRAMES = 20;
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Warns when the browser fell behind during Capture: the page got fewer than SLOW_PAGE_FRAMES animation
|
|
461
|
+
* frames in at least two whole seconds. The Source's own frames cannot tell, since a still page sends few.
|
|
462
|
+
* A second that a navigation or reload touches is left out, since no document draws while one loads.
|
|
463
|
+
* At resolution scale 1 the Take cannot be helped by lowering it again. `tab`, the Timeline's Tab,
|
|
464
|
+
* is named in a Take with several Tabs.
|
|
465
|
+
*/
|
|
466
|
+
export function captureWarnings(capture, scale, tab = null) {
|
|
467
|
+
const loading = second => (capture.navigations ?? []).some(load => load.t < second + 1 && load.end >= second);
|
|
468
|
+
const whole = (capture.pageFrames ?? []).slice(0, Math.floor(capture.duration)).filter((_, second) => !loading(second));
|
|
469
|
+
const slow = whole.filter(n => n < SLOW_PAGE_FRAMES);
|
|
470
|
+
if (slow.length < 2) return [];
|
|
471
|
+
const fix = scale > 1
|
|
472
|
+
? 'Record again with capture: { resolutionScale: 1 } in the Scenario, or close other work'
|
|
473
|
+
: 'Capture already used resolutionScale 1: close other work, use a smaller viewport, or record on a machine with a GPU';
|
|
474
|
+
const lead = tab ? `In Tab ${tab.id}, opened at ${tab.opened.toFixed(2)} s, the browser` : 'The browser';
|
|
475
|
+
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}.`];
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Warns when input landed inside an iframe Capture could not place exactly: one rotated, skewed or
|
|
480
|
+
* 3D-transformed, placed as if it were only scaled, or one it could not place at all, which the Cursor
|
|
481
|
+
* and camera do not follow.
|
|
482
|
+
*/
|
|
483
|
+
export function timelineWarnings(timeline) {
|
|
484
|
+
const { turned = [], unplaced = [] } = timeline.frameInput ?? {};
|
|
485
|
+
const at = times => times.slice(0, 5).map(t => `${t.toFixed(2)} s`).join(', ') + (times.length > 5 ? ` and ${times.length - 5} more` : '');
|
|
486
|
+
return [
|
|
487
|
+
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.`,
|
|
488
|
+
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.`,
|
|
489
|
+
].filter(Boolean);
|
|
490
|
+
}
|
|
491
|
+
|
|
290
492
|
export async function verifyTake(directory) {
|
|
291
493
|
const dir = resolve(directory);
|
|
292
|
-
const { project, edit, narration } = await loadTake(dir);
|
|
494
|
+
const { project, config, timeline, edit, narration } = await loadTake(dir);
|
|
293
495
|
const spoken = narrationForRender(edit, narration, dir);
|
|
294
496
|
const media = await inspectFinal(join(dir, 'final.mp4'), spoken?.lines ?? []);
|
|
295
|
-
const { fps } = edit.output;
|
|
296
|
-
const expected = { ...outputSize(edit), fps, frames: Math.round(
|
|
497
|
+
const { fps } = edit.output, map = timeMap(edit.fastForward, project.duration);
|
|
498
|
+
const expected = { ...outputSize(edit), fps, frames: Math.round(map.duration * fps) };
|
|
297
499
|
const problems = [
|
|
298
500
|
media.width !== expected.width || media.height !== expected.height ? `size ${media.width}×${media.height}, expected ${expected.width}×${expected.height}` : null,
|
|
299
501
|
Math.abs(media.fps - expected.fps) > 0.01 ? `${media.fps} fps, expected ${expected.fps}` : null,
|
|
300
502
|
media.packets !== expected.frames ? `${media.packets} frames, expected ${expected.frames}` : null,
|
|
301
503
|
media.decodedFrames !== media.packets ? `only ${media.decodedFrames} of ${media.packets} frames decoded` : null,
|
|
302
|
-
...(spoken ? await narrationProblems(dir, edit, spoken, media, expected.frames / fps) : []),
|
|
504
|
+
...(spoken ? await narrationProblems(dir, edit, spoken, media, map, expected.frames / fps) : []),
|
|
303
505
|
].filter(Boolean);
|
|
304
506
|
if (problems.length) throw new Error(`Final failed verification: ${problems.join('; ')}`);
|
|
305
|
-
const capture = await readJson(join(dir, 'capture.json'));
|
|
507
|
+
const capture = await readJson(join(dir, 'capture.json')), several = capture.tabs.length > 1;
|
|
508
|
+
const tabOf = id => timeline.tabs.find(tab => tab.id === id);
|
|
306
509
|
const { lines, ...final } = media;
|
|
307
510
|
const verification = {
|
|
308
|
-
passed: true, checkedAt: new Date().toISOString(), media: final,
|
|
511
|
+
passed: true, checkedAt: new Date().toISOString(), media: final,
|
|
512
|
+
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]) : [])],
|
|
513
|
+
sources: capture.tabs.map(stats => ({ tab: stats.tab, settings: stats.settings, ...summarizeFrames(stats.frames, stats.duration), ...(stats.pageFrames && { pageFramesPerSecond: stats.pageFrames }) })), fullDecode: 'passed',
|
|
309
514
|
...(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) } }),
|
|
310
515
|
};
|
|
311
516
|
await writeJson(join(dir, 'verification.json'), verification);
|