@slidevideo/cli 0.1.2 → 0.2.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/CHANGELOG.md +34 -0
- package/IMPRESSUM.md +18 -4
- package/LICENSE-TERMS.md +46 -13
- package/README.md +3 -3
- package/addons/slidevideo/global-top.vue +1 -1
- package/addons/slidevideo/playback-entries.ts +1 -1
- package/addons/slidevideo/preview.ts +2 -2
- package/dist/adapters/browser-runtime.d.ts +3 -0
- package/dist/adapters/elevenlabs.d.ts +1 -0
- package/dist/adapters/elevenlabs.js +8 -4
- package/dist/adapters/powerpoint.d.ts +1 -1
- package/dist/adapters/powerpoint.js +10 -11
- package/dist/adapters/slidev-inspection.js +2 -4
- package/dist/adapters/slidev-server.js +136 -15
- package/dist/adapters/slidev.d.ts +9 -0
- package/dist/adapters/slidev.js +347 -62
- package/dist/annotations.d.ts +1 -1
- package/dist/annotations.js +3 -3
- package/dist/assembly.d.ts +44 -38
- package/dist/assembly.js +60 -21
- package/dist/calibration.js +5 -4
- package/dist/cli.js +86 -31
- package/dist/compositor.d.ts +30 -3
- package/dist/compositor.js +196 -30
- package/dist/contracts.d.ts +6 -6
- package/dist/executables.d.ts +2 -0
- package/dist/executables.js +27 -8
- package/dist/media.d.ts +7 -1
- package/dist/media.js +23 -4
- package/dist/pipeline.d.ts +1 -1
- package/dist/pipeline.js +107 -42
- package/dist/preview/server.js +4 -4
- package/dist/run.d.ts +1 -1
- package/dist/run.js +8 -3
- package/dist/setup-install.d.ts +1 -0
- package/dist/setup-install.js +8 -1
- package/dist/setup.d.ts +26 -8
- package/dist/setup.js +168 -76
- package/dist/speech.js +10 -6
- package/dist/storyboard.js +3 -6
- package/dist/timing.js +2 -2
- package/package.json +1 -3
- package/schemas/schedule.v1.json +389 -1
- package/schemas/storyboard.v1.json +342 -1
- package/skills/slidevideo/SKILL.md +2 -2
- package/skills/slidevideo/references/production.md +7 -6
- package/skills/slidevideo/references/storyboard.md +9 -8
- package/schemas/schedule.v2.json +0 -496
- package/schemas/storyboard.v2.json +0 -802
package/dist/adapters/slidev.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import './browser-runtime.js';
|
|
2
2
|
import { chromium } from 'playwright';
|
|
3
3
|
import { spawn } from 'node:child_process';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
4
5
|
import { createServer } from 'node:net';
|
|
5
|
-
import { mkdir, writeFile } from 'node:fs/promises';
|
|
6
|
+
import { mkdir, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
6
7
|
import { dirname, join, resolve } from 'node:path';
|
|
7
8
|
import { fileURLToPath } from 'node:url';
|
|
8
9
|
import { inspectSlidev, validateSlidev } from './slidev-inspection.js';
|
|
9
10
|
import { calibrate, estimateOrigin } from '../calibration.js';
|
|
10
|
-
import { probe, saveJson, hashFile, digest, videoFramePeriod,
|
|
11
|
+
import { execute, probe, saveJson, hashFile, digest, videoFramePeriod, executionSignal } from '../media.js';
|
|
11
12
|
import { requireCondition, ProductionError } from '../errors.js';
|
|
12
13
|
import { executable } from '../executables.js';
|
|
13
14
|
function browserFailure(error, phase) {
|
|
@@ -22,11 +23,16 @@ function browserFailure(error, phase) {
|
|
|
22
23
|
}
|
|
23
24
|
export class SlidevAdapter {
|
|
24
25
|
id = 'slidev';
|
|
25
|
-
version = '53.1.0-adapter-
|
|
26
|
+
version = '53.1.0-adapter-6';
|
|
26
27
|
browser;
|
|
27
28
|
page;
|
|
28
29
|
server;
|
|
29
30
|
log = '';
|
|
31
|
+
cleanupPromise;
|
|
32
|
+
closed = false;
|
|
33
|
+
stagingDirectory;
|
|
34
|
+
rawCaptureFile;
|
|
35
|
+
captureToken;
|
|
30
36
|
schedule;
|
|
31
37
|
story;
|
|
32
38
|
directory;
|
|
@@ -34,21 +40,80 @@ export class SlidevAdapter {
|
|
|
34
40
|
production = { verify_timing: false };
|
|
35
41
|
inspect = inspectSlidev;
|
|
36
42
|
validate = validateSlidev;
|
|
37
|
-
async
|
|
43
|
+
async stopServer(server) {
|
|
44
|
+
const pid = server.pid;
|
|
45
|
+
if (server.exitCode !== null || server.signalCode !== null || !pid)
|
|
46
|
+
return;
|
|
47
|
+
if (process.platform === 'win32') {
|
|
48
|
+
await new Promise((resolve, reject) => {
|
|
49
|
+
const stop = spawn('taskkill.exe', ['/PID', String(pid), '/T', '/F'], { windowsHide: true, stdio: 'ignore' });
|
|
50
|
+
const timer = setTimeout(() => stop.kill(), 5000);
|
|
51
|
+
stop.once('error', error => { clearTimeout(timer); reject(error); });
|
|
52
|
+
stop.once('close', code => {
|
|
53
|
+
clearTimeout(timer);
|
|
54
|
+
if (code === 0 || server.exitCode !== null || server.signalCode !== null)
|
|
55
|
+
resolve();
|
|
56
|
+
else
|
|
57
|
+
reject(new ProductionError('CLEANUP', 'Could not stop the owned Slidev server process tree', 5));
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const exited = new Promise(resolve => {
|
|
63
|
+
server.once('close', () => resolve());
|
|
64
|
+
server.once('error', () => resolve());
|
|
65
|
+
});
|
|
66
|
+
const wait = async (ms) => {
|
|
67
|
+
let timer;
|
|
68
|
+
try {
|
|
69
|
+
await Promise.race([exited, new Promise(resolve => { timer = setTimeout(resolve, ms); })]);
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
clearTimeout(timer);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const signalGroup = (signal) => {
|
|
76
|
+
try {
|
|
77
|
+
process.kill(-pid, signal);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (error.code !== 'ESRCH')
|
|
81
|
+
server.kill(signal);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
signalGroup('SIGTERM');
|
|
85
|
+
await wait(3000);
|
|
86
|
+
if (server.exitCode === null && server.signalCode === null) {
|
|
87
|
+
signalGroup('SIGKILL');
|
|
88
|
+
await wait(2000);
|
|
89
|
+
}
|
|
90
|
+
if (server.exitCode === null && server.signalCode === null) {
|
|
91
|
+
throw new ProductionError('CLEANUP', 'Could not stop the owned Slidev server process', 5);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async startServer(story, mode) {
|
|
96
|
+
executionSignal()?.throwIfAborted();
|
|
97
|
+
requireCondition(!this.closed, 'INTERRUPTED', 'Slidev startup aborted', 5);
|
|
38
98
|
const port = await new Promise((resolve, reject) => {
|
|
39
99
|
const socket = createServer();
|
|
40
100
|
socket.on('error', reject);
|
|
41
101
|
socket.listen(0, '127.0.0.1', () => { const address = socket.address(); const port = typeof address === 'object' && address ? address.port : 0; socket.close(() => resolve(port)); });
|
|
42
102
|
});
|
|
43
103
|
const server = fileURLToPath(new URL('./slidev-server.js', import.meta.url));
|
|
44
|
-
this.server = spawn(process.execPath, [server, story.deck, String(port), ...(
|
|
104
|
+
this.server = spawn(process.execPath, [server, story.deck, String(port), ...(mode ? [mode.kind, mode.file] : [])], { cwd: dirname(story.deck), stdio: ['ignore', 'pipe', 'pipe'], detached: process.platform !== 'win32', windowsHide: true });
|
|
45
105
|
this.server.stdout?.on('data', data => { this.log += data.toString(); });
|
|
46
106
|
this.server.stderr?.on('data', data => { this.log += data.toString(); });
|
|
107
|
+
if (this.closed || executionSignal()?.aborted) {
|
|
108
|
+
await this.stopServer(this.server);
|
|
109
|
+
executionSignal()?.throwIfAborted();
|
|
110
|
+
throw new ProductionError('INTERRUPTED', 'Slidev startup aborted', 5);
|
|
111
|
+
}
|
|
47
112
|
const url = `http://127.0.0.1:${port}`;
|
|
48
113
|
const deadline = Date.now() + 120000;
|
|
49
114
|
let ready = false;
|
|
50
115
|
while (Date.now() < deadline) {
|
|
51
|
-
|
|
116
|
+
executionSignal()?.throwIfAborted();
|
|
52
117
|
requireCondition(this.server.exitCode === null && this.server.signalCode === null, 'SLIDEV_SERVER', 'Slidev exited before readiness', 5);
|
|
53
118
|
try {
|
|
54
119
|
if ((await fetch(url, { signal: AbortSignal.timeout(1000) })).ok) {
|
|
@@ -68,29 +133,32 @@ export class SlidevAdapter {
|
|
|
68
133
|
const mediaHashes = Object.fromEntries(await Promise.all(story.media.map(async (media) => [media.id, await hashFile(media.src)])));
|
|
69
134
|
const config = resolve(directory, 'preview.json');
|
|
70
135
|
await saveJson(config, { schedule, mediaHashes, parentOrigin });
|
|
71
|
-
const url = await this.startServer(story, config);
|
|
136
|
+
const url = await this.startServer(story, { kind: 'preview', file: config });
|
|
72
137
|
return { url: `${url}/1?slidevideo=1&slidevideo-preview=1` };
|
|
73
138
|
}
|
|
74
|
-
async start(story) {
|
|
139
|
+
async start(story, mode) {
|
|
75
140
|
const executablePath = executable('browser');
|
|
76
|
-
const url = await this.startServer(story);
|
|
77
|
-
|
|
78
|
-
this.
|
|
141
|
+
const url = await this.startServer(story, mode);
|
|
142
|
+
executionSignal()?.throwIfAborted();
|
|
143
|
+
requireCondition(!this.closed, 'INTERRUPTED', 'Browser startup aborted', 5);
|
|
144
|
+
this.browser = await chromium.launch({
|
|
145
|
+
executablePath,
|
|
146
|
+
headless: true,
|
|
147
|
+
...(this.stagingDirectory ? { downloadsPath: this.stagingDirectory } : {}),
|
|
148
|
+
args: ['--no-sandbox', '--enable-usermedia-screen-capturing', '--auto-select-tab-capture-source-by-title=SlideVideo capture', '--disable-features=WebRTCPipeWireCapturer', '--autoplay-policy=no-user-gesture-required', '--disable-dev-shm-usage'],
|
|
149
|
+
});
|
|
150
|
+
if (this.closed || executionSignal()?.aborted) {
|
|
151
|
+
await this.browser.close().catch(() => { });
|
|
152
|
+
executionSignal()?.throwIfAborted();
|
|
153
|
+
throw new ProductionError('INTERRUPTED', 'Browser startup aborted', 5);
|
|
154
|
+
}
|
|
155
|
+
this.page = await this.browser.newPage({ viewport: { width: story.output.width, height: story.output.height }, deviceScaleFactor: 1, acceptDownloads: false });
|
|
156
|
+
this.page.setDefaultNavigationTimeout(120000);
|
|
79
157
|
this.page.on('pageerror', error => { this.log += `\nBrowser error: ${error.message}`; });
|
|
80
|
-
await this.page.addInitScript(
|
|
81
|
-
const getDisplayMedia = navigator.mediaDevices.getDisplayMedia.bind(navigator.mediaDevices);
|
|
82
|
-
navigator.mediaDevices.getDisplayMedia = async (constraints) => {
|
|
83
|
-
const stream = await getDisplayMedia(constraints);
|
|
84
|
-
const track = stream.getVideoTracks()[0];
|
|
85
|
-
track.contentHint = 'motion';
|
|
86
|
-
await track.applyConstraints({ frameRate: { min: output.fps, max: output.fps, ideal: output.fps } });
|
|
87
|
-
return stream;
|
|
88
|
-
};
|
|
158
|
+
await this.page.addInitScript(() => {
|
|
89
159
|
localStorage.setItem('slidev-camera', 'none');
|
|
90
160
|
localStorage.setItem('slidev-mic', 'none');
|
|
91
|
-
|
|
92
|
-
localStorage.setItem('slidev-record-framerate', JSON.stringify(output.fps));
|
|
93
|
-
}, story.output);
|
|
161
|
+
});
|
|
94
162
|
await this.page.goto(`${url}/1?slidevideo=1`);
|
|
95
163
|
await this.page.waitForFunction(() => Boolean(window.__slidevideo), { timeout: 120000 });
|
|
96
164
|
return this.page;
|
|
@@ -107,15 +175,49 @@ export class SlidevAdapter {
|
|
|
107
175
|
await this.cleanup();
|
|
108
176
|
}
|
|
109
177
|
}
|
|
178
|
+
async stopCapture(page, durationMs) {
|
|
179
|
+
const signal = executionSignal();
|
|
180
|
+
signal?.throwIfAborted();
|
|
181
|
+
const limit = Math.max(60_000, Math.ceil(durationMs * 0.25) + 60_000);
|
|
182
|
+
let timer;
|
|
183
|
+
let onAbort;
|
|
184
|
+
try {
|
|
185
|
+
return await Promise.race([
|
|
186
|
+
page.evaluate(() => {
|
|
187
|
+
if (!window.__slidevideoCapture)
|
|
188
|
+
throw new Error('Capture session was not initialized');
|
|
189
|
+
return window.__slidevideoCapture.stop();
|
|
190
|
+
}),
|
|
191
|
+
new Promise((_, reject) => {
|
|
192
|
+
timer = setTimeout(() => reject(new ProductionError('CAPTURE_TIMEOUT', `Capture finalization exceeded ${Math.round(limit / 1000)}s`, 5)), limit);
|
|
193
|
+
if (signal) {
|
|
194
|
+
onAbort = () => reject(signal.reason ?? new ProductionError('INTERRUPTED', 'Capture finalization aborted', 5));
|
|
195
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
196
|
+
}
|
|
197
|
+
}),
|
|
198
|
+
]);
|
|
199
|
+
}
|
|
200
|
+
finally {
|
|
201
|
+
clearTimeout(timer);
|
|
202
|
+
if (signal && onAbort)
|
|
203
|
+
signal.removeEventListener('abort', onAbort);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
110
206
|
async prepare(story, schedule, directory, production = { verify_timing: false }) {
|
|
111
207
|
this.story = story;
|
|
112
208
|
this.schedule = schedule;
|
|
113
209
|
this.directory = directory;
|
|
114
210
|
this.production = production;
|
|
115
211
|
this.references = [];
|
|
212
|
+
this.stagingDirectory = join(directory, '.downloads');
|
|
213
|
+
this.rawCaptureFile = join(this.stagingDirectory, 'capture.webm');
|
|
214
|
+
this.captureToken = randomUUID();
|
|
116
215
|
await mkdir(directory, { recursive: true });
|
|
216
|
+
await mkdir(this.stagingDirectory, { recursive: true, mode: 0o700 });
|
|
217
|
+
const captureConfig = join(this.stagingDirectory, 'capture.json');
|
|
218
|
+
await writeFile(captureConfig, JSON.stringify({ file: this.rawCaptureFile, token: this.captureToken }), { mode: 0o600 });
|
|
117
219
|
try {
|
|
118
|
-
const page = await this.start(story);
|
|
220
|
+
const page = await this.start(story, { kind: 'capture', file: captureConfig });
|
|
119
221
|
const mediaHashes = Object.fromEntries(await Promise.all(story.media.map(async (media) => [media.id, await hashFile(media.src)])));
|
|
120
222
|
await page.evaluate(({ schedule, mediaHashes }) => window.__slidevideo.prepare(schedule, mediaHashes), { schedule, mediaHashes });
|
|
121
223
|
await page.addStyleTag({ content: 'body.slidevideo-capture .slidev-nav-controls, body.slidevideo-capture .slidev-nav {display:none!important}' });
|
|
@@ -172,11 +274,111 @@ export class SlidevAdapter {
|
|
|
172
274
|
await saveJson(join(directory, 'references.json'), { version: 1, references: this.references });
|
|
173
275
|
await page.evaluate(({ schedule, mediaHashes }) => window.__slidevideo.prepare(schedule, mediaHashes), { schedule, mediaHashes });
|
|
174
276
|
}
|
|
175
|
-
await page.evaluate((
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
277
|
+
await page.evaluate(async ({ output, token }) => {
|
|
278
|
+
document.title = 'SlideVideo capture';
|
|
279
|
+
const post = async (op, body) => {
|
|
280
|
+
const response = await fetch(`/__slidevideo_capture?op=${op}`, {
|
|
281
|
+
method: 'POST',
|
|
282
|
+
headers: { 'x-slidevideo-token': token },
|
|
283
|
+
body,
|
|
284
|
+
});
|
|
285
|
+
if (!response.ok) {
|
|
286
|
+
const detail = await response.text().catch(() => '');
|
|
287
|
+
throw new Error(`Capture stream ${op} failed (${response.status})${detail ? `: ${detail}` : ''}`);
|
|
288
|
+
}
|
|
289
|
+
return response;
|
|
290
|
+
};
|
|
291
|
+
await post('start');
|
|
292
|
+
const videoConstraints = {
|
|
293
|
+
frameRate: output.fps,
|
|
294
|
+
width: output.width,
|
|
295
|
+
height: output.height,
|
|
296
|
+
cursor: 'motion',
|
|
297
|
+
resizeMode: 'crop-and-scale',
|
|
298
|
+
};
|
|
299
|
+
const displayOptions = {
|
|
300
|
+
video: videoConstraints,
|
|
301
|
+
selfBrowserSurface: 'include',
|
|
302
|
+
};
|
|
303
|
+
const display = await navigator.mediaDevices.getDisplayMedia(displayOptions);
|
|
304
|
+
const videoTracks = display.getVideoTracks();
|
|
305
|
+
if (!videoTracks.length) {
|
|
306
|
+
for (const track of display.getTracks())
|
|
307
|
+
track.stop();
|
|
308
|
+
throw new Error('Display capture produced no video track');
|
|
309
|
+
}
|
|
310
|
+
const primaryTrack = videoTracks[0];
|
|
311
|
+
primaryTrack.contentHint = 'motion';
|
|
312
|
+
await primaryTrack.applyConstraints({ frameRate: { min: output.fps, max: output.fps, ideal: output.fps } });
|
|
313
|
+
const slidesStream = new MediaStream(videoTracks);
|
|
314
|
+
const mimeType = typeof MediaRecorder.isTypeSupported === 'function' && MediaRecorder.isTypeSupported('video/webm')
|
|
315
|
+
? 'video/webm'
|
|
316
|
+
: undefined;
|
|
317
|
+
const recorder = new MediaRecorder(slidesStream, {
|
|
318
|
+
...(mimeType ? { mimeType } : {}),
|
|
319
|
+
bitsPerSecond: 8192 * 1024,
|
|
320
|
+
});
|
|
321
|
+
let chain = Promise.resolve();
|
|
322
|
+
let failure = '';
|
|
323
|
+
const recordFailure = (error) => {
|
|
324
|
+
if (!failure)
|
|
325
|
+
failure = error instanceof Error ? error.message : String(error);
|
|
326
|
+
if (!window.__slidevideo.state.failure)
|
|
327
|
+
window.__slidevideo.state.failure = failure;
|
|
328
|
+
};
|
|
329
|
+
recorder.ondataavailable = event => {
|
|
330
|
+
if (!event.data || event.data.size === 0 || failure)
|
|
331
|
+
return;
|
|
332
|
+
const chunk = event.data;
|
|
333
|
+
chain = chain.then(async () => {
|
|
334
|
+
if (failure)
|
|
335
|
+
return;
|
|
336
|
+
await post('chunk', chunk);
|
|
337
|
+
}).catch(recordFailure);
|
|
338
|
+
};
|
|
339
|
+
const stopped = new Promise(resolve => {
|
|
340
|
+
recorder.onerror = event => {
|
|
341
|
+
const detail = 'error' in event && event.error instanceof Error ? event.error.message : 'MediaRecorder error';
|
|
342
|
+
recordFailure(detail);
|
|
343
|
+
resolve();
|
|
344
|
+
};
|
|
345
|
+
recorder.onstop = () => resolve();
|
|
346
|
+
});
|
|
347
|
+
display.addEventListener('inactive', () => {
|
|
348
|
+
if (recorder.state !== 'inactive')
|
|
349
|
+
recordFailure('Capture stream ended unexpectedly');
|
|
350
|
+
}, { once: true });
|
|
351
|
+
recorder.start(1000);
|
|
352
|
+
window.__slidevideoCapture = {
|
|
353
|
+
stop: async () => {
|
|
354
|
+
try {
|
|
355
|
+
if (recorder.state !== 'inactive')
|
|
356
|
+
recorder.stop();
|
|
357
|
+
await stopped;
|
|
358
|
+
}
|
|
359
|
+
finally {
|
|
360
|
+
for (const track of display.getTracks())
|
|
361
|
+
track.stop();
|
|
362
|
+
}
|
|
363
|
+
await chain;
|
|
364
|
+
let bytes = 0;
|
|
365
|
+
try {
|
|
366
|
+
const finishResponse = await post('finish');
|
|
367
|
+
const report = await finishResponse.json();
|
|
368
|
+
if (report && typeof report === 'object' && 'bytes' in report && typeof report.bytes === 'number')
|
|
369
|
+
bytes = report.bytes;
|
|
370
|
+
}
|
|
371
|
+
catch (finishError) {
|
|
372
|
+
recordFailure(finishError);
|
|
373
|
+
}
|
|
374
|
+
if (failure)
|
|
375
|
+
throw new Error(failure);
|
|
376
|
+
if (!bytes)
|
|
377
|
+
throw new Error('Capture stream produced an empty recording');
|
|
378
|
+
return bytes;
|
|
379
|
+
},
|
|
380
|
+
};
|
|
381
|
+
}, { output: story.output, token: this.captureToken });
|
|
180
382
|
await page.waitForTimeout(500);
|
|
181
383
|
}
|
|
182
384
|
catch (error) {
|
|
@@ -195,26 +397,75 @@ export class SlidevAdapter {
|
|
|
195
397
|
catch (error) {
|
|
196
398
|
playbackError = error;
|
|
197
399
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
400
|
+
if (this.closed || executionSignal()?.aborted) {
|
|
401
|
+
executionSignal()?.throwIfAborted();
|
|
402
|
+
throw new ProductionError('INTERRUPTED', 'Capture aborted', 5);
|
|
403
|
+
}
|
|
404
|
+
let observed;
|
|
405
|
+
try {
|
|
406
|
+
observed = await page.evaluate(() => ({ events: window.__slidevideo.state.events, markers: window.__slidevideo.state.markers, failure: window.__slidevideo.state.failure, annotation_geometry: window.__slidevideo.state.annotation_geometry }));
|
|
407
|
+
}
|
|
408
|
+
catch (error) {
|
|
409
|
+
if (!playbackError)
|
|
410
|
+
throw error;
|
|
411
|
+
}
|
|
412
|
+
if (observed) {
|
|
413
|
+
await saveJson(join(this.directory, 'events.json'), observed);
|
|
414
|
+
if (this.schedule.annotations.length)
|
|
415
|
+
await saveJson(join(this.directory, 'annotation-geometry.json'), { version: 1, geometry: observed.annotation_geometry ?? [], failure: observed.failure });
|
|
416
|
+
}
|
|
417
|
+
let stopError;
|
|
418
|
+
let stoppedCleanly = false;
|
|
419
|
+
if (!this.closed && !executionSignal()?.aborted) {
|
|
420
|
+
try {
|
|
421
|
+
await this.stopCapture(page, this.schedule.duration_ms);
|
|
422
|
+
stoppedCleanly = true;
|
|
423
|
+
}
|
|
424
|
+
catch (error) {
|
|
425
|
+
stopError = error;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
const rawFile = this.rawCaptureFile;
|
|
206
429
|
const file = join(this.directory, 'native.webm');
|
|
207
|
-
|
|
208
|
-
|
|
430
|
+
let remuxedOk = false;
|
|
431
|
+
if (stoppedCleanly && !this.closed && !executionSignal()?.aborted) {
|
|
432
|
+
const rawStats = await stat(rawFile).catch(() => undefined);
|
|
433
|
+
if (rawStats && rawStats.size > 0) {
|
|
434
|
+
const remuxed = join(this.stagingDirectory, 'remuxed.webm');
|
|
435
|
+
try {
|
|
436
|
+
await execute('ffmpeg', ['-v', 'error', '-xerror', '-y', '-i', rawFile, '-c', 'copy', remuxed]);
|
|
437
|
+
if (!this.closed && !executionSignal()?.aborted) {
|
|
438
|
+
await rename(remuxed, file);
|
|
439
|
+
await rm(rawFile, { force: true });
|
|
440
|
+
remuxedOk = true;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
catch (remuxError) {
|
|
444
|
+
if (!this.closed && !executionSignal()?.aborted) {
|
|
445
|
+
await this.preserveRawCapture();
|
|
446
|
+
if (!playbackError && !observed?.failure)
|
|
447
|
+
throw remuxError;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
if (this.closed || executionSignal()?.aborted) {
|
|
453
|
+
executionSignal()?.throwIfAborted();
|
|
454
|
+
throw new ProductionError('INTERRUPTED', 'Capture aborted', 5);
|
|
455
|
+
}
|
|
456
|
+
if (playbackError || observed?.failure)
|
|
457
|
+
throw new ProductionError('PLAYBACK', observed?.failure || String(playbackError), 5);
|
|
458
|
+
if (stopError)
|
|
459
|
+
throw stopError;
|
|
460
|
+
requireCondition(remuxedOk && Boolean(observed), 'CAPTURE_STREAM', 'Capture stream did not complete', 5);
|
|
209
461
|
progress?.(this.production.verify_timing ? 'Verifying captured timing' : 'Locating capture origin; per-cue timing verification skipped');
|
|
210
462
|
const properties = await probe(file);
|
|
211
463
|
requireCondition(properties.width === this.story.output.width && properties.height === this.story.output.height, 'CAPTURE_DIMENSIONS', 'Capture dimensions differ from requested full audience frame', 5);
|
|
212
|
-
requireCondition(
|
|
213
|
-
requireCondition((observed.annotation_geometry?.length ?? 0) === (this.schedule.annotations?.length ?? 0), 'ANNOTATION_GEOMETRY', 'Annotation geometry collection did not complete. See annotation-geometry.json.', 5);
|
|
464
|
+
requireCondition((observed.annotation_geometry?.length ?? 0) === this.schedule.annotations.length, 'ANNOTATION_GEOMETRY', 'Annotation geometry collection did not complete. See annotation-geometry.json.', 5);
|
|
214
465
|
const timing = this.production.verify_timing
|
|
215
466
|
? await calibrate(file, observed.markers, this.references, this.schedule.duration_ms, this.directory)
|
|
216
467
|
: await estimateOrigin(file, observed.markers, this.schedule.duration_ms, this.directory);
|
|
217
|
-
const visual = { version: 1, file, ...(this.schedule.annotations
|
|
468
|
+
const visual = { version: 1, file, ...(this.schedule.annotations.length ? { annotation_geometry: observed.annotation_geometry ?? [] } : {}), properties, events: observed.events, origin: { method: this.production.verify_timing ? 'decoded_markers' : 'opening_markers', uncertainty_ms: timing.uncertainty_ms, mapping: timing.mapping }, timing, provenance: { adapter: this.id, version: this.version, dependencies: { chromium: this.browser.version(), slidev: '53.1.0', playwright: '1.65.1' } } };
|
|
218
469
|
await saveJson(join(this.directory, 'visual.json'), visual);
|
|
219
470
|
requireCondition(!this.production.verify_timing || timing.status === 'accepted', 'TIMING_ACCEPTANCE', 'Capture completed but decoded timing evidence failed. See calibration.json.', 6);
|
|
220
471
|
return visual;
|
|
@@ -225,27 +476,61 @@ export class SlidevAdapter {
|
|
|
225
476
|
}
|
|
226
477
|
}
|
|
227
478
|
async cleanup() {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
stop.once('close', code => {
|
|
239
|
-
clearTimeout(timer);
|
|
240
|
-
if (code === 0 || server.exitCode !== null)
|
|
241
|
-
resolve();
|
|
242
|
-
else
|
|
243
|
-
reject(new ProductionError('CLEANUP', 'Could not stop the owned Slidev server process tree', 5));
|
|
244
|
-
});
|
|
245
|
-
});
|
|
479
|
+
this.closed = true;
|
|
480
|
+
try {
|
|
481
|
+
await (this.cleanupPromise ??= this.cleanupOnce());
|
|
482
|
+
}
|
|
483
|
+
finally {
|
|
484
|
+
if (this.directory) {
|
|
485
|
+
try {
|
|
486
|
+
await writeFile(join(this.directory, 'slidev.log'), this.log);
|
|
487
|
+
}
|
|
488
|
+
catch { }
|
|
246
489
|
}
|
|
247
|
-
else
|
|
248
|
-
this.server.kill('SIGTERM');
|
|
249
490
|
}
|
|
250
491
|
}
|
|
492
|
+
async preserveRawCapture() {
|
|
493
|
+
if (!this.rawCaptureFile || !this.directory)
|
|
494
|
+
return true;
|
|
495
|
+
const target = join(this.directory, 'native.webm');
|
|
496
|
+
const existing = await stat(target).catch(() => undefined);
|
|
497
|
+
if (existing && existing.size > 0)
|
|
498
|
+
return true;
|
|
499
|
+
const raw = await stat(this.rawCaptureFile).catch(() => undefined);
|
|
500
|
+
if (!raw || raw.size === 0)
|
|
501
|
+
return true;
|
|
502
|
+
try {
|
|
503
|
+
await rename(this.rawCaptureFile, target);
|
|
504
|
+
return true;
|
|
505
|
+
}
|
|
506
|
+
catch {
|
|
507
|
+
return false;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
async cleanupOnce() {
|
|
511
|
+
let browserError;
|
|
512
|
+
let serverError;
|
|
513
|
+
try {
|
|
514
|
+
await this.browser?.close();
|
|
515
|
+
}
|
|
516
|
+
catch (error) {
|
|
517
|
+
browserError = error;
|
|
518
|
+
}
|
|
519
|
+
if (this.server) {
|
|
520
|
+
try {
|
|
521
|
+
await this.stopServer(this.server);
|
|
522
|
+
}
|
|
523
|
+
catch (error) {
|
|
524
|
+
serverError = error;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
const safeToRemoveStaging = await this.preserveRawCapture();
|
|
528
|
+
if (this.stagingDirectory && safeToRemoveStaging) {
|
|
529
|
+
await rm(this.stagingDirectory, { recursive: true, force: true }).catch(() => { });
|
|
530
|
+
}
|
|
531
|
+
if (serverError)
|
|
532
|
+
throw serverError;
|
|
533
|
+
if (browserError)
|
|
534
|
+
throw browserError;
|
|
535
|
+
}
|
|
251
536
|
}
|
package/dist/annotations.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type AppliedAnnotation = AnnotationPaint & {
|
|
|
11
11
|
bottom_border?: AnnotationPaint;
|
|
12
12
|
};
|
|
13
13
|
export declare function annotationApplications(story: Storyboard, schedule: Schedule, visual: VisualArtifact, audioOrigin: number): AppliedAnnotation[];
|
|
14
|
-
export declare function verifyAnnotations(file: string, base: string, baseFilter: string, applications: AppliedAnnotation[], story: Storyboard, directory: string, output: string, overlayBounds?: (frame: number) => Rectangle[]): Promise<{
|
|
14
|
+
export declare function verifyAnnotations(file: string, base: string, baseFilter: string, applications: AppliedAnnotation[], story: Storyboard, directory: string, output: string, overlayBounds?: (frame: number) => Rectangle[], sha256?: string): Promise<{
|
|
15
15
|
source: string;
|
|
16
16
|
target_ms: number;
|
|
17
17
|
checks: Record<string, unknown>[];
|
package/dist/annotations.js
CHANGED
|
@@ -3,7 +3,7 @@ import { execute, hashFile, saveJson } from './media.js';
|
|
|
3
3
|
import { requireCondition } from './errors.js';
|
|
4
4
|
import { annotationPaint } from './annotation-paint.js';
|
|
5
5
|
export function annotationApplications(story, schedule, visual, audioOrigin) {
|
|
6
|
-
return
|
|
6
|
+
return schedule.annotations.map(annotation => {
|
|
7
7
|
const context = { annotation: annotation.id, target: annotation.target };
|
|
8
8
|
const candidates = (visual.annotation_geometry ?? []).filter(item => item.id === annotation.id);
|
|
9
9
|
requireCondition(candidates.length === 1, 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id}: missing or ambiguous capture geometry`, 5, context);
|
|
@@ -23,9 +23,9 @@ export function annotationApplications(story, schedule, visual, audioOrigin) {
|
|
|
23
23
|
return { id: annotation.id, start_ms, end_ms, first_frame, end_frame, ...annotationPaint(annotation, geometry), geometry };
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
-
export async function verifyAnnotations(file, base, baseFilter, applications, story, directory, output, overlayBounds = () => []) {
|
|
26
|
+
export async function verifyAnnotations(file, base, baseFilter, applications, story, directory, output, overlayBounds = () => [], sha256) {
|
|
27
27
|
const evidenceFile = join(directory, 'annotations-evidence.json');
|
|
28
|
-
const provenance = { sha256: await hashFile(file), base: { file: base, filter: baseFilter } };
|
|
28
|
+
const provenance = { sha256: sha256 ?? await hashFile(file), base: { file: base, filter: baseFilter } };
|
|
29
29
|
await saveJson(evidenceFile, { version: 1, status: 'failed', file: join(directory, 'failed-composite.mp4'), ...provenance, checks: [], gaps: ['Final composite verification did not complete.'] });
|
|
30
30
|
const metadata = JSON.parse((await execute('ffprobe', ['-v', 'error', '-select_streams', 'v:0', '-show_frames', '-show_entries', 'frame=best_effort_timestamp_time', '-of', 'json', file])).toString());
|
|
31
31
|
const requested = applications.flatMap(item => [item.first_frame - 1, item.first_frame, item.end_frame - 1, item.end_frame]);
|
package/dist/assembly.d.ts
CHANGED
|
@@ -2,47 +2,53 @@ import type { Schedule, SpeechManifest, Storyboard, VisualArtifact, ProductionOp
|
|
|
2
2
|
type AssemblyOptions = ProductionOptions & {
|
|
3
3
|
licensed?: boolean;
|
|
4
4
|
inputHashes?: Record<string, string>;
|
|
5
|
+
onOutputReserved?: () => Promise<void>;
|
|
5
6
|
};
|
|
6
7
|
export declare function assemble(story: Storyboard, schedule: Schedule, speech: SpeechManifest, visual: VisualArtifact, directory: string, output: string, options?: AssemblyOptions): Promise<{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
8
|
+
report: {
|
|
9
|
+
output_origin_delta_ms: number;
|
|
10
|
+
audio_origin_ms: number;
|
|
11
|
+
picture_lead_hold_ms: number;
|
|
12
|
+
final_hold: string;
|
|
13
|
+
trim_start_ms: number;
|
|
14
|
+
trim_end_ms: number;
|
|
15
|
+
mapping: import("./contracts.js").CaptureMapping;
|
|
16
|
+
transformations: unknown[];
|
|
17
|
+
editorial_review: string;
|
|
18
|
+
compositor?: {
|
|
19
|
+
renderer: string;
|
|
20
|
+
version: string;
|
|
21
|
+
frames: number;
|
|
22
|
+
composited_frames: number;
|
|
23
|
+
mode: string;
|
|
24
|
+
} | undefined;
|
|
25
|
+
base_capture_timing?: "accepted" | "not_evaluated" | undefined;
|
|
26
|
+
applied_annotations?: import("./annotations.js").AppliedAnnotation[] | undefined;
|
|
27
|
+
final_composite?: {
|
|
28
|
+
source: string;
|
|
29
|
+
target_ms: number;
|
|
30
|
+
checks: Record<string, unknown>[];
|
|
31
|
+
gaps: string[];
|
|
32
|
+
sha256: string;
|
|
33
|
+
base: {
|
|
34
|
+
file: string;
|
|
35
|
+
filter: string;
|
|
36
|
+
};
|
|
37
|
+
version: number;
|
|
38
|
+
status: string;
|
|
30
39
|
file: string;
|
|
31
|
-
|
|
32
|
-
|
|
40
|
+
} | {
|
|
41
|
+
status: string;
|
|
42
|
+
gaps: string[];
|
|
43
|
+
} | undefined;
|
|
44
|
+
decode: string;
|
|
45
|
+
timing_status: "accepted" | "not_evaluated";
|
|
46
|
+
image_overlays?: import("./contracts.js").ResolvedOverlay[] | undefined;
|
|
33
47
|
version: number;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
} | undefined;
|
|
40
|
-
decode: string;
|
|
41
|
-
timing_status: "accepted" | "not_evaluated";
|
|
42
|
-
image_overlays?: import("./contracts.js").ResolvedOverlay[] | undefined;
|
|
43
|
-
version: number;
|
|
44
|
-
output: string;
|
|
45
|
-
properties: import("./contracts.js").MediaProperties;
|
|
46
|
-
watermark: boolean;
|
|
48
|
+
output: string;
|
|
49
|
+
properties: import("./contracts.js").MediaProperties;
|
|
50
|
+
watermark: boolean;
|
|
51
|
+
};
|
|
52
|
+
outputSha256: string;
|
|
47
53
|
}>;
|
|
48
54
|
export {};
|