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.

Remove object: fits a phone, brings the first frame into view, a steady before and after

Claudef74eefdcdc43
diff --git a/src/components/remove-object/frame-stage.tsx b/src/components/remove-object/frame-stage.tsx
index 70d2af2f..397ca9c6 100644
--- a/src/components/remove-object/frame-stage.tsx
+++ b/src/components/remove-object/frame-stage.tsx
@@ -42,6 +42,8 @@ export function FrameStage({
}) {
const box = useRef<HTMLDivElement>(null);
const [cursor, setCursor] = useState<{ x: number; y: number } | null>(null);
+ // The crosshair is for the keyboard: focus that comes with a click doesn't show it.
+ const pointer = useRef(false);
const add = (x: number, y: number) => {
if (!onPoints || points.length >= maxPoints) return;
onPoints([...points, { x: Math.round(x * frame.width), y: Math.round(y * frame.height), label: pointLabel }]);
@@ -76,7 +78,11 @@ export function FrameStage({
: undefined
}
onKeyDown={onKey}
- onFocus={() => clickable && setCursor((c) => c ?? { x: 0.5, y: 0.5 })}
+ onPointerDown={() => (pointer.current = true)}
+ onFocus={() => {
+ if (clickable && !pointer.current) setCursor((c) => c ?? { x: 0.5, y: 0.5 });
+ pointer.current = false;
+ }}
onBlur={() => setCursor(null)}
onClick={(e) => {
if (!clickable) return;
diff --git a/src/components/remove-object/remove-object-tool.tsx b/src/components/remove-object/remove-object-tool.tsx
index 6ec4da01..d98ee4a0 100644
--- a/src/components/remove-object/remove-object-tool.tsx
+++ b/src/components/remove-object/remove-object-tool.tsx
@@ -49,6 +49,8 @@ interface Run {
/** The original the result is compared with: the clip and where the selection starts. */
before: string;
start: number;
+ /** The clip's shape, so the compare has its size before the videos load. */
+ ratio?: number;
}
/**
@@ -62,6 +64,7 @@ export function RemoveObjectTool({ tabs }: { tabs?: React.ReactNode }) {
const source = useSourceClip(REMOVE.maxBytes);
const clip = source.clip;
const trimmer = useRef<VideoTrimmerHandle>(null);
+ const framePanel = useRef<HTMLDivElement>(null);
const [range, setRange] = useState<TrimRange | null>(null);
const [mode, setMode] = useState<RemoveMode>("type");
const [prompt, setPrompt] = useState("");
@@ -123,6 +126,18 @@ export function RemoveObjectTool({ tabs }: { tabs?: React.ReactNode }) {
setPreviewId(null);
}
+ const pickMode = (m: RemoveMode) => {
+ setMode(m);
+ setPreviewId(null);
+ // Clicking and painting happen on the first frame: bring it into view when it's off screen.
+ const el = framePanel.current;
+ if (m === "type" || !el) return;
+ const r = el.getBoundingClientRect();
+ if (r.bottom < 160 || r.top > window.innerHeight - 160) {
+ el.scrollIntoView({ block: "start", behavior: window.matchMedia("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth" });
+ }
+ };
+
const reset = () => {
source.clear();
setRange(null);
@@ -165,9 +180,11 @@ export function RemoveObjectTool({ tabs }: { tabs?: React.ReactNode }) {
: !range || !duration
? "Reading the clip…"
: !eraser
- ? "problem" in choice
- ? choice.problem
- : "Pick how to point at it"
+ ? mode === "click" && engine === "open"
+ ? "Switch to Type it or Paint it"
+ : "problem" in choice
+ ? choice.problem
+ : "Pick how to point at it"
: !marked
? mode === "type"
? "Say what to remove"
@@ -183,7 +200,8 @@ export function RemoveObjectTool({ tabs }: { tabs?: React.ReactNode }) {
void runGuard(JSON.stringify(body), (requestId) => actions.run.mutateAsync({ ...body, requestId }))
.then((r) => {
if (!r) return;
- setRun({ final: r.final.id, ids: r.items.map((g) => g.id), before: clip!.preview, start: range!.startTime });
+ const ratio = size.width && size.height ? size.width / size.height : undefined;
+ setRun({ final: r.final.id, ids: r.items.map((g) => g.id), before: clip!.preview, start: range!.startTime, ratio });
toast("Removing it", { description: "Follow it below — it lands in your Library too." });
})
.catch((e: Error) => toast.error(e.message));
@@ -222,7 +240,7 @@ export function RemoveObjectTool({ tabs }: { tabs?: React.ReactNode }) {
}}
/>
) : (
- <div className="grid items-start gap-4 lg:grid-cols-[minmax(0,1fr)_380px]">
+ <div className="grid grid-cols-1 items-start gap-4 lg:grid-cols-[minmax(0,1fr)_380px]">
<div className="min-w-0 space-y-4">
<Panel>
<div className="space-y-3">
@@ -241,45 +259,47 @@ export function RemoveObjectTool({ tabs }: { tabs?: React.ReactNode }) {
/>
</div>
</Panel>
- <Panel
- title="First frame"
- aside={
- mode === "click" && engine === "cloud" ? (
- <Segmented
- label="What a click marks"
- value={pointLabel}
- onChange={setPointLabel}
- className="w-auto"
- options={[
- { value: "positive", label: "Remove" },
- { value: "negative", label: "Keep" },
- ]}
+ <div ref={framePanel} className="scroll-mt-[120px]">
+ <Panel
+ title="First frame"
+ aside={
+ mode === "click" && engine === "cloud" ? (
+ <Segmented
+ label="What a click marks"
+ value={pointLabel}
+ onChange={setPointLabel}
+ className="w-auto"
+ options={[
+ { value: "positive", label: "Remove" },
+ { value: "negative", label: "Keep" },
+ ]}
+ />
+ ) : null
+ }
+ >
+ {frame ? (
+ <FrameStage
+ frame={frame}
+ points={mode === "click" ? points : []}
+ onPoints={mode === "click" && engine === "cloud" ? setPoints : undefined}
+ pointLabel={pointLabel}
+ overlay={mode === "paint" ? paint?.overlay : undefined}
+ clickable={mode === "click" && engine === "cloud"}
+ maxPoints={REMOVE.maxPoints}
/>
- ) : null
- }
- >
- {frame ? (
- <FrameStage
- frame={frame}
- points={mode === "click" ? points : []}
- onPoints={mode === "click" && engine === "cloud" ? setPoints : undefined}
- pointLabel={pointLabel}
- overlay={mode === "paint" ? paint?.overlay : undefined}
- clickable={mode === "click" && engine === "cloud"}
- maxPoints={REMOVE.maxPoints}
- />
- ) : (
- <div className="grid aspect-video place-items-center rounded-xl bg-muted text-[13px] text-muted-foreground">
- {frameError ? (
- <p className="max-w-xs px-4 text-center">This browser can&apos;t show the clip&apos;s frames (an H.265 or ProRes file?). Type it works without them.</p>
- ) : (
- <Loader2 className="size-5 animate-spin" aria-label="Reading the first frame" />
- )}
- </div>
- )}
- <p className="mt-2 text-[12px] text-muted-foreground">{frameHint(mode, engine, points.length, !!paint)}</p>
- {preview && <MaskPreview g={preview} />}
- </Panel>
+ ) : (
+ <div className="grid aspect-video place-items-center rounded-xl bg-muted text-[13px] text-muted-foreground">
+ {frameError ? (
+ <p className="max-w-xs px-4 text-center">This browser can&apos;t show the clip&apos;s frames (an H.265 or ProRes file?). Type it works without them.</p>
+ ) : (
+ <Loader2 className="size-5 animate-spin" aria-label="Reading the first frame" />
+ )}
+ </div>
+ )}
+ <p className="mt-2 text-[12px] text-muted-foreground">{frameHint(mode, engine, points.length, !!paint)}</p>
+ {preview && <MaskPreview g={preview} />}
+ </Panel>
+ </div>
</div>
<Panel className="space-y-4 lg:sticky lg:top-[112px]">
@@ -287,10 +307,7 @@ export function RemoveObjectTool({ tabs }: { tabs?: React.ReactNode }) {
<Segmented
label="How do you point at it?"
value={mode}
- onChange={(m) => {
- setMode(m);
- setPreviewId(null);
- }}
+ onChange={pickMode}
options={REMOVE_MODES.map((m) => ({ value: m.id, label: m.label }))}
/>
</Field>
@@ -327,10 +344,10 @@ export function RemoveObjectTool({ tabs }: { tabs?: React.ReactNode }) {
<div className="space-y-2 rounded-xl bg-muted/60 p-3 text-[13px]" role="status">
<p>{CLICK_OPEN_PROBLEM}.</p>
<div className="flex flex-wrap gap-1.5">
- <Button size="sm" variant="outline" className="rounded-full" onClick={() => setMode("type")}>
+ <Button size="sm" variant="outline" className="rounded-full" onClick={() => pickMode("type")}>
<Type className="size-3.5" /> Type it
</Button>
- <Button size="sm" variant="outline" className="rounded-full" onClick={() => setMode("paint")}>
+ <Button size="sm" variant="outline" className="rounded-full" onClick={() => pickMode("paint")}>
<Brush className="size-3.5" /> Paint it
</Button>
{engineMode === "both" && (
@@ -412,7 +429,7 @@ export function RemoveObjectTool({ tabs }: { tabs?: React.ReactNode }) {
{estimate.isFetching && <Loader2 className="size-3 animate-spin text-muted-foreground" aria-label="Updating the price" />}
</p>
{est && (
- <p className="truncate text-[12px] text-muted-foreground">
+ <p className="text-[12px] leading-snug text-muted-foreground">
{est.modelName} · {est.seconds} s{est.pieces > 1 ? ` in ${est.pieces} ${engine === "open" ? "windows" : "pieces"}` : ""}
</p>
)}
@@ -466,7 +483,7 @@ export function RemoveObjectTool({ tabs }: { tabs?: React.ReactNode }) {
function frameHint(mode: RemoveMode, engine: "cloud" | "open", points: number, painted: boolean): string {
if (mode === "type") return "Name it in the panel — the first frame is here to check what you mean.";
- if (mode === "click") return engine === "open" ? "Clicking works on the cloud engine." : points ? "Add more points on the same object, or mark what stays with Keep." : "Click the object you want gone. Keyboard: arrows move the crosshair, Enter adds a point.";
+ if (mode === "click") return engine === "open" ? "Points need the cloud engine's SAM 3.1 — the open graphs follow words or paint." : points ? "Add more points on the same object, or mark what stays with Keep." : "Click the object you want gone. Keyboard: arrows move the crosshair, Enter adds a point.";
return painted ? "Red is what goes. Touch up the paint, or clear it to start over." : "Paint over what should go — the paint only needs to cover it on this frame.";
}
@@ -556,7 +573,7 @@ function RunPanel({ run, onAgain }: { run: Run; onAgain: () => void }) {
}
>
{out ? (
- <VideoCompare before={run.before} after={out.url} start={run.start} />
+ <VideoCompare before={run.before} after={out.url} start={run.start} ratio={run.ratio} />
) : (
<div className="space-y-3">
<div className="h-1.5 overflow-hidden rounded-full bg-muted" role="progressbar" aria-valuemin={0} aria-valuemax={100} aria-valuenow={Math.round(state.progress * 100)} aria-label="Progress">
diff --git a/src/components/remove-object/video-compare.tsx b/src/components/remove-object/video-compare.tsx
index ed876b73..1093f624 100644
--- a/src/components/remove-object/video-compare.tsx
+++ b/src/components/remove-object/video-compare.tsx
@@ -9,7 +9,20 @@ import { Button } from "@/components/ui/button";
* (or use ← → on the slider) to wipe between them. The original follows the result's clock from `start` (the
* selection's start in the original clip), so both show the same moment.
*/
-export function VideoCompare({ before, after, start = 0, label = "Compare the original and the result" }: { before: string; after: string; start?: number; label?: string }) {
+export function VideoCompare({
+ before,
+ after,
+ start = 0,
+ ratio,
+ label = "Compare the original and the result",
+}: {
+ before: string;
+ after: string;
+ start?: number;
+ /** The clip's width / height: the box keeps that shape while the videos load. */
+ ratio?: number;
+ label?: string;
+}) {
const box = useRef<HTMLDivElement>(null);
const a = useRef<HTMLVideoElement>(null);
const b = useRef<HTMLVideoElement>(null);
@@ -58,14 +71,21 @@ export function VideoCompare({ before, after, start = 0, label = "Compare the or
<div className="space-y-2">
<div
ref={box}
- className="relative grid touch-none place-items-center overflow-hidden rounded-xl bg-media select-none"
+ className="relative mx-auto grid touch-none place-items-center overflow-hidden rounded-xl bg-media select-none"
+ style={ratio ? { aspectRatio: String(ratio), maxHeight: "56vh" } : undefined}
onPointerDown={(e) => {
(e.target as HTMLElement).setPointerCapture(e.pointerId);
move(e.clientX);
}}
onPointerMove={(e) => e.buttons && move(e.clientX)}
>
- <video ref={a} src={after} playsInline loop className="block max-h-[56vh] w-full object-contain" onLoadedMetadata={() => b.current && (b.current.currentTime = start)} />
+ <video
+ ref={a}
+ src={after}
+ playsInline
+ loop
+ className={ratio ? "absolute inset-0 size-full object-contain" : "block max-h-[56vh] w-full object-contain"}
+ onLoadedMetadata={() => b.current && (b.current.currentTime = start)} />
<video
ref={b}
src={before}
diff --git a/src/server/remove-object.ts b/src/server/remove-object.ts
index e0a87290..de664108 100644
--- a/src/server/remove-object.ts
+++ b/src/server/remove-object.ts
@@ -5,6 +5,7 @@ import {
chooseEraser,
paintedPoints,
pieceSeconds,
+ planPieces,
planMaskPreview,
planRemoval,
rangeProblem,
@@ -167,8 +168,9 @@ async function planInput(body: RemovalBody, opts: { probe: boolean; preview?: bo
if (eraser.window) {
const fps = source.fps ?? 30;
const per = eraser.window.cap / fps;
- if (len > per + 0.01) {
- notes.push(`${model?.name ?? eraser.label} works on ${eraser.window.cap} frames at a time (${per.toFixed(1)} s of this clip): the clip runs as ${Math.ceil((len * fps) / eraser.window.cap)} windows, joined with its own sound. Seams between windows aren't tested on a GPU yet`);
+ const windows = source.fps ? planPieces(eraser, source, range).length : Math.ceil((len * fps) / eraser.window.cap);
+ if (windows > 1) {
+ notes.push(`${model?.name ?? eraser.label} works on ${eraser.window.cap} frames at a time (${per.toFixed(1)} s of this clip): the clip runs as ${windows} windows, joined with its own sound. Seams between windows aren't tested on a GPU yet`);
if (eraser.modes.includes("paint")) notes.push("SAM 3.1 hands what you painted on from window to window (each starts on the last frame of the one before), so the windows run one after another");
}
notes.push(eraser.effects ? "VOID needs a 24–40 GB GPU (unverified). Its CogVideoX base is licensed for commercial use only after registering, up to 1 million visits a month" : "Wan 2.1 VACE 14B needs a 24 GB GPU · Apache-2.0 (SAM 3.1: Meta's SAM License)");
diff --git a/tests/remove-object-api.test.ts b/tests/remove-object-api.test.ts
index b62fff9f..624c7f22 100644
--- a/tests/remove-object-api.test.ts
+++ b/tests/remove-object-api.test.ts
@@ -112,7 +112,12 @@ describe("Remove object: estimates", () => {
const e = await (await estimateRoute.POST(json(body({ engine: "open", source: { url: clip, duration: 12, fps: 16, width: 72, height: 128, hasAudio: true } })))).json();
expect(e).toMatchObject({ modelId: "oss-vace-remove", pieces: 3, costUsd: 0 });
expect(e.notes.join(" ")).toMatch(/81 frames at a time/);
+ expect(e.notes.join(" ")).toMatch(/runs as 3 windows/);
expect(e.notes.join(" ")).toMatch(/24 GB GPU/);
+ // Painted windows overlap by a frame: 162 frames take three windows, and the note counts what runs.
+ const painted = await (await estimateRoute.POST(json(body({ engine: "open", mode: "paint", mask: "/api/files/m.png", source: { url: clip, duration: 6, fps: 27 } })))).json();
+ expect(painted).toMatchObject({ modelId: "oss-vace-remove-painted", pieces: 3 });
+ expect(painted.notes.join(" ")).toMatch(/runs as 3 windows/);
const effects = await (await estimateRoute.POST(json(body({ engine: "open", effects: true, source: { url: clip, duration: 12, fps: 16 } })))).json();
expect(effects.modelId).toBe("oss-void-remove");
expect(effects.notes.join(" ")).toMatch(/CogVideoX/);