@slidevideo/cli 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/IMPRESSUM.md +13 -0
- package/LICENSE-TERMS.md +58 -0
- package/README.md +25 -0
- package/addons/slidevideo/geometry.ts +127 -0
- package/addons/slidevideo/global-top.vue +232 -0
- package/addons/slidevideo/package.json +1 -0
- package/addons/slidevideo/playback-entries.ts +14 -0
- package/addons/slidevideo/preview.ts +157 -0
- package/dist/adapters/browser-runtime.d.ts +37 -0
- package/dist/adapters/browser-runtime.js +1 -0
- package/dist/adapters/edge.d.ts +7 -0
- package/dist/adapters/edge.js +46 -0
- package/dist/adapters/elevenlabs.d.ts +7 -0
- package/dist/adapters/elevenlabs.js +58 -0
- package/dist/adapters/powerpoint-preview.d.ts +2 -0
- package/dist/adapters/powerpoint-preview.js +18 -0
- package/dist/adapters/powerpoint.d.ts +21 -0
- package/dist/adapters/powerpoint.js +434 -0
- package/dist/adapters/registry.d.ts +4 -0
- package/dist/adapters/registry.js +13 -0
- package/dist/adapters/slidev-inputs.d.ts +1 -0
- package/dist/adapters/slidev-inputs.js +86 -0
- package/dist/adapters/slidev-inspection.d.ts +3 -0
- package/dist/adapters/slidev-inspection.js +79 -0
- package/dist/adapters/slidev-server.d.ts +1 -0
- package/dist/adapters/slidev-server.js +48 -0
- package/dist/adapters/slidev.d.ts +30 -0
- package/dist/adapters/slidev.js +251 -0
- package/dist/annotation-paint.d.ts +19 -0
- package/dist/annotation-paint.js +13 -0
- package/dist/annotations.d.ts +27 -0
- package/dist/annotations.js +115 -0
- package/dist/assembly.d.ts +48 -0
- package/dist/assembly.js +138 -0
- package/dist/calibration.d.ts +24 -0
- package/dist/calibration.js +346 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +180 -0
- package/dist/compositor.d.ts +18 -0
- package/dist/compositor.js +155 -0
- package/dist/contracts.d.ts +358 -0
- package/dist/contracts.js +1 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +15 -0
- package/dist/executables.d.ts +23 -0
- package/dist/executables.js +165 -0
- package/dist/installation.d.ts +6 -0
- package/dist/installation.js +32 -0
- package/dist/license-key.d.ts +12 -0
- package/dist/license-key.js +55 -0
- package/dist/license-status.d.ts +16 -0
- package/dist/license-status.js +12 -0
- package/dist/media.d.ts +12 -0
- package/dist/media.js +57 -0
- package/dist/overlay-assets.d.ts +2 -0
- package/dist/overlay-assets.js +58 -0
- package/dist/pipeline.d.ts +50 -0
- package/dist/pipeline.js +257 -0
- package/dist/preview/contracts.d.ts +34 -0
- package/dist/preview/contracts.js +1 -0
- package/dist/preview/player.d.ts +1 -0
- package/dist/preview/player.js +129 -0
- package/dist/preview/server.d.ts +1 -0
- package/dist/preview/server.js +112 -0
- package/dist/preview/view.d.ts +1 -0
- package/dist/preview/view.js +36 -0
- package/dist/revoked-keys.json +1 -0
- package/dist/run.d.ts +12 -0
- package/dist/run.js +109 -0
- package/dist/setup-install.d.ts +7 -0
- package/dist/setup-install.js +98 -0
- package/dist/setup-license.d.ts +2 -0
- package/dist/setup-license.js +63 -0
- package/dist/setup.d.ts +34 -0
- package/dist/setup.js +218 -0
- package/dist/speech.d.ts +6 -0
- package/dist/speech.js +125 -0
- package/dist/storyboard.d.ts +6 -0
- package/dist/storyboard.js +86 -0
- package/dist/timing.d.ts +6 -0
- package/dist/timing.js +162 -0
- package/package.json +134 -0
- package/schemas/annotation-geometry.v1.json +130 -0
- package/schemas/revoked-keys.schema.json +11 -0
- package/schemas/run-manifest.v1.json +96 -0
- package/schemas/schedule.v1.json +108 -0
- package/schemas/schedule.v2.json +496 -0
- package/schemas/speech.v1.json +173 -0
- package/schemas/storyboard.v1.json +461 -0
- package/schemas/storyboard.v2.json +802 -0
- package/schemas/timing-evidence.v1.json +129 -0
- package/skills/slidevideo/SKILL.md +56 -0
- package/skills/slidevideo/references/production.md +76 -0
- package/skills/slidevideo/references/storyboard.md +272 -0
- package/tools/edge-tts/edge-tts.py +19 -0
- package/tools/edge-tts/requirements.lock +34 -0
- package/tools/powerpoint/Native.cs +277 -0
- package/tools/powerpoint/powerpoint.ps1 +714 -0
- package/tools/powerpoint/preview.ps1 +100 -0
- package/tools/powerpoint/requirements.json +11 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createServer, resolveOptions, createDataUtils } from '@slidev/cli';
|
|
2
|
+
import { readFile, realpath } from 'node:fs/promises';
|
|
3
|
+
import { packagePath } from '../installation.js';
|
|
4
|
+
const [entry, port, previewFile] = process.argv.slice(2);
|
|
5
|
+
const options = await resolveOptions({ entry, remote: '', base: '/' }, 'dev');
|
|
6
|
+
if (port === 'inspect') {
|
|
7
|
+
if (!process.send || !process.disconnect)
|
|
8
|
+
throw new Error('Inspection requires an IPC channel');
|
|
9
|
+
process.send({
|
|
10
|
+
slides: options.data.slides.map(slide => ({ frontmatter: slide.frontmatter, content: slide.content })),
|
|
11
|
+
headmatter: options.data.headmatter,
|
|
12
|
+
files: Object.keys(options.data.markdownFiles),
|
|
13
|
+
errors: Object.values(options.data.markdownFiles).flatMap(file => (file.errors ?? []).map(error => `${file.filepath}:${error.row + 1}: ${error.message}`)),
|
|
14
|
+
});
|
|
15
|
+
process.disconnect();
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const addon = await realpath(packagePath('addons', 'slidevideo'));
|
|
19
|
+
const addonRoots = await Promise.all(options.addonRoots.map(root => realpath(root)));
|
|
20
|
+
if (!addonRoots.includes(addon)) {
|
|
21
|
+
options.addonRoots.push(addon);
|
|
22
|
+
options.roots = [...new Set([...options.themeRoots, ...options.addonRoots, options.userRoot])];
|
|
23
|
+
options.utils = await createDataUtils(options);
|
|
24
|
+
}
|
|
25
|
+
const config = previewFile ? await readFile(previewFile, 'utf8') : undefined;
|
|
26
|
+
const server = await createServer(options, {
|
|
27
|
+
server: {
|
|
28
|
+
host: '127.0.0.1', port: Number(port), strictPort: true,
|
|
29
|
+
fs: { allow: [packagePath('dist', 'annotation-paint.js')] },
|
|
30
|
+
},
|
|
31
|
+
logLevel: 'warn',
|
|
32
|
+
base: '/',
|
|
33
|
+
plugins: config ? [{
|
|
34
|
+
name: 'slidevideo-preview',
|
|
35
|
+
configureServer(server) {
|
|
36
|
+
server.middlewares.use('/__slidevideo_preview', (_request, response) => {
|
|
37
|
+
response.setHeader('Content-Type', 'application/json');
|
|
38
|
+
response.setHeader('Cache-Control', 'no-store');
|
|
39
|
+
response.end(config);
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
}] : [],
|
|
43
|
+
});
|
|
44
|
+
const close = () => { void server.close().finally(() => process.exit()); };
|
|
45
|
+
process.once('SIGINT', close);
|
|
46
|
+
process.once('SIGTERM', close);
|
|
47
|
+
await server.listen();
|
|
48
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import './browser-runtime.js';
|
|
2
|
+
import { type Browser, type Page } from 'playwright';
|
|
3
|
+
import { type ChildProcess } from 'node:child_process';
|
|
4
|
+
import type { PresentationAdapter, Schedule, Storyboard, VisualArtifact, ProgressReporter, ProductionOptions, PresentationInspection } from '../contracts.js';
|
|
5
|
+
import { inspectSlidev, validateSlidev } from './slidev-inspection.js';
|
|
6
|
+
import { type Reference } from '../calibration.js';
|
|
7
|
+
export declare class SlidevAdapter implements PresentationAdapter {
|
|
8
|
+
id: string;
|
|
9
|
+
version: string;
|
|
10
|
+
browser?: Browser;
|
|
11
|
+
page?: Page;
|
|
12
|
+
server?: ChildProcess;
|
|
13
|
+
log: string;
|
|
14
|
+
schedule: Schedule;
|
|
15
|
+
story: Storyboard;
|
|
16
|
+
directory: string;
|
|
17
|
+
references: Reference[];
|
|
18
|
+
production: ProductionOptions;
|
|
19
|
+
inspect: typeof inspectSlidev;
|
|
20
|
+
validate: typeof validateSlidev;
|
|
21
|
+
private startServer;
|
|
22
|
+
startPreview(story: Storyboard, schedule: Schedule, directory: string, parentOrigin: string): Promise<{
|
|
23
|
+
url: string;
|
|
24
|
+
}>;
|
|
25
|
+
private start;
|
|
26
|
+
inspectTargets(story: Storyboard): Promise<PresentationInspection['annotation_targets']>;
|
|
27
|
+
prepare(story: Storyboard, schedule: Schedule, directory: string, production?: ProductionOptions): Promise<void>;
|
|
28
|
+
execute(progress?: ProgressReporter): Promise<VisualArtifact>;
|
|
29
|
+
cleanup(): Promise<void>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import './browser-runtime.js';
|
|
2
|
+
import { chromium } from 'playwright';
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { createServer } from 'node:net';
|
|
5
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
6
|
+
import { dirname, join, resolve } from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { inspectSlidev, validateSlidev } from './slidev-inspection.js';
|
|
9
|
+
import { calibrate, estimateOrigin } from '../calibration.js';
|
|
10
|
+
import { probe, saveJson, hashFile, digest, videoFramePeriod, executionScope } from '../media.js';
|
|
11
|
+
import { requireCondition, ProductionError } from '../errors.js';
|
|
12
|
+
import { executable } from '../executables.js';
|
|
13
|
+
function browserFailure(error, phase) {
|
|
14
|
+
if (error instanceof ProductionError && error.code !== 'SUBPROCESS')
|
|
15
|
+
throw error;
|
|
16
|
+
if (error instanceof TypeError)
|
|
17
|
+
throw error;
|
|
18
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
19
|
+
if (message.includes('MEDIA_SOURCE_MISMATCH') || message.includes('MEDIA_SOURCE_UNAVAILABLE'))
|
|
20
|
+
throw new ProductionError('MEDIA_SOURCE_MISMATCH', message, 2);
|
|
21
|
+
throw new ProductionError(phase, message, 5);
|
|
22
|
+
}
|
|
23
|
+
export class SlidevAdapter {
|
|
24
|
+
id = 'slidev';
|
|
25
|
+
version = '53.1.0-adapter-5';
|
|
26
|
+
browser;
|
|
27
|
+
page;
|
|
28
|
+
server;
|
|
29
|
+
log = '';
|
|
30
|
+
schedule;
|
|
31
|
+
story;
|
|
32
|
+
directory;
|
|
33
|
+
references = [];
|
|
34
|
+
production = { verify_timing: false };
|
|
35
|
+
inspect = inspectSlidev;
|
|
36
|
+
validate = validateSlidev;
|
|
37
|
+
async startServer(story, previewFile) {
|
|
38
|
+
const port = await new Promise((resolve, reject) => {
|
|
39
|
+
const socket = createServer();
|
|
40
|
+
socket.on('error', reject);
|
|
41
|
+
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
|
+
});
|
|
43
|
+
const server = fileURLToPath(new URL('./slidev-server.js', import.meta.url));
|
|
44
|
+
this.server = spawn(process.execPath, [server, story.deck, String(port), ...(previewFile ? [previewFile] : [])], { cwd: dirname(story.deck), stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
|
|
45
|
+
this.server.stdout?.on('data', data => { this.log += data.toString(); });
|
|
46
|
+
this.server.stderr?.on('data', data => { this.log += data.toString(); });
|
|
47
|
+
const url = `http://127.0.0.1:${port}`;
|
|
48
|
+
const deadline = Date.now() + 120000;
|
|
49
|
+
let ready = false;
|
|
50
|
+
while (Date.now() < deadline) {
|
|
51
|
+
executionScope.getStore()?.throwIfAborted();
|
|
52
|
+
requireCondition(this.server.exitCode === null && this.server.signalCode === null, 'SLIDEV_SERVER', 'Slidev exited before readiness', 5);
|
|
53
|
+
try {
|
|
54
|
+
if ((await fetch(url, { signal: AbortSignal.timeout(1000) })).ok) {
|
|
55
|
+
ready = true;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch { }
|
|
60
|
+
await new Promise(resolve => setTimeout(resolve, 200));
|
|
61
|
+
}
|
|
62
|
+
requireCondition(ready, 'SLIDEV_TIMEOUT', 'Slidev did not become ready', 5);
|
|
63
|
+
return url;
|
|
64
|
+
}
|
|
65
|
+
async startPreview(story, schedule, directory, parentOrigin) {
|
|
66
|
+
this.directory = directory;
|
|
67
|
+
await mkdir(directory, { recursive: true });
|
|
68
|
+
const mediaHashes = Object.fromEntries(await Promise.all(story.media.map(async (media) => [media.id, await hashFile(media.src)])));
|
|
69
|
+
const config = resolve(directory, 'preview.json');
|
|
70
|
+
await saveJson(config, { schedule, mediaHashes, parentOrigin });
|
|
71
|
+
const url = await this.startServer(story, config);
|
|
72
|
+
return { url: `${url}/1?slidevideo=1&slidevideo-preview=1` };
|
|
73
|
+
}
|
|
74
|
+
async start(story) {
|
|
75
|
+
const executablePath = executable('browser');
|
|
76
|
+
const url = await this.startServer(story);
|
|
77
|
+
this.browser = await chromium.launch({ executablePath, headless: true, 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'] });
|
|
78
|
+
this.page = await this.browser.newPage({ viewport: { width: story.output.width, height: story.output.height }, deviceScaleFactor: 1, acceptDownloads: true });
|
|
79
|
+
this.page.on('pageerror', error => { this.log += `\nBrowser error: ${error.message}`; });
|
|
80
|
+
await this.page.addInitScript(output => {
|
|
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
|
+
};
|
|
89
|
+
localStorage.setItem('slidev-camera', 'none');
|
|
90
|
+
localStorage.setItem('slidev-mic', 'none');
|
|
91
|
+
localStorage.setItem('slidev-record-resolution', `${output.width}x${output.height}`);
|
|
92
|
+
localStorage.setItem('slidev-record-framerate', JSON.stringify(output.fps));
|
|
93
|
+
}, story.output);
|
|
94
|
+
await this.page.goto(`${url}/1?slidevideo=1`);
|
|
95
|
+
await this.page.waitForFunction(() => Boolean(window.__slidevideo), { timeout: 120000 });
|
|
96
|
+
return this.page;
|
|
97
|
+
}
|
|
98
|
+
async inspectTargets(story) {
|
|
99
|
+
try {
|
|
100
|
+
const page = await this.start(story);
|
|
101
|
+
return await page.evaluate(() => window.__slidevideo.inspectTargets());
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
browserFailure(error, 'ANNOTATION_INSPECTION');
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
await this.cleanup();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async prepare(story, schedule, directory, production = { verify_timing: false }) {
|
|
111
|
+
this.story = story;
|
|
112
|
+
this.schedule = schedule;
|
|
113
|
+
this.directory = directory;
|
|
114
|
+
this.production = production;
|
|
115
|
+
this.references = [];
|
|
116
|
+
await mkdir(directory, { recursive: true });
|
|
117
|
+
try {
|
|
118
|
+
const page = await this.start(story);
|
|
119
|
+
const mediaHashes = Object.fromEntries(await Promise.all(story.media.map(async (media) => [media.id, await hashFile(media.src)])));
|
|
120
|
+
await page.evaluate(({ schedule, mediaHashes }) => window.__slidevideo.prepare(schedule, mediaHashes), { schedule, mediaHashes });
|
|
121
|
+
await page.addStyleTag({ content: 'body.slidevideo-capture .slidev-nav-controls, body.slidevideo-capture .slidev-nav {display:none!important}' });
|
|
122
|
+
await page.evaluate(() => { document.body.classList.add('slidevideo-capture'); });
|
|
123
|
+
if (production.verify_timing) {
|
|
124
|
+
const saved = new Set();
|
|
125
|
+
const reference = async () => {
|
|
126
|
+
const image = await page.screenshot();
|
|
127
|
+
const file = join(directory, `reference-${digest(image)}.png`);
|
|
128
|
+
if (!saved.has(file)) {
|
|
129
|
+
await writeFile(file, image);
|
|
130
|
+
saved.add(file);
|
|
131
|
+
}
|
|
132
|
+
return file;
|
|
133
|
+
};
|
|
134
|
+
for (const item of schedule.actions) {
|
|
135
|
+
if (!['slide', 'reveal', 'play'].includes(item.action.type))
|
|
136
|
+
continue;
|
|
137
|
+
const safe = item.id.replaceAll(':', '-');
|
|
138
|
+
const before = await reference();
|
|
139
|
+
const exclude = await page.evaluate(() => Array.from(document.querySelectorAll('video')).filter(element => element.checkVisibility({ opacityProperty: true, visibilityProperty: true })).map(element => {
|
|
140
|
+
const rect = element.getBoundingClientRect();
|
|
141
|
+
return { left: rect.left / innerWidth, top: rect.top / innerHeight, right: rect.right / innerWidth, bottom: rect.bottom / innerHeight };
|
|
142
|
+
}));
|
|
143
|
+
await page.evaluate(item => window.__slidevideo.apply(item), item);
|
|
144
|
+
if (item.action.type === 'play') {
|
|
145
|
+
const action = item.action;
|
|
146
|
+
const framePeriod = await videoFramePeriod(schedule.media.find(media => media.id === action.media).src) / (action.rate ?? 1);
|
|
147
|
+
requireCondition(Number.isFinite(framePeriod) && framePeriod > 0 && framePeriod <= 100, 'SOURCE_FRAME_TIMING', `Cannot bound video frame timing for ${action.media}`, 3);
|
|
148
|
+
const duration = item.end_ms - item.start_ms;
|
|
149
|
+
const samples = [500, 1500].filter(t => t < duration);
|
|
150
|
+
if (!samples.length)
|
|
151
|
+
samples.push(duration / 2);
|
|
152
|
+
for (const sample_ms of [...samples, duration]) {
|
|
153
|
+
await page.evaluate(async ({ id, seconds }) => {
|
|
154
|
+
const element = window.__slidevideo.media(id);
|
|
155
|
+
element.pause();
|
|
156
|
+
await new Promise(resolve => { element.addEventListener('seeked', () => resolve(), { once: true }); element.currentTime = seconds; });
|
|
157
|
+
await new Promise(requestAnimationFrame);
|
|
158
|
+
await new Promise(requestAnimationFrame);
|
|
159
|
+
}, { id: action.media, seconds: ((action.trim_start_ms ?? 0) + sample_ms * (action.rate ?? 1)) / 1000 });
|
|
160
|
+
if (sample_ms === duration)
|
|
161
|
+
continue;
|
|
162
|
+
const after = await reference();
|
|
163
|
+
this.references.push({ id: `${safe}-${sample_ms}`, expected_ms: item.start_ms + sample_ms, before, after, mode: 'sample', frame_period_ms: framePeriod });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else if (item.start_ms > 0) {
|
|
167
|
+
await page.waitForTimeout(item.action.type === 'slide' || item.action.type === 'reveal' ? item.action.duration_ms : 0);
|
|
168
|
+
const after = await reference();
|
|
169
|
+
this.references.push({ id: safe, expected_ms: item.start_ms, before, after, mode: 'transition', frame_period_ms: 0, settle_ms: item.action.type === 'slide' || item.action.type === 'reveal' ? item.action.duration_ms : 0, exclude });
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
await saveJson(join(directory, 'references.json'), { version: 1, references: this.references });
|
|
173
|
+
await page.evaluate(({ schedule, mediaHashes }) => window.__slidevideo.prepare(schedule, mediaHashes), { schedule, mediaHashes });
|
|
174
|
+
}
|
|
175
|
+
await page.evaluate(() => { document.body.classList.remove('slidevideo-capture'); document.title = 'SlideVideo capture'; });
|
|
176
|
+
await page.locator('[title="Record video"]').click({ force: true });
|
|
177
|
+
await page.getByRole('button', { name: 'Start', exact: true }).click();
|
|
178
|
+
await page.waitForSelector('[title="Stop record video"]', { timeout: 30000 });
|
|
179
|
+
await page.evaluate(() => { document.body.classList.add('slidevideo-capture'); });
|
|
180
|
+
await page.waitForTimeout(500);
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
this.log += `\nPreparation failed: ${String(error)}`;
|
|
184
|
+
browserFailure(error, 'BROWSER_PREPARATION');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async execute(progress) {
|
|
188
|
+
try {
|
|
189
|
+
progress?.('Recording presentation');
|
|
190
|
+
const page = this.page;
|
|
191
|
+
let playbackError;
|
|
192
|
+
try {
|
|
193
|
+
await page.evaluate(verify => window.__slidevideo.play(verify), this.production.verify_timing);
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
playbackError = error;
|
|
197
|
+
}
|
|
198
|
+
const 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 }));
|
|
199
|
+
await saveJson(join(this.directory, 'events.json'), observed);
|
|
200
|
+
if (this.schedule.annotations?.length)
|
|
201
|
+
await saveJson(join(this.directory, 'annotation-geometry.json'), { version: 1, geometry: observed.annotation_geometry ?? [], failure: observed.failure });
|
|
202
|
+
await page.evaluate(() => document.body.classList.remove('slidevideo-capture'));
|
|
203
|
+
const download = page.waitForEvent('download', { timeout: 30000 });
|
|
204
|
+
await page.locator('[title="Stop record video"]').click({ force: true });
|
|
205
|
+
const artifact = await download;
|
|
206
|
+
const file = join(this.directory, 'native.webm');
|
|
207
|
+
await artifact.saveAs(file);
|
|
208
|
+
requireCondition(!await artifact.failure(), 'CAPTURE_DOWNLOAD', 'Capture download did not complete', 5);
|
|
209
|
+
progress?.(this.production.verify_timing ? 'Verifying captured timing' : 'Locating capture origin; per-cue timing verification skipped');
|
|
210
|
+
const properties = await probe(file);
|
|
211
|
+
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(!playbackError && !observed.failure, 'PLAYBACK', observed.failure || String(playbackError), 5);
|
|
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);
|
|
214
|
+
const timing = this.production.verify_timing
|
|
215
|
+
? await calibrate(file, observed.markers, this.references, this.schedule.duration_ms, this.directory)
|
|
216
|
+
: await estimateOrigin(file, observed.markers, this.schedule.duration_ms, this.directory);
|
|
217
|
+
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
|
+
await saveJson(join(this.directory, 'visual.json'), visual);
|
|
219
|
+
requireCondition(!this.production.verify_timing || timing.status === 'accepted', 'TIMING_ACCEPTANCE', 'Capture completed but decoded timing evidence failed. See calibration.json.', 6);
|
|
220
|
+
return visual;
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
this.log += `\nCapture failed: ${String(error)}`;
|
|
224
|
+
browserFailure(error, 'CAPTURE');
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async cleanup() {
|
|
228
|
+
if (this.directory)
|
|
229
|
+
await writeFile(join(this.directory, 'slidev.log'), this.log);
|
|
230
|
+
await this.browser?.close();
|
|
231
|
+
if (this.server?.exitCode === null && this.server.pid) {
|
|
232
|
+
if (process.platform === 'win32') {
|
|
233
|
+
const server = this.server;
|
|
234
|
+
await new Promise((resolve, reject) => {
|
|
235
|
+
const stop = spawn('taskkill.exe', ['/PID', String(server.pid), '/T', '/F'], { windowsHide: true, stdio: 'ignore' });
|
|
236
|
+
const timer = setTimeout(() => stop.kill(), 5000);
|
|
237
|
+
stop.once('error', error => { clearTimeout(timer); reject(error); });
|
|
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
|
+
});
|
|
246
|
+
}
|
|
247
|
+
else
|
|
248
|
+
this.server.kill('SIGTERM');
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Annotation, AnnotationGeometry, Rectangle } from './contracts.js';
|
|
2
|
+
export type AnnotationPaint = {
|
|
3
|
+
rectangle: Rectangle;
|
|
4
|
+
color: string;
|
|
5
|
+
opacity: number;
|
|
6
|
+
blend: 'source-over' | 'darken';
|
|
7
|
+
};
|
|
8
|
+
export declare function annotationPaint(annotation: Annotation, { content, bounds, viewport }: Pick<AnnotationGeometry, 'content' | 'bounds' | 'viewport'>): {
|
|
9
|
+
bottom_border?: AnnotationPaint | undefined;
|
|
10
|
+
rectangle: {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
};
|
|
16
|
+
color: string;
|
|
17
|
+
opacity: number;
|
|
18
|
+
blend: "source-over" | "darken";
|
|
19
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function annotationPaint(annotation, { content, bounds, viewport }) {
|
|
2
|
+
const padding = annotation.appearance.padding;
|
|
3
|
+
const x = Math.max(0, content.x, Math.floor(content.x + (bounds.x - padding.x) * content.width));
|
|
4
|
+
const y = Math.max(0, content.y, Math.floor(content.y + (bounds.y - padding.y) * content.height));
|
|
5
|
+
const right = Math.min(viewport.width, content.x + content.width, Math.ceil(content.x + (bounds.x + bounds.width + padding.x) * content.width));
|
|
6
|
+
const bottom = Math.min(viewport.height, content.y + content.height, Math.ceil(content.y + (bounds.y + bounds.height + padding.y) * content.height));
|
|
7
|
+
const border = annotation.appearance.bottom_border;
|
|
8
|
+
const bottom_border = border ? {
|
|
9
|
+
rectangle: { x, y: bottom, width: right - x, height: Math.max(0, Math.min(border.height * content.height, content.y + content.height - bottom, viewport.height - bottom)) },
|
|
10
|
+
color: border.color, opacity: border.opacity, blend: 'source-over',
|
|
11
|
+
} : undefined;
|
|
12
|
+
return { rectangle: { x, y, width: right - x, height: bottom - y }, color: annotation.appearance.color, opacity: annotation.appearance.opacity, blend: annotation.appearance.blend ?? 'source-over', ...(bottom_border ? { bottom_border } : {}) };
|
|
13
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AnnotationGeometry, Rectangle, Schedule, Storyboard, VisualArtifact } from './contracts.js';
|
|
2
|
+
import { type AnnotationPaint } from './annotation-paint.js';
|
|
3
|
+
export type { AnnotationPaint } from './annotation-paint.js';
|
|
4
|
+
export type AppliedAnnotation = AnnotationPaint & {
|
|
5
|
+
id: string;
|
|
6
|
+
start_ms: number;
|
|
7
|
+
end_ms: number;
|
|
8
|
+
first_frame: number;
|
|
9
|
+
end_frame: number;
|
|
10
|
+
geometry: AnnotationGeometry;
|
|
11
|
+
bottom_border?: AnnotationPaint;
|
|
12
|
+
};
|
|
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<{
|
|
15
|
+
source: string;
|
|
16
|
+
target_ms: number;
|
|
17
|
+
checks: Record<string, unknown>[];
|
|
18
|
+
gaps: string[];
|
|
19
|
+
sha256: string;
|
|
20
|
+
base: {
|
|
21
|
+
file: string;
|
|
22
|
+
filter: string;
|
|
23
|
+
};
|
|
24
|
+
version: number;
|
|
25
|
+
status: string;
|
|
26
|
+
file: string;
|
|
27
|
+
}>;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { execute, hashFile, saveJson } from './media.js';
|
|
3
|
+
import { requireCondition } from './errors.js';
|
|
4
|
+
import { annotationPaint } from './annotation-paint.js';
|
|
5
|
+
export function annotationApplications(story, schedule, visual, audioOrigin) {
|
|
6
|
+
return (schedule.annotations ?? []).map(annotation => {
|
|
7
|
+
const context = { annotation: annotation.id, target: annotation.target };
|
|
8
|
+
const candidates = (visual.annotation_geometry ?? []).filter(item => item.id === annotation.id);
|
|
9
|
+
requireCondition(candidates.length === 1, 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id}: missing or ambiguous capture geometry`, 5, context);
|
|
10
|
+
const geometry = candidates[0];
|
|
11
|
+
const { content, bounds, viewport } = geometry;
|
|
12
|
+
const finite = [content.x, content.y, content.width, content.height, bounds.x, bounds.y, bounds.width, bounds.height, viewport.width, viewport.height, geometry.samples, geometry.observed_start_ms, geometry.observed_end_ms].every(Number.isFinite);
|
|
13
|
+
requireCondition(finite && geometry.scene === annotation.scene && geometry.slide === annotation.slide && geometry.visit === annotation.visit && geometry.click === annotation.click && geometry.start_ms === annotation.start_ms && geometry.end_ms === annotation.end_ms && geometry.samples >= 2 && geometry.observed_start_ms >= annotation.start_ms && geometry.observed_start_ms < annotation.end_ms && geometry.observed_end_ms >= annotation.end_ms, 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id}: incomplete or stale playback geometry`, 5, context);
|
|
14
|
+
requireCondition(viewport.width === visual.properties.width && viewport.height === visual.properties.height && viewport.width === story.output.width && viewport.height === story.output.height && content.x >= -0.01 && content.y >= -0.01 && content.width > 0 && content.height > 0 && content.x + content.width <= viewport.width + 0.01 && content.y + content.height <= viewport.height + 0.01 && bounds.x >= -0.00001 && bounds.y >= -0.00001 && bounds.width > 0 && bounds.height > 0 && bounds.x + bounds.width <= 1.00001 && bounds.y + bounds.height <= 1.00001, 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id}: invalid viewport, slide-content rectangle or target bounds`, 5, context);
|
|
15
|
+
const target = annotation.target;
|
|
16
|
+
if (target.type === 'region')
|
|
17
|
+
requireCondition(['x', 'y', 'width', 'height'].every(key => Math.abs(bounds[key] - target[key]) < 0.00001), 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id}: region geometry differs from authored coordinates`, 5, context);
|
|
18
|
+
const start_ms = annotation.start_ms + audioOrigin;
|
|
19
|
+
const end_ms = annotation.end_ms + audioOrigin;
|
|
20
|
+
const first_frame = Math.ceil(start_ms * story.output.fps / 1000 - 1e-9);
|
|
21
|
+
const end_frame = Math.ceil(end_ms * story.output.fps / 1000 - 1e-9);
|
|
22
|
+
requireCondition(first_frame < end_frame, 'ANNOTATION_FRAME_RANGE', `Annotation ${annotation.id}: interval contains no output frame at ${story.output.fps} fps`, 2, context);
|
|
23
|
+
return { id: annotation.id, start_ms, end_ms, first_frame, end_frame, ...annotationPaint(annotation, geometry), geometry };
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export async function verifyAnnotations(file, base, baseFilter, applications, story, directory, output, overlayBounds = () => []) {
|
|
27
|
+
const evidenceFile = join(directory, 'annotations-evidence.json');
|
|
28
|
+
const provenance = { sha256: await hashFile(file), base: { file: base, filter: baseFilter } };
|
|
29
|
+
await saveJson(evidenceFile, { version: 1, status: 'failed', file: join(directory, 'failed-composite.mp4'), ...provenance, checks: [], gaps: ['Final composite verification did not complete.'] });
|
|
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
|
+
const requested = applications.flatMap(item => [item.first_frame - 1, item.first_frame, item.end_frame - 1, item.end_frame]);
|
|
32
|
+
const indices = [...new Set(requested.filter(index => index >= 0 && index < metadata.frames.length))].sort((a, b) => a - b);
|
|
33
|
+
const select = `select='${indices.map(index => `eq(n,${index})`).join('+')}',scale=320:180,format=rgb24`;
|
|
34
|
+
const frames = await execute('ffmpeg', ['-v', 'error', '-xerror', '-i', file, '-vf', select, '-fps_mode', 'passthrough', '-f', 'rawvideo', '-']);
|
|
35
|
+
const originals = await execute('ffmpeg', ['-v', 'error', '-xerror', '-i', base, '-vf', `${baseFilter},${select}`, '-fps_mode', 'passthrough', '-f', 'rawvideo', '-']);
|
|
36
|
+
const bytes = 320 * 180 * 3;
|
|
37
|
+
requireCondition(frames.length === indices.length * bytes && originals.length === frames.length, 'ANNOTATION_EVIDENCE', 'Final and base frame decoding did not return the requested encoded frame samples', 6);
|
|
38
|
+
const checks = [];
|
|
39
|
+
const gaps = [];
|
|
40
|
+
const layers = applications.flatMap(item => [
|
|
41
|
+
{ ...item, part: 'fill' },
|
|
42
|
+
...(item.bottom_border ? [{ ...item, ...item.bottom_border, part: 'bottom_border' }] : []),
|
|
43
|
+
]);
|
|
44
|
+
const rgb = layers.map(item => [1, 3, 5].map(offset => Number.parseInt(item.color.slice(offset, offset + 2), 16)));
|
|
45
|
+
function blend(value, item, color) {
|
|
46
|
+
const painted = item.blend === 'darken' ? Math.min(value, color) : color;
|
|
47
|
+
return value * (1 - item.opacity) + painted * item.opacity;
|
|
48
|
+
}
|
|
49
|
+
function inside(rect, x, y) {
|
|
50
|
+
return x >= rect.x && x < rect.x + rect.width && y >= rect.y && y < rect.y + rect.height;
|
|
51
|
+
}
|
|
52
|
+
for (const [layer, item] of layers.entries()) {
|
|
53
|
+
if (item.first_frame >= item.end_frame || item.first_frame >= metadata.frames.length) {
|
|
54
|
+
gaps.push(`${item.id}: no active encoded frame is available to prove appearance`);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
for (const [boundary, first, expectedTime] of [['start', item.first_frame, item.start_ms], ['end', item.end_frame, item.end_ms]]) {
|
|
58
|
+
if (first >= metadata.frames.length) {
|
|
59
|
+
gaps.push(`${item.id}:${boundary}: no encoded frame exists after this boundary`);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
for (const index of [first - 1, first].filter(index => index >= 0)) {
|
|
63
|
+
const frameOffset = indices.indexOf(index) * bytes;
|
|
64
|
+
const covered = overlayBounds(index);
|
|
65
|
+
let expectedError = 0;
|
|
66
|
+
let oppositeError = 0;
|
|
67
|
+
let contrast = 0;
|
|
68
|
+
let count = 0;
|
|
69
|
+
for (let y = 0; y < 180; y++)
|
|
70
|
+
for (let x = 0; x < 320; x++) {
|
|
71
|
+
const px = (x + 0.5) * story.output.width / 320;
|
|
72
|
+
const py = (y + 0.5) * story.output.height / 180;
|
|
73
|
+
const rect = item.rectangle;
|
|
74
|
+
if (px < rect.x + story.output.width / 320 * 2 || px >= rect.x + rect.width - story.output.width / 320 * 2 || py < rect.y + story.output.height / 180 * 2 || py >= rect.y + rect.height - story.output.height / 180 * 2)
|
|
75
|
+
continue;
|
|
76
|
+
if (covered.some(bounds => inside(bounds, px, py)))
|
|
77
|
+
continue;
|
|
78
|
+
const offset = frameOffset + (y * 320 + x) * 3;
|
|
79
|
+
for (let channel = 0; channel < 3; channel++) {
|
|
80
|
+
let expected = originals[offset + channel];
|
|
81
|
+
let opposite = expected;
|
|
82
|
+
for (const [otherLayer, other] of layers.entries()) {
|
|
83
|
+
if (!inside(other.rectangle, px, py))
|
|
84
|
+
continue;
|
|
85
|
+
const active = index >= other.first_frame && index < other.end_frame;
|
|
86
|
+
if (active)
|
|
87
|
+
expected = blend(expected, other, rgb[otherLayer][channel]);
|
|
88
|
+
if (otherLayer === layer ? !active : active)
|
|
89
|
+
opposite = blend(opposite, other, rgb[otherLayer][channel]);
|
|
90
|
+
}
|
|
91
|
+
expectedError += Math.abs(frames[offset + channel] - expected);
|
|
92
|
+
oppositeError += Math.abs(frames[offset + channel] - opposite);
|
|
93
|
+
contrast += Math.abs(expected - opposite);
|
|
94
|
+
count++;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const timestamp = Number(metadata.frames[index].best_effort_timestamp_time) * 1000;
|
|
98
|
+
const passed = count > 0 && contrast / count >= 4 && expectedError / count <= 12 && expectedError < oppositeError * 0.7;
|
|
99
|
+
checks.push({ annotation: item.id, part: item.part, boundary, frame_index: index, encoded_ms: timestamp, expected_active: index >= item.first_frame && index < item.end_frame, expected_error: count ? expectedError / count : null, opposite_error: count ? oppositeError / count : null, contrast: count ? contrast / count : null, passed });
|
|
100
|
+
if (!passed)
|
|
101
|
+
gaps.push(`${item.id}:${item.part}:${boundary}: frame ${index} does not distinguish the expected highlight state from its opposite`);
|
|
102
|
+
}
|
|
103
|
+
const observed = Number(metadata.frames[first].best_effort_timestamp_time) * 1000;
|
|
104
|
+
if (!Number.isFinite(observed) || Math.abs(observed - expectedTime) + 1000 / story.output.fps > 100)
|
|
105
|
+
gaps.push(`${item.id}:${boundary}: encoded timestamp uncertainty exceeds 100 ms`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
for (const item of layers)
|
|
109
|
+
if (!checks.some(check => check.annotation === item.id && check.part === item.part && check.expected_active === true && check.passed === true))
|
|
110
|
+
gaps.push(`${item.id}:${item.part}: no verified active encoded frame proves appearance`);
|
|
111
|
+
const evidence = { version: 1, status: gaps.length ? 'failed' : 'accepted', file: gaps.length ? join(directory, 'failed-composite.mp4') : output, ...provenance, source: 'final encoded MP4 compared with decoded unannotated capture in the same output timebase', target_ms: 100, checks, gaps };
|
|
112
|
+
await saveJson(evidenceFile, evidence);
|
|
113
|
+
requireCondition(evidence.status === 'accepted', 'ANNOTATION_TIMING', `Final composite annotation timing failed. See ${evidenceFile}`, 6);
|
|
114
|
+
return evidence;
|
|
115
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Schedule, SpeechManifest, Storyboard, VisualArtifact, ProductionOptions } from './contracts.js';
|
|
2
|
+
type AssemblyOptions = ProductionOptions & {
|
|
3
|
+
licensed?: boolean;
|
|
4
|
+
inputHashes?: Record<string, string>;
|
|
5
|
+
};
|
|
6
|
+
export declare function assemble(story: Storyboard, schedule: Schedule, speech: SpeechManifest, visual: VisualArtifact, directory: string, output: string, options?: AssemblyOptions): Promise<{
|
|
7
|
+
output_origin_delta_ms: number;
|
|
8
|
+
audio_origin_ms: number;
|
|
9
|
+
picture_lead_hold_ms: number;
|
|
10
|
+
final_hold: string;
|
|
11
|
+
trim_start_ms: number;
|
|
12
|
+
trim_end_ms: number;
|
|
13
|
+
mapping: import("./contracts.js").CaptureMapping;
|
|
14
|
+
transformations: unknown[];
|
|
15
|
+
editorial_review: string;
|
|
16
|
+
compositor?: {
|
|
17
|
+
renderer: string;
|
|
18
|
+
version: string;
|
|
19
|
+
frames: number;
|
|
20
|
+
} | undefined;
|
|
21
|
+
base_capture_timing?: "accepted" | "not_evaluated" | undefined;
|
|
22
|
+
applied_annotations?: import("./annotations.js").AppliedAnnotation[] | undefined;
|
|
23
|
+
final_composite?: {
|
|
24
|
+
source: string;
|
|
25
|
+
target_ms: number;
|
|
26
|
+
checks: Record<string, unknown>[];
|
|
27
|
+
gaps: string[];
|
|
28
|
+
sha256: string;
|
|
29
|
+
base: {
|
|
30
|
+
file: string;
|
|
31
|
+
filter: string;
|
|
32
|
+
};
|
|
33
|
+
version: number;
|
|
34
|
+
status: string;
|
|
35
|
+
file: string;
|
|
36
|
+
} | {
|
|
37
|
+
status: string;
|
|
38
|
+
gaps: string[];
|
|
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;
|
|
47
|
+
}>;
|
|
48
|
+
export {};
|