Skip to content

Explainer videos and product demos made by your AI agent. Free and open source: a local voice (Kokoro), word timing (Whisper) and a canvas renderer turn a script into a narrated MP4.

Leave burned-in captions out of the cover image (#19)

Vincent Schmalbachf6cd26f31867
diff --git a/AGENTS.md b/AGENTS.md
index 6c25c4d..16bf0a0 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -683,7 +683,7 @@ videos/<name>/
| `music` | `true` | `true` (the look's style), `warm`, `upbeat`, `calm`, `tech`, `playful`, `{ "style", "volume" }` or `false` |
| `sfx` | `true` | sound effects: `true`, `"minimal"` or `false` |
| `captions` | `"auto"` | text of the narration at the bottom; auto turns it on for vertical and square videos |
-| `cover` | `"auto"` | full-size JPEG at the end of the first scene, or a still spec: `12.5`, `"intro"`, `"[email protected]"`, `"intro@end"` |
+| `cover` | `"auto"` | full-size JPEG, without captions, at the end of the first scene, or a still spec: `12.5`, `"intro"`, `"[email protected]"`, `"intro@end"` |
| `transition` | `"auto"` | the look's default, or `fade`, `slide`, `wipe`, `zoom`, `brush`, `cut` |
| `lead`, `hold`, `end` | 0.35, 0.7, 1.4 | seconds before the voice, after it, and extra at the very end |
| `sentenceGap`, `paragraphGap` | 0.3, 0.55 | pauses in generated narration; recordings keep their own pauses |
diff --git a/engine/frame.html b/engine/frame.html
index 27875e8..7856d15 100644
--- a/engine/frame.html
+++ b/engine/frame.html
@@ -41,11 +41,11 @@ window.explainrooReady = (async () => {
}
return out;
},
- async stills(list, { type = 'image/png', quality } = {}) {
+ async stills(list, { type = 'image/png', quality, captions = true } = {}) {
for (const { T, path } of list) {
try {
if (engine.clips.size) await engine.prepareFrame(T);
- engine.renderFrame(T);
+ engine.renderFrame(T, undefined, { captions });
} catch (e) {
throw new Error(describe(e));
}
diff --git a/engine/runtime.js b/engine/runtime.js
index 5b276f1..d7042db 100644
--- a/engine/runtime.js
+++ b/engine/runtime.js
@@ -247,7 +247,7 @@ export class Engine {
return s;
}
- renderFrame(T, ctx = this.ctx) {
+ renderFrame(T, ctx = this.ctx, { captions = true } = {}) {
const i = this.sceneAt(T);
const sc = this.timeline.scenes[i];
const t = T - sc.start;
@@ -266,7 +266,7 @@ export class Engine {
} else {
this.drawScene(ctx, i, t);
}
- if (this.phrases.length) {
+ if (captions && this.phrases.length) {
ctx.setTransform(this.scale, 0, 0, this.scale, 0, 0);
drawCaptions(ctx, this.phrases, T, this.theme, this.W, this.H, this.captionArea);
}
diff --git a/src/render.js b/src/render.js
index 0a529c1..5ba06da 100644
--- a/src/render.js
+++ b/src/render.js
@@ -143,7 +143,7 @@ export async function render(project, opts = {}) {
if (coverTime) {
const temp = path.join(project.paths.build, 'cover.jpg');
try {
- await withEngine(project, timeline, { scale: 1, log }, (page) => page.evaluate((T) => window.explainroo.stills([{ T, path: 'build/cover.jpg' }], { type: 'image/jpeg', quality: 0.9 }), coverTime.T));
+ await withEngine(project, timeline, { scale: 1, log }, (page) => page.evaluate((T) => window.explainroo.stills([{ T, path: 'build/cover.jpg' }], { type: 'image/jpeg', quality: 0.9, captions: false }), coverTime.T));
files.cover = `${base}.cover.jpg`;
fs.copyFileSync(temp, files.cover);
} finally { fs.rmSync(temp, { force: true }); }
diff --git a/test/stills-browser.test.js b/test/stills-browser.test.js
index ab0e97e..0de76f0 100644
--- a/test/stills-browser.test.js
+++ b/test/stills-browser.test.js
@@ -33,3 +33,38 @@ test('stills preserve PNG by default and support JPEG covers', { skip: !chrome }
assert.deepEqual([...fs.readFileSync(path.join(dir, 'build/cover.jpg')).subarray(0, 3)], [0xff, 0xd8, 0xff]);
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
});
+
+test('covers leave out the burned-in captions', { skip: !chrome }, async () => {
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-cover-captions-'));
+ try {
+ fs.writeFileSync(path.join(dir, 'video.json'), JSON.stringify({ theme: 'clean', size: '640x360', captions: true, watermark: false }));
+ fs.writeFileSync(path.join(dir, 'script.md'), '## intro\nHello there.\n');
+ fs.writeFileSync(path.join(dir, 'scenes.js'), 'export default { intro(s) { s.bg("#ffffff"); } };');
+ const project = loadProject(dir);
+ const timeline = { duration: 2, frames: 60, fps: 30, width: 640, height: 360, transitionSeconds: 0,
+ scenes: [{ id: 'intro', index: 0, start: 0, dur: 2, marks: {}, voice: null, transition: 'none',
+ words: [{ text: 'Hello', start: 0.2, end: 0.6 }, { text: 'there.', start: 0.7, end: 1.1 }] }] };
+ await withEngine(project, timeline, {}, async (page) => {
+ const dark = await page.evaluate(async () => {
+ const count = async (options) => {
+ await window.explainroo.stills([{ T: 0.9, path: 'out/c.png' }], options);
+ const img = new Image();
+ img.src = '/project/out/c.png?' + Math.random();
+ await img.decode();
+ const c = document.createElement('canvas');
+ c.width = img.naturalWidth;
+ c.height = img.naturalHeight;
+ const g = c.getContext('2d');
+ g.drawImage(img, 0, 0);
+ const d = g.getImageData(0, 0, c.width, c.height).data;
+ let n = 0;
+ for (let i = 0; i < d.length; i += 4) if (d[i] < 128) n++;
+ return n;
+ };
+ return { with: await count({}), without: await count({ captions: false }) };
+ });
+ assert.ok(dark.with > 100, `captions should draw dark pixels, got ${dark.with}`);
+ assert.equal(dark.without, 0);
+ });
+ } finally { fs.rmSync(dir, { recursive: true, force: true }); }
+});