Skip to content

The VS Code of video editing, built for agents.

TypeScript

Enhance auto captions functionality in use-auto-captions.tsx

konstantin-paulusea2830bb415a
diff --git a/apps/web/src/components/genai/use-auto-captions.tsx b/apps/web/src/components/genai/use-auto-captions.tsx
index 66c0256e..6ddd042b 100644
--- a/apps/web/src/components/genai/use-auto-captions.tsx
+++ b/apps/web/src/components/genai/use-auto-captions.tsx
@@ -4,7 +4,14 @@
import { createMemo } from "solid-js";
import { Captions, authoredElement } from "@diffusionstudio/reconciler";
-import { Caption, getEntityTree, isScene } from "@diffusionstudio/runtime";
+import {
+ Caption,
+ Computed,
+ FrameRate,
+ framesToSeconds,
+ getEntityTree,
+ isScene,
+} from "@diffusionstudio/runtime";
import { useWorld } from "@diffusionstudio/koota-solid";
import { useEditor, useSelection } from "@/engine/hooks";
import { toast } from "somoto";
@@ -19,15 +26,26 @@ export function useAutoCaptions() {
const scenes = createMemo(() => nodes().filter(isScene));
const hasScene = () => scenes().length > 0;
+ /**
+ * The scene's own length in seconds, for the caption element's `end`. A
+ * fresh <Captions> has no source to take a length from, so without one it
+ * runs for the 16s default and stretches the very scene it captions.
+ */
+ const sceneSpan = (scene: Entity) => {
+ const computed = scene.get(Computed);
+ const frames = (computed?.end ?? 0) - (computed?.origin ?? 0);
+ if (frames <= 0) return undefined;
+ return framesToSeconds(frames, world.get(FrameRate)?.value ?? 30);
+ };
+
const insertFresh = (scene: Entity) => {
- const [entity] = editor.insertElement(scene, () => <Captions />);
+ const [entity] = editor.insertElement(scene, () => <Captions end={sceneSpan(scene)} />);
if (!entity) {
toast.error("Could not add captions", {
description: "The scene has no source to write the element into.",
});
return;
}
- editor.select(entity);
};
const generate = () => {