@slidevideo/cli 0.10.0 → 0.11.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 +5 -0
- package/addons/slidevideo/global-top.vue +15 -2
- package/addons/slidevideo/preview.ts +27 -3
- package/dist/adapters/powerpoint.js +67 -52
- package/dist/adapters/slidev-inspection.js +10 -3
- package/dist/assembly.d.ts +2 -2
- package/dist/assembly.js +129 -10
- package/dist/contracts.d.ts +77 -18
- package/dist/pipeline.js +56 -27
- package/dist/preview/contracts.d.ts +20 -0
- package/dist/preview/player.js +435 -14
- package/dist/preview/server.js +146 -45
- package/dist/standalone-media.d.ts +27 -0
- package/dist/standalone-media.js +201 -0
- package/dist/storyboard.js +83 -8
- package/dist/timing.js +306 -35
- package/package.json +3 -1
- package/schemas/schedule.v1.json +67 -0
- package/schemas/storyboard.v1.json +673 -494
- package/skills/slidevideo/SKILL.md +3 -3
- package/skills/slidevideo/references/decks.md +3 -3
- package/skills/slidevideo/references/production.md +1 -1
- package/skills/slidevideo/references/storyboard.md +74 -9
package/dist/preview/server.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createServer } from 'node:http';
|
|
2
|
-
import {
|
|
2
|
+
import { createReadStream } from 'node:fs';
|
|
3
|
+
import { mkdtemp, readFile, rm, stat } from 'node:fs/promises';
|
|
3
4
|
import { tmpdir } from 'node:os';
|
|
4
|
-
import { basename, join, resolve } from 'node:path';
|
|
5
|
+
import { basename, extname, join, resolve } from 'node:path';
|
|
5
6
|
import { defaultViewport } from '../contracts.js';
|
|
6
7
|
import { presentationAdapter, ttsAdapters } from '../adapters/registry.js';
|
|
7
8
|
import { ProductionError, requireCondition } from '../errors.js';
|
|
@@ -9,31 +10,41 @@ import { executionScope } from '../media.js';
|
|
|
9
10
|
import { loadStoryboard } from '../storyboard.js';
|
|
10
11
|
import { resolvePreviewTiming } from '../timing.js';
|
|
11
12
|
import { resolveSpeechCache } from '../speech.js';
|
|
13
|
+
import { hasSlideScenes, hasStandaloneMediaSchedule, projectDeckSchedule } from '../standalone-media.js';
|
|
12
14
|
import { BUNDLED_STAMP_FONTS, bundledFontPath } from '../stamp-fonts.js';
|
|
13
15
|
import { playerPage } from './view.js';
|
|
14
16
|
function send(res, status, contentType, body) {
|
|
15
17
|
res.writeHead(status, { 'Content-Type': contentType });
|
|
16
18
|
res.end(body);
|
|
17
19
|
}
|
|
18
|
-
function
|
|
19
|
-
switch (format.toLowerCase()) {
|
|
20
|
+
function mediaContentType(format) {
|
|
21
|
+
switch (format.toLowerCase().replace(/^\./, '')) {
|
|
20
22
|
case 'mp3': return 'audio/mpeg';
|
|
21
23
|
case 'wav': return 'audio/wav';
|
|
22
24
|
case 'ogg': return 'audio/ogg';
|
|
23
25
|
case 'm4a': return 'audio/mp4';
|
|
24
|
-
case 'webm': return '
|
|
26
|
+
case 'webm': return 'video/webm';
|
|
27
|
+
case 'mp4': return 'video/mp4';
|
|
28
|
+
case 'mov': return 'video/quicktime';
|
|
25
29
|
case 'aac': return 'audio/aac';
|
|
26
30
|
default: return 'application/octet-stream';
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
|
-
async function
|
|
30
|
-
const
|
|
31
|
-
const contentType =
|
|
33
|
+
async function sendRangeFile(req, res, filePath, format) {
|
|
34
|
+
const { size } = await stat(filePath);
|
|
35
|
+
const contentType = mediaContentType(format);
|
|
32
36
|
const range = req.headers.range;
|
|
37
|
+
const pipeStream = (start, end) => {
|
|
38
|
+
const stream = createReadStream(filePath, { start, end });
|
|
39
|
+
res.once('close', () => stream.destroy());
|
|
40
|
+
stream.once('error', () => { if (!res.destroyed)
|
|
41
|
+
res.destroy(); });
|
|
42
|
+
stream.pipe(res);
|
|
43
|
+
};
|
|
33
44
|
if (range) {
|
|
34
45
|
const match = /^bytes=(\d*)-(\d*)$/.exec(range.trim());
|
|
35
|
-
if (!match || (!match[1] && !match[2]) ||
|
|
36
|
-
res.writeHead(416, { 'Content-Range': `bytes */${
|
|
46
|
+
if (!match || (!match[1] && !match[2]) || size === 0) {
|
|
47
|
+
res.writeHead(416, { 'Content-Range': `bytes */${size}` });
|
|
37
48
|
res.end();
|
|
38
49
|
return;
|
|
39
50
|
}
|
|
@@ -42,40 +53,43 @@ async function sendAudio(req, res, filePath, format) {
|
|
|
42
53
|
if (!match[1]) {
|
|
43
54
|
const suffix = Number(match[2]);
|
|
44
55
|
if (suffix === 0) {
|
|
45
|
-
res.writeHead(416, { 'Content-Range': `bytes */${
|
|
56
|
+
res.writeHead(416, { 'Content-Range': `bytes */${size}` });
|
|
46
57
|
res.end();
|
|
47
58
|
return;
|
|
48
59
|
}
|
|
49
|
-
start = Math.max(0,
|
|
50
|
-
end =
|
|
60
|
+
start = Math.max(0, size - suffix);
|
|
61
|
+
end = size - 1;
|
|
51
62
|
}
|
|
52
63
|
else {
|
|
53
64
|
start = Number(match[1]);
|
|
54
|
-
end = match[2] ? Math.min(
|
|
65
|
+
end = match[2] ? Math.min(size - 1, Number(match[2])) : size - 1;
|
|
55
66
|
}
|
|
56
|
-
if (start >=
|
|
57
|
-
res.writeHead(416, { 'Content-Range': `bytes */${
|
|
67
|
+
if (start >= size || start > end) {
|
|
68
|
+
res.writeHead(416, { 'Content-Range': `bytes */${size}` });
|
|
58
69
|
res.end();
|
|
59
70
|
return;
|
|
60
71
|
}
|
|
61
|
-
const chunk = data.subarray(start, end + 1);
|
|
62
72
|
res.writeHead(206, {
|
|
63
73
|
'Content-Type': contentType,
|
|
64
|
-
'Content-Length':
|
|
65
|
-
'Content-Range': `bytes ${start}-${end}/${
|
|
74
|
+
'Content-Length': end - start + 1,
|
|
75
|
+
'Content-Range': `bytes ${start}-${end}/${size}`,
|
|
66
76
|
'Accept-Ranges': 'bytes',
|
|
67
77
|
'Cache-Control': 'private, max-age=3600',
|
|
68
78
|
});
|
|
69
|
-
|
|
79
|
+
pipeStream(start, end);
|
|
70
80
|
return;
|
|
71
81
|
}
|
|
72
82
|
res.writeHead(200, {
|
|
73
83
|
'Content-Type': contentType,
|
|
74
|
-
'Content-Length':
|
|
84
|
+
'Content-Length': size,
|
|
75
85
|
'Accept-Ranges': 'bytes',
|
|
76
86
|
'Cache-Control': 'private, max-age=3600',
|
|
77
87
|
});
|
|
78
|
-
|
|
88
|
+
if (size === 0) {
|
|
89
|
+
res.end();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
pipeStream(0, size - 1);
|
|
79
93
|
}
|
|
80
94
|
export async function servePreview(storyboard, cache, port, viewport = defaultViewport, ready) {
|
|
81
95
|
let origin = '';
|
|
@@ -84,6 +98,7 @@ export async function servePreview(storyboard, cache, port, viewport = defaultVi
|
|
|
84
98
|
let adapter;
|
|
85
99
|
let directory;
|
|
86
100
|
let audioFiles = new Map();
|
|
101
|
+
let mediaFiles = new Map();
|
|
87
102
|
let preserveDiagnostics = false;
|
|
88
103
|
const controller = new AbortController();
|
|
89
104
|
const stop = () => controller.abort();
|
|
@@ -94,10 +109,10 @@ export async function servePreview(storyboard, cache, port, viewport = defaultVi
|
|
|
94
109
|
if (req.headers.host !== new URL(origin).host || (req.method === 'POST' && req.headers.origin !== origin)) {
|
|
95
110
|
return send(res, 403, 'text/plain', 'Open the local preview URL printed by SlideVideo.');
|
|
96
111
|
}
|
|
97
|
-
if (!config
|
|
112
|
+
if (!config)
|
|
98
113
|
return send(res, 503, 'text/plain', 'Preparing presentation');
|
|
99
114
|
const { pathname } = new URL(req.url ?? '/', origin);
|
|
100
|
-
if (pathname.startsWith('/native/') && 'request' in session)
|
|
115
|
+
if (pathname.startsWith('/native/') && session && 'request' in session)
|
|
101
116
|
return session.request(req, res);
|
|
102
117
|
if (req.method !== 'GET')
|
|
103
118
|
return send(res, 405, 'text/plain', 'Method not allowed');
|
|
@@ -139,7 +154,20 @@ export async function servePreview(storyboard, cache, port, viewport = defaultVi
|
|
|
139
154
|
const file = audioFiles.get(segment);
|
|
140
155
|
if (!file)
|
|
141
156
|
return send(res, 404, 'text/plain', 'Not found');
|
|
142
|
-
return
|
|
157
|
+
return sendRangeFile(req, res, file.path, file.format);
|
|
158
|
+
}
|
|
159
|
+
if (pathname.startsWith('/media/')) {
|
|
160
|
+
let mediaId;
|
|
161
|
+
try {
|
|
162
|
+
mediaId = decodeURIComponent(pathname.slice('/media/'.length));
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return send(res, 400, 'text/plain', 'Invalid media ID');
|
|
166
|
+
}
|
|
167
|
+
const file = mediaFiles.get(mediaId);
|
|
168
|
+
if (!file)
|
|
169
|
+
return send(res, 404, 'text/plain', 'Not found');
|
|
170
|
+
return sendRangeFile(req, res, file, extname(file) || 'mp4');
|
|
143
171
|
}
|
|
144
172
|
send(res, 404, 'text/plain', 'Not found');
|
|
145
173
|
}
|
|
@@ -159,13 +187,18 @@ export async function servePreview(storyboard, cache, port, viewport = defaultVi
|
|
|
159
187
|
const source = resolve(storyboard);
|
|
160
188
|
const story = await loadStoryboard(source);
|
|
161
189
|
requireCondition(!story.overlays?.length, 'PREVIEW_CAPABILITY', 'Image overlays require an exported video. Use slidevideo build to review them.', 3);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
190
|
+
const needsDeck = hasSlideScenes(story);
|
|
191
|
+
adapter = needsDeck ? presentationAdapter(story.deck) : undefined;
|
|
192
|
+
if (adapter)
|
|
193
|
+
requireCondition(adapter.startPreview, 'PREVIEW_CAPABILITY', `Adapter ${adapter.id} does not support preview`, 3);
|
|
194
|
+
const inspection = adapter ? await adapter.inspect(story.deck) : undefined;
|
|
195
|
+
if (adapter && inspection)
|
|
196
|
+
await adapter.validate(story, inspection, { viewport });
|
|
166
197
|
const { schedule, approximate, approximateCues, audio: verifiedAudio } = await resolvePreviewTiming(story, ttsAdapters, resolveSpeechCache(source, cache));
|
|
167
198
|
audioFiles = verifiedAudio;
|
|
168
|
-
|
|
199
|
+
mediaFiles = new Map(schedule.media.map(item => [item.id, item.src]));
|
|
200
|
+
if (adapter && inspection)
|
|
201
|
+
await adapter.validate(story, inspection, { viewport, schedule });
|
|
169
202
|
controller.signal.throwIfAborted();
|
|
170
203
|
await new Promise((resolve, reject) => {
|
|
171
204
|
server.once('error', reject);
|
|
@@ -176,19 +209,52 @@ export async function servePreview(storyboard, cache, port, viewport = defaultVi
|
|
|
176
209
|
origin = `http://127.0.0.1:${address.port}`;
|
|
177
210
|
directory = await mkdtemp(join(tmpdir(), 'slidevideo-preview-'));
|
|
178
211
|
controller.signal.throwIfAborted();
|
|
179
|
-
|
|
212
|
+
const hasStandalone = hasStandaloneMediaSchedule(schedule);
|
|
213
|
+
const projection = hasStandalone ? projectDeckSchedule(story, schedule) : undefined;
|
|
214
|
+
if (adapter) {
|
|
215
|
+
session = await adapter.startPreview(projection?.storyboard ?? story, projection?.schedule ?? schedule, directory, origin, viewport);
|
|
216
|
+
}
|
|
180
217
|
controller.signal.throwIfAborted();
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
218
|
+
let scenes;
|
|
219
|
+
if (hasStandalone && schedule.scenes?.length) {
|
|
220
|
+
const deckByScene = new Map((projection?.windows ?? []).map(win => [win.id, win]));
|
|
221
|
+
scenes = schedule.scenes.map(scene => {
|
|
222
|
+
if (scene.kind === 'media') {
|
|
223
|
+
return {
|
|
224
|
+
id: scene.id,
|
|
225
|
+
kind: 'media',
|
|
226
|
+
slide: scene.media,
|
|
227
|
+
media: scene.media,
|
|
228
|
+
media_url: `/media/${encodeURIComponent(scene.media)}`,
|
|
229
|
+
start_ms: scene.start_ms,
|
|
230
|
+
end_ms: scene.end_ms,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
const win = deckByScene.get(scene.id);
|
|
234
|
+
return {
|
|
235
|
+
id: scene.id,
|
|
236
|
+
kind: 'slide',
|
|
237
|
+
slide: scene.slide,
|
|
238
|
+
start_ms: scene.start_ms,
|
|
239
|
+
end_ms: scene.end_ms,
|
|
240
|
+
...(win ? { deck_start_ms: win.deck_start_ms, deck_end_ms: win.deck_end_ms } : {}),
|
|
241
|
+
};
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
const slideActions = schedule.actions.filter(item => item.action.type === 'slide');
|
|
246
|
+
scenes = slideActions.map((item, index) => {
|
|
247
|
+
const target = item.action.type === 'slide' ? item.action.target : '';
|
|
248
|
+
const isSceneStart = item.id === `${item.scene}:slide`;
|
|
249
|
+
return {
|
|
250
|
+
id: isSceneStart ? item.scene : `${item.scene} · ${target}`,
|
|
251
|
+
kind: 'slide',
|
|
252
|
+
slide: target,
|
|
253
|
+
start_ms: item.start_ms,
|
|
254
|
+
end_ms: slideActions[index + 1]?.start_ms ?? schedule.duration_ms,
|
|
255
|
+
};
|
|
256
|
+
});
|
|
257
|
+
}
|
|
192
258
|
const audio = [];
|
|
193
259
|
for (const item of schedule.actions) {
|
|
194
260
|
if (item.action.type === 'speak' && audioFiles.has(item.action.segment)) {
|
|
@@ -200,9 +266,44 @@ export async function servePreview(storyboard, cache, port, viewport = defaultVi
|
|
|
200
266
|
});
|
|
201
267
|
}
|
|
202
268
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
269
|
+
const media = [];
|
|
270
|
+
for (const item of schedule.actions) {
|
|
271
|
+
if (item.action.type === 'play') {
|
|
272
|
+
const rate = item.action.rate ?? 1;
|
|
273
|
+
const trimStart = item.action.trim_start_ms ?? 0;
|
|
274
|
+
const trimEnd = item.action.trim_end_ms ?? (trimStart + (item.end_ms - item.start_ms) * rate);
|
|
275
|
+
media.push({
|
|
276
|
+
media: item.action.media,
|
|
277
|
+
scene: item.scene,
|
|
278
|
+
start_ms: item.start_ms,
|
|
279
|
+
end_ms: item.end_ms,
|
|
280
|
+
trim_start_ms: trimStart,
|
|
281
|
+
trim_end_ms: trimEnd,
|
|
282
|
+
rate,
|
|
283
|
+
audio: item.action.audio,
|
|
284
|
+
volume: item.action.volume,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const mediaSceneIds = new Set((schedule.scenes ?? []).filter(scene => scene.kind === 'media').map(scene => scene.id));
|
|
289
|
+
const standaloneAnnotations = schedule.annotations.filter(ann => mediaSceneIds.has(ann.scene));
|
|
290
|
+
config = {
|
|
291
|
+
deck: story.deck ? basename(story.deck) : basename(source),
|
|
292
|
+
width: viewport.width,
|
|
293
|
+
height: viewport.height,
|
|
294
|
+
duration: schedule.duration_ms,
|
|
295
|
+
approximate,
|
|
296
|
+
approximate_cues: approximateCues,
|
|
297
|
+
scenes,
|
|
298
|
+
audio,
|
|
299
|
+
media,
|
|
300
|
+
...(standaloneAnnotations.length ? { standalone_annotations: standaloneAnnotations } : {}),
|
|
301
|
+
stage: !session
|
|
302
|
+
? { standalone: true }
|
|
303
|
+
: 'url' in session
|
|
304
|
+
? { url: session.url }
|
|
305
|
+
: { annotations: projection?.schedule.annotations ?? schedule.annotations },
|
|
306
|
+
};
|
|
206
307
|
ready(origin, approximate, approximateCues);
|
|
207
308
|
await new Promise(resolve => controller.signal.addEventListener('abort', () => resolve(), { once: true }));
|
|
208
309
|
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Annotation, AnnotationGeometry, MediaScene, Schedule, Scene, SlideScene, Storyboard, VideoOutput, VisualArtifact } from './contracts.js';
|
|
2
|
+
export type DeckSceneWindow = {
|
|
3
|
+
id: string;
|
|
4
|
+
slide: string;
|
|
5
|
+
full_start_ms: number;
|
|
6
|
+
full_end_ms: number;
|
|
7
|
+
deck_start_ms: number;
|
|
8
|
+
deck_end_ms: number;
|
|
9
|
+
};
|
|
10
|
+
export type DeckProjection = {
|
|
11
|
+
storyboard: Storyboard;
|
|
12
|
+
schedule: Schedule;
|
|
13
|
+
windows: DeckSceneWindow[];
|
|
14
|
+
};
|
|
15
|
+
export declare function isMediaScene(scene: Scene): scene is MediaScene;
|
|
16
|
+
export declare function isSlideScene(scene: Scene): scene is SlideScene;
|
|
17
|
+
export declare function hasStandaloneMedia(story: Storyboard): boolean;
|
|
18
|
+
export declare function hasSlideScenes(story: Storyboard): boolean;
|
|
19
|
+
export declare function hasStandaloneMediaSchedule(schedule: Schedule): boolean;
|
|
20
|
+
export declare function hasSlideScenesSchedule(schedule: Schedule): boolean;
|
|
21
|
+
export declare function cueOwners(story: Storyboard): Map<string, string>;
|
|
22
|
+
export declare function slideSceneCues(story: Storyboard): Storyboard['cues'];
|
|
23
|
+
export declare function deckMediaIds(story: Storyboard): Set<string>;
|
|
24
|
+
export declare function annotationHasDeckTarget(annotation: Annotation): boolean;
|
|
25
|
+
export declare function projectDeckSchedule(story: Storyboard, schedule: Schedule): DeckProjection | undefined;
|
|
26
|
+
export declare function remapDeckVisualToFull(visual: VisualArtifact, windows: DeckSceneWindow[]): VisualArtifact;
|
|
27
|
+
export declare function standaloneAnnotationGeometry(schedule: Schedule, video: VideoOutput): AnnotationGeometry[];
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { geometryRequests } from './annotation-paint.js';
|
|
2
|
+
export function isMediaScene(scene) {
|
|
3
|
+
return 'media' in scene && scene.media !== undefined;
|
|
4
|
+
}
|
|
5
|
+
export function isSlideScene(scene) {
|
|
6
|
+
return 'slide' in scene && scene.slide !== undefined;
|
|
7
|
+
}
|
|
8
|
+
export function hasStandaloneMedia(story) {
|
|
9
|
+
return story.scenes.some(isMediaScene);
|
|
10
|
+
}
|
|
11
|
+
export function hasSlideScenes(story) {
|
|
12
|
+
return story.scenes.some(isSlideScene);
|
|
13
|
+
}
|
|
14
|
+
export function hasStandaloneMediaSchedule(schedule) {
|
|
15
|
+
return Boolean(schedule.scenes?.some(scene => scene.kind === 'media'));
|
|
16
|
+
}
|
|
17
|
+
export function hasSlideScenesSchedule(schedule) {
|
|
18
|
+
if (!schedule.scenes?.length)
|
|
19
|
+
return true;
|
|
20
|
+
return schedule.scenes.some(scene => scene.kind === 'slide');
|
|
21
|
+
}
|
|
22
|
+
export function cueOwners(story) {
|
|
23
|
+
const segmentScene = new Map();
|
|
24
|
+
const scenePlayScene = new Map();
|
|
25
|
+
const scenePlaysByMedia = new Map();
|
|
26
|
+
for (const scene of story.scenes) {
|
|
27
|
+
for (const action of scene.actions) {
|
|
28
|
+
if (action.type === 'speak')
|
|
29
|
+
segmentScene.set(action.segment, scene.id);
|
|
30
|
+
if (action.type === 'play') {
|
|
31
|
+
scenePlayScene.set(action.id, scene.id);
|
|
32
|
+
scenePlaysByMedia.set(action.media, [...(scenePlaysByMedia.get(action.media) ?? []), action.id]);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
for (const cue of story.cues) {
|
|
37
|
+
if ('media' in cue.at && cue.action.type === 'speak') {
|
|
38
|
+
const playId = cue.at.play ?? scenePlaysByMedia.get(cue.at.media)?.[0];
|
|
39
|
+
const sceneId = playId ? scenePlayScene.get(playId) : undefined;
|
|
40
|
+
if (sceneId)
|
|
41
|
+
segmentScene.set(cue.action.segment, sceneId);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const owners = new Map();
|
|
45
|
+
for (const cue of story.cues) {
|
|
46
|
+
let sceneId;
|
|
47
|
+
if ('media' in cue.at) {
|
|
48
|
+
const playId = cue.at.play ?? scenePlaysByMedia.get(cue.at.media)?.[0];
|
|
49
|
+
sceneId = playId ? scenePlayScene.get(playId) : undefined;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
sceneId = segmentScene.get(cue.at.segment);
|
|
53
|
+
}
|
|
54
|
+
if (sceneId)
|
|
55
|
+
owners.set(cue.id, sceneId);
|
|
56
|
+
}
|
|
57
|
+
return owners;
|
|
58
|
+
}
|
|
59
|
+
export function slideSceneCues(story) {
|
|
60
|
+
const slideSceneIds = new Set(story.scenes.filter(isSlideScene).map(scene => scene.id));
|
|
61
|
+
const owners = cueOwners(story);
|
|
62
|
+
return story.cues.filter(cue => {
|
|
63
|
+
const sceneId = owners.get(cue.id);
|
|
64
|
+
return sceneId !== undefined && slideSceneIds.has(sceneId);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
export function deckMediaIds(story) {
|
|
68
|
+
const ids = new Set();
|
|
69
|
+
for (const scene of story.scenes) {
|
|
70
|
+
if (!isSlideScene(scene))
|
|
71
|
+
continue;
|
|
72
|
+
for (const action of scene.actions) {
|
|
73
|
+
if (action.type === 'play')
|
|
74
|
+
ids.add(action.media);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
for (const cue of slideSceneCues(story)) {
|
|
78
|
+
if (cue.action.type === 'play')
|
|
79
|
+
ids.add(cue.action.media);
|
|
80
|
+
}
|
|
81
|
+
return ids;
|
|
82
|
+
}
|
|
83
|
+
export function annotationHasDeckTarget(annotation) {
|
|
84
|
+
const targets = annotation.target.type === 'path'
|
|
85
|
+
? annotation.target.points.flatMap(point => 'target' in point ? [point.target] : [])
|
|
86
|
+
: annotation.target.type === 'connector'
|
|
87
|
+
? [annotation.target.from, annotation.target.to].flatMap(ep => 'target' in ep ? [ep.target] : [])
|
|
88
|
+
: [annotation.target];
|
|
89
|
+
return targets.some(target => target.type === 'element' || target.type === 'shape' || target.type === 'text');
|
|
90
|
+
}
|
|
91
|
+
export function projectDeckSchedule(story, schedule) {
|
|
92
|
+
const scenes = schedule.scenes ?? [];
|
|
93
|
+
const slideScenes = scenes.filter((scene) => scene.kind === 'slide');
|
|
94
|
+
if (!slideScenes.length)
|
|
95
|
+
return undefined;
|
|
96
|
+
let deckCursor = 0;
|
|
97
|
+
const windows = [];
|
|
98
|
+
const byScene = new Map();
|
|
99
|
+
for (const scene of slideScenes) {
|
|
100
|
+
const duration = scene.end_ms - scene.start_ms;
|
|
101
|
+
const window = {
|
|
102
|
+
id: scene.id,
|
|
103
|
+
slide: scene.slide,
|
|
104
|
+
full_start_ms: scene.start_ms,
|
|
105
|
+
full_end_ms: scene.end_ms,
|
|
106
|
+
deck_start_ms: deckCursor,
|
|
107
|
+
deck_end_ms: deckCursor + duration,
|
|
108
|
+
};
|
|
109
|
+
windows.push(window);
|
|
110
|
+
byScene.set(scene.id, window);
|
|
111
|
+
deckCursor += duration;
|
|
112
|
+
}
|
|
113
|
+
const mapTime = (sceneId, fullMs) => {
|
|
114
|
+
const win = byScene.get(sceneId);
|
|
115
|
+
return win.deck_start_ms + (fullMs - win.full_start_ms);
|
|
116
|
+
};
|
|
117
|
+
const deckActions = schedule.actions
|
|
118
|
+
.filter(item => byScene.has(item.scene))
|
|
119
|
+
.map(item => ({
|
|
120
|
+
...item,
|
|
121
|
+
start_ms: mapTime(item.scene, item.start_ms),
|
|
122
|
+
end_ms: mapTime(item.scene, item.end_ms),
|
|
123
|
+
}));
|
|
124
|
+
const deckAnnotations = schedule.annotations
|
|
125
|
+
.filter(ann => byScene.has(ann.scene))
|
|
126
|
+
.map(ann => ({
|
|
127
|
+
...ann,
|
|
128
|
+
start_ms: mapTime(ann.scene, ann.start_ms),
|
|
129
|
+
end_ms: mapTime(ann.scene, ann.end_ms),
|
|
130
|
+
}));
|
|
131
|
+
const usedMedia = deckMediaIds(story);
|
|
132
|
+
for (const item of deckActions) {
|
|
133
|
+
if (item.action.type === 'play')
|
|
134
|
+
usedMedia.add(item.action.media);
|
|
135
|
+
}
|
|
136
|
+
const deckSchedule = {
|
|
137
|
+
version: 1,
|
|
138
|
+
duration_ms: deckCursor,
|
|
139
|
+
scenes: windows.map(win => ({ id: win.id, kind: 'slide', slide: win.slide, start_ms: win.deck_start_ms, end_ms: win.deck_end_ms })),
|
|
140
|
+
actions: deckActions,
|
|
141
|
+
media: schedule.media.filter(item => usedMedia.has(item.id)),
|
|
142
|
+
annotations: deckAnnotations,
|
|
143
|
+
};
|
|
144
|
+
const slideSceneIds = new Set(windows.map(win => win.id));
|
|
145
|
+
const deckStoryboard = {
|
|
146
|
+
...story,
|
|
147
|
+
media: story.media.filter(item => usedMedia.has(item.id)),
|
|
148
|
+
scenes: story.scenes.filter(isSlideScene),
|
|
149
|
+
annotations: story.annotations.filter(ann => slideSceneIds.has(ann.scene)),
|
|
150
|
+
};
|
|
151
|
+
return { storyboard: deckStoryboard, schedule: deckSchedule, windows };
|
|
152
|
+
}
|
|
153
|
+
export function remapDeckVisualToFull(visual, windows) {
|
|
154
|
+
if (!visual.annotation_geometry?.length)
|
|
155
|
+
return visual;
|
|
156
|
+
const byScene = new Map(windows.map(win => [win.id, win]));
|
|
157
|
+
const remapped = visual.annotation_geometry.map(entry => {
|
|
158
|
+
const win = byScene.get(entry.scene);
|
|
159
|
+
if (!win)
|
|
160
|
+
return entry;
|
|
161
|
+
const delta = win.full_start_ms - win.deck_start_ms;
|
|
162
|
+
return {
|
|
163
|
+
...entry,
|
|
164
|
+
start_ms: entry.start_ms + delta,
|
|
165
|
+
end_ms: entry.end_ms + delta,
|
|
166
|
+
observed_start_ms: entry.observed_start_ms + delta,
|
|
167
|
+
observed_end_ms: entry.observed_end_ms + delta,
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
return { ...visual, annotation_geometry: remapped };
|
|
171
|
+
}
|
|
172
|
+
export function standaloneAnnotationGeometry(schedule, video) {
|
|
173
|
+
const mediaSceneIds = new Set((schedule.scenes ?? []).filter(scene => scene.kind === 'media').map(scene => scene.id));
|
|
174
|
+
if (!mediaSceneIds.size)
|
|
175
|
+
return [];
|
|
176
|
+
const mediaSchedule = {
|
|
177
|
+
...schedule,
|
|
178
|
+
annotations: schedule.annotations.filter(ann => mediaSceneIds.has(ann.scene)),
|
|
179
|
+
};
|
|
180
|
+
if (!mediaSchedule.annotations.length)
|
|
181
|
+
return [];
|
|
182
|
+
const fullRect = { x: 0, y: 0, width: video.width, height: video.height };
|
|
183
|
+
return geometryRequests(mediaSchedule).map(request => ({
|
|
184
|
+
key: request.key,
|
|
185
|
+
target: request.target,
|
|
186
|
+
scene: request.scene,
|
|
187
|
+
slide: request.slide,
|
|
188
|
+
visit: request.visit,
|
|
189
|
+
click: request.click,
|
|
190
|
+
start_ms: request.start_ms,
|
|
191
|
+
end_ms: request.end_ms,
|
|
192
|
+
observed_start_ms: request.start_ms,
|
|
193
|
+
observed_end_ms: request.end_ms,
|
|
194
|
+
viewport: { width: video.width, height: video.height },
|
|
195
|
+
content: fullRect,
|
|
196
|
+
fragments: request.target.type === 'region'
|
|
197
|
+
? [{ x: request.target.x, y: request.target.y, width: request.target.width, height: request.target.height }]
|
|
198
|
+
: [],
|
|
199
|
+
samples: 2,
|
|
200
|
+
}));
|
|
201
|
+
}
|
package/dist/storyboard.js
CHANGED
|
@@ -3,6 +3,7 @@ import { dirname, extname, isAbsolute, resolve } from 'node:path';
|
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { parse } from 'yaml';
|
|
5
5
|
import { Ajv } from 'ajv';
|
|
6
|
+
import { annotationHasDeckTarget, isMediaScene, isSlideScene } from './standalone-media.js';
|
|
6
7
|
import { unsupportedStampGlyph } from './stamp-fonts.js';
|
|
7
8
|
import { requireCondition, ProductionError } from './errors.js';
|
|
8
9
|
import { hashFile, digest } from './media.js';
|
|
@@ -19,7 +20,9 @@ export async function loadStoryboard(file) {
|
|
|
19
20
|
}
|
|
20
21
|
export function validateStoryboard(data, file) {
|
|
21
22
|
requireCondition(validate(data), 'SCHEMA', JSON.stringify(validate.errors));
|
|
22
|
-
data.deck
|
|
23
|
+
if (data.deck !== undefined)
|
|
24
|
+
data.deck = resolve(dirname(file), data.deck);
|
|
25
|
+
requireCondition(data.deck !== undefined || !data.scenes.some(isSlideScene), 'DECK_REQUIRED', 'Storyboard with slide scenes requires a deck path');
|
|
23
26
|
data.media = data.media.map(media => ({ ...media, src: resolve(dirname(file), media.src) }));
|
|
24
27
|
const ids = new Set();
|
|
25
28
|
for (const item of [...data.scenes, ...data.narration, ...data.media, ...data.cues, ...data.annotations, ...(data.overlays ?? []), ...data.scenes.flatMap(s => s.actions)]) {
|
|
@@ -28,28 +31,101 @@ export function validateStoryboard(data, file) {
|
|
|
28
31
|
}
|
|
29
32
|
const segments = new Set(data.narration.map(n => n.id));
|
|
30
33
|
const spoken = new Set();
|
|
34
|
+
const segmentScene = new Map();
|
|
31
35
|
const mediaIds = new Set(data.media.map(m => m.id));
|
|
32
|
-
|
|
36
|
+
const mediaScenes = new Map();
|
|
37
|
+
const scenePlays = [];
|
|
38
|
+
for (const scene of data.scenes) {
|
|
39
|
+
if (isMediaScene(scene)) {
|
|
40
|
+
requireCondition(mediaIds.has(scene.media), 'MEDIA_REFERENCE', `Scene ${scene.id}: unknown media ${scene.media}`);
|
|
41
|
+
mediaScenes.set(scene.id, scene.media);
|
|
42
|
+
let hasPlay = false;
|
|
43
|
+
for (const action of scene.actions) {
|
|
44
|
+
const actionType = action.type;
|
|
45
|
+
requireCondition(actionType !== 'slide' && actionType !== 'reveal', 'MEDIA_SCENE_ACTION', `Scene ${scene.id}: standalone media scene does not support ${actionType} actions`);
|
|
46
|
+
if (action.type === 'play') {
|
|
47
|
+
requireCondition(action.media === scene.media, 'MEDIA_SCENE_ACTION', `Scene ${scene.id}: play action ${action.id} must reference scene media ${scene.media}`);
|
|
48
|
+
hasPlay = true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
requireCondition(hasPlay, 'MEDIA_SCENE_ACTION', `Standalone media scene ${scene.id} must include a play action for ${scene.media}`);
|
|
52
|
+
}
|
|
33
53
|
for (const action of scene.actions) {
|
|
34
54
|
if (action.type === 'speak') {
|
|
35
55
|
requireCondition(segments.has(action.segment) && !spoken.has(action.segment), 'SEGMENT_REFERENCE', `Narration ${action.segment} must exist and be scheduled once`);
|
|
36
56
|
spoken.add(action.segment);
|
|
57
|
+
segmentScene.set(action.segment, scene.id);
|
|
37
58
|
}
|
|
38
|
-
if (action.type === 'play')
|
|
59
|
+
if (action.type === 'play') {
|
|
39
60
|
requireCondition(mediaIds.has(action.media), 'MEDIA_REFERENCE', `Unknown media ${action.media}`);
|
|
61
|
+
const overflow = action.overflow ?? 'continuous';
|
|
62
|
+
if (action.min_rate !== undefined || action.max_rate !== undefined) {
|
|
63
|
+
requireCondition(overflow === 'fit_video', 'MEDIA_RATE_BOUNDS', `Play ${action.id}: min_rate and max_rate require overflow: fit_video`);
|
|
64
|
+
const minRate = action.min_rate ?? 0.75;
|
|
65
|
+
const maxRate = action.max_rate ?? 1.3;
|
|
66
|
+
requireCondition(minRate <= maxRate, 'MEDIA_RATE_BOUNDS', `Play ${action.id}: min_rate (${minRate}) cannot exceed max_rate (${maxRate})`);
|
|
67
|
+
}
|
|
68
|
+
scenePlays.push({ id: action.id, scene: scene.id, media: action.media });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function resolveMediaCueTarget(ownerLabel, at, context) {
|
|
73
|
+
requireCondition(mediaIds.has(at.media), 'MEDIA_REFERENCE', `${ownerLabel}: unknown media ${at.media}`, 2, context);
|
|
74
|
+
const matches = scenePlays.filter(entry => entry.media === at.media && (at.play === undefined || entry.id === at.play));
|
|
75
|
+
if (at.play !== undefined) {
|
|
76
|
+
requireCondition(matches.length === 1, 'MEDIA_CUE_TARGET', `${ownerLabel}: unknown play action ${at.play} for media ${at.media}`, 2, context);
|
|
77
|
+
return matches[0];
|
|
78
|
+
}
|
|
79
|
+
requireCondition(matches.length > 0, 'MEDIA_CUE_TARGET', `${ownerLabel}: media ${at.media} has no scene play action`, 2, context);
|
|
80
|
+
requireCondition(matches.length === 1, 'MEDIA_CUE_AMBIGUOUS', `${ownerLabel}: media ${at.media} is played multiple times; specify at.play`, 2, context);
|
|
81
|
+
return matches[0];
|
|
82
|
+
}
|
|
83
|
+
for (const cue of data.cues) {
|
|
84
|
+
if ('media' in cue.at) {
|
|
85
|
+
const targetPlay = resolveMediaCueTarget(`Cue ${cue.id}`, cue.at);
|
|
86
|
+
if (cue.action.type === 'speak') {
|
|
87
|
+
requireCondition(segments.has(cue.action.segment) && !spoken.has(cue.action.segment), 'SEGMENT_REFERENCE', `Narration ${cue.action.segment} must exist and be scheduled once`);
|
|
88
|
+
spoken.add(cue.action.segment);
|
|
89
|
+
segmentScene.set(cue.action.segment, targetPlay.scene);
|
|
90
|
+
}
|
|
40
91
|
}
|
|
92
|
+
}
|
|
41
93
|
requireCondition(spoken.size === segments.size, 'UNSCHEDULED_NARRATION', 'Each narration segment must be scheduled exactly once');
|
|
42
94
|
for (const cue of data.cues) {
|
|
43
|
-
|
|
44
|
-
if (cue.
|
|
95
|
+
let cueScene;
|
|
96
|
+
if ('media' in cue.at) {
|
|
97
|
+
cueScene = resolveMediaCueTarget(`Cue ${cue.id}`, cue.at).scene;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
requireCondition(segments.has(cue.at.segment), 'CUE_REFERENCE', `Cue ${cue.id} references unknown narration ${cue.at.segment}`);
|
|
101
|
+
cueScene = segmentScene.get(cue.at.segment);
|
|
102
|
+
}
|
|
103
|
+
if (cue.action.type === 'play') {
|
|
45
104
|
requireCondition(mediaIds.has(cue.action.media), 'MEDIA_REFERENCE', `Unknown media ${cue.action.media}`);
|
|
105
|
+
requireCondition((cue.action.overflow ?? 'continuous') === 'continuous' && cue.action.min_rate === undefined && cue.action.max_rate === undefined, 'MEDIA_OVERFLOW', `Cue ${cue.id}: beat-synced overflow policies require a scene play action`);
|
|
106
|
+
}
|
|
107
|
+
if (cueScene && mediaScenes.has(cueScene)) {
|
|
108
|
+
requireCondition(cue.action.type !== 'slide' && cue.action.type !== 'reveal', 'MEDIA_SCENE_ACTION', `Cue ${cue.id}: standalone media scene ${cueScene} does not support ${cue.action.type} actions`);
|
|
109
|
+
if (cue.action.type === 'play') {
|
|
110
|
+
requireCondition(cue.action.media === mediaScenes.get(cueScene), 'MEDIA_SCENE_ACTION', `Cue ${cue.id}: play action must reference standalone scene media ${mediaScenes.get(cueScene)}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
46
113
|
}
|
|
47
114
|
for (const annotation of data.annotations) {
|
|
48
115
|
const context = { annotation: annotation.id, target: annotation.target };
|
|
49
116
|
requireCondition(data.scenes.some(scene => scene.id === annotation.scene), 'ANNOTATION_SCENE', `Annotation ${annotation.id}: unknown scene ${annotation.scene}`, 2, context);
|
|
117
|
+
if (mediaScenes.has(annotation.scene)) {
|
|
118
|
+
requireCondition(!annotationHasDeckTarget(annotation), 'ANNOTATION_TARGET', `Annotation ${annotation.id}: standalone media scene ${annotation.scene} supports only normalized region, point, path, and connector targets`, 2, context);
|
|
119
|
+
}
|
|
50
120
|
if ('at' in annotation && annotation.at !== undefined) {
|
|
51
121
|
if (typeof annotation.at !== 'number') {
|
|
52
|
-
|
|
122
|
+
if ('media' in annotation.at) {
|
|
123
|
+
const targetPlay = resolveMediaCueTarget(`Annotation ${annotation.id}`, annotation.at, context);
|
|
124
|
+
requireCondition(targetPlay.scene === annotation.scene, 'ANNOTATION_SCENE', `Annotation ${annotation.id}: media cue targets play ${targetPlay.id} in scene ${targetPlay.scene}, not ${annotation.scene}`, 2, context);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
requireCondition(segments.has(annotation.at.segment), 'CUE_REFERENCE', `Annotation ${annotation.id}: unknown narration ${annotation.at.segment}`, 2, context);
|
|
128
|
+
}
|
|
53
129
|
}
|
|
54
130
|
}
|
|
55
131
|
else {
|
|
@@ -147,8 +223,7 @@ export function validateStoryboard(data, file) {
|
|
|
147
223
|
for (const { start, end } of overlay.visible ?? []) {
|
|
148
224
|
for (const boundary of [start, end]) {
|
|
149
225
|
requireCondition(typeof boundary === 'number' || segments.has(boundary.segment), 'CUE_REFERENCE', `Overlay ${overlay.id}: unknown narration segment`);
|
|
150
|
-
requireCondition(typeof boundary === 'number' || !overlay.scene ||
|
|
151
|
-
.find(scene => scene.id === overlay.scene)?.actions.some(action => action.type === 'speak' && action.segment === boundary.segment), 'OVERLAY_SCENE', `Overlay ${overlay.id}: phrase boundaries must refer to narration in scene ${overlay.scene}`);
|
|
226
|
+
requireCondition(typeof boundary === 'number' || !overlay.scene || segmentScene.get(boundary.segment) === overlay.scene, 'OVERLAY_SCENE', `Overlay ${overlay.id}: phrase boundaries must refer to narration in scene ${overlay.scene}`);
|
|
152
227
|
}
|
|
153
228
|
}
|
|
154
229
|
}
|