Skip to content

The VS Code of video editing, built for agents.

TypeScript

Update caption handling and seed management in auto-captions feature

konstantin-paulusce691821bbc7
diff --git a/apps/web/src/components/genai/use-auto-captions.tsx b/apps/web/src/components/genai/use-auto-captions.tsx
index 6ddd042b..5a368411 100644
--- a/apps/web/src/components/genai/use-auto-captions.tsx
+++ b/apps/web/src/components/genai/use-auto-captions.tsx
@@ -33,13 +33,15 @@ export function useAutoCaptions() {
*/
const sceneSpan = (scene: Entity) => {
const computed = scene.get(Computed);
- const frames = (computed?.end ?? 0) - (computed?.origin ?? 0);
+ const frames = computed?.duration ?? 0;
if (frames <= 0) return undefined;
return framesToSeconds(frames, world.get(FrameRate)?.value ?? 30);
};
const insertFresh = (scene: Entity) => {
- const [entity] = editor.insertElement(scene, () => <Captions end={sceneSpan(scene)} />);
+ const [entity] = editor.insertElement(scene, () => (
+ <Captions end={sceneSpan(scene)} seed={Date.now()} />
+ ));
if (!entity) {
toast.error("Could not add captions", {
description: "The scene has no source to write the element into.",
@@ -69,10 +71,8 @@ export function useAutoCaptions() {
return;
}
- // A new take: bumping the seed re-transcribes the scene.
- const seed = authored?.props.seed;
- const next = (typeof seed === "number" && Number.isFinite(seed) ? Math.trunc(seed) : 0) + 1;
- editor.editProperty(existing, "seed", next);
+ // A new take: a fresh seed re-transcribes the scene.
+ editor.editProperty(existing, "seed", Date.now());
editor.select(existing);
}
};
diff --git a/apps/web/src/components/sidebar-right/inspector/caption-settings.tsx b/apps/web/src/components/sidebar-right/inspector/caption-settings.tsx
index 0759b3fb..e177497f 100644
--- a/apps/web/src/components/sidebar-right/inspector/caption-settings.tsx
+++ b/apps/web/src/components/sidebar-right/inspector/caption-settings.tsx
@@ -14,12 +14,6 @@ import {
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
-import {
- ContextMenu,
- ContextMenuContent,
- ContextMenuItem,
- ContextMenuTrigger,
-} from "@/components/ui/context-menu";
import {
FloatingInspector,
FloatingInspectorContent,
@@ -28,11 +22,10 @@ import {
} from "@/components/ui/floating-inspector";
import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
-import { SegmentedIconTabs } from "@/components/ui/segmented-icon-tabs";
import { ColorOpacityRow } from "@/components/ui/color-opacity-row";
import { ColorOpacityPicker } from "@/components/ui/color-opacity-picker";
import { useTrait } from "@diffusionstudio/koota-solid";
-import { Caption, CaptionAlign, colorToHex } from "@diffusionstudio/runtime";
+import { Caption, colorToHex } from "@diffusionstudio/runtime";
import { useEditor } from "@/engine/hooks";
import {
CAPTION_PRESET_OPTIONS,
@@ -47,23 +40,10 @@ type CaptionSettingsProps = {
selection: Entity[];
};
-const VERTICAL_ALIGN_TABS = [
- { value: 'top', label: 'Align top', icon: 'vertical-align-top' },
- { value: 'center', label: 'Align center', icon: 'vertical-align-center' },
- { value: 'bottom', label: 'Align bottom', icon: 'vertical-align-bottom' },
-];
-
-/** The prop's spelling for a `CaptionAlign`, for the tabs to compare against. */
-const ALIGN_NAMES: Record<CaptionAlign, string> = {
- [CaptionAlign.TOP]: 'top',
- [CaptionAlign.CENTER]: 'center',
- [CaptionAlign.BOTTOM]: 'bottom',
-};
-
/**
* What a `<captions>` element says for itself: which preset draws it
- * (`preset`), the colors filling that preset's slots (`colors`) and where the
- * block sits (`verticalAlign`). Everything else about a caption's look — the
+ * (`preset`) and the colors filling that preset's slots (`colors`).
+ * Everything else about a caption's look — the
* font, the box, the paints and shadows it is drawn with — is the preset's,
* authored onto the entity by its decoder and not in the file at all, which
* is why this panel is as short as it is.
@@ -78,13 +58,6 @@ export function CaptionSettings(props: CaptionSettingsProps) {
const preset = createMemo(() => captionPresetOption(caption()?.type));
const slots = () => preset().slots;
const colors = () => caption()?.colors ?? [];
- const align = () => caption()?.verticalAlign;
- // No tab is active while the placement is the preset's own, which is not one
- // of the three the prop can say.
- const alignName = () => {
- const current = align();
- return current === undefined ? '' : ALIGN_NAMES[current];
- };
const [openSlot, setOpenSlot] = createSignal<number | null>(null);
@@ -113,10 +86,6 @@ export function CaptionSettings(props: CaptionSettingsProps) {
editor.editProperty(entity(), "colors", values);
};
- const handleAlignChange = (name: string) => {
- editor.editProperty(entity(), "verticalAlign", name);
- };
-
return (
<PanelSection title="Caption" ref={anchorRef}>
<ControlRow label="Preset">
@@ -146,24 +115,6 @@ export function CaptionSettings(props: CaptionSettingsProps) {
</Select>
</ControlRow>
- <ContextMenu>
- <ContextMenuTrigger<typeof ControlRow> as={ControlRow} label="Align">
- <SegmentedIconTabs
- value={alignName}
- onChange={handleAlignChange}
- items={VERTICAL_ALIGN_TABS}
- />
- </ContextMenuTrigger>
- <ContextMenuContent>
- <ContextMenuItem
- disabled={align() === undefined}
- onSelect={() => editor.editProperty(entity(), "verticalAlign", false)}
- >
- Reset to Default
- </ContextMenuItem>
- </ContextMenuContent>
- </ContextMenu>
-
<For each={slots()}>
{(slot, index) => (
<ControlRow label={slot.label}>
diff --git a/apps/web/src/utils/gen-ai.ts b/apps/web/src/utils/gen-ai.ts
index 339d4d57..2b8df4f1 100644
--- a/apps/web/src/utils/gen-ai.ts
+++ b/apps/web/src/utils/gen-ai.ts
@@ -179,11 +179,21 @@ export class EditorGenAi extends GenAi {
);
const blob = new Blob([JSON.stringify(transcript)], { type: "application/json" });
- return this.library.store(blob, {
+ const asset = await this.library.store(blob, {
name: `${this.nextCaptionsName()}.json`,
folder: GENERATED_DIR,
generation: { key },
});
+
+ // A re-take of unchanged speech comes back byte-identical, and the library
+ // dedups by content: `store` then hands back the earlier take still keyed
+ // by its old seed. Re-key it, or the authored seed misses the cache and
+ // transcribes again on every load.
+ if (asset.generation?.key !== key) {
+ this.library.update(asset, { generation: { key } });
+ }
+
+ return asset;
}
private nextCaptionsName(): string {
diff --git a/packages/runtime/src/media/caption/spotlight.ts b/packages/runtime/src/media/caption/spotlight.ts
index 52eb67d5..01e5db7c 100644
--- a/packages/runtime/src/media/caption/spotlight.ts
+++ b/packages/runtime/src/media/caption/spotlight.ts
@@ -54,7 +54,7 @@ export class SpotlightCaptionDecoder implements CaptionDecoder {
entity.set(TextStyle, {
fontFamily: 'The Bold Font',
fontWeight: '500',
- fontStyle: FontStyle.ITALIC,
+ fontStyle: FontStyle.NORMAL,
fontSize: 70,
textAlign: TextAlign.CENTER,
textBaseline: TextBaseline.MIDDLE,