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.

Camera: a scene too short for the pull-back ends on the whole picture (#38)

Vincent Schmalbach6c0d8426e621
diff --git a/engine/director.js b/engine/director.js
index 9ffb16b..13c1d7e 100644
--- a/engine/director.js
+++ b/engine/director.js
@@ -360,6 +360,16 @@ export function planCamera(elements, { dur, view, frame, pace = 1, voiceEnd = nu
// Near the end the camera shows the whole picture when the shot leaves
// part of it out.
const reveal = Math.max(revealAt, last + hold);
+ // A scene too short for that ends on its last move. When that move is a
+ // close-up that leaves part of the picture out, the last frame would not
+ // show the whole idea, so the move frames the whole picture instead. A
+ // move in that becomes a wide shot is then usually no move at all.
+ const atEnd = items.filter((e) => e.kind !== 'focus' && e.at <= dur - 0.1 && e.out >= dur - 0.05);
+ const tail = shots[shots.length - 1];
+ if (reveal >= dur - 1.1 && atEnd.length && tail && tail.begin > 0 && ['push', 'follow'].includes(tail.kind) && !fits(cur, atEnd)) {
+ const wide = overview(tail.begin, dur);
+ if (wide) cur = tail.shot = wide;
+ }
if (cur && reveal < dur - 1.1) {
const all = picture(visibleDuring(reveal, reveal + 0.1));
if (all.length && !fits(cur, all)) take(compose(all, visibleDuring(reveal, dur), view, frame, usable, PICTURE_FILL), reveal, 'reveal');
diff --git a/test/director.test.js b/test/director.test.js
index 928ff6b..fc502ee 100644
--- a/test/director.test.js
+++ b/test/director.test.js
@@ -243,3 +243,29 @@ test('a push in makes way for a focus point that comes soon after', () => {
}
assert.ok(whole(cameraAt(plan, 8), items[3]) && cameraAt(plan, 8).z > 1.5, 'the focus gets its close-up');
});
+
+test('a scene too short for the pull-back still ends on the whole picture', () => {
+ // Three steps in a row; the last one comes a second before the scene ends.
+ // They stay until the end, also when they leave right at the end.
+ for (const out of [Infinity, 5.6]) {
+ const steps = [0, 1, 2].map((i) => el('shape', 300 + i * 520, 470, 260, 140, [0.3, 2.4, 4.4][i], out));
+ const plan = planCamera(steps, { dur: 5.6, view, frame, voiceEnd: 5 });
+ const end = cameraAt(plan, 5.55);
+ for (const e of steps) assert.ok(whole(end, e), `step at ${e.at}, out ${out}`);
+ }
+});
+
+test('a last move in that becomes a wide shot keeps later things whole', () => {
+ const boxes = [[1383, 438, 382, 227, 0], [1632, 306, 119, 209, 0.89], [622, 541, 303, 71, 1.38], [737, 839, 113, 70, 2.19], [252, 632, 252, 163, 3.06]];
+ const items = boxes.map(([x, y, w, h, at]) => centered('shape', x, y, w, h, at));
+ const plan = planCamera(items, { dur: 5.7, view, frame, pace: 1 });
+ const settled = Math.max(3.06, ...plan.moves.map((m) => m.start + m.dur));
+ for (let t = settled + 0.05; t < 5.7; t += 0.1) assert.ok(whole(cameraAt(plan, t), items[4]), `t=${t.toFixed(2)}`);
+});
+
+test('a continued scene also ends on the whole picture', () => {
+ const items = [centered('shape', 350, 540, 260, 140, 0), centered('shape', 850, 540, 260, 140, 0), centered('shape', 1450, 540, 260, 140, 3.5)];
+ const plan = planCamera(items, { dur: 4.8, view, frame, from: { x: 600, y: 540, z: 1.7 }, still: 0.7 });
+ const end = cameraAt(plan, 4.75);
+ for (const e of items) assert.ok(whole(end, e), `box at ${e.box.x}`);
+});