@slidevideo/cli 0.2.0 → 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.
Files changed (47) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +2 -2
  3. package/addons/slidevideo/geometry.ts +63 -30
  4. package/addons/slidevideo/global-top.vue +41 -9
  5. package/addons/slidevideo/playback-entries.ts +16 -5
  6. package/addons/slidevideo/preview.ts +26 -14
  7. package/dist/adapters/powerpoint.d.ts +7 -4
  8. package/dist/adapters/powerpoint.js +116 -26
  9. package/dist/adapters/slidev-inspection.d.ts +5 -2
  10. package/dist/adapters/slidev-inspection.js +3 -2
  11. package/dist/adapters/slidev.d.ts +3 -4
  12. package/dist/adapters/slidev.js +20 -19
  13. package/dist/annotation-paint.d.ts +65 -11
  14. package/dist/annotation-paint.js +290 -10
  15. package/dist/annotations.d.ts +13 -8
  16. package/dist/annotations.js +619 -88
  17. package/dist/assembly.d.ts +4 -2
  18. package/dist/assembly.js +23 -18
  19. package/dist/cli.js +102 -16
  20. package/dist/compositor.d.ts +10 -5
  21. package/dist/compositor.js +215 -128
  22. package/dist/contracts.d.ts +91 -30
  23. package/dist/contracts.js +2 -1
  24. package/dist/media.d.ts +5 -0
  25. package/dist/media.js +30 -0
  26. package/dist/pipeline.d.ts +35 -9
  27. package/dist/pipeline.js +62 -10
  28. package/dist/preview/contracts.d.ts +3 -3
  29. package/dist/preview/player.js +20 -15
  30. package/dist/preview/server.d.ts +2 -1
  31. package/dist/preview/server.js +6 -5
  32. package/dist/setup.d.ts +3 -0
  33. package/dist/setup.js +16 -1
  34. package/dist/skill-install.d.ts +35 -0
  35. package/dist/skill-install.js +132 -0
  36. package/dist/storyboard.js +9 -0
  37. package/package.json +4 -1
  38. package/schemas/annotation-geometry.v1.json +260 -28
  39. package/schemas/run-manifest.v1.json +31 -0
  40. package/schemas/schedule.v1.json +448 -182
  41. package/schemas/storyboard.v1.json +358 -174
  42. package/skills/slidevideo/SKILL.md +11 -9
  43. package/skills/slidevideo/references/decks.md +228 -0
  44. package/skills/slidevideo/references/production.md +14 -10
  45. package/skills/slidevideo/references/storyboard.md +65 -33
  46. package/tools/powerpoint/powerpoint.ps1 +52 -41
  47. package/tools/powerpoint/preview.ps1 +5 -5
@@ -1,7 +1,9 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { writeFile } from 'node:fs/promises';
3
+ import { join } from 'node:path';
3
4
  import { createCanvas, ImageData } from '@napi-rs/canvas';
4
- import { executionSignal, hasStageDeadline } from './media.js';
5
+ import { effectDirtyBounds, effectNeedsBaseFrames, paintEffects } from './annotation-paint.js';
6
+ import { balancedSum, executionSignal, ffmpegFilterScriptFlags, hasStageDeadline } from './media.js';
5
7
  import { executable } from './executables.js';
6
8
  import { ProductionError, requireCondition } from './errors.js';
7
9
  import { loadOverlayImage } from './overlay-assets.js';
@@ -100,66 +102,165 @@ export function splitFrameLayers(layers) {
100
102
  staticTopLayers: layers.slice(lastDynamic + 1),
101
103
  };
102
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
+ }
103
129
  export function planCompositor(frameCount, fps, audioOrigin, applications, canvasLayers) {
104
130
  if (frameCount <= 0 || (!applications.length && !canvasLayers.length))
105
131
  return { kind: 'none' };
106
- const raw = [];
132
+ const rawActive = [];
133
+ const rawReadback = [];
107
134
  let activeFrames = 0;
108
- let openStart = -1;
135
+ let openActiveStart = -1;
136
+ let openReadbackStart = -1;
109
137
  for (let frame = 0; frame < frameCount; frame++) {
110
- const time = Math.max(0, frame * 1000 / fps - audioOrigin);
111
- const active = applications.some(item => frame >= item.first_frame && frame < item.end_frame)
112
- || canvasLayers.some(layer => (layer.opacityAt ? layer.opacityAt(time) : layer.opacity) > 0);
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);
113
144
  if (active) {
114
145
  activeFrames++;
115
- if (openStart < 0)
116
- openStart = frame;
146
+ if (openActiveStart < 0)
147
+ openActiveStart = frame;
117
148
  }
118
- else if (openStart >= 0) {
119
- raw.push({ start: openStart, end: frame });
120
- openStart = -1;
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;
121
160
  }
122
161
  }
