Skip to content

One-click character swap for videos: an open-source, local Higgsfield Genjutsu alternative built on ComfyUI and MiniMax H3, with FLUX.3 Klein relighting.

Make Add work for people and moving things (#7)

mixbagc0a590472647
diff --git a/app/api/jobs/route.ts b/app/api/jobs/route.ts
index fff6b9a..f0bf977 100644
--- a/app/api/jobs/route.ts
+++ b/app/api/jobs/route.ts
@@ -79,7 +79,7 @@ function parseObject(form: FormData) {
const settings: ObjectSettings = {
mode: mode as EditMode, target, changeTo, biggestOnly: form.get("biggest_only") === "true", keepOutline: form.get("keep_outline") === "true",
margin: margin as ObjectMargin, ...parseRun(form),
- ...(mode === "add" ? { placement: parsePlacement(form.get("placement")) } : {}),
+ ...(mode === "add" ? { placement: parsePlacement(form.get("placement")), action: String(form.get("action") ?? "").replace(/\s+/g, " ").trim().slice(0, 300) } : {}),
};
return { picture, settings };
}
diff --git a/components/openjutsu.tsx b/components/openjutsu.tsx
index 2f70a4e..1f2430f 100644
--- a/components/openjutsu.tsx
+++ b/components/openjutsu.tsx
@@ -248,6 +248,7 @@ export function Openjutsu() {
const [editMode, setEditMode] = useState<EditTab>("change");
const [editTarget, setEditTarget] = useState(EDITS[0].target);
const [changeTo, setChangeTo] = useState("");
+ const [action, setAction] = useState("");
const [look, setLook] = useState<{ file: File; url: string } | null>(null);
const [biggestOnly, setBiggestOnly] = useState(false);
const [keepOutline, setKeepOutline] = useState(true);
@@ -546,7 +547,10 @@ export function Openjutsu() {
if (look && editMode !== "remove") form.set("picture", look.file);
form.set("biggest_only", String(biggestOnly));
form.set("keep_outline", String(keepOutline));
- if (editMode === "add") form.set("placement", JSON.stringify(placement.map((p) => ({ ...p, frame: p.frame - Math.round((whole ? 0 : part.start) * 24) }))));
+ if (editMode === "add") {
+ form.set("placement", JSON.stringify(placement.map((p) => ({ ...p, frame: p.frame - Math.round((whole ? 0 : part.start) * 24) }))));
+ form.set("action", action);
+ }
form.set("resolution", resolutionField);
form.set("seed", String(seed));
form.set("clip_seconds", String(clipSeconds));
@@ -807,7 +811,7 @@ export function Openjutsu() {
<button key={e.id} className={e.id === editMode ? "on" : ""} onClick={() => {
// Each tab's fields mean something else: "top, pants" left over from Change made From picture swap only the top.
// The default goes in as a value, not a placeholder, so an untouched box shows what SAM tracks.
- if (e.id !== editMode) { setEditTarget(e.target); setChangeTo(""); }
+ if (e.id !== editMode) { setEditTarget(e.target); setChangeTo(""); setAction(""); }
setEditMode(e.id);
}}>{e.label}</button>
))}
@@ -820,6 +824,10 @@ export function Openjutsu() {
<span>{edit.toHint}</span>
<input value={changeTo} maxLength={300} placeholder={`e.g. ${edit.to}`} onChange={(event) => setChangeTo(event.target.value)} />
</label>}
+ {editMode === "add" && <label>
+ <span>What happens with it <small>Optional. Leave empty for a still object.</small></span>
+ <input value={action} maxLength={300} placeholder="e.g. she dances the same routine in sync with the others" onChange={(event) => setAction(event.target.value)} />
+ </label>}
{editMode !== "remove" && (look ? (
<div className="character look">
<img src={look.url} alt="Reference picture" />
diff --git a/lib/object.ts b/lib/object.ts
index c2668a0..0526c49 100644
--- a/lib/object.ts
+++ b/lib/object.ts
@@ -44,6 +44,7 @@ export type ObjectSettings = {
seed: number;
clipSeconds: number;
placement?: PlacementKeyframe[];
+ action?: string; // add: what the new thing does over the clip; empty for a still object
};
export const OBJECT_VIDEO = "Source video";
@@ -85,7 +86,8 @@ export function pruneObject(source: ApiGraph, picture: boolean, settings: Object
delete ref["ref_images.ref_image_0"];
}
// H3 copies a grey shape's outline, so a changed top keeps the old silhouette and a removed object would come back grey.
- if (settings.mode === "remove" || settings.mode === "change" && !settings.keepOutline) {
+ // For add, the original clip shows the spot empty and H3 copied that back: a dancer never appeared beside the others.
+ if (settings.mode === "remove" || settings.mode === "add" || settings.mode === "change" && !settings.keepOutline) {
delete ref["ref_videos.ref_video_0"];
delete ref["ref_video_audios.ref_video_audio_0"];
}
@@ -114,7 +116,7 @@ export function pruneObject(source: ApiGraph, picture: boolean, settings: Object
plan.placement = placement;
plan.change_to = addedObject(settings.changeTo);
plan.keep_outline = false;
- ref["ref_videos.ref_video_0"] = [id("Motion reference for this clip"), 0];
+ plan.action = settings.action ?? "";
graph.object_placement = { class_type: "H3ObjectPlacementMask", inputs: {
images: [id("Source clip (frames + audio)"), 0], start_frame: [id("Clip start frame"), 1], placement,
}, _meta: { title: "Object placement area" } };
diff --git a/test/object.test.ts b/test/object.test.ts
index 2f65835..e6d3551 100644
--- a/test/object.test.ts
+++ b/test/object.test.ts
@@ -79,18 +79,20 @@ test("the model settings reach the Object Swap Plan", () => {
assert.deepEqual(dangling(pruned), []);
});
-test("adding an object uses placement keyframes and the original video, without SAM or grey references", () => {
+test("adding an object uses placement keyframes, without SAM, grey shapes or the original video as a reference", () => {
const placement = [{ frame: 0, x: 0.3, y: 0.4, width: 0.2, height: 0.25 }];
for (const picture of [false, true]) {
- const pruned = pruneObject(graph, picture, { ...settings("add"), target: "on the table", changeTo: "a cake", placement });
+ const pruned = pruneObject(graph, picture, { ...settings("add"), target: "on the table", changeTo: "a cake", placement, action: "Steam rises from it." });
assert.deepEqual(dangling(pruned), []);
assert.ok(!Object.values(pruned).some((n) => ["SAM3_VideoTrack", "H3PeopleMask", "H3GreyMannequins", "CheckpointLoaderSimple"].includes(n.class_type)));
const ref = node(pruned, "Reference Conditioning").inputs;
- assert.deepEqual(ref["ref_videos.ref_video_0"], [nodeByTitle(pruned, "Motion reference for this clip"), 0]);
+ assert.equal(ref["ref_videos.ref_video_0"], undefined);
+ assert.equal(ref["ref_video_audios.ref_video_audio_0"], undefined);
assert.equal(!!ref["ref_images.ref_image_0"], picture);
const plan = node(pruned, "Object Swap Plan (what to change)").inputs;
assert.equal(plan.mode, "add");
assert.equal(plan.keep_outline, false);
+ assert.equal(plan.action, "Steam rises from it.");
assert.equal(plan.placement, JSON.stringify(placement));
assert.equal(pruned.object_placement.class_type, "H3ObjectPlacementMask");
assert.equal(pruned.object_placement.inputs.placement, plan.placement);