Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
TL7c: in progress: a film's captions are clips on a text track over its scenes (sdk/timeline fromRender): each line its words and its span, one line at a time, moved and removed with the scene it sits on; 60 tests
shinyobjectzd7e3d8b2b2be
diff --git a/sdk/timeline/src/read.ts b/sdk/timeline/src/read.tsindex 1eddb142..8b114a6e 100644--- a/sdk/timeline/src/read.ts+++ b/sdk/timeline/src/read.ts@@ -89,10 +89,22 @@ export function fromSequences(rows: SeqRow[], fps: number): Timeline {/** A film with no composition behind it: its scenes as clips of one main track (cut where the picture cuts). Each* clip is the film's picture and its sound together, as footage is until its sound is extracted (TL4c), so a cut,* a move or a speed takes both. Its magnet is on: a scene removed closes up, as a cut of footage does. */-export function fromRender(o: { frames: Frames; fps: number; cuts?: Frames[] }): Timeline {+export function fromRender(o: { frames: Frames; fps: number; cuts?: Frames[]; /** the words on screen, each with its span in frames: clips on a text track over the picture (TL7c) */ captions?: { text: string; start: Frames; end: Frames }[] }): Timeline {const edges = [0, ...[...new Set(o.cuts ?? [])].filter((c) => c > 0 && c < o.frames).sort((a, b) => a - b), o.frames]const scenes: Clip[] = edges.slice(0, -1).map((from, n) => ({ id: `scene-${n + 1}`, kind: "video", name: `Scene ${n + 1}`, start: from, length: edges[n + 1] - from, in: from, source: o.frames }))- return { ...empty(o.fps), tracks: [{ id: "main", kind: "main", clips: scenes }] }+ const main: Track = { id: "main", kind: "main", clips: scenes }+ const words = (o.captions ?? [])+ .map((c) => ({ text: c.text, start: Math.max(0, Math.round(c.start)), end: Math.min(o.frames, Math.round(c.end)) }))+ .filter((c) => c.text.trim() && c.end > c.start)+ .sort((a, b) => a.start - b.start)+ if (!words.length) return { ...empty(o.fps), tracks: [main] }+ // captions that overlap the one before start where it ends: a text track holds one line at a time+ const captions: Clip[] = []+ for (const [n, c] of words.entries()) {+ const from = Math.max(c.start, captions.length ? end(captions[captions.length - 1]) : 0)+ if (c.end > from) captions.push({ id: `caption-${n + 1}`, kind: "caption", name: c.text, start: from, length: c.end - from })+ }+ return { ...empty(o.fps), tracks: [{ id: "captions", kind: "text", name: "Captions", clips: captions }, main] }}/** A render's cut, as the frames of the source played in order (the hand edit's `segments`): what a film's maindiff --git a/sdk/timeline/test/read.test.ts b/sdk/timeline/test/read.test.tsindex c9dc8d83..e3832102 100644--- a/sdk/timeline/test/read.test.ts+++ b/sdk/timeline/test/read.test.ts@@ -147,6 +147,17 @@ describe("TL0d: a feed item or a controller declares a timeline of its own data"expect(done(timeline!, { op: "move", ids: ["set-1"], by: 600 }).tracks[0].clips[1].start).toBe(2400)})+ test("a film's captions are clips on a text track over its scenes, and go with the scene they sit on", () => {+ const t = fromRender({ frames: 300, fps: 30, cuts: [90], captions: [{ text: "Hello", start: 10, end: 60 }, { text: "there", start: 50, end: 80 }, { text: " ", start: 0, end: 5 }, { text: "Later", start: 120, end: 400 }] })+ expect(t.tracks.map((k) => [k.id, k.kind])).toEqual([["captions", "text"], ["main", "main"]])+ expect(t.tracks[0].clips.map((c) => `${c.name} ${c.start}-${c.start + c.length}`)).toEqual(["Hello 10-60", "there 60-80", "Later 120-300"])+ // the first scene removed: the second scene's caption moves back with it, the first scene's go with it (linkage)+ const cut = done(t, { op: "remove", ids: ["scene-1"] })+ expect(cut.tracks[0].clips.map((c) => `${c.name} ${c.start}`)).toEqual(["Later 30"])+ // a caption's words are its name+ expect(done(t, { op: "set", id: "caption-1", set: { name: "Hello!" } }).tracks[0].clips[0].name).toBe("Hello!")+ })+test("what isn't a timeline says what one is", () => {expect(readTimeline("x").errors[0]).toContain("a timeline is an object")expect(readTimeline({ fps: 30 })).toEqual({ errors: ["tracks is a list of { id, kind, clips }"] })