@slidevideo/cli 0.3.0 → 0.3.2
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 +20 -0
- package/README.md +3 -3
- package/addons/slidevideo/geometry.ts +334 -1
- package/addons/slidevideo/global-top.vue +57 -6
- package/addons/slidevideo/preview.ts +242 -25
- package/assets/fonts/OFL-LICENSES.txt +95 -0
- package/assets/fonts/instrument-serif-latin-2.woff2 +0 -0
- package/assets/fonts/instrument-serif-latin-ext-1.woff2 +0 -0
- package/assets/fonts/jetbrains-mono-latin-4.woff2 +0 -0
- package/assets/fonts/jetbrains-mono-latin-ext-3.woff2 +0 -0
- package/assets/fonts/plus-jakarta-sans-latin-6.woff2 +0 -0
- package/assets/fonts/plus-jakarta-sans-latin-ext-5.woff2 +0 -0
- package/dist/adapters/edge.d.ts +1 -0
- package/dist/adapters/edge.js +4 -3
- package/dist/adapters/elevenlabs.d.ts +1 -0
- package/dist/adapters/elevenlabs.js +4 -3
- package/dist/adapters/powerpoint-preview.d.ts +1 -1
- package/dist/adapters/powerpoint-preview.js +13 -2
- package/dist/adapters/powerpoint.js +91 -14
- package/dist/adapters/slidev-inspection.js +7 -2
- package/dist/annotation-paint.d.ts +195 -5
- package/dist/annotation-paint.js +1188 -2
- package/dist/annotations.d.ts +26 -2
- package/dist/annotations.js +1117 -29
- package/dist/assembly.js +143 -37
- package/dist/captions.d.ts +6 -0
- package/dist/captions.js +320 -0
- package/dist/cli.js +59 -19
- package/dist/compositor.d.ts +17 -2
- package/dist/compositor.js +108 -26
- package/dist/contracts.d.ts +254 -14
- package/dist/media.js +24 -1
- package/dist/pipeline.d.ts +6 -1
- package/dist/pipeline.js +68 -20
- package/dist/preview/contracts.d.ts +15 -0
- package/dist/preview/player.js +527 -34
- package/dist/preview/server.d.ts +1 -1
- package/dist/preview/server.js +125 -4
- package/dist/preview/view.d.ts +1 -1
- package/dist/preview/view.js +26 -7
- package/dist/run.d.ts +1 -0
- package/dist/run.js +20 -0
- package/dist/speech.d.ts +13 -3
- package/dist/speech.js +164 -45
- package/dist/stamp-fonts.d.ts +17 -0
- package/dist/stamp-fonts.js +202 -0
- package/dist/storyboard.js +60 -3
- package/dist/timing.d.ts +4 -1
- package/dist/timing.js +322 -14
- package/dist/update-check-worker.js +43 -11
- package/dist/update-check.js +14 -10
- package/package.json +12 -1
- package/schemas/annotation-geometry.v1.json +111 -0
- package/schemas/schedule.v1.json +1672 -84
- package/schemas/storyboard.v1.json +3725 -85
- package/skills/slidevideo/SKILL.md +5 -5
- package/skills/slidevideo/references/decks.md +6 -4
- package/skills/slidevideo/references/production.md +12 -11
- package/skills/slidevideo/references/storyboard.md +268 -5
- package/tools/powerpoint/powerpoint.ps1 +155 -6
- package/tools/powerpoint/preview.ps1 +68 -1
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ import { existsSync } from 'node:fs';
|
|
|
4
4
|
import { readFile } from 'node:fs/promises';
|
|
5
5
|
import { servePreview } from './preview/server.js';
|
|
6
6
|
import { produce } from './pipeline.js';
|
|
7
|
-
import {
|
|
7
|
+
import { join } from 'node:path';
|
|
8
8
|
import { json } from './media.js';
|
|
9
9
|
import { ProductionError, requireCondition } from './errors.js';
|
|
10
10
|
import { packagePath, userConfigFile } from './installation.js';
|
|
@@ -97,15 +97,20 @@ let previewReady = false;
|
|
|
97
97
|
let runDirectory;
|
|
98
98
|
try {
|
|
99
99
|
const { values, positionals } = parseArgs({ options: {
|
|
100
|
-
storyboard: { type: 'string' }, deck: { type: 'string' }, width: { type: 'string' }, height: { type: 'string' }, fps: { type: 'string' }, port: { type: 'string' }, run: { type: 'string' }, 'cache-dir': { type: 'string' }, output: { type: 'string' }, export: { type: 'string' }, 'timeout-minutes': { type: 'string' },
|
|
100
|
+
storyboard: { type: 'string' }, deck: { type: 'string' }, width: { type: 'string' }, height: { type: 'string' }, fps: { type: 'string' }, port: { type: 'string' }, run: { type: 'string' }, 'cache-dir': { type: 'string' }, output: { type: 'string' }, captions: { type: 'string' }, export: { type: 'string' }, 'timeout-minutes': { type: 'string' },
|
|
101
101
|
browser: { type: 'string' }, python: { type: 'string' }, ffmpeg: { type: 'string' }, ffprobe: { type: 'string' },
|
|
102
102
|
presentation: { type: 'string' }, provider: { type: 'string' }, 'voice-id': { type: 'string' }, install: { type: 'boolean' }, project: { type: 'boolean' }, manual: { type: 'boolean' },
|
|
103
103
|
license: { type: 'boolean' },
|
|
104
|
-
json: { type: 'boolean' }, quiet: { type: 'boolean' }, resume: { type: 'boolean' }, 'verify-timing': { type: 'boolean' }, help: { type: 'boolean', short: 'h' }, version: { type: 'boolean' },
|
|
104
|
+
json: { type: 'boolean' }, quiet: { type: 'boolean' }, resume: { type: 'boolean' }, 'no-cache': { type: 'boolean' }, 'verify-timing': { type: 'boolean' }, help: { type: 'boolean', short: 'h' }, version: { type: 'boolean' },
|
|
105
105
|
}, allowPositionals: true });
|
|
106
|
-
runDirectory = values.run;
|
|
107
106
|
command = positionals[0] ?? 'help';
|
|
108
|
-
|
|
107
|
+
const skipUpdateCheck = Boolean(values.version || values.help)
|
|
108
|
+
|| ['help', 'license', 'impressum'].includes(command)
|
|
109
|
+
|| (command === 'setup' && Boolean(values.manual))
|
|
110
|
+
|| (command === 'skill' && !values.install);
|
|
111
|
+
if (!skipUpdateCheck) {
|
|
112
|
+
notifyUpdate(Boolean(values.json), Boolean(values.quiet));
|
|
113
|
+
}
|
|
109
114
|
if (values.version) {
|
|
110
115
|
const { version } = JSON.parse(await readFile(packagePath('package.json'), 'utf8'));
|
|
111
116
|
console.log(values.json ? JSON.stringify({ version: 1, package_version: version }) : version);
|
|
@@ -117,10 +122,12 @@ try {
|
|
|
117
122
|
--deck <file> Inspect a .md or .pptx deck directly before a storyboard exists.
|
|
118
123
|
--width/--height <px> Even viewport or output size (default: 1920x1080; PPTX inspect --deck uses slide size).
|
|
119
124
|
--fps <15|24|30|60> Output frame rate for record, assemble, or build (default: 30).
|
|
120
|
-
--run <directory>
|
|
121
|
-
--cache-dir <dir> Speech cache for tts or build
|
|
125
|
+
--run <directory> Run directory (default: runs/YYYYMMDD-HHmmss for build and tts; required for resolve, record, assemble, and build --resume).
|
|
126
|
+
--cache-dir <dir> Speech cache directory for play, tts, or build (default: .slidevideo/speech beside storyboard).
|
|
127
|
+
--no-cache Disable speech cache reading and writing for play, tts, or build.
|
|
122
128
|
--port <number> Local play server port (default: auto).
|
|
123
129
|
--output <file> New final MP4 destination for assemble or build.
|
|
130
|
+
--captions <vtt|srt|both|none> Caption export (default: both for build/assemble with narration; optional for resolve).
|
|
124
131
|
--resume Reuse intact build stages with matching inputs and mode.
|
|
125
132
|
--verify-timing Opt in to decoded timing proof for build or record; assemble checks the recorded mode.
|
|
126
133
|
--export <file> Optional resolved schedule export.
|
|
@@ -134,7 +141,7 @@ setup prepares shared tools and speech providers, and detects Slidev and native
|
|
|
134
141
|
Normal production leaves timing unevaluated and the video for user review.
|
|
135
142
|
inspect lists slide targets, click counts, media IDs and annotation targets from --deck or --storyboard without recording.
|
|
136
143
|
validate checks inputs without recording.
|
|
137
|
-
play --storyboard <file> serves
|
|
144
|
+
play --storyboard <file> serves slides and annotations (with cached audio when available) with Play, Pause and Replay. Ctrl+C stops the server.
|
|
138
145
|
skill displays or registers (--install) the bundled coding-agent skill; see skill --help for references and options.
|
|
139
146
|
license displays the bundled license terms. Use setup --license to manage activation.
|
|
140
147
|
impressum displays the provider's contact details.
|
|
@@ -167,7 +174,7 @@ impressum displays the provider's contact details.
|
|
|
167
174
|
await withExecutables({}, setupLicense);
|
|
168
175
|
}
|
|
169
176
|
else if (command === 'setup') {
|
|
170
|
-
requireCondition(positionals.length === 1 && !['storyboard', 'deck', 'width', 'height', 'fps', 'port', 'run', 'cache-dir', 'output', 'export', 'timeout-minutes', 'resume', 'verify-timing', 'project'].some(key => key in values), 'OPTION', 'Run slidevideo setup --help for setup options');
|
|
177
|
+
requireCondition(positionals.length === 1 && !['storyboard', 'deck', 'width', 'height', 'fps', 'port', 'run', 'cache-dir', 'no-cache', 'output', 'captions', 'export', 'timeout-minutes', 'resume', 'verify-timing', 'project'].some(key => key in values), 'OPTION', 'Run slidevideo setup --help for setup options');
|
|
171
178
|
let initialChecklist;
|
|
172
179
|
const report = await withExecutables(values, () => setup(values, current => {
|
|
173
180
|
initialChecklist = setupChecklist(current, configuredLicense());
|
|
@@ -228,9 +235,20 @@ impressum displays the provider's contact details.
|
|
|
228
235
|
requireCondition(/^(?:\d+(?:\.\d+)?|\.\d+)$/.test(raw) && Number.isFinite(minutes) && minutes > 0 && minutes <= 180, 'TIMEOUT', '--timeout-minutes must be a positive number up to 180');
|
|
229
236
|
timeout = Math.ceil(minutes * 60_000);
|
|
230
237
|
}
|
|
238
|
+
requireCondition(values.run === undefined || values.run.trim().length > 0, 'OPTION', '--run requires a directory path');
|
|
231
239
|
requireCondition(!values.output || ['assemble', 'build'].includes(command), 'OPTION', '--output requires assemble or build');
|
|
240
|
+
requireCondition(values.captions === undefined || ['resolve', 'assemble', 'build'].includes(command), 'OPTION', '--captions requires resolve, assemble or build');
|
|
241
|
+
let captions;
|
|
242
|
+
if (values.captions !== undefined) {
|
|
243
|
+
const normalized = values.captions.trim().toLowerCase();
|
|
244
|
+
requireCondition(normalized === 'vtt' || normalized === 'srt' || normalized === 'both' || normalized === 'none', 'OPTION', '--captions must be vtt, srt, both or none');
|
|
245
|
+
captions = normalized;
|
|
246
|
+
}
|
|
232
247
|
requireCondition(!values.resume || command === 'build', 'OPTION', '--resume requires build');
|
|
233
|
-
requireCondition(
|
|
248
|
+
requireCondition(values['cache-dir'] === undefined || ['tts', 'build', 'play'].includes(command), 'OPTION', '--cache-dir requires play, tts or build');
|
|
249
|
+
requireCondition(values['cache-dir'] === undefined || values['cache-dir'].trim().length > 0, 'OPTION', '--cache-dir requires a directory path');
|
|
250
|
+
requireCondition(!values['no-cache'] || ['tts', 'build', 'play'].includes(command), 'OPTION', '--no-cache requires play, tts or build');
|
|
251
|
+
requireCondition(!(values['cache-dir'] !== undefined && values['no-cache']), 'OPTION', 'Cannot combine --cache-dir and --no-cache');
|
|
234
252
|
requireCondition(!values.export || ['resolve', 'build'].includes(command), 'OPTION', '--export requires resolve or build');
|
|
235
253
|
requireCondition(!values['verify-timing'] || ['record', 'assemble', 'build'].includes(command), 'OPTION', '--verify-timing requires record, assemble or build');
|
|
236
254
|
requireCondition(values.port === undefined || command === 'play', 'OPTION', '--port requires play');
|
|
@@ -265,15 +283,27 @@ impressum displays the provider's contact details.
|
|
|
265
283
|
else {
|
|
266
284
|
requireCondition(values.deck === undefined, 'OPTION', '--deck requires inspect');
|
|
267
285
|
}
|
|
286
|
+
const cache = values['no-cache'] ? false : values['cache-dir'];
|
|
268
287
|
await withExecutables(values, async () => {
|
|
269
288
|
if (command === 'play') {
|
|
270
289
|
requireCondition(values.storyboard, 'STORYBOARD_REQUIRED', 'play requires --storyboard');
|
|
271
|
-
requireCondition(values.run === undefined && values['timeout-minutes'] === undefined, 'OPTION', 'play takes --storyboard, --cache-dir, --port, --width and --height; Ctrl+C stops the server');
|
|
290
|
+
requireCondition(values.run === undefined && values['timeout-minutes'] === undefined, 'OPTION', 'play takes --storyboard, --cache-dir, --no-cache, --port, --width and --height; Ctrl+C stops the server');
|
|
272
291
|
const port = Number(values.port ?? 0);
|
|
273
292
|
requireCondition(values.port === undefined || /^\d+$/.test(values.port) && Number.isInteger(port) && port <= 65535, 'PREVIEW_PORT', '--port must be between 0 and 65535');
|
|
274
|
-
await servePreview(values.storyboard,
|
|
293
|
+
await servePreview(values.storyboard, cache, port, viewport, (url, approximate, approximateCues) => {
|
|
275
294
|
previewReady = true;
|
|
276
|
-
|
|
295
|
+
if (values.json) {
|
|
296
|
+
console.log(JSON.stringify({ version: 1, command, status: 'ready', url, approximate, approximate_cues: approximateCues, timing_status: 'not_evaluated' }));
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
console.log(`Open ${url} to preview the storyboard. Press Ctrl+C to stop.`);
|
|
300
|
+
if (approximate.length) {
|
|
301
|
+
const cueNote = approximateCues.length
|
|
302
|
+
? `; approximate phrase cues (not synthesized alignment): ${approximateCues.join(', ')}. Run tts or build for synthesized alignment.`
|
|
303
|
+
: '.';
|
|
304
|
+
console.log(`Estimated timing (150 words/min, uncached speech): ${approximate.join(', ')}${cueNote}`);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
277
307
|
});
|
|
278
308
|
}
|
|
279
309
|
else {
|
|
@@ -289,9 +319,18 @@ impressum displays the provider's contact details.
|
|
|
289
319
|
progress?.(operation);
|
|
290
320
|
const heartbeat = progress ? setInterval(() => process.stderr.write(`[slidevideo] ${operation} (${Math.floor((Date.now() - started) / 1000)}s elapsed)\n`), 5000) : undefined;
|
|
291
321
|
try {
|
|
292
|
-
const result = await produce({ command, storyboard: values.storyboard, inspect: inspectInput, viewport, fps, run: values.run, cache
|
|
322
|
+
const result = await produce({ command, storyboard: values.storyboard, inspect: inspectInput, viewport, fps, run: values.run, cache, output: values.output, captions, export: values.export, resume: values.resume, verify_timing: values['verify-timing'], timeout_ms: timeout, progress, onRunResolved: directory => { runDirectory = directory; } });
|
|
293
323
|
progress?.(`${command} completed`);
|
|
294
|
-
|
|
324
|
+
const captionFiles = [result.artifacts.captions_vtt, result.artifacts.captions_srt].filter(Boolean);
|
|
325
|
+
const details = [
|
|
326
|
+
...(result.run_dir ? [`run: ${result.run_dir}`] : []),
|
|
327
|
+
...(captionFiles.length ? [`captions: ${captionFiles.join(', ')}`] : []),
|
|
328
|
+
];
|
|
329
|
+
const suffix = details.length ? ` (${details.join('; ')})` : '';
|
|
330
|
+
const summary = result.artifacts.video
|
|
331
|
+
? `${command} completed: ${result.artifacts.video}${suffix}`
|
|
332
|
+
: `${command} completed${suffix}`;
|
|
333
|
+
console.log(values.json || command === 'inspect' ? JSON.stringify(result) : summary);
|
|
295
334
|
}
|
|
296
335
|
catch (error) {
|
|
297
336
|
progress?.(`${command} failed`);
|
|
@@ -307,14 +346,15 @@ impressum displays the provider's contact details.
|
|
|
307
346
|
catch (error) {
|
|
308
347
|
const failure = error instanceof ProductionError ? error : new ProductionError('INTERNAL', error instanceof Error ? error.message : String(error), error instanceof TypeError ? 2 : 1);
|
|
309
348
|
let run;
|
|
310
|
-
|
|
349
|
+
const resolvedRun = runDirectory;
|
|
350
|
+
if (resolvedRun) {
|
|
311
351
|
try {
|
|
312
|
-
run = await json(join(
|
|
352
|
+
run = await json(join(resolvedRun, 'manifest.json'));
|
|
313
353
|
}
|
|
314
354
|
catch { }
|
|
315
355
|
}
|
|
316
|
-
const result = { version: 1, command, status: 'failed', run_id: run?.run_id, completed_stages: Object.entries(run?.stages ?? {}).filter(([, stage]) => stage?.status === 'completed').map(([name]) => name), artifacts: run ? { manifest: join(
|
|
317
|
-
const diagnostic = jsonMode ? JSON.stringify(result) : `${failure.code}: ${failure.message}`;
|
|
356
|
+
const result = { version: 1, command, status: 'failed', run_id: run?.run_id, ...(resolvedRun ? { run_dir: resolvedRun } : {}), completed_stages: Object.entries(run?.stages ?? {}).filter(([, stage]) => stage?.status === 'completed').map(([name]) => name), artifacts: run && resolvedRun ? { manifest: join(resolvedRun, 'manifest.json') } : {}, timing_status: 'not_accepted', warnings: [], errors: [{ stage: command, code: failure.code, message: failure.message, ...failure.context }] };
|
|
357
|
+
const diagnostic = jsonMode ? JSON.stringify(result) : `${failure.code}: ${failure.message}${resolvedRun ? ` (run: ${resolvedRun})` : ''}`;
|
|
318
358
|
if (previewReady)
|
|
319
359
|
console.error(diagnostic);
|
|
320
360
|
else
|
package/dist/compositor.d.ts
CHANGED
|
@@ -30,9 +30,24 @@ export type CompositorPlan = {
|
|
|
30
30
|
selectedReadbackFrames: number;
|
|
31
31
|
canvasLayers: FrameLayer[];
|
|
32
32
|
};
|
|
33
|
-
export
|
|
33
|
+
export type WatermarkLayout = {
|
|
34
|
+
text: string;
|
|
35
|
+
font: string;
|
|
36
|
+
textX: number;
|
|
37
|
+
textY: number;
|
|
38
|
+
maxTextWidth: number;
|
|
39
|
+
rectangle: Rectangle;
|
|
40
|
+
};
|
|
41
|
+
export declare function frameLayers(output: VideoOutput, schedule: Schedule, hashes?: Record<string, string>): Promise<FrameLayer[]>;
|
|
42
|
+
export declare function watermarkLayout(output: VideoOutput): WatermarkLayout;
|
|
43
|
+
export declare function renderWatermarkCanvas(output: VideoOutput, fillStyle?: string): {
|
|
44
|
+
canvas: Canvas;
|
|
45
|
+
layout: WatermarkLayout;
|
|
46
|
+
};
|
|
47
|
+
export declare function writeWatermarkMask(file: string, output: VideoOutput): Promise<Rectangle>;
|
|
48
|
+
export declare function watermarkFilters(inputStream: string, maskInput: number, outputStream: string, rectangle: Rectangle): string[];
|
|
34
49
|
export declare function writeStaticFrameLayers(file: string, output: VideoOutput, layers: FrameLayer[]): Promise<void>;
|
|
35
|
-
export declare function visibleFrameLayerBounds(layers: FrameLayer[], frame: number, fps: number, audioOrigin: number): Rectangle[];
|
|
50
|
+
export declare function visibleFrameLayerBounds(layers: FrameLayer[], frame: number, fps: number, audioOrigin: number, extraRectangle?: Rectangle): Rectangle[];
|
|
36
51
|
export declare function splitFrameLayers(layers: FrameLayer[]): {
|
|
37
52
|
canvasLayers: FrameLayer[];
|
|
38
53
|
staticTopLayers: FrameLayer[];
|
package/dist/compositor.js
CHANGED
|
@@ -2,12 +2,13 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import { writeFile } from 'node:fs/promises';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { createCanvas, ImageData } from '@napi-rs/canvas';
|
|
5
|
-
import { effectDirtyBounds, effectNeedsBaseFrames, paintEffects } from './annotation-paint.js';
|
|
5
|
+
import { activeViewTransform, effectDirtyBounds, effectNeedsBaseFrames, hasActiveSpotlight, paintEffects } from './annotation-paint.js';
|
|
6
6
|
import { balancedSum, executionSignal, ffmpegFilterScriptFlags, hasStageDeadline } from './media.js';
|
|
7
7
|
import { executable } from './executables.js';
|
|
8
8
|
import { ProductionError, requireCondition } from './errors.js';
|
|
9
9
|
import { loadOverlayImage } from './overlay-assets.js';
|
|
10
|
-
|
|
10
|
+
import { ensureStampFonts } from './stamp-fonts.js';
|
|
11
|
+
export async function frameLayers(output, schedule, hashes) {
|
|
11
12
|
const layers = [];
|
|
12
13
|
const images = new Map();
|
|
13
14
|
for (const overlay of schedule.overlays ?? []) {
|
|
@@ -36,30 +37,61 @@ export async function frameLayers(output, schedule, licensed, hashes) {
|
|
|
36
37
|
};
|
|
37
38
|
layers.push({ image, rectangle, opacity: overlay.opacity, opacityAt });
|
|
38
39
|
}
|
|
39
|
-
if (!licensed)
|
|
40
|
-
layers.push(watermark(output));
|
|
41
40
|
return layers;
|
|
42
41
|
}
|
|
43
|
-
function
|
|
42
|
+
export function watermarkLayout(output) {
|
|
43
|
+
ensureStampFonts();
|
|
44
44
|
const text = 'slidevideo.io';
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
45
|
+
const fontSize = Math.max(1, Math.round(output.height * 0.0204));
|
|
46
|
+
const font = `700 ${fontSize}px SlideVideoSans`;
|
|
47
|
+
const measure = createCanvas(16, 16).getContext('2d');
|
|
48
|
+
measure.font = font;
|
|
49
|
+
const metrics = measure.measureText(text);
|
|
50
|
+
const ascent = Math.ceil(metrics.actualBoundingBoxAscent || fontSize * 0.78);
|
|
51
|
+
const descent = Math.ceil(metrics.actualBoundingBoxDescent || 0);
|
|
52
|
+
const pad = Math.max(1, Math.min(4, Math.floor(Math.min(output.width, output.height) * 0.05)));
|
|
53
|
+
const marginX = Math.max(1, Math.min(Math.max(1, Math.floor(output.width * 0.1)), Math.round(Math.min(output.width, output.height) * 0.0204)));
|
|
54
|
+
const marginY = Math.max(1, Math.min(Math.max(1, Math.floor(output.height * 0.1)), Math.round(Math.min(output.width, output.height) * 0.0185)));
|
|
55
|
+
const maxWidth = Math.max(1, output.width - marginX);
|
|
56
|
+
const maxHeight = Math.max(1, output.height - marginY);
|
|
57
|
+
const rawWidth = Math.min(Math.ceil(metrics.width) + pad * 2, maxWidth);
|
|
58
|
+
const rawHeight = Math.min(ascent + descent + pad * 2, maxHeight);
|
|
59
|
+
const width = rawWidth % 2 === 1 && rawWidth + 1 <= maxWidth ? rawWidth + 1 : rawWidth;
|
|
60
|
+
const height = rawHeight % 2 === 1 && rawHeight + 1 <= maxHeight ? rawHeight + 1 : rawHeight;
|
|
61
|
+
const rawX = Math.max(0, Math.min(output.width - width, output.width - marginX - width + pad));
|
|
62
|
+
const rawY = Math.max(0, Math.min(output.height - height, output.height - marginY - height + pad + descent));
|
|
63
|
+
const x = rawX % 2 === 1 && rawX > 0 ? rawX - 1 : rawX;
|
|
64
|
+
const y = rawY % 2 === 1 && rawY > 0 ? rawY - 1 : rawY;
|
|
65
|
+
const textX = Math.max(1, width - pad);
|
|
66
|
+
const textY = Math.max(1, height - pad - descent);
|
|
67
|
+
const maxTextWidth = Math.max(1, width - Math.min(pad * 2, width - 1));
|
|
68
|
+
return { text, font, textX, textY, maxTextWidth, rectangle: { x, y, width, height } };
|
|
69
|
+
}
|
|
70
|
+
export function renderWatermarkCanvas(output, fillStyle = 'rgba(255, 255, 255, 0.38)') {
|
|
71
|
+
const layout = watermarkLayout(output);
|
|
72
|
+
const canvas = createCanvas(layout.rectangle.width, layout.rectangle.height);
|
|
73
|
+
const context = canvas.getContext('2d');
|
|
74
|
+
context.font = layout.font;
|
|
52
75
|
context.textAlign = 'right';
|
|
53
|
-
context.textBaseline = '
|
|
54
|
-
context.
|
|
55
|
-
context.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
76
|
+
context.textBaseline = 'alphabetic';
|
|
77
|
+
context.fillStyle = fillStyle;
|
|
78
|
+
context.fillText(layout.text, layout.textX, layout.textY, layout.maxTextWidth);
|
|
79
|
+
return { canvas, layout };
|
|
80
|
+
}
|
|
81
|
+
export async function writeWatermarkMask(file, output) {
|
|
82
|
+
const { canvas, layout } = renderWatermarkCanvas(output);
|
|
83
|
+
await writeFile(file, canvas.toBuffer('image/png'));
|
|
84
|
+
return layout.rectangle;
|
|
85
|
+
}
|
|
86
|
+
export function watermarkFilters(inputStream, maskInput, outputStream, rectangle) {
|
|
87
|
+
const { x, y, width, height } = rectangle;
|
|
88
|
+
return [
|
|
89
|
+
`[${inputStream}]split[wm_bg][wm_probe]`,
|
|
90
|
+
`[wm_probe]crop=${width}:${height}:${x}:${y},format=gray,scale=1:1:flags=area,format=rgb24,lutrgb=r='if(gte(val,116),20,236)':g='if(gte(val,116),28,242)':b='if(gte(val,116),36,248)',scale=${width}:${height}:flags=neighbor[wm_ink]`,
|
|
91
|
+
`[${maskInput}:v]alphaextract[wm_alpha]`,
|
|
92
|
+
'[wm_ink][wm_alpha]alphamerge[wm_patch]',
|
|
93
|
+
`[wm_bg][wm_patch]overlay=x=${x}:y=${y}:eof_action=repeat,format=yuv420p[${outputStream}]`,
|
|
94
|
+
];
|
|
63
95
|
}
|
|
64
96
|
function paintFrameLayers(context, layers, time) {
|
|
65
97
|
for (const layer of layers) {
|
|
@@ -77,9 +109,12 @@ export async function writeStaticFrameLayers(file, output, layers) {
|
|
|
77
109
|
paintFrameLayers(canvas.getContext('2d'), layers, 0);
|
|
78
110
|
await writeFile(file, canvas.toBuffer('image/png'));
|
|
79
111
|
}
|
|
80
|
-
export function visibleFrameLayerBounds(layers, frame, fps, audioOrigin) {
|
|
112
|
+
export function visibleFrameLayerBounds(layers, frame, fps, audioOrigin, extraRectangle) {
|
|
81
113
|
const time = Math.max(0, frame * 1000 / fps - audioOrigin);
|
|
82
|
-
|
|
114
|
+
const bounds = layers.filter(layer => (layer.opacityAt?.(time) ?? layer.opacity) > 0).map(layer => layer.rectangle);
|
|
115
|
+
if (extraRectangle)
|
|
116
|
+
bounds.push(extraRectangle);
|
|
117
|
+
return bounds;
|
|
83
118
|
}
|
|
84
119
|
function completion(child, operation) {
|
|
85
120
|
let diagnostic = '';
|
|
@@ -241,6 +276,8 @@ function createFrameReader(stream, frameBytes, decoded) {
|
|
|
241
276
|
export async function compositeFrames(source, baseFilter, encoderArgs, output, applications, plan, frameCount, audioOrigin, stagingDirectory) {
|
|
242
277
|
const signal = executionSignal();
|
|
243
278
|
signal?.throwIfAborted();
|
|
279
|
+
if (applications.some(app => app.effect === 'stamp'))
|
|
280
|
+
ensureStampFonts();
|
|
244
281
|
const bytes = output.width * output.height * 4;
|
|
245
282
|
const slots = [Buffer.alloc(bytes), Buffer.alloc(bytes)];
|
|
246
283
|
const slotOpaque = [false, false];
|
|
@@ -289,10 +326,29 @@ export async function compositeFrames(source, baseFilter, encoderArgs, output, a
|
|
|
289
326
|
signal?.addEventListener('abort', onAbort, { once: true });
|
|
290
327
|
});
|
|
291
328
|
let readbackContext;
|
|
329
|
+
let sourceCanvas;
|
|
330
|
+
let sourceContext;
|
|
292
331
|
let overlayContext;
|
|
293
332
|
let overlayCanvasDirty;
|
|
333
|
+
let maskCanvas;
|
|
334
|
+
let maskContext;
|
|
294
335
|
const ensureReadbackContext = () => readbackContext ??= createCanvas(output.width, output.height).getContext('2d', { alpha: false });
|
|
336
|
+
const ensureSourceCanvas = () => {
|
|
337
|
+
sourceCanvas ??= createCanvas(output.width, output.height);
|
|
338
|
+
sourceContext ??= sourceCanvas.getContext('2d', { alpha: false });
|
|
339
|
+
return { canvas: sourceCanvas, context: sourceContext };
|
|
340
|
+
};
|
|
295
341
|
const ensureOverlayContext = () => overlayContext ??= createCanvas(output.width, output.height).getContext('2d');
|
|
342
|
+
const ensureSpotlightScratch = () => {
|
|
343
|
+
maskCanvas ??= createCanvas(output.width, output.height);
|
|
344
|
+
maskContext ??= maskCanvas.getContext('2d');
|
|
345
|
+
return {
|
|
346
|
+
context: maskContext,
|
|
347
|
+
drawTo: (target, { x, y, width, height }) => {
|
|
348
|
+
target.drawImage(maskCanvas, x, y, width, height, x, y, width, height);
|
|
349
|
+
},
|
|
350
|
+
};
|
|
351
|
+
};
|
|
296
352
|
let emittedCount = 0;
|
|
297
353
|
let paintedFrames = 0;
|
|
298
354
|
let intervalIndex = 0;
|
|
@@ -343,7 +399,33 @@ export async function compositeFrames(source, baseFilter, encoderArgs, output, a
|
|
|
343
399
|
const context = ensureReadbackContext();
|
|
344
400
|
const { x: dx, y: dy, width: dw, height: dh } = dirty;
|
|
345
401
|
context.putImageData(slotImages[slot], 0, 0, dx, dy, dw, dh);
|
|
346
|
-
|
|
402
|
+
const view = activeViewTransform(activeAnnotations, outputTime);
|
|
403
|
+
if (view) {
|
|
404
|
+
const source = ensureSourceCanvas();
|
|
405
|
+
const { x: cx, y: cy, width: cw, height: ch } = view.content;
|
|
406
|
+
source.context.putImageData(slotImages[slot], 0, 0, cx, cy, cw, ch);
|
|
407
|
+
context.save();
|
|
408
|
+
context.beginPath();
|
|
409
|
+
context.rect(cx, cy, cw, ch);
|
|
410
|
+
context.clip();
|
|
411
|
+
context.translate(cx, cy);
|
|
412
|
+
context.scale(view.scale, view.scale);
|
|
413
|
+
context.translate(-view.source.x, -view.source.y);
|
|
414
|
+
context.imageSmoothingEnabled = true;
|
|
415
|
+
context.imageSmoothingQuality = 'high';
|
|
416
|
+
context.drawImage(source.canvas, 0, 0);
|
|
417
|
+
paintEffects(context, activeAnnotations, outputTime, {
|
|
418
|
+
backdrop: true,
|
|
419
|
+
spotlightScratch: hasActiveSpotlight(activeAnnotations, outputTime) ? ensureSpotlightScratch() : undefined,
|
|
420
|
+
});
|
|
421
|
+
context.restore();
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
paintEffects(context, activeAnnotations, outputTime, {
|
|
425
|
+
backdrop: true,
|
|
426
|
+
spotlightScratch: hasActiveSpotlight(activeAnnotations, outputTime) ? ensureSpotlightScratch() : undefined,
|
|
427
|
+
});
|
|
428
|
+
}
|
|
347
429
|
paintFrameLayers(context, plan.canvasLayers, scheduleTime);
|
|
348
430
|
copyPatchToBuffer(context.getImageData(dx, dy, dw, dh).data, target, output.width, dirty);
|
|
349
431
|
paintedFrames++;
|
|
@@ -364,7 +446,7 @@ export async function compositeFrames(source, baseFilter, encoderArgs, output, a
|
|
|
364
446
|
if (overlayCanvasDirty) {
|
|
365
447
|
context.clearRect(overlayCanvasDirty.x, overlayCanvasDirty.y, overlayCanvasDirty.width, overlayCanvasDirty.height);
|
|
366
448
|
}
|
|
367
|
-
paintEffects(context, activeAnnotations, outputTime);
|
|
449
|
+
paintEffects(context, activeAnnotations, outputTime, { backdrop: false });
|
|
368
450
|
paintFrameLayers(context, plan.canvasLayers, scheduleTime);
|
|
369
451
|
overlayCanvasDirty = dirty;
|
|
370
452
|
copyPatchToBuffer(context.getImageData(dirty.x, dirty.y, dirty.width, dirty.height).data, target, output.width, dirty);
|