123
- if (openStart >= 0)
124
- raw.push({ start: openStart, end: frameCount });
162
+ if (openActiveStart >= 0)
163
+ rawActive.push({ start: openActiveStart, end: frameCount });
164
+ if (openReadbackStart >= 0)
165
+ rawReadback.push({ start: openReadbackStart, end: frameCount });
125
166
  if (activeFrames === 0)
126
167
  return { kind: 'none' };
127
- const merged = [];
128
- for (const interval of raw) {
129
- const previous = merged[merged.length - 1];
130
- if (previous && interval.start - previous.end <= 4)
131
- previous.end = interval.end;
132
- else
133
- merged.push({ ...interval });
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 };
134
174
  }
135
- const selectedFrames = merged.reduce((sum, item) => sum + (item.end - item.start), 0);
136
- if (selectedFrames < frameCount * 0.65 && merged.length <= 64) {
137
- const betweenExpr = merged.map(({ start, end }) => start === end - 1 ? `eq(n,${start})` : `between(n,${start},${end - 1})`).join('+');
138
- const terms = [`N+${merged[0].start}`];
139
- let cumulative = merged[0].end - merged[0].start;
140
- for (let index = 1; index < merged.length; index++) {
141
- const gap = merged[index].start - merged[index - 1].end;
142
- terms.push(`${gap}*gte(N,${cumulative})`);
143
- cumulative += merged[index].end - merged[index].start;
144
- }
145
- const ptsExpr = `(${terms.join('+')})/(${fps}*TB)`;
146
- return { kind: 'sparse', intervals: merged, selectedFrames, activeFrames, betweenExpr, ptsExpr, canvasLayers };
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);
147
206
  }
148
- return { kind: 'full', activeFrames, canvasLayers };
149
207
  }
150
- export async function compositeFrames(source, baseFilter, encoderArgs, output, applications, plan, frameCount, audioOrigin) {
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) {
151
242
  const signal = executionSignal();
152
243
  signal?.throwIfAborted();
153
- const canvas = createCanvas(output.width, output.height);
154
- const context = canvas.getContext('2d', { alpha: false });
155
244
  const bytes = output.width * output.height * 4;
156
- const slots = [Buffer.allocUnsafe(bytes), Buffer.allocUnsafe(bytes)];
157
- const slotImages = slots.map(buffer => new ImageData(new Uint8ClampedArray(buffer.buffer, buffer.byteOffset, buffer.byteLength), output.width, output.height));
245
+ const slots = [Buffer.alloc(bytes), Buffer.alloc(bytes)];
246
+ const slotOpaque = [false, false];
247
+ const slotDirty = [undefined, undefined];
158
248
  const ffmpeg = executable('ffmpeg');
159
- const expectedDecodedFrames = plan.kind === 'sparse' ? plan.selectedFrames : frameCount;
160
- const decoderFilter = plan.kind === 'sparse' ? `${baseFilter},select='${plan.betweenExpr}'` : baseFilter;
161
- const decoder = spawn(ffmpeg, ['-v', 'error', '-xerror', '-i', source, '-vf', decoderFilter, '-frames:v', String(expectedDecodedFrames), '-pix_fmt', 'rgba', '-fps_mode', 'passthrough', '-f', 'rawvideo', '-'], { stdio: ['ignore', 'pipe', 'pipe'], signal, killSignal: 'SIGKILL', windowsHide: true });
162
- const decoded = completion(decoder, 'Composite frame decoding');
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;
163
264
  const encoder = spawn(ffmpeg, encoderArgs, { stdio: ['pipe', 'ignore', 'pipe'], signal, killSignal: 'SIGKILL', windowsHide: true });
164
265
  encoder.stdin.on('error', () => { });
165
266
  const encoded = completion(encoder, 'Composite frame encoding');
@@ -187,109 +288,95 @@ export async function compositeFrames(source, baseFilter, encoderArgs, output, a
187
288
  encoder.stdin.once('close', onClose);
188
289
  signal?.addEventListener('abort', onAbort, { once: true });
189
290
  });
190
- let decodedCount = 0;
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;
191
297
  let paintedFrames = 0;
192
298
  let intervalIndex = 0;
193
299
  let frameInInterval = plan.kind === 'sparse' ? plan.intervals[0].start : 0;
