@slidevideo/cli 0.1.2 → 0.2.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 +41 -0
- package/IMPRESSUM.md +18 -4
- package/LICENSE-TERMS.md +46 -13
- package/README.md +5 -5
- package/addons/slidevideo/geometry.ts +63 -30
- package/addons/slidevideo/global-top.vue +41 -9
- package/addons/slidevideo/playback-entries.ts +17 -6
- package/addons/slidevideo/preview.ts +27 -15
- 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 +7 -4
- package/dist/adapters/powerpoint.js +123 -34
- package/dist/adapters/slidev-inspection.d.ts +5 -2
- package/dist/adapters/slidev-inspection.js +5 -6
- package/dist/adapters/slidev-server.js +136 -15
- package/dist/adapters/slidev.d.ts +12 -4
- package/dist/adapters/slidev.js +356 -70
- package/dist/annotation-paint.d.ts +65 -11
- package/dist/annotation-paint.js +290 -10
- package/dist/annotations.d.ts +13 -8
- package/dist/annotations.js +620 -89
- package/dist/assembly.d.ts +48 -40
- package/dist/assembly.js +72 -28
- package/dist/calibration.js +5 -4
- package/dist/cli.js +180 -39
- package/dist/compositor.d.ts +38 -6
- package/dist/compositor.js +299 -46
- package/dist/contracts.d.ts +96 -35
- package/dist/contracts.js +2 -1
- package/dist/executables.d.ts +2 -0
- package/dist/executables.js +27 -8
- package/dist/media.d.ts +12 -1
- package/dist/media.js +53 -4
- package/dist/pipeline.d.ts +36 -10
- package/dist/pipeline.js +163 -46
- package/dist/preview/contracts.d.ts +3 -3
- package/dist/preview/player.js +20 -15
- package/dist/preview/server.d.ts +2 -1
- package/dist/preview/server.js +8 -7
- 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 +29 -8
- package/dist/setup.js +183 -76
- package/dist/skill-install.d.ts +35 -0
- package/dist/skill-install.js +132 -0
- package/dist/speech.js +10 -6
- package/dist/storyboard.js +12 -6
- package/dist/timing.js +2 -2
- package/package.json +4 -3
- package/schemas/annotation-geometry.v1.json +260 -28
- package/schemas/run-manifest.v1.json +31 -0
- package/schemas/schedule.v1.json +655 -1
- package/schemas/storyboard.v1.json +558 -33
- package/skills/slidevideo/SKILL.md +11 -9
- package/skills/slidevideo/references/decks.md +228 -0
- package/skills/slidevideo/references/production.md +17 -12
- package/skills/slidevideo/references/storyboard.md +71 -38
- package/tools/powerpoint/powerpoint.ps1 +52 -41
- package/tools/powerpoint/preview.ps1 +5 -5
- package/schemas/schedule.v2.json +0 -496
- package/schemas/storyboard.v2.json +0 -802
package/dist/compositor.d.ts
CHANGED
|
@@ -1,18 +1,50 @@
|
|
|
1
1
|
import { type Canvas, type Image } from '@napi-rs/canvas';
|
|
2
|
-
import type { Rectangle, Schedule,
|
|
2
|
+
import type { Rectangle, Schedule, VideoOutput } from './contracts.js';
|
|
3
3
|
import type { AppliedAnnotation } from './annotations.js';
|
|
4
|
-
type FrameLayer = {
|
|
4
|
+
export type FrameLayer = {
|
|
5
5
|
image: Image | Canvas;
|
|
6
6
|
rectangle: Rectangle;
|
|
7
7
|
opacityAt?: (time: number) => number;
|
|
8
8
|
opacity: number;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
11
|
-
|
|
10
|
+
export type ActiveInterval = {
|
|
11
|
+
start: number;
|
|
12
|
+
end: number;
|
|
13
|
+
};
|
|
14
|
+
export type CompositorPlan = {
|
|
15
|
+
kind: 'none';
|
|
16
|
+
} | {
|
|
17
|
+
kind: 'sparse';
|
|
18
|
+
intervals: ActiveInterval[];
|
|
19
|
+
selectedFrames: number;
|
|
20
|
+
activeFrames: number;
|
|
21
|
+
betweenExpr: string;
|
|
22
|
+
ptsExpr: string;
|
|
23
|
+
readbackIntervals: ActiveInterval[];
|
|
24
|
+
selectedReadbackFrames: number;
|
|
25
|
+
readbackBetweenExpr?: string;
|
|
26
|
+
canvasLayers: FrameLayer[];
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'full';
|
|
29
|
+
activeFrames: number;
|
|
30
|
+
selectedReadbackFrames: number;
|
|
31
|
+
canvasLayers: FrameLayer[];
|
|
32
|
+
};
|
|
33
|
+
export declare function frameLayers(output: VideoOutput, schedule: Schedule, licensed: boolean, hashes?: Record<string, string>): Promise<FrameLayer[]>;
|
|
34
|
+
export declare function writeStaticFrameLayers(file: string, output: VideoOutput, layers: FrameLayer[]): Promise<void>;
|
|
12
35
|
export declare function visibleFrameLayerBounds(layers: FrameLayer[], frame: number, fps: number, audioOrigin: number): Rectangle[];
|
|
13
|
-
export declare function
|
|
36
|
+
export declare function splitFrameLayers(layers: FrameLayer[]): {
|
|
37
|
+
canvasLayers: FrameLayer[];
|
|
38
|
+
staticTopLayers: FrameLayer[];
|
|
39
|
+
};
|
|
40
|
+
export declare function planCompositor(frameCount: number, fps: number, audioOrigin: number, applications: AppliedAnnotation[], canvasLayers: FrameLayer[]): CompositorPlan;
|
|
41
|
+
export declare function compositeFrames(source: string, baseFilter: string, encoderArgs: string[], output: VideoOutput, applications: AppliedAnnotation[], plan: Exclude<CompositorPlan, {
|
|
42
|
+
kind: 'none';
|
|
43
|
+
}>, frameCount: number, audioOrigin: number, stagingDirectory: string): Promise<{
|
|
14
44
|
renderer: string;
|
|
15
45
|
version: string;
|
|
16
46
|
frames: number;
|
|
47
|
+
composited_frames: number;
|
|
48
|
+
readback_frames: number;
|
|
49
|
+
mode: "sparse" | "full";
|
|
17
50
|
}>;
|
|
18
|
-
export {};
|
package/dist/compositor.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { writeFile } from 'node:fs/promises';
|
|
3
|
-
import {
|
|
3
|
+
import { join } from 'node:path';
|
|
4
4
|
import { createCanvas, ImageData } from '@napi-rs/canvas';
|
|
5
|
-
import {
|
|
5
|
+
import { effectDirtyBounds, effectNeedsBaseFrames, paintEffects } from './annotation-paint.js';
|
|
6
|
+
import { balancedSum, executionSignal, ffmpegFilterScriptFlags, hasStageDeadline } from './media.js';
|
|
6
7
|
import { executable } from './executables.js';
|
|
7
8
|
import { ProductionError, requireCondition } from './errors.js';
|
|
8
9
|
import { loadOverlayImage } from './overlay-assets.js';
|
|
@@ -90,63 +91,315 @@ function completion(child, operation) {
|
|
|
90
91
|
void done.catch(() => { });
|
|
91
92
|
return done;
|
|
92
93
|
}
|
|
93
|
-
export
|
|
94
|
-
|
|
94
|
+
export function splitFrameLayers(layers) {
|
|
95
|
+
let lastDynamic = -1;
|
|
96
|
+
for (let index = 0; index < layers.length; index++) {
|
|
97
|
+
if (layers[index].opacityAt !== undefined)
|
|
98
|
+
lastDynamic = index;
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
canvasLayers: layers.slice(0, lastDynamic + 1),
|
|
102
|
+
staticTopLayers: layers.slice(lastDynamic + 1),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function mergeIntervals(raw) {
|
|
106
|
+
const merged = [];
|
|
107
|
+
for (const interval of raw) {
|
|
108
|
+
const previous = merged.at(-1);
|
|
109
|
+
if (previous && interval.start - previous.end <= 4)
|
|
110
|
+
previous.end = interval.end;
|
|
111
|
+
else
|
|
112
|
+
merged.push({ ...interval });
|
|
113
|
+
}
|
|
114
|
+
return merged;
|
|
115
|
+
}
|
|
116
|
+
function betweenExpression(intervals) {
|
|
117
|
+
return balancedSum(intervals.map(({ start, end }) => start === end - 1 ? `eq(n,${start})` : `between(n,${start},${end - 1})`));
|
|
118
|
+
}
|
|
119
|
+
function ptsExpression(intervals, fps) {
|
|
120
|
+
const terms = [`N+${intervals[0].start}`];
|
|
121
|
+
let cumulative = intervals[0].end - intervals[0].start;
|
|
122
|
+
for (let index = 1; index < intervals.length; index++) {
|
|
123
|
+
const gap = intervals[index].start - intervals[index - 1].end;
|
|
124
|
+
terms.push(`${gap}*gte(N,${cumulative})`);
|
|
125
|
+
cumulative += intervals[index].end - intervals[index].start;
|
|
126
|
+
}
|
|
127
|
+
return `(${balancedSum(terms)})/(${fps}*TB)`;
|
|
128
|
+
}
|
|
129
|
+
export function planCompositor(frameCount, fps, audioOrigin, applications, canvasLayers) {
|
|
130
|
+
if (frameCount <= 0 || (!applications.length && !canvasLayers.length))
|
|
131
|
+
return { kind: 'none' };
|
|
132
|
+
const rawActive = [];
|
|
133
|
+
const rawReadback = [];
|
|
134
|
+
let activeFrames = 0;
|
|
135
|
+
let openActiveStart = -1;
|
|
136
|
+
let openReadbackStart = -1;
|
|
137
|
+
for (let frame = 0; frame < frameCount; frame++) {
|
|
138
|
+
const outputTime = frame * 1000 / fps;
|
|
139
|
+
const scheduleTime = Math.max(0, outputTime - audioOrigin);
|
|
140
|
+
const activeEffects = applications.filter(item => frame >= item.first_frame && frame < item.end_frame);
|
|
141
|
+
const hasLayer = canvasLayers.some(layer => (layer.opacityAt ? layer.opacityAt(scheduleTime) : layer.opacity) > 0);
|
|
142
|
+
const active = activeEffects.length > 0 || hasLayer;
|
|
143
|
+
const needsBase = activeEffects.length > 0 && effectNeedsBaseFrames(activeEffects, outputTime);
|
|
144
|
+
if (active) {
|
|
145
|
+
activeFrames++;
|
|
146
|
+
if (openActiveStart < 0)
|
|
147
|
+
openActiveStart = frame;
|
|
148
|
+
}
|
|
149
|
+
else if (openActiveStart >= 0) {
|
|
150
|
+
rawActive.push({ start: openActiveStart, end: frame });
|
|
151
|
+
openActiveStart = -1;
|
|
152
|
+
}
|
|
153
|
+
if (needsBase) {
|
|
154
|
+
if (openReadbackStart < 0)
|
|
155
|
+
openReadbackStart = frame;
|
|
156
|
+
}
|
|
157
|
+
else if (openReadbackStart >= 0) {
|
|
158
|
+
rawReadback.push({ start: openReadbackStart, end: frame });
|
|
159
|
+
openReadbackStart = -1;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (openActiveStart >= 0)
|
|
163
|
+
rawActive.push({ start: openActiveStart, end: frameCount });
|
|
164
|
+
if (openReadbackStart >= 0)
|
|
165
|
+
rawReadback.push({ start: openReadbackStart, end: frameCount });
|
|
166
|
+
if (activeFrames === 0)
|
|
167
|
+
return { kind: 'none' };
|
|
168
|
+
const intervals = mergeIntervals(rawActive);
|
|
169
|
+
const selectedFrames = intervals.reduce((sum, item) => sum + (item.end - item.start), 0);
|
|
170
|
+
const readbackIntervals = mergeIntervals(rawReadback);
|
|
171
|
+
const selectedReadbackFrames = readbackIntervals.reduce((sum, item) => sum + (item.end - item.start), 0);
|
|
172
|
+
if (selectedReadbackFrames >= frameCount * 0.65) {
|
|
173
|
+
return { kind: 'full', activeFrames, selectedReadbackFrames, canvasLayers };
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
kind: 'sparse',
|
|
177
|
+
intervals,
|
|
178
|
+
selectedFrames,
|
|
179
|
+
activeFrames,
|
|
180
|
+
betweenExpr: betweenExpression(intervals),
|
|
181
|
+
ptsExpr: ptsExpression(intervals, fps),
|
|
182
|
+
readbackIntervals,
|
|
183
|
+
selectedReadbackFrames,
|
|
184
|
+
...(readbackIntervals.length ? { readbackBetweenExpr: betweenExpression(readbackIntervals) } : {}),
|
|
185
|
+
canvasLayers,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function clearBufferRect(target, frameWidth, { x, y, width, height }) {
|
|
189
|
+
if (x === 0 && width === frameWidth) {
|
|
190
|
+
target.fill(0, y * frameWidth * 4, (y + height) * frameWidth * 4);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
for (let row = 0; row < height; row++) {
|
|
194
|
+
const start = ((y + row) * frameWidth + x) * 4;
|
|
195
|
+
target.fill(0, start, start + width * 4);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function copyPatchToBuffer(patch, target, frameWidth, { x, y, width, height }) {
|
|
199
|
+
const patchBuffer = Buffer.from(patch.buffer, patch.byteOffset, patch.byteLength);
|
|
200
|
+
if (x === 0 && width === frameWidth) {
|
|
201
|
+
patchBuffer.copy(target, y * frameWidth * 4, 0, height * frameWidth * 4);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
for (let row = 0; row < height; row++) {
|
|
205
|
+
patchBuffer.copy(target, ((y + row) * frameWidth + x) * 4, row * width * 4, (row + 1) * width * 4);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function createFrameReader(stream, frameBytes, decoded) {
|
|
209
|
+
const iterator = stream[Symbol.asyncIterator]();
|
|
210
|
+
let leftover = Buffer.alloc(0);
|
|
211
|
+
let offset = 0;
|
|
212
|
+
let readCount = 0;
|
|
213
|
+
return {
|
|
214
|
+
async readFrame(target) {
|
|
215
|
+
let filled = 0;
|
|
216
|
+
while (filled < frameBytes) {
|
|
217
|
+
if (offset < leftover.length) {
|
|
218
|
+
const count = Math.min(frameBytes - filled, leftover.length - offset);
|
|
219
|
+
leftover.copy(target, filled, offset, offset + count);
|
|
220
|
+
offset += count;
|
|
221
|
+
filled += count;
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
const next = await iterator.next();
|
|
225
|
+
if (next.done) {
|
|
226
|
+
await decoded;
|
|
227
|
+
requireCondition(false, 'ANNOTATION_FRAMES', `Compositor received ${readCount} complete base frames before EOF`, 7);
|
|
228
|
+
}
|
|
229
|
+
leftover = Buffer.isBuffer(next.value) ? next.value : Buffer.from(next.value);
|
|
230
|
+
offset = 0;
|
|
231
|
+
}
|
|
232
|
+
readCount++;
|
|
233
|
+
},
|
|
234
|
+
async verifyEnd(expectedFrames) {
|
|
235
|
+
const next = offset < leftover.length ? { done: false } : await iterator.next();
|
|
236
|
+
await decoded;
|
|
237
|
+
requireCondition(offset === leftover.length && Boolean(next.done) && readCount === expectedFrames, 'ANNOTATION_FRAMES', `Compositor received ${readCount} complete base frames, expected ${expectedFrames}`, 7);
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
export async function compositeFrames(source, baseFilter, encoderArgs, output, applications, plan, frameCount, audioOrigin, stagingDirectory) {
|
|
242
|
+
const signal = executionSignal();
|
|
95
243
|
signal?.throwIfAborted();
|
|
96
|
-
const canvas = createCanvas(output.width, output.height);
|
|
97
|
-
const context = canvas.getContext('2d', { alpha: false });
|
|
98
244
|
const bytes = output.width * output.height * 4;
|
|
99
|
-
const
|
|
100
|
-
const
|
|
245
|
+
const slots = [Buffer.alloc(bytes), Buffer.alloc(bytes)];
|
|
246
|
+
const slotOpaque = [false, false];
|
|
247
|
+
const slotDirty = [undefined, undefined];
|
|
101
248
|
const ffmpeg = executable('ffmpeg');
|
|
102
|
-
const
|
|
103
|
-
const
|
|
249
|
+
const expectedDecodedFrames = plan.kind === 'sparse' ? plan.selectedReadbackFrames : frameCount;
|
|
250
|
+
const slotImages = expectedDecodedFrames > 0
|
|
251
|
+
? slots.map(buffer => new ImageData(new Uint8ClampedArray(buffer.buffer, buffer.byteOffset, buffer.byteLength), output.width, output.height))
|
|
252
|
+
: undefined;
|
|
253
|
+
let decoder;
|
|
254
|
+
let decoded = Promise.resolve();
|
|
255
|
+
if (expectedDecodedFrames > 0) {
|
|
256
|
+
const decoderFilter = plan.kind === 'sparse' ? `${baseFilter},select='${plan.readbackBetweenExpr}'` : baseFilter;
|
|
257
|
+
const decoderScript = join(stagingDirectory, 'decoder-filter.txt');
|
|
258
|
+
await writeFile(decoderScript, decoderFilter);
|
|
259
|
+
const filterFlags = await ffmpegFilterScriptFlags(ffmpeg);
|
|
260
|
+
decoder = spawn(ffmpeg, ['-v', 'error', '-xerror', '-i', source, filterFlags.video, decoderScript, '-frames:v', String(expectedDecodedFrames), '-pix_fmt', 'rgba', '-fps_mode', 'passthrough', '-f', 'rawvideo', '-'], { stdio: ['ignore', 'pipe', 'pipe'], signal, killSignal: 'SIGKILL', windowsHide: true });
|
|
261
|
+
decoded = completion(decoder, 'Composite frame decoding');
|
|
262
|
+
}
|
|
263
|
+
const frameReader = decoder?.stdout ? createFrameReader(decoder.stdout, bytes, decoded) : undefined;
|
|
104
264
|
const encoder = spawn(ffmpeg, encoderArgs, { stdio: ['pipe', 'ignore', 'pipe'], signal, killSignal: 'SIGKILL', windowsHide: true });
|
|
265
|
+
encoder.stdin.on('error', () => { });
|
|
105
266
|
const encoded = completion(encoder, 'Composite frame encoding');
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
267
|
+
const writeToEncoder = (buffer) => new Promise((resolve, reject) => {
|
|
268
|
+
const onError = (error) => { cleanup(); reject(error); };
|
|
269
|
+
const onDrain = () => { cleanup(); resolve(); };
|
|
270
|
+
const onClose = () => { cleanup(); reject(new ProductionError('ANNOTATION_COMPOSITOR', 'Composite frame encoder closed its input early', 7)); };
|
|
271
|
+
const onAbort = () => { cleanup(); reject(signal?.reason ?? new ProductionError('INTERRUPTED', 'Compositor aborted', 7)); };
|
|
272
|
+
const cleanup = () => {
|
|
273
|
+
encoder.stdin.off('error', onError);
|
|
274
|
+
encoder.stdin.off('drain', onDrain);
|
|
275
|
+
encoder.stdin.off('close', onClose);
|
|
276
|
+
signal?.removeEventListener('abort', onAbort);
|
|
277
|
+
};
|
|
278
|
+
if (encoder.stdin.destroyed || !encoder.stdin.writable) {
|
|
279
|
+
reject(new ProductionError('ANNOTATION_COMPOSITOR', 'Composite frame encoder input is not writable', 7));
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (encoder.stdin.write(buffer)) {
|
|
283
|
+
resolve();
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
encoder.stdin.once('error', onError);
|
|
287
|
+
encoder.stdin.once('drain', onDrain);
|
|
288
|
+
encoder.stdin.once('close', onClose);
|
|
289
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
290
|
+
});
|
|
291
|
+
let readbackContext;
|
|
292
|
+
let overlayContext;
|
|
293
|
+
let overlayCanvasDirty;
|
|
294
|
+
const ensureReadbackContext = () => readbackContext ??= createCanvas(output.width, output.height).getContext('2d', { alpha: false });
|
|
295
|
+
const ensureOverlayContext = () => overlayContext ??= createCanvas(output.width, output.height).getContext('2d');
|
|
296
|
+
let emittedCount = 0;
|
|
297
|
+
let paintedFrames = 0;
|
|
298
|
+
let intervalIndex = 0;
|
|
299
|
+
let frameInInterval = plan.kind === 'sparse' ? plan.intervals[0].start : 0;
|
|
300
|
+
let readbackIndex = 0;
|
|
301
|
+
const totalEmittedFrames = plan.kind === 'sparse' ? plan.selectedFrames : frameCount;
|
|
302
|
+
const nextFrameIndex = () => {
|
|
303
|
+
if (plan.kind === 'full')
|
|
304
|
+
return emittedCount++;
|
|
305
|
+
const current = frameInInterval++;
|
|
306
|
+
if (frameInInterval >= plan.intervals[intervalIndex].end && intervalIndex + 1 < plan.intervals.length) {
|
|
307
|
+
intervalIndex++;
|
|
308
|
+
frameInInterval = plan.intervals[intervalIndex].start;
|
|
309
|
+
}
|
|
310
|
+
emittedCount++;
|
|
311
|
+
return current;
|
|
312
|
+
};
|
|
313
|
+
const isReadbackFrame = (frameIndex) => {
|
|
314
|
+
if (plan.kind === 'full')
|
|
315
|
+
return true;
|
|
316
|
+
while (readbackIndex < plan.readbackIntervals.length && frameIndex >= plan.readbackIntervals[readbackIndex].end) {
|
|
317
|
+
readbackIndex++;
|
|
318
|
+
}
|
|
319
|
+
return readbackIndex < plan.readbackIntervals.length && frameIndex >= plan.readbackIntervals[readbackIndex].start;
|
|
320
|
+
};
|
|
321
|
+
const pump = async () => {
|
|
322
|
+
let slot = 0;
|
|
323
|
+
while (emittedCount < totalEmittedFrames) {
|
|
324
|
+
signal?.throwIfAborted();
|
|
325
|
+
const frameIndex = nextFrameIndex();
|
|
326
|
+
const needsBase = isReadbackFrame(frameIndex);
|
|
327
|
+
const target = slots[slot];
|
|
328
|
+
const outputTime = frameIndex * 1000 / output.fps;
|
|
329
|
+
const scheduleTime = Math.max(0, outputTime - audioOrigin);
|
|
330
|
+
const activeAnnotations = applications.filter(item => frameIndex >= item.first_frame && frameIndex < item.end_frame);
|
|
331
|
+
const activeLayers = [];
|
|
332
|
+
for (const layer of plan.canvasLayers) {
|
|
333
|
+
const opacity = layer.opacityAt ? layer.opacityAt(scheduleTime) : layer.opacity;
|
|
334
|
+
if (opacity > 0)
|
|
335
|
+
activeLayers.push(layer.rectangle);
|
|
336
|
+
}
|
|
337
|
+
const dirty = effectDirtyBounds(activeAnnotations, outputTime, activeLayers, output);
|
|
338
|
+
if (needsBase) {
|
|
339
|
+
await frameReader.readFrame(target);
|
|
340
|
+
slotOpaque[slot] = true;
|
|
341
|
+
slotDirty[slot] = undefined;
|
|
342
|
+
if (dirty) {
|
|
343
|
+
const context = ensureReadbackContext();
|
|
344
|
+
const { x: dx, y: dy, width: dw, height: dh } = dirty;
|
|
345
|
+
context.putImageData(slotImages[slot], 0, 0, dx, dy, dw, dh);
|
|
346
|
+
paintEffects(context, activeAnnotations, outputTime);
|
|
347
|
+
paintFrameLayers(context, plan.canvasLayers, scheduleTime);
|
|
348
|
+
copyPatchToBuffer(context.getImageData(dx, dy, dw, dh).data, target, output.width, dirty);
|
|
349
|
+
paintedFrames++;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
if (slotOpaque[slot]) {
|
|
354
|
+
target.fill(0);
|
|
355
|
+
slotOpaque[slot] = false;
|
|
356
|
+
slotDirty[slot] = undefined;
|
|
357
|
+
}
|
|
358
|
+
else if (slotDirty[slot]) {
|
|
359
|
+
clearBufferRect(target, output.width, slotDirty[slot]);
|
|
360
|
+
slotDirty[slot] = undefined;
|
|
361
|
+
}
|
|
362
|
+
if (dirty) {
|
|
363
|
+
const context = ensureOverlayContext();
|
|
364
|
+
if (overlayCanvasDirty) {
|
|
365
|
+
context.clearRect(overlayCanvasDirty.x, overlayCanvasDirty.y, overlayCanvasDirty.width, overlayCanvasDirty.height);
|
|
131
366
|
}
|
|
367
|
+
paintEffects(context, activeAnnotations, outputTime);
|
|
368
|
+
paintFrameLayers(context, plan.canvasLayers, scheduleTime);
|
|
369
|
+
overlayCanvasDirty = dirty;
|
|
370
|
+
copyPatchToBuffer(context.getImageData(dirty.x, dirty.y, dirty.width, dirty.height).data, target, output.width, dirty);
|
|
371
|
+
slotDirty[slot] = dirty;
|
|
372
|
+
paintedFrames++;
|
|
132
373
|
}
|
|
133
|
-
paintFrameLayers(context, layers, Math.max(0, frames * 1000 / output.fps - audioOrigin));
|
|
134
|
-
const pixels = context.getImageData(0, 0, output.width, output.height).data;
|
|
135
|
-
yield Buffer.from(pixels.buffer, pixels.byteOffset, pixels.byteLength);
|
|
136
|
-
frames++;
|
|
137
|
-
filled = 0;
|
|
138
374
|
}
|
|
375
|
+
await writeToEncoder(target);
|
|
376
|
+
slot ^= 1;
|
|
139
377
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
378
|
+
if (frameReader)
|
|
379
|
+
await frameReader.verifyEnd(expectedDecodedFrames);
|
|
380
|
+
if (!encoder.stdin.destroyed && encoder.stdin.writable) {
|
|
381
|
+
await new Promise(resolve => {
|
|
382
|
+
const done = () => {
|
|
383
|
+
encoder.stdin.off('finish', done);
|
|
384
|
+
encoder.stdin.off('close', done);
|
|
385
|
+
encoder.stdin.off('error', done);
|
|
386
|
+
resolve();
|
|
387
|
+
};
|
|
388
|
+
encoder.stdin.once('finish', done);
|
|
389
|
+
encoder.stdin.once('close', done);
|
|
390
|
+
encoder.stdin.once('error', done);
|
|
391
|
+
encoder.stdin.end();
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
const timer = hasStageDeadline() ? undefined : setTimeout(() => { decoder?.kill('SIGKILL'); encoder.kill('SIGKILL'); }, 120000);
|
|
143
396
|
try {
|
|
144
|
-
await Promise.all([
|
|
145
|
-
return { renderer: 'canvas-skia', version: '1.1.1', frames };
|
|
397
|
+
await Promise.all([pump(), decoded, encoded]);
|
|
398
|
+
return { renderer: 'canvas-skia', version: '1.1.1', frames: frameCount, composited_frames: paintedFrames, readback_frames: expectedDecodedFrames, mode: plan.kind };
|
|
146
399
|
}
|
|
147
400
|
finally {
|
|
148
401
|
clearTimeout(timer);
|
|
149
|
-
if (decoder.exitCode === null)
|
|
402
|
+
if (decoder && decoder.exitCode === null)
|
|
150
403
|
decoder.kill('SIGKILL');
|
|
151
404
|
if (encoder.exitCode === null)
|
|
152
405
|
encoder.kill('SIGKILL');
|
package/dist/contracts.d.ts
CHANGED
|
@@ -63,31 +63,61 @@ export type AnnotationTarget = ({
|
|
|
63
63
|
type: 'shape';
|
|
64
64
|
id: number;
|
|
65
65
|
};
|
|
66
|
-
export type
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
export type GeometryTarget = AnnotationTarget | {
|
|
67
|
+
type: 'slide';
|
|
68
|
+
};
|
|
69
|
+
export type HighlightAppearance = {
|
|
70
|
+
color: string;
|
|
71
|
+
opacity: number;
|
|
72
|
+
blend?: 'source-over' | 'darken';
|
|
73
|
+
padding: {
|
|
74
|
+
units: 'normalized';
|
|
75
|
+
x: number;
|
|
76
|
+
y: number;
|
|
77
|
+
};
|
|
78
|
+
bottom_border?: {
|
|
72
79
|
color: string;
|
|
73
80
|
opacity: number;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
units: 'normalized';
|
|
77
|
-
x: number;
|
|
78
|
-
y: number;
|
|
79
|
-
};
|
|
80
|
-
bottom_border?: {
|
|
81
|
-
color: string;
|
|
82
|
-
opacity: number;
|
|
83
|
-
units: 'normalized';
|
|
84
|
-
height: number;
|
|
85
|
-
};
|
|
81
|
+
units: 'normalized';
|
|
82
|
+
height: number;
|
|
86
83
|
};
|
|
84
|
+
};
|
|
85
|
+
export type HighlightAnnotation = {
|
|
86
|
+
id: string;
|
|
87
|
+
scene: string;
|
|
88
|
+
effect: 'highlight';
|
|
89
|
+
target: AnnotationTarget;
|
|
90
|
+
appearance: HighlightAppearance;
|
|
91
|
+
at: PhraseCue;
|
|
92
|
+
duration_ms: number;
|
|
93
|
+
};
|
|
94
|
+
export type UnderlineAppearance = {
|
|
95
|
+
color: string;
|
|
96
|
+
opacity: number;
|
|
97
|
+
blend?: 'source-over' | 'darken';
|
|
98
|
+
style?: 'solid' | 'dashed';
|
|
99
|
+
units: 'normalized';
|
|
100
|
+
width: number;
|
|
101
|
+
offset?: number;
|
|
102
|
+
padding_x?: number;
|
|
103
|
+
};
|
|
104
|
+
export type UnderlineMotion = {
|
|
105
|
+
type: 'wipe';
|
|
106
|
+
in_ms?: number;
|
|
107
|
+
out_ms?: number;
|
|
108
|
+
};
|
|
109
|
+
export type UnderlineAnnotation = {
|
|
110
|
+
id: string;
|
|
111
|
+
scene: string;
|
|
112
|
+
effect: 'underline';
|
|
113
|
+
target: AnnotationTarget;
|
|
114
|
+
appearance: UnderlineAppearance;
|
|
115
|
+
motion?: UnderlineMotion;
|
|
87
116
|
at: PhraseCue;
|
|
88
117
|
duration_ms: number;
|
|
89
118
|
};
|
|
90
|
-
export type
|
|
119
|
+
export type Annotation = HighlightAnnotation | UnderlineAnnotation;
|
|
120
|
+
export type ResolvedAnnotationWindow = {
|
|
91
121
|
start_ms: number;
|
|
92
122
|
end_ms: number;
|
|
93
123
|
slide: string;
|
|
@@ -100,14 +130,21 @@ export type ResolvedAnnotation = Annotation & {
|
|
|
100
130
|
form: string;
|
|
101
131
|
};
|
|
102
132
|
};
|
|
103
|
-
export type
|
|
104
|
-
|
|
133
|
+
export type ResolvedHighlightAnnotation = HighlightAnnotation & ResolvedAnnotationWindow;
|
|
134
|
+
export type ResolvedUnderlineAnnotation = UnderlineAnnotation & ResolvedAnnotationWindow;
|
|
135
|
+
export type ResolvedAnnotation = ResolvedHighlightAnnotation | ResolvedUnderlineAnnotation;
|
|
136
|
+
export type GeometryRequest = {
|
|
137
|
+
key: string;
|
|
138
|
+
target: GeometryTarget;
|
|
105
139
|
scene: string;
|
|
106
140
|
slide: string;
|
|
107
141
|
visit: string;
|
|
108
142
|
click: number;
|
|
109
143
|
start_ms: number;
|
|
110
144
|
end_ms: number;
|
|
145
|
+
annotations: string[];
|
|
146
|
+
};
|
|
147
|
+
export type AnnotationGeometry = Omit<GeometryRequest, 'annotations'> & {
|
|
111
148
|
observed_start_ms: number;
|
|
112
149
|
observed_end_ms: number;
|
|
113
150
|
viewport: {
|
|
@@ -115,7 +152,7 @@ export type AnnotationGeometry = {
|
|
|
115
152
|
height: number;
|
|
116
153
|
};
|
|
117
154
|
content: Rectangle;
|
|
118
|
-
|
|
155
|
+
fragments: Rectangle[];
|
|
119
156
|
samples: number;
|
|
120
157
|
};
|
|
121
158
|
export type ImageOverlay = {
|
|
@@ -146,14 +183,9 @@ export type ResolvedOverlay = Pick<ImageOverlay, 'id' | 'src' | 'box' | 'opacity
|
|
|
146
183
|
}[];
|
|
147
184
|
};
|
|
148
185
|
export type Storyboard = {
|
|
149
|
-
version: 1
|
|
186
|
+
version: 1;
|
|
150
187
|
deck: string;
|
|
151
188
|
voice?: Voice;
|
|
152
|
-
output: {
|
|
153
|
-
width: number;
|
|
154
|
-
height: number;
|
|
155
|
-
fps: number;
|
|
156
|
-
};
|
|
157
189
|
media: {
|
|
158
190
|
id: string;
|
|
159
191
|
src: string;
|
|
@@ -166,7 +198,7 @@ export type Storyboard = {
|
|
|
166
198
|
actions: Action[];
|
|
167
199
|
}[];
|
|
168
200
|
cues: Cue[];
|
|
169
|
-
annotations
|
|
201
|
+
annotations: Annotation[];
|
|
170
202
|
overlays?: ImageOverlay[];
|
|
171
203
|
};
|
|
172
204
|
export type Alignment = {
|
|
@@ -222,7 +254,7 @@ export type ScheduledAction = {
|
|
|
222
254
|
};
|
|
223
255
|
};
|
|
224
256
|
export type Schedule = {
|
|
225
|
-
version: 1
|
|
257
|
+
version: 1;
|
|
226
258
|
duration_ms: number;
|
|
227
259
|
actions: ScheduledAction[];
|
|
228
260
|
media: {
|
|
@@ -231,7 +263,7 @@ export type Schedule = {
|
|
|
231
263
|
duration_ms: number;
|
|
232
264
|
has_audio: boolean;
|
|
233
265
|
}[];
|
|
234
|
-
annotations
|
|
266
|
+
annotations: ResolvedAnnotation[];
|
|
235
267
|
overlays?: ResolvedOverlay[];
|
|
236
268
|
};
|
|
237
269
|
export type ObservedEvent = {
|
|
@@ -278,6 +310,16 @@ export type TimingEvidence = {
|
|
|
278
310
|
coverage: string[];
|
|
279
311
|
gaps: string[];
|
|
280
312
|
};
|
|
313
|
+
export type Viewport = {
|
|
314
|
+
width: number;
|
|
315
|
+
height: number;
|
|
316
|
+
};
|
|
317
|
+
export type FrameRate = 15 | 24 | 30 | 60;
|
|
318
|
+
export type VideoOutput = Viewport & {
|
|
319
|
+
fps: FrameRate;
|
|
320
|
+
};
|
|
321
|
+
export declare const defaultViewport: Viewport;
|
|
322
|
+
export declare const defaultVideoOutput: VideoOutput;
|
|
281
323
|
export type CaptureOrigin = {
|
|
282
324
|
method: 'opening_markers' | 'decoded_markers';
|
|
283
325
|
uncertainty_ms: number;
|
|
@@ -285,6 +327,7 @@ export type CaptureOrigin = {
|
|
|
285
327
|
};
|
|
286
328
|
export type ProductionOptions = {
|
|
287
329
|
verify_timing: boolean;
|
|
330
|
+
output: VideoOutput;
|
|
288
331
|
};
|
|
289
332
|
export type VisualArtifact = {
|
|
290
333
|
version: 1;
|
|
@@ -307,17 +350,31 @@ export interface TtsAdapter {
|
|
|
307
350
|
synthesize(segment: Narration, voice: Voice, destination: string): Promise<Omit<SpeechAsset, 'key'>>;
|
|
308
351
|
}
|
|
309
352
|
export type PresentationInspection = {
|
|
353
|
+
dimensions?: Viewport;
|
|
310
354
|
slides: {
|
|
311
355
|
id: string;
|
|
356
|
+
alias?: string;
|
|
312
357
|
index: number;
|
|
313
358
|
clicks: number;
|
|
314
359
|
clicks_known?: boolean;
|
|
360
|
+
click_durations_ms?: number[];
|
|
315
361
|
}[];
|
|
316
362
|
media_ids: string[];
|
|
363
|
+
media?: {
|
|
364
|
+
id: string;
|
|
365
|
+
slide: string;
|
|
366
|
+
sha256: string;
|
|
367
|
+
duration_ms: number;
|
|
368
|
+
}[];
|
|
317
369
|
files: string[];
|
|
318
370
|
capabilities: string[];
|
|
371
|
+
unsupported?: {
|
|
372
|
+
slide?: string;
|
|
373
|
+
reason: string;
|
|
374
|
+
}[];
|
|
319
375
|
annotation_targets?: {
|
|
320
376
|
slide: string;
|
|
377
|
+
clicks?: number;
|
|
321
378
|
targets: {
|
|
322
379
|
identity: string;
|
|
323
380
|
description: string;
|
|
@@ -328,14 +385,17 @@ export interface PresentationAdapter {
|
|
|
328
385
|
id: string;
|
|
329
386
|
version: string;
|
|
330
387
|
inspect(deck: string): Promise<PresentationInspection>;
|
|
331
|
-
inspectTargets?(
|
|
332
|
-
validate(storyboard: Storyboard, inspection: PresentationInspection,
|
|
333
|
-
|
|
388
|
+
inspectTargets?(deck: string, viewport: Viewport): Promise<PresentationInspection['annotation_targets']>;
|
|
389
|
+
validate(storyboard: Storyboard, inspection: PresentationInspection, options?: {
|
|
390
|
+
viewport?: Viewport;
|
|
391
|
+
schedule?: Schedule;
|
|
392
|
+
}): void | Promise<void>;
|
|
393
|
+
startPreview?(storyboard: Storyboard, schedule: Schedule, directory: string, parentOrigin: string, viewport: Viewport): Promise<import('./preview/contracts.js').PreviewSession>;
|
|
334
394
|
prepare(storyboard: Storyboard, schedule: Schedule, directory: string, options?: ProductionOptions): Promise<void>;
|
|
335
395
|
execute(progress?: ProgressReporter): Promise<VisualArtifact>;
|
|
336
396
|
cleanup(): Promise<void>;
|
|
337
397
|
}
|
|
338
|
-
export type Stage = '
|
|
398
|
+
export type Stage = 'tts' | 'resolve' | 'record' | 'assemble';
|
|
339
399
|
export type RunManifest = {
|
|
340
400
|
version: 1;
|
|
341
401
|
run_id: string;
|
|
@@ -353,6 +413,7 @@ export type RunManifest = {
|
|
|
353
413
|
};
|
|
354
414
|
}>>;
|
|
355
415
|
verify_timing?: boolean;
|
|
416
|
+
video?: VideoOutput;
|
|
356
417
|
assembly_licensed?: boolean;
|
|
357
418
|
output?: string;
|
|
358
419
|
};
|
package/dist/contracts.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export const defaultViewport = { width: 1920, height: 1080 };
|
|
2
|
+
export const defaultVideoOutput = { width: 1920, height: 1080, fps: 30 };
|