Open source CapCut alternative.
TypeScript
fix(site): render silent, action-only beats instead of failing the video run
David Led421b6dd1725
diff --git a/site/scripts/genvideo-selftest.ts b/site/scripts/genvideo-selftest.tsindex a1da34f0..a472e4cc 100644--- a/site/scripts/genvideo-selftest.ts+++ b/site/scripts/genvideo-selftest.ts@@ -432,6 +432,30 @@ async function run(): Promise<void> {assertTiling("split-beat shots still tile", editor.placed, project.durationFrames);}+ // ── a silent, action-only beat renders instead of failing the run ────────+ // (an empty line reaching TTS threw "Nothing to say." and killed the render)+ section("a silent beat renders without a voiceover, doesn't fail the run");+ {+ const editor = emptyEditor();+ const { d, studio } = deps(editor, { audioNative: true, scriptBeats: 3, silentBeats: [1] });+ const project = generatedProject();+ const orch = new VideoOrchestrator(project, d);+ await orch.run();+ await orch.approveBreakdown();+ check("run with a silent beat reaches done", project.phase === "done");+ check("only the two spoken beats were voiced", studio.calls.filter((c) => c.role === "voice").length === 2);+ check("the silent beat holds no voiceover asset", !project.beatVoices?.[1]?.voiceAssetId);+ check(+ "the spoken beats each hold a voiceover asset",+ !!project.beatVoices?.[0]?.voiceAssetId && !!project.beatVoices?.[2]?.voiceAssetId+ );+ check("voiceovers placed only for the spoken beats", editor.placedAudio.filter((a) => a.kind === "voice").length === 2);+ const silentShots = project.shots.filter((s) => !s.dialogue?.trim());+ check("the silent beat still rendered a shot", silentShots.length > 0);+ check("silent shots carry a clip but no voice", silentShots.every((s) => !!s.clip && !s.voiceAssetId));+ assertTiling("the silent-beat scene still tiles the spine", editor.placed, project.durationFrames);+ }+// ── the bible is the run's spine: a failed design fails the run loudly ───// (a stand-in look would silently corrupt every render downstream)section("style-bible failure fails the run loudly (finding 8, revised)");diff --git a/site/src/cut/lib/genvideo/fakes.ts b/site/src/cut/lib/genvideo/fakes.tsindex 1e1ec6ff..e532bc20 100644--- a/site/src/cut/lib/genvideo/fakes.ts+++ b/site/src/cut/lib/genvideo/fakes.ts@@ -50,6 +50,9 @@ export interface FakeStudioOptions {videoVariant?: string;/** Beats the fake script writes when starting from a brief. */scriptBeats?: number;+ /** Beat indices the fake script writes with no dialogue — a silent,+ * action-only beat, which must render without a voiceover rather than fail. */+ silentBeats?: number[];/** Force every voiceover to this many seconds (else derived from the line);* used to exercise a beat whose VO outruns one clip and spans several shots. */voiceSeconds?: number;@@ -108,8 +111,9 @@ export class FakeStudio {private async writeScript(input: ScriptInput): Promise<ScriptPlan> {const n = this.opts.scriptBeats ?? Math.max(2, Math.round((input.targetSeconds ?? 30) / 6));+ const silent = new Set(this.opts.silentBeats ?? []);const beats = Array.from({ length: n }, (_, i) => ({- dialogue: `Line ${i + 1}: ${input.brief}`.slice(0, 80),+ dialogue: silent.has(i) ? "" : `Line ${i + 1}: ${input.brief}`.slice(0, 80),action: i === 0 ? "establishing the scene" : "the story continues",characters: ["char:1"],location: "loc:1",@@ -161,6 +165,9 @@ export class FakeStudio {}private async speak(input: VoiceInput): Promise<VoiceResult> {+ // Faithful to the real TTS guard: empty text has nothing to say and throws.+ // A silent beat must be skipped upstream, never reach here.+ if (!input.script.trim()) throw new Error("Nothing to say.");// Length from the line (or forced via voiceSeconds). A line longer than one// clip is a real case — the orchestrator spans it across several shots.const raw = Math.max(1, input.script.length) * 0.06;diff --git a/site/src/cut/lib/genvideo/orchestrator.ts b/site/src/cut/lib/genvideo/orchestrator.tsindex 23d51dca..c19b1a12 100644--- a/site/src/cut/lib/genvideo/orchestrator.ts+++ b/site/src/cut/lib/genvideo/orchestrator.ts@@ -24,7 +24,7 @@ import { fanOut } from "./pool";import { buildNegative, buildPrompt, buildRefPrompt, refsForAsset, shotRefs, styleAnchor } from "./prompt";import { segmentByDuration, type ModelSuite, type ReviewVerdict } from "./capabilities";import type { EditorBridge } from "./editor";-import type { BeatVoice, RefAsset, Shot, TranscriptWord, VideoAsset, VideoEmit, VideoPhase, VideoProject } from "./types";+import type { BeatVoice, RefAsset, ScriptBeat, Shot, TranscriptWord, VideoAsset, VideoEmit, VideoPhase, VideoProject } from "./types";export interface OrchestratorDeps {editor: EditorBridge;@@ -164,7 +164,7 @@ export class VideoOrchestrator {// is likewise deferred to polish.const minF = Math.round(MIN_SHOT_SEC * this.fps);const frames = this.project.script.beats.map((b) =>- Math.max(minF, secToFrame(estimateSpokenSeconds(b.dialogue), this.fps))+ Math.max(minF, secToFrame(estimateBeatSeconds(b), this.fps)));this.layoutBeats(frames,@@ -177,14 +177,18 @@ export class VideoOrchestrator {private async voice(): Promise<void> {if (this.aborted) return;if (this.project.audioMode !== "generated" || !this.project.script) return;- // Idempotent across resumes: done once every beat carries its asset id AND- // the shots have been re-laid onto the voiced spine (a later resume must- // never rebuild shots that already rendered).+ // Idempotent across resumes: done once every spoken beat carries its asset+ // id AND the shots have been re-laid onto the voiced spine (a later resume+ // must never rebuild shots that already rendered). A silent, action-only+ // beat has no line to voice, so it counts as settled without an asset —+ // otherwise a scene with one would re-run this phase on every resume.+ const beats = this.project.script.beats;+ const spoken = (bi: number) => !!beats[bi]?.dialogue.trim();const voices = this.project.beatVoices ?? [];if (voices.length > 0 &&- voices.every((bv) => bv.voiceAssetId) &&- this.project.shots.every((s) => s.voiceAssetId)+ voices.every((bv, bi) => bv.voiceAssetId || !spoken(bi)) &&+ this.project.shots.every((s) => s.voiceAssetId || !s.dialogue?.trim())) {return;}@@ -194,9 +198,9 @@ export class VideoOrchestrator {// lip-sync to their own slice — so a long line is never cut off. Each beat// persists as it lands, so an interruption never re-bills voiced beats.const minF = Math.round(MIN_SHOT_SEC * this.fps);- const voiceIds: string[] = [];+ const voiceIds: (string | undefined)[] = [];const frames: number[] = [];- for (const [bi, beat] of this.project.script.beats.entries()) {+ for (const [bi, beat] of beats.entries()) {if (this.aborted) return;const prior = voices[bi];if (prior?.voiceAssetId) {@@ -204,7 +208,14 @@ export class VideoOrchestrator {frames.push(prior.durationFrames);continue;}- this.deps.emit({ type: "activity", message: `Voicing line ${bi + 1} of ${this.project.script.beats.length}…` });+ // A silent, action-only beat carries no line: keep its estimated span and+ // render it without audio. Sending empty text to TTS fails the whole run.+ if (!beat.dialogue.trim()) {+ voiceIds.push(undefined);+ frames.push(prior?.durationFrames ?? Math.max(minF, secToFrame(estimateBeatSeconds(beat), this.fps)));+ continue;+ }+ this.deps.emit({ type: "activity", message: `Voicing line ${bi + 1} of ${beats.length}…` });const vo = await this.deps.suite.voice.speak({ script: beat.dialogue });const id = await this.deps.editor.importMedia(vo.mediaId);const dur = Math.max(minF, secToFrame(vo.durationSec, this.fps));@@ -1123,6 +1134,13 @@ function estimateSpokenSeconds(dialogue: string): number {return Math.max(1.2, (words / 165) * 60);}+/** Planning length for a beat before any voiceover exists: a spoken beat scales+ * with its word count; a silent, action-only beat has no line to time, so it+ * holds the scripted `approxSeconds` instead of collapsing to the floor. */+function estimateBeatSeconds(beat: ScriptBeat): number {+ return beat.dialogue.trim() ? estimateSpokenSeconds(beat.dialogue) : Math.max(1.2, beat.approxSeconds || 0);+}+/** Split one beat's span into contiguous shots each no longer than `maxFrames`,* distributing the remainder so the pieces stay as even as possible. */function splitBeat(start: number, frames: number, maxFrames: number): [number, number][] {