@phil65/demoreel 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -3
- package/dist/args.js +8 -0
- package/dist/cli.js +43 -1
- package/dist/compose.d.ts +3 -0
- package/dist/compose.js +16 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/layout.d.ts +10 -1
- package/dist/layout.js +41 -0
- package/dist/marks.d.ts +7 -12
- package/dist/marks.js +73 -43
- package/dist/mcp.js +35 -0
- package/dist/music.d.ts +81 -0
- package/dist/music.js +344 -0
- package/dist/project.d.ts +16 -2
- package/dist/project.js +25 -14
- package/dist/record.d.ts +3 -0
- package/dist/record.js +1 -0
- package/dist/render.d.ts +4 -0
- package/dist/render.js +52 -15
- package/dist/scene.d.ts +6 -0
- package/dist/scene.js +27 -3
- package/dist/types.d.ts +2 -0
- package/dist/voice.d.ts +10 -1
- package/dist/voice.js +31 -0
- package/package.json +1 -1
- package/skills/demoreel/SKILL.md +4 -3
package/dist/render.js
CHANGED
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
import fs from "node:fs";
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import { DemoreelError, launchChromium, renderArgs } from "./env.js";
|
|
10
|
+
import { muxAudioTracks, normalizeMusicConfig, resolveMusicTrack } from "./music.js";
|
|
10
11
|
import { openscreenProjectApi, rendererDir } from "./openscreen.js";
|
|
11
12
|
import { sendFile, serveStatic } from "./server.js";
|
|
12
|
-
import {
|
|
13
|
+
import { probeDuration } from "./sheet.js";
|
|
14
|
+
import { lintVoiceCues } from "./voice.js";
|
|
13
15
|
function readProject(projectPath) {
|
|
14
16
|
if (!fs.existsSync(projectPath))
|
|
15
17
|
throw new DemoreelError(`project not found: ${projectPath}`);
|
|
@@ -101,31 +103,65 @@ export async function renderProject(opts) {
|
|
|
101
103
|
const warnings = [...(result.warnings ?? [])];
|
|
102
104
|
let bytes = result.bytes;
|
|
103
105
|
let audioMuxed = false;
|
|
106
|
+
let musicMuxed = false;
|
|
104
107
|
let vttPath;
|
|
105
|
-
//
|
|
108
|
+
// Mux voiceCues and/or background music into the MP4 (stream-copying video via `-c:v copy`).
|
|
106
109
|
const projectDir = path.dirname(projectPath);
|
|
107
110
|
const timelinePath = path.join(projectDir, "timeline.json");
|
|
111
|
+
let tl = null;
|
|
108
112
|
if (fs.existsSync(timelinePath)) {
|
|
109
113
|
try {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
tl = JSON.parse(fs.readFileSync(timelinePath, "utf8"));
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
warnings.push(`timeline.json parse skipped: ${e.message}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const voiceCues = tl?.voiceCues ?? [];
|
|
121
|
+
const baseMusic = normalizeMusicConfig(tl?.options?.music);
|
|
122
|
+
const overrideMusic = normalizeMusicConfig(opts.music);
|
|
123
|
+
const effectiveMusic = overrideMusic || baseMusic ? { ...baseMusic, ...overrideMusic } : undefined;
|
|
124
|
+
const wantsMusic = Boolean(effectiveMusic &&
|
|
125
|
+
effectiveMusic.enabled !== false &&
|
|
126
|
+
(effectiveMusic.src || (effectiveMusic.provider && effectiveMusic.prompt)));
|
|
127
|
+
if (voiceCues.length > 0 || wantsMusic) {
|
|
128
|
+
try {
|
|
129
|
+
const outDurMs = tl?.outputDurationMs && tl.outputDurationMs > 0
|
|
130
|
+
? tl.outputDurationMs
|
|
131
|
+
: Math.round((await probeDuration(outputPath)) * 1000);
|
|
132
|
+
let musicPath;
|
|
133
|
+
if (wantsMusic && effectiveMusic) {
|
|
134
|
+
const resolved = await resolveMusicTrack(effectiveMusic, {
|
|
135
|
+
durationMs: outDurMs,
|
|
136
|
+
baseDir: projectDir,
|
|
137
|
+
log,
|
|
116
138
|
});
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
139
|
+
musicPath = resolved.filePath;
|
|
140
|
+
}
|
|
141
|
+
const mux = await muxAudioTracks(outputPath, {
|
|
142
|
+
voiceCues,
|
|
143
|
+
musicPath,
|
|
144
|
+
music: effectiveMusic,
|
|
145
|
+
outputDurationMs: outDurMs,
|
|
146
|
+
baseDir: projectDir,
|
|
147
|
+
trims: tl?.trimRegions,
|
|
148
|
+
speeds: tl?.speedRegions,
|
|
149
|
+
writeVtt: tl?.options?.voice?.captions !== "off",
|
|
150
|
+
});
|
|
151
|
+
audioMuxed = mux.audioMuxed;
|
|
152
|
+
musicMuxed = mux.musicMuxed;
|
|
153
|
+
vttPath = mux.vttPath;
|
|
154
|
+
if (audioMuxed && fs.existsSync(outputPath)) {
|
|
155
|
+
bytes = fs.statSync(outputPath).size;
|
|
156
|
+
}
|
|
157
|
+
if (voiceCues.length > 0) {
|
|
158
|
+
const voiceFindings = lintVoiceCues(voiceCues, outDurMs, tl?.trimRegions, tl?.speedRegions);
|
|
123
159
|
for (const f of voiceFindings)
|
|
124
160
|
warnings.push(`[voice:${f.severity}] ${f.message}`);
|
|
125
161
|
}
|
|
126
162
|
}
|
|
127
163
|
catch (e) {
|
|
128
|
-
warnings.push(`
|
|
164
|
+
warnings.push(`audio mux skipped: ${e.message}`);
|
|
129
165
|
}
|
|
130
166
|
}
|
|
131
167
|
return {
|
|
@@ -140,6 +176,7 @@ export async function renderProject(opts) {
|
|
|
140
176
|
setupMs: tReady - t0,
|
|
141
177
|
totalMs: Date.now() - t0,
|
|
142
178
|
...(audioMuxed ? { audioMuxed } : {}),
|
|
179
|
+
...(musicMuxed ? { musicMuxed } : {}),
|
|
143
180
|
...(vttPath ? { vttPath } : {}),
|
|
144
181
|
};
|
|
145
182
|
}
|
package/dist/scene.d.ts
CHANGED
|
@@ -116,6 +116,12 @@ export interface BlurOptions {
|
|
|
116
116
|
blockSize?: number;
|
|
117
117
|
/** Extra px padding around a DOM target box (default `4`). */
|
|
118
118
|
padding?: number;
|
|
119
|
+
/**
|
|
120
|
+
* `"auto"` (default): CSS `filter: blur(...)` on DOM elements for Gaussian blur (stays locked
|
|
121
|
+
* through scrolling & camera zooms), OpenScreen post-process overlay for `"mosaic"` or stage rects.
|
|
122
|
+
* Pass `"dom"` or `"overlay"` to force one explicitly.
|
|
123
|
+
*/
|
|
124
|
+
mode?: "auto" | "dom" | "overlay";
|
|
119
125
|
/** Block until `duration` elapses (ignored when `duration === "end"`, default `false`). */
|
|
120
126
|
wait?: boolean;
|
|
121
127
|
label?: string;
|
package/dist/scene.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import fs from "node:fs";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { easeAimed, makePath, mulberry32, sleep, travelDuration } from "./motion.js";
|
|
9
|
-
import { createVoiceSynthesizer, DEFAULT_VOICE_GAP_MS, DEFAULT_VOICE_PAD_MS, findWordTiming, } from "./voice.js";
|
|
9
|
+
import { chunkVoiceCaptions, createVoiceSynthesizer, DEFAULT_VOICE_GAP_MS, DEFAULT_VOICE_PAD_MS, findWordTiming, } from "./voice.js";
|
|
10
10
|
function isLocator(target) {
|
|
11
11
|
return typeof target === "object" && target !== null && typeof target.filter === "function";
|
|
12
12
|
}
|
|
@@ -744,14 +744,37 @@ export class Scene {
|
|
|
744
744
|
let box;
|
|
745
745
|
let rect;
|
|
746
746
|
let label = opts.label;
|
|
747
|
+
const modePref = opts.mode ?? "auto";
|
|
748
|
+
const useDom = !isStageRect && (modePref === "dom" || (modePref === "auto" && (opts.type ?? "blur") === "blur"));
|
|
747
749
|
if (isStageRect) {
|
|
748
750
|
rect = target;
|
|
749
751
|
label ??= "blur rect";
|
|
750
752
|
}
|
|
751
753
|
else {
|
|
752
|
-
const
|
|
754
|
+
const loc = this.locate(target);
|
|
755
|
+
const inspected = await this.inspect(loc, target);
|
|
753
756
|
box = inspected.box;
|
|
754
757
|
label ??= describeTarget(target);
|
|
758
|
+
if (useDom) {
|
|
759
|
+
const intensity = Math.min(40, Math.max(2, opts.intensity ?? 14));
|
|
760
|
+
const blurPx = Math.max(2, Math.round(intensity * 0.65));
|
|
761
|
+
const restoreAfterMs = typeof endMs === "number" ? Math.max(0, endMs - startMs) : null;
|
|
762
|
+
await loc.evaluate((el, o) => {
|
|
763
|
+
const h = el;
|
|
764
|
+
const prevFilter = h.style.filter;
|
|
765
|
+
const prevSelect = h.style.userSelect;
|
|
766
|
+
h.setAttribute("data-demoreel-blur", "");
|
|
767
|
+
h.style.filter = prevFilter ? `${prevFilter} blur(${o.blurPx}px)` : `blur(${o.blurPx}px)`;
|
|
768
|
+
h.style.userSelect = "none";
|
|
769
|
+
if (o.restoreAfterMs !== null) {
|
|
770
|
+
setTimeout(() => {
|
|
771
|
+
h.style.filter = prevFilter;
|
|
772
|
+
h.style.userSelect = prevSelect;
|
|
773
|
+
h.removeAttribute("data-demoreel-blur");
|
|
774
|
+
}, o.restoreAfterMs);
|
|
775
|
+
}
|
|
776
|
+
}, { blurPx, restoreAfterMs });
|
|
777
|
+
}
|
|
755
778
|
}
|
|
756
779
|
this.blurs.push({
|
|
757
780
|
startMs,
|
|
@@ -764,6 +787,7 @@ export class Scene {
|
|
|
764
787
|
color: opts.color,
|
|
765
788
|
intensity: opts.intensity,
|
|
766
789
|
blockSize: opts.blockSize,
|
|
790
|
+
mode: useDom ? "dom" : "overlay",
|
|
767
791
|
label,
|
|
768
792
|
});
|
|
769
793
|
this.record({
|
|
@@ -935,7 +959,7 @@ export class Scene {
|
|
|
935
959
|
this.lastVoiceEndMs = endMs;
|
|
936
960
|
const captionsMode = opts.captions ?? this.voiceConfig.captions ?? "vtt";
|
|
937
961
|
if (captionsMode === "burned") {
|
|
938
|
-
this.captions.push(
|
|
962
|
+
this.captions.push(...chunkVoiceCaptions(cue));
|
|
939
963
|
}
|
|
940
964
|
const padMs = opts.padMs ?? this.voiceConfig.padMs ?? DEFAULT_VOICE_PAD_MS;
|
|
941
965
|
let wordCursor = 0;
|
package/dist/types.d.ts
CHANGED
|
@@ -111,6 +111,8 @@ export interface BlurAnnotation {
|
|
|
111
111
|
color?: "black" | "white";
|
|
112
112
|
intensity?: number;
|
|
113
113
|
blockSize?: number;
|
|
114
|
+
/** `"dom"` = CSS blur injected on the DOM element (tracks zoom & scroll); `"overlay"` = OpenScreen post-process region. */
|
|
115
|
+
mode?: "dom" | "overlay";
|
|
114
116
|
label?: string;
|
|
115
117
|
}
|
|
116
118
|
export interface ArrowAnnotation {
|
package/dist/voice.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SpeedRegion, TrimRegion, VoiceCue, WordTiming } from "./types.ts";
|
|
1
|
+
import type { Caption, CaptionAnimation, SpeedRegion, TrimRegion, VoiceCue, WordTiming } from "./types.ts";
|
|
2
2
|
export type VoiceProviderName = "edge" | "openai" | "elevenlabs" | "gemini" | "cartesia" | "deepgram";
|
|
3
3
|
export declare const VOICE_PROVIDERS: readonly VoiceProviderName[];
|
|
4
4
|
export interface VoiceConfig {
|
|
@@ -68,6 +68,15 @@ export declare function findWordTiming(timings: WordTiming[], query: string | Re
|
|
|
68
68
|
} | null;
|
|
69
69
|
/** Builds a WebVTT subtitle file from voice cues, mapped onto rendered output timestamps. */
|
|
70
70
|
export declare function buildVoiceVtt(cues: VoiceCue[], trims?: TrimRegion[], speeds?: SpeedRegion[], wordsPerCue?: number): string;
|
|
71
|
+
/**
|
|
72
|
+
* Splits a spoken `VoiceCue` into balanced, word-timed burned-in `Caption` chunks
|
|
73
|
+
* so longer narrations never overflow or wrap awkwardly on screen. Short cues
|
|
74
|
+
* (`<= maxWords` words or without word timings) stay as a single caption.
|
|
75
|
+
*/
|
|
76
|
+
export declare function chunkVoiceCaptions(cue: VoiceCue, opts?: {
|
|
77
|
+
maxWords?: number;
|
|
78
|
+
animation?: CaptionAnimation;
|
|
79
|
+
}): Caption[];
|
|
71
80
|
/**
|
|
72
81
|
* Mixes all voice cue `.wav` files into an AAC audio track at their post-trim output timestamps
|
|
73
82
|
* and stream-copies the video (`-c:v copy`) so OpenScreen's H.264 output is never re-encoded.
|
package/dist/voice.js
CHANGED
|
@@ -161,6 +161,37 @@ export function buildVoiceVtt(cues, trims = [], speeds = [], wordsPerCue = 8) {
|
|
|
161
161
|
}
|
|
162
162
|
return lines.join("\n");
|
|
163
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Splits a spoken `VoiceCue` into balanced, word-timed burned-in `Caption` chunks
|
|
166
|
+
* so longer narrations never overflow or wrap awkwardly on screen. Short cues
|
|
167
|
+
* (`<= maxWords` words or without word timings) stay as a single caption.
|
|
168
|
+
*/
|
|
169
|
+
export function chunkVoiceCaptions(cue, opts = {}) {
|
|
170
|
+
const maxWords = Math.max(1, opts.maxWords ?? 7);
|
|
171
|
+
const anim = opts.animation ? { animation: opts.animation } : {};
|
|
172
|
+
const text = cue.text.trim();
|
|
173
|
+
if (!text)
|
|
174
|
+
return [];
|
|
175
|
+
if (cue.timings.length <= maxWords || cue.timings.length === 0) {
|
|
176
|
+
return [{ text, startMs: cue.startMs, endMs: cue.endMs, ...anim }];
|
|
177
|
+
}
|
|
178
|
+
const numChunks = Math.ceil(cue.timings.length / maxWords);
|
|
179
|
+
const perChunk = Math.ceil(cue.timings.length / numChunks);
|
|
180
|
+
const out = [];
|
|
181
|
+
for (let i = 0; i < cue.timings.length; i += perChunk) {
|
|
182
|
+
const group = cue.timings.slice(i, i + perChunk);
|
|
183
|
+
const nextGroup = cue.timings[i + perChunk];
|
|
184
|
+
const first = group[0];
|
|
185
|
+
const last = group[group.length - 1];
|
|
186
|
+
const startMs = Math.round(cue.startMs + first.offsetMs);
|
|
187
|
+
const naturalEnd = Math.round(cue.startMs + last.offsetMs + last.durationMs);
|
|
188
|
+
const endMs = nextGroup
|
|
189
|
+
? Math.max(startMs + 200, Math.min(cue.endMs, Math.round(cue.startMs + nextGroup.offsetMs)))
|
|
190
|
+
: Math.max(startMs + 200, cue.endMs, naturalEnd);
|
|
191
|
+
out.push({ text: group.map((w) => w.text).join(" "), startMs, endMs, ...anim });
|
|
192
|
+
}
|
|
193
|
+
return out;
|
|
194
|
+
}
|
|
164
195
|
/**
|
|
165
196
|
* Mixes all voice cue `.wav` files into an AAC audio track at their post-trim output timestamps
|
|
166
197
|
* and stream-copies the video (`-c:v copy`) so OpenScreen's H.264 output is never re-encoded.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phil65/demoreel",
|
|
3
3
|
"mcpName": "io.github.phil65/demoreel",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Scripted product demo videos (videos as code): Playwright scenarios with auto cursor + auto zoom, rendered headless by OpenScreen's exporter.",
|
|
7
7
|
"keywords": [
|
package/skills/demoreel/SKILL.md
CHANGED
|
@@ -57,8 +57,8 @@ export default defineScenario({
|
|
|
57
57
|
renders crisp shortcut keycap pills (`Ctrl + K`, `Esc`) as OpenScreen annotations (also toggleable via `demoreel rezoom --show-keys`).
|
|
58
58
|
- `clickRipple: true` (or `{ color, size, durationMs }`) adds an expanding translucent ring at each click.
|
|
59
59
|
- `scene.highlight(target, { dim: true, badge: "..." })` adds a spotlight backdrop dim and optional callout pill.
|
|
60
|
-
- `scene.blur(target, { type: "blur" | "mosaic" })` (alias `scene.redact()`) blurs sensitive API keys, emails, or account IDs
|
|
61
|
-
- `scene.arrow(target, { direction: "down-right", color: "#ffcc00" })` draws a crisp vector arrow pointing at an element.
|
|
60
|
+
- `scene.blur(target, { type: "blur" | "mosaic", mode?: "auto" | "dom" | "overlay" })` (alias `scene.redact()`) blurs sensitive API keys, emails, or account IDs (DOM Gaussian blurs stay locked through scrolling & zooms; defaults to `"end"`).
|
|
61
|
+
- `scene.arrow(target, { direction: "down-right", color: "#ffcc00" })` draws a crisp camera-projected vector arrow pointing at an element.
|
|
62
62
|
- `scene.image("./badge.png", { x, y, width, height })` and `look: { watermark: { src: "./logo.png", position: "bottom-right" } }` render image/logo overlays.
|
|
63
63
|
- `look: { captionAnimation: "fade" | "rise" | "pop" | "typewriter", showBlur: true, crop: { x, y, width, height } }` tune caption animations, blurred wallpaper backdrop, and frame crop.
|
|
64
64
|
- `cursor: { size, clickBounce, smoothing, motionBlur, show }` tunes OpenScreen's rendered cursor per scenario.
|
|
@@ -82,9 +82,10 @@ export default defineScenario({
|
|
|
82
82
|
bright default gradients.
|
|
83
83
|
- **Voiceover narration (`scene.say`)**: backed by `@phil65/anyvoice` (defaults to free `edge` TTS with SHA-256 disk caching; also supports `openai` and `gemini` with delivery `instructions`, `cartesia` and `elevenlabs` with native word timestamps, and `deepgram` Aura-2).
|
|
84
84
|
- Set `voice: { provider: "edge", voice: "en-US-AndrewMultilingualNeural", speed: 1.05 }` on the scenario.
|
|
85
|
-
- Chain short beats (`await scene.say("Welcome.")`) or narrate *while* acting (`await scene.say("Pick Bracket and orbit.", async (cue) => { await scene.click(...); await cue.at("orbit", -150); await scene.drag(...); })`) — `demoreel` automatically holds if actions finish faster than speech, prevents overlapping cues, protects voice cues from `trimIdle`, muxes AAC audio into the rendered MP4, and writes `<name>.vtt` subtitles (opt-in `captions: "burned"`
|
|
85
|
+
- Chain short beats (`await scene.say("Welcome.")`) or narrate *while* acting (`await scene.say("Pick Bracket and orbit.", async (cue) => { await scene.click(...); await cue.at("orbit", -150); await scene.drag(...); })`) — `demoreel` automatically holds if actions finish faster than speech, prevents overlapping cues, protects voice cues from `trimIdle`, muxes AAC audio into the rendered MP4, and writes `<name>.vtt` subtitles (opt-in `captions: "burned"` draws balanced word-chunked captions on-video).
|
|
86
86
|
- Always run `--dry-run` first so the SHA-256 voice cache is warmed (<1ms hits during real recording), and check the printed **voice lint** findings (`voice-overlap`, `voice-clipped-end`, `voice-longer-than-action`, `voice-long-cue`) alongside `framesheet` — that's how you verify audio pacing without listening to the MP4.
|
|
87
87
|
- Override on the CLI/MCP without editing the scenario: `--voice-provider openai --voice nova` for studio final cuts, or `--no-voice` to test visuals silently.
|
|
88
|
+
- **Background music (`music`)**: accepts a local audio file (`"./bed.mp3"`), cached `https://` URL, or AI-generated instrumental track (`{ provider: "elevenlabs" | "gemini", prompt: "minimal upbeat lo-fi tech bed", volume: 0.18, duck: 0.3, fadeInMs: 800, fadeOutMs: 1500 }`, SHA-256 cached on disk). Automatically loops/trims to the rendered video length, fades in/out, and smoothly auto-ducks under `scene.say()` voiceover cues via `-c:v copy` (CLI/MCP overrides: `--music`, `--music-provider`, `--music-prompt`, `--no-music`).
|
|
88
89
|
- **AI / streaming apps**: mock only the LLM fetch/SSE boundary via `scene.page.evaluate(...)`
|
|
89
90
|
or `page.route(...)` while keeping real client-side/WASM tools live — deterministic, fast,
|
|
90
91
|
zero API cost, and authentic tool results.
|