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.

Use the whole picture scene in From picture (#22)

mixbag02817e59421d
diff --git a/README.md b/README.md
index 9df2adf..718f982 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ The app is a small Next.js front end over a ComfyUI workflow. It uses [`@comfyor
- **Simple motion transfer**: available. One character replaces the main person (the one who fills the most of the frame). Runs `workflows/simple.api.json`, exported from `H3 One-Click Single Swap (DMAD 6 step).json`.
- **Advanced motion transfer**: available. 1–4 characters, each with an optional role; every tracked person is matched to a role per shot, and people without a character stay untouched. Runs `workflows/advanced.api.json`, exported from `H3 One-Click Advanced Swap (DMAD 6 step).json`; **One pass per person** (two characters) runs `workflows/advanced_maxq.api.json`.
-- **Object swap**: available. **Change** what SAM tracks (hair, a jacket, a car) into what you describe or show in a picture; **Remove** it; or change the **Background** around it (`person` stays). Only that area is regenerated. **From picture** runs the Simple swap with the picture as the character: its face, hair and outfit, with the original background. **ControlNet** takes both the person and the place from the picture: the whole frame is regenerated, and a depth map of the person in the video (SAM 3.1 + Depth Anything V2, through the H3 Fun ControlNet Union 2.0) keeps their framing, camera and motion. Everyone else in the video is replaced by the picture's setting. It runs as one H3 clip of up to 15 s (a longer part is cut to its first 15 s), because a continuation clip loses the depth framing. Runs `workflows/object.api.json`, exported from `H3 One-Click Object Swap (DMAD 6 step).json`; ControlNet runs `workflows/control.api.json`, exported from `H3 One-Click Picture Swap ControlNet (DMAD 6 step).json`.
+- **Object swap**: available. **Change** what SAM tracks (hair, a jacket, a car) into what you describe or show in a picture; **Remove** it; or change the **Background** around it (`person` stays). Only that area is regenerated. **From picture** recreates the person, outfit, setting and lighting from the uploaded picture, using a grey motion guide without ControlNet. For relighting, upload an edited frame from the selected source section. Portrait pictures can produce side bars. **ControlNet** takes both the person and the place from the picture: the whole frame is regenerated, and a depth map of the person in the video (SAM 3.1 + Depth Anything V2, through the H3 Fun ControlNet Union 2.0) keeps their framing, camera and motion. Everyone else in the video is replaced by the picture's setting. It runs as one H3 clip of up to 15 s (a longer part is cut to its first 15 s), because a continuation clip loses the depth framing. Runs `workflows/object.api.json`, exported from `H3 One-Click Object Swap (DMAD 6 step).json`; ControlNet runs `workflows/control.api.json`, exported from `H3 One-Click Picture Swap ControlNet (DMAD 6 step).json`.
- **Post-processing**: available, for a finished video. **Fix faces**: H3 draws faces poorly when the person is small in the frame, so this redraws the face of the person in a photo at close-up size and pastes it back. Runs `workflows/face.api.json`, written by `workflows/build/openjutsu_face_build.py`. **Fix colours** softens H3's harsh look without an H3 run: Image Detail Contrast takes some fine detail contrast out, then Orion4D's DCTL Tone Mapper grades every frame. Runs `workflows/color.api.json`.
## Requirements
diff --git a/app/api/jobs/route.ts b/app/api/jobs/route.ts
index 8fc0d8b..ee46161 100644
--- a/app/api/jobs/route.ts
+++ b/app/api/jobs/route.ts
@@ -141,7 +141,7 @@ function parseColor(form: FormData): ColorSettings {
function parseSimple(form: FormData) {
const picture = parsePicture(form.get("picture"));
- const settings: SimpleSettings = { role: String(form.get("role") ?? "").slice(0, 200), noLipSync: form.get("no_lip_sync") === "true", ...parseRun(form), ...parseMask(form) };
+ const settings: SimpleSettings = { sceneFromPicture: form.get("scene_from_picture") === "true", role: String(form.get("role") ?? "").slice(0, 200), noLipSync: form.get("no_lip_sync") === "true", ...parseRun(form), ...parseMask(form) };
return { picture, settings };
}
diff --git a/components/openjutsu.tsx b/components/openjutsu.tsx
index 46753ba..76ace94 100644
--- a/components/openjutsu.tsx
+++ b/components/openjutsu.tsx
@@ -52,7 +52,7 @@ const FACE_STYLE_TEXT: Record<FaceStyle, { label: string; hint: string }> = {
mouth: { label: "Follow the mouth", hint: "The face follows the video's expressions and mouth movements; a little less like the photo." },
};
-// "From picture" is the Simple person swap with the picture as the character; "ControlNet" takes the person and the setting from it.
+// "From picture" recreates the whole scene with a grey motion reference.
type EditTab = EditMode | "picture" | "controlnet";
const EDITS: { id: EditTab; label: string; target: string; what: string; to: string; toHint: string }[] = [
{ id: "change", label: "Change", target: "hair, top", what: "What to change", to: "short bright pink hair and a black leather jacket", toHint: "What it becomes" },
@@ -500,6 +500,7 @@ export function Openjutsu() {
if (kind === "simple" && fromPicture && look) {
form.set("picture", look.file);
form.set("role", "");
+ form.set("scene_from_picture", "true");
} else if (kind === "simple" && character) {
form.set("picture", character.file);
form.set("role", character.role);
@@ -584,7 +585,7 @@ export function Openjutsu() {
const shared = { resolution, motion, hatFix, noLipSync, margin, seed, clipSeconds };
const selectedModel = { model, loras, steps };
let selection: SetupRequest;
- if (kind === "simple") selection = { kind, settings: { ...shared, role: fromPicture ? "" : character?.role ?? "", target: String(form.get("target")) }, model: selectedModel };
+ if (kind === "simple") selection = { kind, settings: { ...shared, sceneFromPicture: fromPicture, role: fromPicture ? "" : character?.role ?? "", target: String(form.get("target")) }, model: selectedModel };
else if (kind === "advanced" || kind === "advanced_maxq") selection = { kind, settings: { ...shared, roles: shown.map((c) => c.role) }, pictures: shown.length, model: selectedModel };
else if (kind === "montage") selection = { kind, settings: { ...shared, roles: shown.map((c) => c.role) }, pictures: shown.length, review: review ?? null, model: selectedModel };
else if (kind === "object") selection = { kind, settings: { ...shared, mode: editMode as EditMode, target: String(form.get("target")), changeTo, biggestOnly, keepOutline,
@@ -863,7 +864,7 @@ export function Openjutsu() {
{editMode === "add" && "A new object is generated inside your placement area while the scene continues. Keep the supporting surface visible and describe where the object rests."}
{editMode === "remove" && "What SAM tracks is erased and filled with what is around it. The camera, people and sound stay."}
{editMode === "background" && "Everything except what SAM tracks becomes the new place; the camera movement stays."}
- {fromPicture && "The person in the video becomes the person in the picture: face, hair and outfit. The background, motion, camera and sound stay."}
+ {fromPicture && "The person, background and lighting come from the picture. The video guides the motion and timing; its soundtrack stays. For relighting, upload an edited frame from the selected video section."}
{controlNet && `The person and the place both come from the picture. A depth map of the person in the video keeps their framing, camera and motion; the sound stays. Everyone else in the video is replaced by the picture's setting. Runs as one clip of up to ${CONTROL_MAX_SECONDS} s.`}
</p>
{editMode === "change" && video && canvas && <details>
@@ -1000,7 +1001,7 @@ export function Openjutsu() {
<input type="checkbox" checked={hatFix} onChange={(event) => setHatFix(event.target.checked)} />
<i aria-hidden />
</label>}
- {(mode === "simple" || mode === "advanced" || controlNet) && <label className="setting toggle">
+ {(mode === "simple" || mode === "advanced" || pictureOnly) && <label className="setting toggle">
<span>No lip-sync <small>For songs the people in the video do not sing or talk along to, so the new {mode === "advanced" ? "people" : "person"} do{mode === "advanced" ? "" : "es"} not lip-sync them{controlNet ? "" : " (about 30 s more per clip)"}.</small></span>
<input type="checkbox" checked={noLipSync} onChange={(event) => setNoLipSync(event.target.checked)} />
<i aria-hidden />
@@ -1012,7 +1013,7 @@ export function Openjutsu() {
<i aria-hidden />
</label>
)}
- {mode !== "post" && !controlNet && <div className="setting">
+ {mode !== "post" && !pictureOnly && <div className="setting">
<span>Mask margin <small>{mode === "object"
? editMode === "background" ? "How far the new place reaches into the edge of what stays." : "Room around it for a bigger new shape and its shadow."
: <>Room around the person for a differently built character.{mode === "simple" ? " Check mask shows it." : ""}</>}</small></span>
diff --git a/lib/model.ts b/lib/model.ts
index 5a2425e..75d8a6a 100644
--- a/lib/model.ts
+++ b/lib/model.ts
@@ -18,7 +18,7 @@ export const STRENGTH = { min: -4, max: 4 };
// Mutates graph: the steps (on the Swap Plan, or the Schedule in Fix faces, which has no plan), the chosen diffusion model,
// then the LoRAs in order into whatever read the old LoRA node.
export function applyModel(graph: ApiGraph, settings: ModelSettings) {
- const plans = Object.values(graph).filter((node) => ["H3OneClickSwapPlan", "H3AdvancedSwapPlan", "H3PictureSwapPlan", "H3MontagePlan", "H3ObjectSwapPlan"].includes(node.class_type));
+ const plans = Object.values(graph).filter((node) => ["H3OneClickSwapPlan", "H3AdvancedSwapPlan", "H3PictureSwapPlan", "H3SceneSwapPlan", "H3MontagePlan", "H3ObjectSwapPlan"].includes(node.class_type));
if (plans.length > 1) throw new Error(`Expected one Swap Plan node in the workflow, found ${plans.length}.`);
(plans[0] ?? graph[nodeByTitle(graph, "Schedule")]).inputs.steps = settings.steps;
const unet = nodeByTitle(graph, "H3 Diffusion Model");
diff --git a/lib/setup.ts b/lib/setup.ts
index 16d2546..7ab5b7e 100644
--- a/lib/setup.ts
+++ b/lib/setup.ts
@@ -32,7 +32,7 @@ export type NodeRegistry = Record<string, NodeInfo>;
const PACKS = [
{ name: "ComfyUI-MiniMaxH3-Context-Loop (0.7.3+)", url: "https://github.com/ethanfel/ComfyUI-MiniMaxH3-Context-Loop", nodes: ["MiniMaxH3GenerationProfile", "MiniMaxH3SourceTimeline", "MiniMaxH3ChainPlanModern", "MiniMaxH3ChainLoopStart", "MiniMaxH3ChainCurrent", "MiniMaxH3ChainContext", "MiniMaxH3ChainSegmentSave", "MiniMaxH3ChainReview", "MiniMaxH3ChainLoopEnd", "MiniMaxH3ChainAssemble", "MiniMaxH3ContexLoopSourceSlice", "MiniMaxH3ContexLoopMaskSlice", "MiniMaxH3ContexMaskedTarget", "MiniMaxH3ContexMaskGridPreview", "MiniMaxH3LoopTrim"] },
- { name: "comfyui-h3-oneclick-swap", url: "https://github.com/D3voz/comfyui-h3-oneclick-swap", nodes: ["H3OneClickSwapPlan", "H3AdvancedSwapPlan", "H3PictureSwapPlan", "H3ObjectSwapPlan", "H3ObjectPlacementMask", "H3AddFitCheck", "H3AddMovingArea", "H3PaintedEditArea", "H3SoundtrackOrSilence", "H3PeopleMask", "H3GreyMannequins", "H3ClipShots", "H3FillShots", "H3TrackCrops", "H3TrackRoles", "H3RoleMask", "H3SubjectPrompt", "H3MontagePeople", "H3MontageTracks", "H3MontagePicks", "H3MontagePlan", "H3MontagePass", "H3FaceChunks", "H3FaceJoin"] },
+ { name: "comfyui-h3-oneclick-swap", url: "https://github.com/D3voz/comfyui-h3-oneclick-swap", nodes: ["H3OneClickSwapPlan", "H3AdvancedSwapPlan", "H3PictureSwapPlan", "H3SceneSwapPlan", "H3ObjectSwapPlan", "H3ObjectPlacementMask", "H3AddFitCheck", "H3AddMovingArea", "H3PaintedEditArea", "H3SoundtrackOrSilence", "H3PeopleMask", "H3GreyMannequins", "H3ClipShots", "H3FillShots", "H3TrackCrops", "H3TrackRoles", "H3RoleMask", "H3SubjectPrompt", "H3MontagePeople", "H3MontageTracks", "H3MontagePicks", "H3MontagePlan", "H3MontagePass", "H3FaceChunks", "H3FaceJoin"] },
{ name: "ComfyUI-Fantastic-MiniMaxH3-PromptBuilder", url: "https://github.com/Adudeguyman/ComfyUI-Fantastic-MiniMaxH3-PromptBuilder", nodes: ["MiniMaxH3FantasticVideoEditLatent"] },
{ name: "ComfyUI-KJNodes", url: "https://github.com/kijai/ComfyUI-KJNodes", nodes: ["GrowMaskWithBlur", "ImageAndMaskPreview"] },
{ name: "ComfyUI-VideoHelperSuite", url: "https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite", nodes: ["VHS_LoadVideo", "VHS_SelectEveryNthImage", "VHS_VideoCombine"] },
diff --git a/lib/simple.ts b/lib/simple.ts
index 6a9bcb0..304a516 100644
--- a/lib/simple.ts
+++ b/lib/simple.ts
@@ -61,6 +61,7 @@ export function setSection(graph: ApiGraph, video: string, section: Section) {
export const DEFAULT_TARGET = "person";
export type SimpleSettings = {
+ sceneFromPicture?: boolean;
role: string; // who the character replaces, "" to let the describer name the main person
resolution: Resolution;
motion: MotionSize;
@@ -159,10 +160,16 @@ export function suffixRunName(graph: ApiGraph, id: string, suffix: string, title
}
export function pruneSimple(source: ApiGraph, settings: SimpleSettings): ApiGraph {
- const graph = maskSettings(source, settings.hatFix, settings.margin, settings.target, NODES);
+ const graph = maskSettings(source, settings.sceneFromPicture ? false : settings.hatFix, settings.margin, settings.target, NODES);
if (!settings.noLipSync) dropNoLipSync(graph);
setMotionSize(graph, settings.motion);
const plan = graph[NODES.plan].inputs;
+ if (settings.sceneFromPicture) {
+ graph[NODES.plan].class_type = "H3SceneSwapPlan";
+ graph[NODES.growMask] = { class_type: "SolidMask", inputs: { value: 1, width: 64, height: 64 }, _meta: { title: "Edit the whole frame" } };
+ const mannequin = Object.values(graph).find((node) => node.class_type === "H3GreyMannequins")!;
+ mannequin.inputs.neutral_background = true;
+ }
setResolution(graph, NODES.plan, NODES.video, settings.resolution);
plan.seed = settings.seed;
plan.clip_seconds = settings.clipSeconds;
diff --git a/test/picture.test.ts b/test/picture.test.ts
new file mode 100644
index 0000000..daea0d7
--- /dev/null
+++ b/test/picture.test.ts
@@ -0,0 +1,32 @@
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import test from "node:test";
+import { applyModel, DEFAULT_MODEL } from "../lib/model.ts";
+import { setupGraph } from "../lib/setup.ts";
+import { NODES, isLink, pruneSimple, type ApiGraph, type SimpleSettings } from "../lib/simple.ts";
+
+const graph: ApiGraph = JSON.parse(readFileSync(new URL("../workflows/simple.api.json", import.meta.url), "utf8"));
+const settings: SimpleSettings = { sceneFromPicture: true, role: "the dancer", resolution: "768p", motion: 512, hatFix: true, noLipSync: true, margin: "normal", target: "person", seed: 0, clipSeconds: 6 };
+
+test("From picture edits the whole frame using the picture and a neutral motion guide, without ControlNet", () => {
+ const result = pruneSimple(graph, settings);
+ applyModel(result, DEFAULT_MODEL);
+ assert.equal(result[NODES.plan].class_type, "H3SceneSwapPlan");
+ assert.deepEqual(result[NODES.growMask].inputs, { value: 1, width: 64, height: 64 });
+ const ref = Object.values(result).find((n) => n.class_type === "MiniMaxH3ReferenceToVideo")!;
+ assert.deepEqual(ref.inputs["ref_images.ref_image_0"], [NODES.picture, 0]);
+ const motion = ref.inputs["ref_videos.ref_video_0"] as [string, number];
+ assert.equal(result[motion[0]].inputs.neutral_background, true);
+ assert.ok(!Object.values(result).some((n) => /ControlNet|DepthAnything/.test(n.class_type)));
+ for (const node of Object.values(result)) for (const value of Object.values(node.inputs)) {
+ if (isLink(value)) assert.ok(result[value[0]], `missing ${value[0]}`);
+ }
+ assert.deepEqual(setupGraph(graph, { kind: "simple", settings, model: DEFAULT_MODEL }), result);
+});
+
+test("Simple motion transfer retains its original mask and surroundings", () => {
+ const result = pruneSimple(graph, { ...settings, sceneFromPicture: false });
+ assert.equal(result[NODES.plan].class_type, "H3OneClickSwapPlan");
+ assert.equal(result[NODES.growMask].class_type, "GrowMaskWithBlur");
+ assert.ok(!Object.values(result).some((n) => n.inputs.neutral_background));
+});