Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Frames strip: each frame says whether it is the start, a middle or the end frame, and the counts read clearly

Claude0f80000396b3
diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsx
index 2a9a1fc4..4d44f4fa 100644
--- a/src/components/studio/composer.tsx
+++ b/src/components/studio/composer.tsx
@@ -437,10 +437,7 @@ export function Composer({ docked }: { docked: boolean }) {
const alt = catalog.getModel(FRAMES_MODELS[model.engine].id);
const action = alt && alt.id !== model.id ? { label: `Use ${alt.name}`, onClick: () => pickModel(alt) } : undefined;
const count = draft.frames.length;
- const times = frameTimes(
- draft.frames.map((f) => f.at),
- framesCtx.duration,
- );
+ const times = frameTimes(draft.frames.map((f) => f.at), framesCtx.duration);
const gap = framesCtx.chained && count > 1 ? chainGapProblem(times, framesCtx.duration, chainTiming(model)) : null;
const note = framesNote(model, count, draft.frames.at(-1)?.at);
if (framesCtx.support === "start" || framesCtx.support === "none") framesNotice = { text: `${framesBlocker(model, count)!.message}.`, tone: "warn", action };
@@ -558,12 +555,7 @@ export function Composer({ docked }: { docked: boolean }) {
onMove={(i, seconds) =>
setDraft((d) => {
if (!d.frames || !framesCtx) return {};
- const ats = moveFrameAt(
- d.frames.map((f) => f.at),
- i,
- seconds,
- framesCtx.duration,
- );
+ const ats = moveFrameAt(d.frames.map((f) => f.at), i, seconds, framesCtx.duration);
return { frames: d.frames.map((f, j) => ({ ...f, at: ats[j] })) };
})
}
diff --git a/src/components/studio/frames-strip.tsx b/src/components/studio/frames-strip.tsx
index 6814bcc3..0077be3d 100644
--- a/src/components/studio/frames-strip.tsx
+++ b/src/components/studio/frames-strip.tsx
@@ -4,7 +4,7 @@ import { Loader2, Minus, Plus, X } from "lucide-react";
import { useId, useRef, useState } from "react";
import { toast } from "sonner";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
-import { FRAMES_HINT, frameRange, frameTimes, KEYFRAME_SNAP, MAX_KEYFRAMES, secondsLabel } from "@/lib/catalog/keyframes";
+import { FRAMES_HINT, frameRange, frameRole, frameTimes, KEYFRAME_SNAP, MAX_KEYFRAMES, secondsLabel } from "@/lib/catalog/keyframes";
import type { FrameAttachment } from "@/lib/composer";
import { cn } from "@/lib/utils";
import { ACCEPT, kindOfFile, MediaSlot, SlotPreview, wrongKindMessage, type SlotValue } from "./media-slot";
@@ -52,10 +52,7 @@ export function FramesStrip({
}) {
const titleId = useId();
const hintId = useId();
- const times = frameTimes(
- frames.map((f) => f.at),
- duration,
- );
+ const times = frameTimes(frames.map((f) => f.at), duration);
return (
<div role="group" aria-labelledby={titleId} aria-describedby={hintId} data-frames-strip className="space-y-1.5 px-1 pt-1 pb-2">
<div className="flex flex-wrap items-center gap-x-2 gap-y-0.5 pl-1">
@@ -85,12 +82,20 @@ export function FramesStrip({
<div className="scrollbar-none flex items-start gap-2 overflow-x-auto px-1 pt-1.5">
{frames.map((f, i) => (
- <FrameTile key={f.value.id ?? `${f.value.ref}-${i}`} index={i} value={f.value} time={times[i]} onChange={(v) => onFrame(i, v)} onFile={(file) => onFrameFile(i, file)} />
+ <FrameTile
+ key={f.value.id ?? `${f.value.ref}-${i}`}
+ index={i}
+ role={frameRole(i, frames.length, f.at)}
+ value={f.value}
+ time={times[i]}
+ onChange={(v) => onFrame(i, v)}
+ onFile={(file) => onFrameFile(i, file)}
+ />
))}
{frames.length < MAX_KEYFRAMES && (
<div className="flex shrink-0 flex-col items-center gap-1">
<MediaSlot slotKey="frames" label={frames.length ? "Add frame" : "Start frame"} kind="image" required={!frames.length} value={null} onChange={(v) => v && onAddPick(v)} onFile={onAddFile} />
- <span className="text-[11px] text-subtle-foreground tabular-nums">
+ <span className="text-[11px] text-muted-foreground tabular-nums">
{frames.length} of {MAX_KEYFRAMES}
</span>
</div>
@@ -150,7 +155,21 @@ function LengthStepper({ value, options, onDuration }: { value: number; options:
}
/** A filled frame: its still (click or drop to replace it), its number, its time, and remove. */
-function FrameTile({ index, value, time, onChange, onFile }: { index: number; value: SlotValue; time: number; onChange: (v: SlotValue | null) => void; onFile: (f: File) => void }) {
+function FrameTile({
+ index,
+ role,
+ value,
+ time,
+ onChange,
+ onFile,
+}: {
+ index: number;
+ role: ReturnType<typeof frameRole>;
+ value: SlotValue;
+ time: number;
+ onChange: (v: SlotValue | null) => void;
+ onFile: (f: File) => void;
+}) {
const input = useRef<HTMLInputElement>(null);
const [over, setOver] = useState(false);
const name = index === 0 ? "the start frame" : `frame ${index + 1}`;
@@ -181,13 +200,16 @@ function FrameTile({ index, value, time, onChange, onFile }: { index: number; va
<button
type="button"
onClick={() => input.current?.click()}
- aria-label={`Frame ${index + 1}${index === 0 ? ", the start frame" : ""}, at ${secondsLabel(time)}: replace`}
+ aria-label={`Frame ${index + 1}, ${role.toLowerCase()} at ${secondsLabel(time)}: replace`}
className={cn("size-full overflow-hidden rounded-xl border bg-muted outline-none focus-visible:ring-2 focus-visible:ring-ring/50", over && "ring-2 ring-primary")}
>
<SlotPreview value={{ ...value, name: "" }} />
</button>
</TooltipTrigger>
- <TooltipContent>{index === 0 ? "Start frame" : `Frame ${index + 1} at ${secondsLabel(time)}`} — click or drop to replace</TooltipContent>
+ <TooltipContent>
+ {role}
+ {index > 0 && ` · ${secondsLabel(time)}`} — click or drop to replace
+ </TooltipContent>
</Tooltip>
{value.uploading && (
<div className="pointer-events-none absolute inset-0 grid place-items-center rounded-xl bg-background/60" role="status" aria-label="Uploading">
@@ -311,7 +333,7 @@ function Ruler({ frames, times, duration, onMove }: { frames: FrameAttachment<Sl
</span>
)}
</div>
- <div aria-hidden className="relative h-3.5 text-[10px] text-subtle-foreground tabular-nums">
+ <div aria-hidden className="relative h-3.5 text-[10px] text-muted-foreground tabular-nums">
{labels.map((t, k) => (
<span key={t} className={cn("absolute top-0 whitespace-nowrap", k === 0 ? "" : t === duration ? "-translate-x-full" : "-translate-x-1/2")} style={{ left: pct(t, duration) }}>
{secondsLabel(t)}
diff --git a/src/lib/catalog/keyframes.ts b/src/lib/catalog/keyframes.ts
index 5ec2706a..bd86ef68 100644
--- a/src/lib/catalog/keyframes.ts
+++ b/src/lib/catalog/keyframes.ts
@@ -81,6 +81,12 @@ export function framesNote(model: Pick<ModelDef, "name" | "engine" | "routes" |
return lastAt < 1 - EPS ? `${model.name} puts the last frame at the end of the clip — ${alt} keeps it at its time.` : null;
}
+/** What a frame is to the clip, as Kling 4.0 names them: the start frame, the end frame (the last one, at the end), or a middle frame. */
+export function frameRole(i: number, count: number, at: number): "Start frame" | "End frame" | "Middle frame" {
+ if (i === 0) return "Start frame";
+ return i === count - 1 && at >= 1 - EPS ? "End frame" : "Middle frame";
+}
+
/** Clip lengths to offer in Frames mode: the open chain's own list, else the model's. */
export function framesDurations(model: Pick<ModelDef, "routes" | "options">): number[] {
if (keyframeChain(model)) return CHAIN_DURATIONS;
diff --git a/src/lib/composer.ts b/src/lib/composer.ts
index afc4bde4..70377eb9 100644
--- a/src/lib/composer.ts
+++ b/src/lib/composer.ts
@@ -373,16 +373,9 @@ export function framesRequest(
frames: FrameAttachment[],
ctx: { support: FrameSupport; duration: number; chained: boolean },
): { images: string[]; endImage?: string; params: Pick<GenParams, "duration" | "keyframeTimes" | "shots" | "multiShot" | "numOutputs"> } {
- const times = frameTimes(
- frames.map((f) => f.at),
- ctx.duration,
- );
+ const times = frameTimes(frames.map((f) => f.at), ctx.duration);
const kept = frames.map((f, i) => ({ ref: f.value.ref, time: times[i] })).filter((f) => !!f.ref);
- const sent = framesInputs(
- kept.map((f) => f.ref),
- kept.map((f) => f.time),
- ctx.support,
- );
+ const sent = framesInputs(kept.map((f) => f.ref), kept.map((f) => f.time), ctx.support);
// Frames and shots don't mix; the open chain makes one film (its clips are the jobs).
return { images: sent.images ?? [], endImage: sent.endImage, params: { duration: ctx.duration, keyframeTimes: sent.keyframeTimes, shots: undefined, multiShot: undefined, ...(ctx.chained && { numOutputs: 1 }) } };
}
diff --git a/tests/keyframes.test.ts b/tests/keyframes.test.ts
index 3e236aa8..9152bec6 100644
--- a/tests/keyframes.test.ts
+++ b/tests/keyframes.test.ts
@@ -4,6 +4,7 @@ import {
addFrameAt,
chainGapProblem,
frameRange,
+ frameRole,
frameSupport,
framesBlocker,
framesDuration,
@@ -66,6 +67,12 @@ describe("frame times", () => {
expect(frameTimes([0, 0.5, 1], 8)).toEqual([0, 4, 8]);
});
+ it("names the frames as Kling 4.0 does", () => {
+ expect([0, 1, 2].map((i) => frameRole(i, 3, [0, 0.5, 1][i]))).toEqual(["Start frame", "Middle frame", "End frame"]);
+ // A last frame before the end is a middle frame too.
+ expect(frameRole(1, 2, 0.6)).toBe("Middle frame");
+ });
+
it("drags a frame between its neighbours, snapped to 0.1 s; the start frame never moves", () => {
const at = [0, 0.5, 1];
expect(frameTimes(moveFrameAt(at, 1, 1.234, 5), 5)).toEqual([0, 1.2, 5]);