300
+ let readbackIndex = 0;
301
+ const totalEmittedFrames = plan.kind === 'sparse' ? plan.selectedFrames : frameCount;
194
302
  const nextFrameIndex = () => {
195
303
  if (plan.kind === 'full')
196
- return decodedCount++;
304
+ return emittedCount++;
197
305
  const current = frameInInterval++;
198
306
  if (frameInInterval >= plan.intervals[intervalIndex].end && intervalIndex + 1 < plan.intervals.length) {
199
307
  intervalIndex++;
200
308
  frameInInterval = plan.intervals[intervalIndex].start;
201
309
  }
202
- decodedCount++;
310
+ emittedCount++;
203
311
  return current;
204
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
+ };
205
321
  const pump = async () => {
206
- let filled = 0;
207
322
  let slot = 0;
208
- for await (const chunk of decoder.stdout) {
209
- let position = 0;
210
- while (position < chunk.length) {
211
- signal?.throwIfAborted();
212
- const target = slots[slot];
213
- const count = Math.min(bytes - filled, chunk.length - position);
214
- chunk.copy(target, filled, position, position + count);
215
- position += count;
216
- filled += count;
217
- if (filled !== bytes)
218
- continue;
219
- const frameIndex = nextFrameIndex();
220
- const time = Math.max(0, frameIndex * 1000 / output.fps - audioOrigin);
221
- let minLeft = Infinity;
222
- let minTop = Infinity;
223
- let maxRight = -Infinity;
224
- let maxBottom = -Infinity;
225
- const expand = (rect) => {
226
- if (rect.width <= 0 || rect.height <= 0)
227
- return;
228
- if (rect.x < minLeft)
229
- minLeft = rect.x;
230
- if (rect.y < minTop)
231
- minTop = rect.y;
232
- if (rect.x + rect.width > maxRight)
233
- maxRight = rect.x + rect.width;
234
- if (rect.y + rect.height > maxBottom)
235
- maxBottom = rect.y + rect.height;
236
- };
237
- for (const annotation of applications) {
238
- if (frameIndex < annotation.first_frame || frameIndex >= annotation.end_frame)
239
- continue;
240
- expand(annotation.rectangle);
241
- if (annotation.bottom_border)
242
- expand(annotation.bottom_border.rectangle);
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;
243
357
  }
244
- for (const layer of plan.canvasLayers) {
245
- const opacity = layer.opacityAt ? layer.opacityAt(time) : layer.opacity;
246
- if (opacity > 0)
247
- expand(layer.rectangle);
358
+ else if (slotDirty[slot]) {
359
+ clearBufferRect(target, output.width, slotDirty[slot]);
360
+ slotDirty[slot] = undefined;
248
361
  }
249
- if (minLeft < maxRight && minTop < maxBottom) {
250
- const dx = Math.max(0, Math.floor(minLeft) - 1);
251
- const dy = Math.max(0, Math.floor(minTop) - 1);
252
- const maxX = Math.min(output.width, Math.ceil(maxRight) + 1);
253
- const maxY = Math.min(output.height, Math.ceil(maxBottom) + 1);
254
- const dw = maxX - dx;
255
- const dh = maxY - dy;
256
- if (dw > 0 && dh > 0) {
257
- context.putImageData(slotImages[slot], 0, 0, dx, dy, dw, dh);
258
- for (const annotation of applications) {
259
- if (frameIndex < annotation.first_frame || frameIndex >= annotation.end_frame)
260
- continue;
261
- for (const paint of [annotation, ...(annotation.bottom_border ? [annotation.bottom_border] : [])]) {
262
- const rect = paint.rectangle;
263
- if (rect.width <= 0 || rect.height <= 0)
264
- continue;
265
- context.save();
266
- context.fillStyle = paint.color;
267
- context.globalAlpha = paint.opacity;
268
- context.globalCompositeOperation = paint.blend;
269
- context.fillRect(rect.x, rect.y, rect.width, rect.height);
270
- context.restore();
271
- }
272
- }
273
- paintFrameLayers(context, plan.canvasLayers, time);
274
- const patch = context.getImageData(dx, dy, dw, dh).data;
275
- const patchBuffer = Buffer.from(patch.buffer, patch.byteOffset, patch.byteLength);
276
- if (dx === 0 && dw === output.width) {
277
- patchBuffer.copy(target, dy * output.width * 4, 0, dh * output.width * 4);
278
- }
279
- else {
280
- for (let row = 0; row < dh; row++) {
281
- patchBuffer.copy(target, ((dy + row) * output.width + dx) * 4, row * dw * 4, (row + 1) * dw * 4);
282
- }
283
- }
284
- paintedFrames++;
362
+ if (dirty) {
363
+ const context = ensureOverlayContext();
364
+ if (overlayCanvasDirty) {
365
+ context.clearRect(overlayCanvasDirty.x, overlayCanvasDirty.y, overlayCanvasDirty.width, overlayCanvasDirty.height);
285
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++;
286
373
  }
287
- await writeToEncoder(target);
288
- filled = 0;
289
- slot ^= 1;
290
374
  }
375
+ await writeToEncoder(target);
376
+ slot ^= 1;
291
377
  }
292
- requireCondition(filled === 0 && decodedCount === expectedDecodedFrames, 'ANNOTATION_FRAMES', `Compositor received ${decodedCount} complete frames, expected ${expectedDecodedFrames}`, 7);
378
+ if (frameReader)
379
+ await frameReader.verifyEnd(expectedDecodedFrames);
293
380
  if (!encoder.stdin.destroyed && encoder.stdin.writable) {
294
381
  await new Promise(resolve => {
295
382
  const done = () => {
@@ -305,14 +392,14 @@ export async function compositeFrames(source, baseFilter, encoderArgs, output, a
305
392
  });
306
393
  }
307
394
  };
308
- const timer = hasStageDeadline() ? undefined : setTimeout(() => { decoder.kill('SIGKILL'); encoder.kill('SIGKILL'); }, 120000);
395
+ const timer = hasStageDeadline() ? undefined : setTimeout(() => { decoder?.kill('SIGKILL'); encoder.kill('SIGKILL'); }, 120000);
309
396
  try {
310
397
  await Promise.all([pump(), decoded, encoded]);
311
- return { renderer: 'canvas-skia', version: '1.1.1', frames: frameCount, composited_frames: paintedFrames, mode: plan.kind };
398
+ return { renderer: 'canvas-skia', version: '1.1.1', frames: frameCount, composited_frames: paintedFrames, readback_frames: expectedDecodedFrames, mode: plan.kind };
312
399
  }
313
400
  finally {
314
401
  clearTimeout(timer);
315
- if (decoder.exitCode === null)
402
+ if (decoder && decoder.exitCode === null)
316
403
  decoder.kill('SIGKILL');
317
404
  if (encoder.exitCode === null)
318
405
  encoder.kill('SIGKILL');
@@ -63,31 +63,61 @@ export type AnnotationTarget = ({
63
63
  type: 'shape';
64
64
  id: number;
65
65
  };
66
- export type Annotation = {
67
- id: string;
68
- scene: string;
69
- target: AnnotationTarget;
70
- effect: 'highlight';
71
- appearance: {
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
- blend?: 'source-over' | 'darken';
75
- padding: {
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 ResolvedAnnotation = Annotation & {
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 AnnotationGeometry = {
104
- id: string;
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
- bounds: Rectangle;
155
+ fragments: Rectangle[];
119
156
  samples: number;
120
157
  };
121
158
  export type ImageOverlay = {
@@ -149,11 +186,6 @@ export type Storyboard = {
149
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;
@@ -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,9 +385,12 @@ export interface PresentationAdapter {
328
385
  id: string;
329
386
  version: string;
330
387
  inspect(deck: string): Promise<PresentationInspection>;
331
- inspectTargets?(storyboard: Storyboard): Promise<PresentationInspection['annotation_targets']>;
332
- validate(storyboard: Storyboard, inspection: PresentationInspection, schedule?: Schedule): void | Promise<void>;
333
- startPreview?(storyboard: Storyboard, schedule: Schedule, directory: string, parentOrigin: string): Promise<import('./preview/contracts.js').PreviewSession>;
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>;
@@ -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 };
package/dist/media.d.ts CHANGED
@@ -14,5 +14,10 @@ export declare function json<T>(path: string): Promise<T>;
14
14
  export declare function saveJson(path: string, value: unknown): Promise<void>;
15
15
  export declare function probe(path: string): Promise<MediaProperties>;
16
16
  export declare function decode(path: string): Promise<void>;
17
+ export declare function balancedSum(terms: readonly string[]): string;
18
+ export declare function ffmpegFilterScriptFlags(ffmpegPath?: string): Promise<{
19
+ complex: string;
20
+ video: string;
21
+ }>;
17
22
  export declare function audioDuration(path: string): Promise<number>;
18
23
  export declare function videoFramePeriod(path: string): Promise<number>;