More FE changes
This commit is contained in:
parent
f114ada255
commit
a48eb945e0
48 changed files with 4127 additions and 1751 deletions
37
video/src/narration.ts
Normal file
37
video/src/narration.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { writeFileSync } from 'node:fs';
|
||||
|
||||
export interface NarrationCue {
|
||||
text: string;
|
||||
videoTimeMs: number;
|
||||
durationMs: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Narration manifest writer.
|
||||
*
|
||||
* The runner knows the exact video-time of each narration block from the
|
||||
* storyboard itself, so cues come in with an explicit `videoTimeMs` instead
|
||||
* of being stamped against a wall-clock origin. That keeps the manifest in
|
||||
* lockstep with the trimmed video even if step durations drift slightly.
|
||||
*/
|
||||
class NarrationLog {
|
||||
private cues: NarrationCue[] = [];
|
||||
|
||||
reset(): void {
|
||||
this.cues = [];
|
||||
}
|
||||
|
||||
add(cue: NarrationCue): void {
|
||||
if (cue.videoTimeMs < 0) return;
|
||||
this.cues.push(cue);
|
||||
}
|
||||
|
||||
flush(path: string, totalDurationMs: number): NarrationCue[] {
|
||||
const sorted = [...this.cues].sort((a, b) => a.videoTimeMs - b.videoTimeMs);
|
||||
const manifest = { totalDurationMs, cues: sorted };
|
||||
writeFileSync(path, JSON.stringify(manifest, null, 2));
|
||||
return sorted;
|
||||
}
|
||||
}
|
||||
|
||||
export const narrationLog = new NarrationLog();
|
||||
Loading…
Add table
Add a link
Reference in a new issue