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.

Add Object swap mode

D3voz6b4f0f398b31
diff --git a/README.md b/README.md
index 0381eec..7023d1c 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# Openjutsu
-An open-source, Genjutsu-style character swap for video. Drop a video and a character photo, press **Generate**, and the main person in the video is replaced by your character. The camera, cuts, motion and soundtrack stay. Everything runs on open weights on your own GPU: MiniMax H3 for the video, SAM 3.1 to track people, and Qwen3-VL 8B to describe the pictures and shots.
+An open-source, Genjutsu-style character and object swap for video. Drop a video and a character photo, press **Generate**, and the main person in the video is replaced by your character. Or change their hair or clothes, remove something, or put them somewhere else. The camera, cuts, motion and soundtrack stay. Everything runs on open weights on your own GPU: MiniMax H3 for the video, SAM 3.1 to track people, and Qwen3-VL 8B to describe the pictures and shots.
The app is a small Next.js front end over a ComfyUI workflow. It uses [`@comfyorg/sdk`](https://www.npmjs.com/package/@comfyorg/sdk), following Comfy's [comfy-reshoot](https://github.com/Comfy-Org/comfy-reshoot) reference app.
@@ -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**: coming soon.
+- **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. Runs `workflows/object.api.json`, exported from `H3 One-Click Object Swap (DMAD 6 step).json`.
- **Fix faces**: available. Post-processing for a finished video: 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 `user/default/openjutsu_face_build.py`.
## Requirements
@@ -27,7 +27,7 @@ Install these into `ComfyUI/custom_nodes` (ComfyUI Manager finds the first three
| [ComfyUI-Fantastic-MiniMaxH3-PromptBuilder](https://github.com/Adudeguyman/ComfyUI-Fantastic-MiniMaxH3-PromptBuilder) | masked video-edit latent |
| [ComfyUI-KJNodes](https://github.com/kijai/ComfyUI-KJNodes) | Grow Mask With Blur |
| [ComfyUI-VideoHelperSuite](https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite) | video loading |
-| `comfyui-h3-oneclick-swap` | swap plan, people and role masks, grey mannequins, track labelling, cut finder, shot list, face-fix chunks (TODO: link the published pack) |
+| `comfyui-h3-oneclick-swap` | swap and object plans, people and role masks, grey mannequins, track labelling, cut finder, shot list, face-fix chunks (TODO: link the published pack) |
| [ComfyUI-H3-FaceRefine](https://github.com/Carasibana/ComfyUI-H3-FaceRefine) | Fix faces: face tracking and cropping, SAM face masks, pasting back |
| [ComfyUI-Impact-Pack](https://github.com/ltdrdata/ComfyUI-Impact-Pack) | Fix faces: SAM loader |
@@ -88,6 +88,7 @@ A 6 s clip at 480p takes about 6–13 minutes on a 4060 Ti, most of it in H3 sam
- **Motion reference** (under Advanced) is the size of the grey figures H3 copies the motion from: 512 px by default, or 768 or 1376 px. For general, simple videos 512 px is probably enough, but a bigger size does seem to improve quality a bit: H3 follows the source poses and placement more closely. Sampling takes about a third longer at 768 px and about 2.4× as long at 1376 px (H3 uses at most 768×1344 for references). Each size keeps its own saved clips, so switching size renders again instead of resuming.
- Change the **seed** (under Advanced) for a new take. Running the same inputs again resumes from the last finished clip.
- **Steps**, **Base model** and **LoRAs** (under Advanced) default to the H3 pruned INT8 model with the DMAD speed LoRA at 6 steps. LoRAs apply in order; without a speed LoRA, use 20 steps or more. Check mask ignores them.
+- **Object swap:** name what SAM tracks in a word or two (`hair`, `jacket`, `poster`), or several separated by commas (`hair, top`) to change them together. Every match changes unless **Only the biggest one** is on (one of each thing). A picture of an outfit, hairstyle, product or place is copied onto it. For **Remove**, say what shows instead only when it is not obvious (`a plain wall`). Mask margin is smaller here (10, 20 or 40 px). Change keeps the outline of what it replaces: a tank top turned into a flannel shirt stays sleeveless.
- **Fix faces:** drop the finished video and the photo the person was made from. **Match the photo** redraws the face from the photo: the closest likeness, but H3 makes up the expressions and mouth movements. **Follow the mouth** keeps the video's expressions and mouth movements, with a little less likeness. Only that person's face changes (matched by face identity); faces taller than a fifth of the frame are left alone, and stretches with only such faces are skipped. A 17 s video at 768p (4 chunks) took about 28 minutes on a 4060 Ti, including model loading. The video is read at 24 fps.
- **Advanced mode:** give roles as `the drummer`, optionally with how they look after ` - ` (`the drummer - man in a cap`); the look only helps match people and never reaches H3. **One pass per person** gives each of two characters their own H3 pass with only their photo (about twice the time). Check mask is Simple-only for now.
@@ -109,6 +110,8 @@ Each clip, SAM 3.1 tracks everyone at 1008 px (its own working size), and H3 Peo
Advanced mode labels the people before it masks them. Per clip, H3 Track Crops shows each SAM track once per shot (the person alone, and the frame with them boxed) to Qwen3-VL 8B, which names the subject or "other"; H3 Track Roles reads that answer and settles a subject named twice in one shot by colour. H3 Role Mask builds the edit mask from the labelled tracks only, and the shot-list describer sees each labelled person outlined in their subject's colour, so the prompt names the same people the masks do. `lib/advanced.ts` finds nodes by title, drops unused picture branches and, without the hat fix or No lip-sync, their nodes; the exports are made from `user/default/oneclick_advanced_build.js` with every optional group on.
+Object swap uses the same masked edit for the tracked things; SAM 3 tracks each comma-separated thing as its own prompt. The H3 Object Swap Plan writes a MiniMax video-editing prompt (`[video editing + reference generation + audio reuse]`), and the shot-list describer is told not to mention the thing being changed. **Change**: the tracked area is regenerated, and the motion reference shows it as a grey shape that keeps its shape and movement but not its colours. **Background**: the grown person mask is inverted (`flip_input`), so the edit reaches a little into the person's edge, and the whole background turns into a grey blur that keeps the camera movement. **Remove**: there is no motion reference (a grey shape would come back as a grey object), and the prompt describes what fills the area without naming what was there. `lib/object.ts` makes these changes by node title.
+
Fix faces works on the face, not the frame. H3 Face Track + Crop follows the face of the person in the photo over the whole video (InsightFace picks them out when there are several) and crops it to 512×512, so a face a few dozen pixels tall fills the canvas. H3 Face Fix Chunks splits the crops into independent chunks (6.5 s by default, overlapping by at least 1 s) and outputs them as lists, so ComfyUI runs the H3 nodes once per chunk. Each chunk is a masked edit: only the SAM face mask is regenerated with the photo as reference, while the hair, ears, collar and background around it stay, which keeps the new face from sliding against the head. For Follow the mouth, a blurred copy of the crop is the motion reference. H3 Face Fix Join crossfades the chunk overlaps and lowers the per-frame paste weight where the face is large, and H3 Face Stitch pastes the face back through a slightly smaller mask with the original soundtrack. The chunks are not chained through the context loop: each one starts from the swap's own frames, so colours do not drift. `lib/face.ts` removes the blurred face for Match the photo and sets the seed and chunk length.
To change the workflow, edit `user/default/oneclick_single_build.js` in ComfyUI (or the workflow itself), enable the hat-fix group, export **Workflow (API)**, and replace `workflows/simple.api.json`. If node ids change, update `NODES` in `lib/simple.ts`. `npm test` checks the pruning against the export.
diff --git a/app/api/jobs/route.ts b/app/api/jobs/route.ts
index 723a954..6cb733c 100644
--- a/app/api/jobs/route.ts
+++ b/app/api/jobs/route.ts
@@ -1,8 +1,9 @@
import { NextResponse } from "next/server";
-import { listModels, submitAdvanced, submitFace, submitMask, submitSimple } from "../../../lib/comfy.ts";
+import { listModels, submitAdvanced, submitFace, submitMask, submitObject, submitSimple } from "../../../lib/comfy.ts";
import { CHUNK_SECONDS, FACE_STYLES, type FaceSettings, type FaceStyle } from "../../../lib/face.ts";
import { MAX_CHARACTERS } from "../../../lib/advanced.ts";
import { MAX_LORAS, STEPS, STRENGTH, type ModelSettings } from "../../../lib/model.ts";
+import { EDIT_MODES, OBJECT_MARGINS, type EditMode, type ObjectMargin, type ObjectSettings } from "../../../lib/object.ts";
import { CLIP_SECONDS, DEFAULT_TARGET, MARGINS, MAX_SEED, MIN_SECTION_SECONDS, MOTION_SIZES, RESOLUTIONS, type Margin, type MotionSize, type Resolution, type Section, type SimpleSettings } from "../../../lib/simple.ts";
export const runtime = "nodejs";
@@ -48,7 +49,24 @@ function parseRun(form: FormData) {
throw new Error(`Clip length must be ${CLIP_SECONDS.min}-${CLIP_SECONDS.max} s.`);
}
- return { resolution: resolution as Resolution, motion: motion as MotionSize, ...parseMask(form), seed, clipSeconds };
+ return { resolution: resolution as Resolution, motion: motion as MotionSize, seed, clipSeconds };
+}
+
+function parseObject(form: FormData) {
+ const mode = String(form.get("edit_mode"));
+ if (!EDIT_MODES.includes(mode as EditMode)) throw new Error("Choose change, remove or background.");
+ const margin = String(form.get("margin") ?? "normal");
+ if (!Object.hasOwn(OBJECT_MARGINS, margin)) throw new Error("Choose a supported mask margin.");
+ const target = String(form.get("target") ?? "").replace(/\s+/g, " ").trim().slice(0, 100);
+ if (!target) throw new Error(mode === "background" ? "Say what stays, for example person." : "Say what to change, for example hair.");
+ const changeTo = String(form.get("change_to") ?? "").replace(/\s+/g, " ").trim().slice(0, 300);
+ const entry = form.get("picture");
+ const picture = entry instanceof File && entry.size > 0 && mode !== "remove" ? parsePicture(entry) : null;
+ if (mode !== "remove" && !changeTo && !picture) throw new Error("Say what it becomes, or add a picture.");
+ const settings: ObjectSettings = {
+ mode: mode as EditMode, target, changeTo, biggestOnly: form.get("biggest_only") === "true", margin: margin as ObjectMargin, ...parseRun(form),
+ };
+ return { picture, settings };
}
function parseModel(form: FormData, available: { models: string[]; loras: string[] } | null): ModelSettings {
@@ -81,7 +99,7 @@ function parseFace(form: FormData) {
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) };
+ const settings: SimpleSettings = { role: String(form.get("role") ?? "").slice(0, 200), noLipSync: form.get("no_lip_sync") === "true", ...parseRun(form), ...parseMask(form) };
return { picture, settings };
}
@@ -91,7 +109,7 @@ function parseAdvanced(form: FormData) {
const maxQuality = form.get("max_quality") === "true";
if (maxQuality && pictures.length !== 2) throw new Error("One pass per person needs exactly two characters.");
const roles = form.getAll("role").map((role) => String(role).slice(0, 200));
- return { pictures, maxQuality, settings: { roles, noLipSync: form.get("no_lip_sync") === "true", ...parseRun(form) } };
+ return { pictures, maxQuality, settings: { roles, noLipSync: form.get("no_lip_sync") === "true", ...parseRun(form), ...parseMask(form) } };
}
export async function POST(request: Request) {
@@ -112,6 +130,10 @@ export async function POST(request: Request) {
const { pictures, maxQuality, settings } = parseAdvanced(form);
const model = parseModel(form, await listModels());
submit = () => submitAdvanced(video, section, pictures, settings, maxQuality, model);
+ } else if (mode === "object") {
+ const { picture, settings } = parseObject(form);
+ const model = parseModel(form, await listModels());
+ submit = () => submitObject(video, section, picture, settings, model);
} else if (mode === "face") {
const { picture, settings } = parseFace(form);
const model = parseModel(form, await listModels());
diff --git a/app/globals.css b/app/globals.css
index 5991149..55c4753 100644
--- a/app/globals.css
+++ b/app/globals.css
@@ -89,6 +89,13 @@ video { width: 100%; border-radius: 12px; background: #000; max-height: 420px; }
.drop.add { aspect-ratio: 3 / 4; min-height: 0; }
.drop.add strong { font-size: 32px; font-weight: 300; }
+.edit { display: grid; gap: 12px; }
+.edit label { display: grid; gap: 4px; font-size: 0.82em; color: var(--muted); }
+.edit label small { display: block; }
+.edit input { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; font-size: 1rem; }
+.edit input:focus { outline: none; border-color: var(--accent); }
+.edit .look, .edit .drop.add { width: 50%; }
+
.settings { gap: 12px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.setting > span { display: grid; }
diff --git a/components/openjutsu.tsx b/components/openjutsu.tsx
index 01ea92b..7d0faef 100644
--- a/components/openjutsu.tsx
+++ b/components/openjutsu.tsx
@@ -7,11 +7,12 @@ import { clipCount, clipStarts } from "../lib/clips.ts";
import { CLIP_SECONDS, DEFAULT_TARGET, MARGINS, MAX_SEED, MIN_SECTION_SECONDS, MOTION_SIZES, RESOLUTIONS, type Margin, type MotionSize, type Resolution, type Section } from "../lib/simple.ts";
import { MAX_CHARACTERS } from "../lib/advanced.ts";
import { DEFAULT_MODEL, MAX_LORAS, STEPS, STRENGTH, type Lora } from "../lib/model.ts";
+import type { EditMode } from "../lib/object.ts";
import { CHUNK_SECONDS, faceChunkCount, type FaceStyle } from "../lib/face.ts";
type Character = { file: File; url: string; role: string };
-type Mode = "simple" | "advanced" | "face";
-type Kind = "simple" | "mask" | "advanced" | "advanced_maxq" | "face";
+type Mode = "simple" | "advanced" | "object" | "face";
+type Kind = "simple" | "mask" | "advanced" | "advanced_maxq" | "object" | "face";
type Run = { id: string; kind: Kind; margin: Margin; clips: number; clipSeconds: number; startedAt: number };
// pass counts the sampler runs started so far: Fix faces samples its chunks one after another in the same node.
type Progress = NodeInfo & { step: number | null; steps: number | null; pass: number };
@@ -22,7 +23,7 @@ const RUN_KEY = "openjutsu.run";
const MODES = [
{ id: "simple", title: "Simple motion transfer", text: "Swap the main person in a video for your character.", ready: true },
{ id: "advanced", title: "Advanced motion transfer", text: "Several people, pick who becomes who.", ready: true },
- { id: "object", title: "Object swap", text: "Replace a prop or product instead of a person.", ready: false },
+ { id: "object", title: "Object swap", text: "Change hair, clothes, a prop or the background, or remove something.", ready: true },
{ id: "face", title: "Fix faces", text: "Post-processing: redraw a person's face in a finished video from their photo.", ready: true },
] as const;
@@ -31,6 +32,15 @@ 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.
+type EditTab = EditMode | "picture";
+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" },
+ { id: "remove", label: "Remove", target: "poster", what: "What to remove", to: "a plain wall", toHint: "What shows instead (optional)" },
+ { id: "background", label: "Background", target: "person", what: "What stays", to: "a snowy mountain pass at dusk", toHint: "The new place" },
+ { id: "picture", label: "From picture", target: "person", what: "Who is replaced", to: "", toHint: "" },
+];
+
function readRun(): Run | null {
try {
return JSON.parse(localStorage.getItem(RUN_KEY) ?? "null");
@@ -128,6 +138,11 @@ export function Openjutsu() {
const [noLipSync, setNoLipSync] = useState(false);
const [margin, setMargin] = useState<Margin>("normal");
const [target, setTarget] = useState(DEFAULT_TARGET);
+ const [editMode, setEditMode] = useState<EditTab>("change");
+ const [editTarget, setEditTarget] = useState("");
+ const [changeTo, setChangeTo] = useState("");
+ const [look, setLook] = useState<{ file: File; url: string } | null>(null);
+ const [biggestOnly, setBiggestOnly] = useState(false);
const [faceStyle, setFaceStyle] = useState<FaceStyle>("photo");
const [chunkSeconds, setChunkSeconds] = useState(CHUNK_SECONDS.default);
const [seed, setSeed] = useState(0);
@@ -239,9 +254,20 @@ export function Openjutsu() {
}
const clips = !video?.duration ? 0 : mode === "face" ? faceChunkCount(part.length || video.duration, chunkSeconds) : clipCount(part.length || video.duration, clipSeconds);
+ const edit = EDITS.find((e) => e.id === editMode)!;
+ const fromPicture = mode === "object" && editMode === "picture";
+ const ready = mode === "object"
+ ? editMode === "remove" || (fromPicture ? !!look : !!changeTo.trim() || !!look)
+ : !!character;
+
+ function chooseLook(files: File[]) {
+ if (!files[0]) return;
+ if (look) URL.revokeObjectURL(look.url);
+ setLook({ file: files[0], url: URL.createObjectURL(files[0]) });
+ }
async function submit(kind: Kind) {
- if (!video || (kind !== "mask" && !character)) return;
+ if (!video || (kind !== "mask" && !ready)) return;
setSubmitting(true);
setFormError("");
const form = new FormData();
@@ -254,10 +280,15 @@ export function Openjutsu() {
form.set("hat_fix", String(hatFix));
form.set("no_lip_sync", String(noLipSync));
form.set("margin", margin);
- form.set("target", target);
- if (kind === "simple" && character) {
+ form.set("target", fromPicture ? editTarget.trim() || edit.target : target);
+ if (kind === "simple" && fromPicture && look) {
+ form.set("picture", look.file);
+ form.set("role", "");
+ } else if (kind === "simple" && character) {
form.set("picture", character.file);
form.set("role", character.role);
+ }
+ if (kind === "simple") {
form.set("resolution", resolution);
form.set("seed", String(seed));
form.set("clip_seconds", String(clipSeconds));
@@ -279,6 +310,16 @@ export function Openjutsu() {
form.set("seed", String(seed));
form.set("clip_seconds", String(chunkSeconds));
}
+ if (kind === "object") {
+ form.set("edit_mode", editMode);
+ form.set("target", editTarget.trim() || edit.target);
+ form.set("change_to", changeTo);
+ if (look && editMode !== "remove") form.set("picture", look.file);
+ form.set("biggest_only", String(biggestOnly));
+ form.set("resolution", resolution);
+ form.set("seed", String(seed));
+ form.set("clip_seconds", String(clipSeconds));
+ }
if (kind !== "mask") {
form.set("motion", String(motion));
form.set("steps", String(steps));
@@ -328,7 +369,7 @@ export function Openjutsu() {
<span className="mark" aria-hidden>忍</span>
<div>
<h1>Openjutsu</h1>
- <p>Swap the person in any video for your own character. Open weights, on your own GPU.</p>
+ <p>Swap the people or things in any video. Open weights, on your own GPU.</p>
</div>
</div>
</header>
@@ -337,7 +378,7 @@ export function Openjutsu() {
{MODES.map((m) => (
<button
key={m.id} className={`mode ${m.id === mode ? "active" : ""}`} disabled={!m.ready || !!run} aria-pressed={m.id === mode}
- onClick={() => m.id !== "object" && setMode(m.id)}
+ onClick={() => setMode(m.id)}
>
<strong>{m.title}</strong>
<span>{m.text}</span>
@@ -397,7 +438,41 @@ export function Openjutsu() {
</div>
<div className="panel">
- <h2><span>2</span> {mode === "face" ? "Whose face" : mode === "simple" ? "Character" : "Characters"}</h2>
+ <h2><span>2</span> {mode === "object" ? "What to change" : mode === "face" ? "Whose face" : mode === "simple" ? "Character" : "Characters"}</h2>
+ {mode === "object" ? (
+ <div className="edit">
+ <div className="segmented">
+ {EDITS.map((e) => (
+ <button key={e.id} className={e.id === editMode ? "on" : ""} onClick={() => setEditMode(e.id)}>{e.label}</button>
+ ))}
+ </div>
+ <label>
+ <span>{edit.what} <small>What SAM tracks, in English.{(editMode === "change" || editMode === "remove") && " Separate several with commas."}</small></span>
+ <input value={editTarget} maxLength={100} placeholder={edit.target} onChange={(event) => setEditTarget(event.target.value)} />
+ </label>
+ {!fromPicture && <label>
+ <span>{edit.toHint}</span>
+ <input value={changeTo} maxLength={300} placeholder={`e.g. ${edit.to}`} onChange={(event) => setChangeTo(event.target.value)} />
+ </label>}
+ {editMode !== "remove" && (look ? (
+ <div className="character look">
+ <img src={look.url} alt="Reference picture" />
+ <button className="remove" onClick={() => { URL.revokeObjectURL(look.url); setLook(null); }} aria-label="Remove picture">×</button>
+ </div>
+ ) : (
+ <DropZone accept="image/*" onFiles={chooseLook} className="add">
+ <strong>+</strong>
+ <span>{fromPicture ? "The picture to copy" : editMode === "background" ? "Picture of the place (optional)" : "Picture of the new look (optional)"}</span>
+ </DropZone>
+ ))}
+ <p className="hint">
+ {editMode === "change" && "Only what SAM tracks is regenerated: hair, a top, a car. A picture of an outfit, hairstyle or product is copied onto it."}
+ {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."}
+ </p>
+ </div>
+ ) : (<>
<div className="characters">
{shown.map((c, i) => (
<div className="character" key={c.url}>
@@ -445,6 +520,7 @@ export function Openjutsu() {
most screen time.
</p>
)}
+ </>)}
</div>
</section>
@@ -458,18 +534,25 @@ export function Openjutsu() {
))}
</div>
</div>}
+ {mode === "object" && editMode !== "background" && !fromPicture && (
+ <label className="setting toggle">
+ <span>Only the biggest one <small>Off: every match SAM finds changes (everyone&apos;s hair). On: only the one that fills the most of the frame.</small></span>
+ <input type="checkbox" checked={biggestOnly} onChange={(event) => setBiggestOnly(event.target.checked)} />
+ <i aria-hidden />
+ </label>
+ )}
{mode === "simple" && (
<div className="setting">
<span>What to replace <small>What SAM tracks, in English: person, cat, dog, or a short description such as “black and white cat”. The biggest match is replaced.</small></span>
<input className="target-input" aria-label="What to replace" placeholder={DEFAULT_TARGET} value={target} onChange={(event) => setTarget(event.target.value)} />
</div>
)}
- {mode !== "face" && <label className="setting toggle">
+ {(mode === "simple" || mode === "advanced") && <label className="setting toggle">
<span>Hat fix <small>Also replaces hats{mode === "advanced" ? " worn by the people being replaced" : ""} (about 45 s more per clip).</small></span>
<input type="checkbox" checked={hatFix} onChange={(event) => setHatFix(event.target.checked)} />
<i aria-hidden />
</label>}
- {mode !== "face" && <label className="setting toggle">
+ {(mode === "simple" || mode === "advanced") && <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 (about 30 s more per clip).</small></span>
<input type="checkbox" checked={noLipSync} onChange={(event) => setNoLipSync(event.target.checked)} />
<i aria-hidden />
@@ -482,7 +565,9 @@ export function Openjutsu() {
</label>
)}
{mode !== "face" && <div className="setting">
- <span>Mask margin <small>Room around the person for a differently built character.{mode === "simple" ? " Check mask shows it." : ""}</small></span>
+ <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>
<MarginPicker value={margin} onChange={setMargin} />
</div>}
<details>
@@ -549,13 +634,13 @@ export function Openjutsu() {
{formError && <p className="error">{formError}</p>}
<div className="row">
{mode === "simple" && <button className="secondary" disabled={!video || submitting} onClick={() => submit("mask")}>Check mask</button>}
- <button className="primary" disabled={!video || !character || submitting} onClick={() => submit(mode === "face" ? "face" : mode === "simple" ? "simple" : onePassEach ? "advanced_maxq" : "advanced")}>
+ <button className="primary" disabled={!video || !ready || submitting} onClick={() => submit(mode === "object" ? fromPicture ? "simple" : "object" : mode === "face" ? "face" : mode === "simple" ? "simple" : onePassEach ? "advanced_maxq" : "advanced")}>
{submitting ? "Uploading…" : "Generate"}
</button>
</div>
- <small>{clips
+ <small>{clips && ready
? mode === "face" ? `Up to ${clips} chunk${clips > 1 ? "s" : ""} of face` : `${clips} clip${clips > 1 ? "s" : ""} at ${resolution}`
- : `Add a video and ${mode === "face" ? "the photo of the person" : mode === "simple" ? "a character photo" : "character photos"}.`}</small>
+ : `Add a video and ${mode === "object" ? "say what it becomes" : mode === "face" ? "the photo of the person" : mode === "simple" ? "a character photo" : "character photos"}.`}</small>
</div>
</>
)}
@@ -587,7 +672,7 @@ function RunView({ run, job, progress, preview, streamError, now, onCancel, onRe
<video src={job.video.url} controls autoPlay playsInline />
<div className="row">
<a className="primary" href={`${job.video.url}?download`} download={job.video.name}>Download MP4</a>
- <button className="secondary" onClick={onReset}>{run.kind === "face" ? "Fix another" : "New swap"}</button>
+ <button className="secondary" onClick={onReset}>{run.kind === "object" ? "New edit" : run.kind === "face" ? "Fix another" : "New swap"}</button>
</div>
</section>
);
@@ -598,7 +683,7 @@ function RunView({ run, job, progress, preview, streamError, now, onCancel, onRe
<section className="panel">
<h2>{status === "canceled" ? "Canceled" : status === "succeeded" ? "Finished without a video" : status === "expired" ? "Job no longer available" : "Something went wrong"}</h2>
{job?.error && <p className="error">{job.error}</p>}
- {status === "expired" && <p className="hint">ComfyUI no longer knows this job, for example after a restart. Finished videos are in ComfyUI&apos;s output/{run.kind === "face" ? "openjutsu_face" : "h3_oneclick_swap"} folder.</p>}
+ {status === "expired" && <p className="hint">ComfyUI no longer knows this job, for example after a restart. Finished videos are in ComfyUI&apos;s output/{run.kind === "object" ? "h3_oneclick_edit" : run.kind === "face" ? "openjutsu_face" : "h3_oneclick_swap"} folder.</p>}
<button className="secondary" onClick={onReset}>Back</button>
</section>
);
diff --git a/lib/comfy.ts b/lib/comfy.ts
index a5e6ac0..defb60e 100644
--- a/lib/comfy.ts
+++ b/lib/comfy.ts
@@ -5,6 +5,7 @@ import { ComfyLow } from "@comfyorg/sdk/low";
import { MASK_NODES, NODES, pruneMask, pruneSimple, setSection, type ApiGraph, type Margin, type Section, type SimpleSettings } from "./simple.ts";
import { VIDEO, nodeByTitle, pruneAdvanced, type AdvancedSettings } from "./advanced.ts";
import { applyModel, type ModelSettings } from "./model.ts";
+import { OBJECT_PICTURE, OBJECT_VIDEO, pruneObject, type ObjectSettings } from "./object.ts";
import { FACE_PICTURE, FACE_VIDEO, pruneFace, type FaceSettings } from "./face.ts";
export type PublicJob = {
@@ -34,7 +35,7 @@ export function rawJobEvents(job: Job, signal: AbortSignal) {
return low().getJobEvents(job.urls.events || job.id, { signal });
}
-export const JOB_KINDS = ["simple", "mask", "advanced", "advanced_maxq", "face"] as const;
+export const JOB_KINDS = ["simple", "mask", "advanced", "advanced_maxq", "object", "face"] as const;
export type JobKind = (typeof JOB_KINDS)[number];
export async function loadGraph(kind: JobKind): Promise<ApiGraph> {
@@ -92,6 +93,17 @@ export async function submitAdvanced(video: File, section: Section, pictures: Fi
return publicJob(await comfy.submit(workflow));
}
+export async function submitObject(video: File, section: Section, picture: File | null, settings: ObjectSettings, model: ModelSettings) {
+ const comfy = client();
+ const graph = pruneObject(await loadGraph("object"), !!picture, settings);
+ applyModel(graph, model);
+ setSection(graph, nodeByTitle(graph, OBJECT_VIDEO), section);
+ const workflow = comfy.workflows.fromJson(graph);
+ workflow.setInput(nodeByTitle(graph, OBJECT_VIDEO), "video", await upload(comfy, video));
+ if (picture && settings.mode !== "remove") workflow.setInput(nodeByTitle(graph, OBJECT_PICTURE), "image", await upload(comfy, picture));
+ return publicJob(await comfy.submit(workflow));
+}
+
export async function submitFace(video: File, section: Section, picture: File, settings: FaceSettings, model: ModelSettings) {
const comfy = client();
const graph = pruneFace(await loadGraph("face"), settings);
diff --git a/lib/model.ts b/lib/model.ts
index a99a480..c5ba0d4 100644
--- a/lib/model.ts
+++ b/lib/model.ts
@@ -1,4 +1,4 @@
-// Base model, LoRAs and steps, shared by every swap workflow. Each export has one "H3 Diffusion Model" UNETLoader
+// Base model, LoRAs and steps, shared by every swap and edit workflow. Each export has one "H3 Diffusion Model" UNETLoader
// feeding one "DMAD LoRA" LoraLoaderModelOnly; the LoRA list replaces that node with a chain (or removes it).
import { nodeByTitle } from "./advanced.ts";
import { isLink, type ApiGraph } from "./simple.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) => node.class_type === "H3OneClickSwapPlan" || node.class_type === "H3AdvancedSwapPlan");
+ const plans = Object.values(graph).filter((node) => ["H3OneClickSwapPlan", "H3AdvancedSwapPlan", "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/object.ts b/lib/object.ts
new file mode 100644
index 0000000..db33f7a
--- /dev/null
+++ b/lib/object.ts
@@ -0,0 +1,84 @@
+// Object swap: change, remove or re-set the things SAM tracks, keeping the rest of the shot.
+// workflows/object.api.json is exported (ComfyUI user/default/oneclick_object_build.js) in change mode with a picture;
+// each request prunes it. Nodes are found by title.
+import { nodeByTitle } from "./advanced.ts";
+import { setMotionSize, type ApiGraph, type MotionSize, type Resolution } from "./simple.ts";
+
+export const EDIT_MODES = ["change", "remove", "background"] as const;
+export type EditMode = (typeof EDIT_MODES)[number];
+
+// Edit-mask grow in pixels at SAM's 1008 px canvas. For background, how far the new setting reaches into the edge of what stays.
+export const OBJECT_MARGINS = { tight: 10, normal: 20, loose: 40 } as const;
+export type ObjectMargin = keyof typeof OBJECT_MARGINS;
+
+export type ObjectSettings = {
+ mode: EditMode;
+ target: string; // what SAM tracks, several separated by commas; for background, what stays
+ changeTo: string; // what it becomes, or for remove what shows instead
+ biggestOnly: boolean;
+ resolution: Resolution;
+ motion: MotionSize;
+ margin: ObjectMargin;
+ seed: number;
+ clipSeconds: number;
+};
+
+export const OBJECT_VIDEO = "Source video";
+export const OBJECT_PICTURE = "Picture 1";
+
+export const objectTargets = (target: string) => target.split(",").map((t) => t.trim()).filter(Boolean);
+
+// The picture describer names only what is copied from the picture, with about 20 more words for each thing.
+function describer(settings: ObjectSettings) {
+ const things = settings.mode === "background" ? ["place (the setting, its lighting and what is around)"] : objectTargets(settings.target);
+ const named = things.length === 1 ? things[0] : things.slice(0, -1).join(", ") + " and the " + things.at(-1);
+ const words = 30 + 20 * things.length;
+ return {
+ prompt: `Describe the ${named} in this picture in about ${words} words${things.length > 1 ? ", one sentence for each" : ""}: their shape, colours, `
+ + "materials, patterns and details. No preamble, and nothing about anything else in the picture.",
+ max_length: 2 * words + 40,
+ };
+}
+
+export function pruneObject(source: ApiGraph, picture: boolean, settings: ObjectSettings): ApiGraph {
+ const graph: ApiGraph = structuredClone(source);
+ const id = (title: string) => nodeByTitle(graph, title);
+ const plan = graph[id("Object Swap Plan (what to change)")].inputs;
+ const ref = graph[id("Reference Conditioning")].inputs;
+ const grow = graph[id("Grow mask")].inputs;
+ const grey = graph[id("Turn it grey (shape and movement only)")].inputs;
+
+ if (picture && settings.mode !== "remove") Object.assign(graph[id("Describe picture 1")].inputs, describer(settings));
+ if (!picture || settings.mode === "remove") {
+ for (const title of [OBJECT_PICTURE, "Shrink for the describer", "Describe picture 1"]) delete graph[id(title)];
+ delete plan.picture_1;
+ delete plan.picture_1_text;
+ delete ref["ref_images.ref_image_0"];
+ }
+ // A grey shape in the motion reference would come back as a grey object.
+ if (settings.mode === "remove") {
+ delete ref["ref_videos.ref_video_0"];
+ delete ref["ref_video_audios.ref_video_audio_0"];
+ }
+ // The edit area is everything but what stays, reaching a little into its edge; the whole of it turns grey.
+ if (settings.mode === "background") {
+ grow.flip_input = true;
+ grey.mask = [id("Grow mask"), 0];
+ grey.size = [id("Grow mask"), 0];
+ }
+ grow.expand = OBJECT_MARGINS[settings.margin];
+ setMotionSize(graph, settings.motion);
+ // One of each thing when only the biggest is kept: hair and top are two tracked objects.
+ const most = settings.biggestOnly ? objectTargets(settings.target).length : 0;
+ for (const title of ["Tracked area", "Tracked area, tight (for the grey shape)"]) graph[id(title)].inputs.max_people = most;
+ graph[id("SAM: what to change")].inputs.text = settings.target;
+ Object.assign(plan, {
+ mode: settings.mode,
+ target: settings.target,
+ change_to: settings.changeTo,
+ resolution: settings.resolution,
+ seed: settings.seed,
+ clip_seconds: settings.clipSeconds,
+ });
+ return graph;
+}
diff --git a/test/object.test.ts b/test/object.test.ts
new file mode 100644
index 0000000..4ff7d13
--- /dev/null
+++ b/test/object.test.ts
@@ -0,0 +1,70 @@
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import test from "node:test";
+import { nodeByTitle } from "../lib/advanced.ts";
+import { applyModel, DEFAULT_MODEL } from "../lib/model.ts";
+import { OBJECT_PICTURE, OBJECT_VIDEO, pruneObject, type ObjectSettings } from "../lib/object.ts";
+import { isLink, type ApiGraph } from "../lib/simple.ts";
+
+const graph: ApiGraph = JSON.parse(readFileSync(new URL("../workflows/object.api.json", import.meta.url), "utf8"));
+const settings = (mode: ObjectSettings["mode"]): ObjectSettings => ({
+ mode, target: "hair", changeTo: "pink hair", biggestOnly: true, resolution: "480p", motion: 512, margin: "loose", seed: 5, clipSeconds: 4,
+});
+const dangling = (g: ApiGraph) => Object.entries(g).flatMap(([id, node]) =>
+ Object.entries(node.inputs).filter(([, v]) => isLink(v) && !g[v[0]]).map(([name]) => `${id}.${name}`));
+const node = (g: ApiGraph, title: string) => g[nodeByTitle(g, title)];
+const titles = (g: ApiGraph) => Object.values(g).map((n) => n._meta?.title ?? "");
+
+test("the export has the picture, the grey motion reference and the video", () => {
+ const ref = node(graph, "Reference Conditioning").inputs;
+ assert.ok(ref["ref_images.ref_image_0"] && ref["ref_videos.ref_video_0"]);
+ assert.equal(node(graph, OBJECT_VIDEO).class_type, "VHS_LoadVideo");
+ assert.equal(node(graph, OBJECT_PICTURE).class_type, "LoadImage");
+});
+
+test("change with a picture keeps the graph and sets the plan", () => {
+ const pruned = pruneObject(graph, true, settings("change"));
+ assert.equal(Object.keys(pruned).length, Object.keys(graph).length);
+ const plan = node(pruned, "Object Swap Plan (what to change)").inputs;
+ assert.deepEqual([plan.mode, plan.target, plan.change_to, plan.resolution, plan.seed, plan.clip_seconds], ["change", "hair", "pink hair", "480p", 5, 4]);
+ assert.equal(node(pruned, "SAM: what to change").inputs.text, "hair");
+ assert.equal(node(pruned, "Grow mask").inputs.expand, 40);
+ assert.equal(node(pruned, "Tracked area").inputs.max_people, 1);
+ assert.ok(node(graph, OBJECT_PICTURE), "the source graph is not modified");
+});
+
+test("several things are tracked together, one of each when only the biggest is kept", () => {
+ const pruned = pruneObject(graph, true, { ...settings("change"), target: "hair, top" });
+ assert.equal(node(pruned, "SAM: what to change").inputs.text, "hair, top");
+ assert.equal(node(pruned, "Tracked area").inputs.max_people, 2);
+ assert.ok(String(node(pruned, "Describe picture 1").inputs.prompt).startsWith("Describe the hair and the top in this picture in about 70 words, one sentence for each:"));
+});
+
+test("without a picture the picture branch goes", () => {
+ const pruned = pruneObject(graph, false, settings("change"));
+ assert.deepEqual(dangling(pruned), []);
+ assert.ok(!titles(pruned).includes(OBJECT_PICTURE));
+ assert.ok(node(pruned, "Reference Conditioning").inputs["ref_videos.ref_video_0"]);
+});
+
+test("remove drops the picture and the grey motion reference", () => {
+ const pruned = pruneObject(graph, true, settings("remove"));
+ assert.deepEqual(dangling(pruned), []);
+ const ref = node(pruned, "Reference Conditioning").inputs;
+ assert.deepEqual(Object.keys(ref).filter((name) => name.startsWith("ref_")), ["ref_image_size"]);
+});
+
+test("background flips the mask and greys all of it", () => {
+ const pruned = pruneObject(graph, false, settings("background"));
+ const grow = nodeByTitle(pruned, "Grow mask");
+ assert.equal(pruned[grow].inputs.flip_input, true);
+ const grey = node(pruned, "Turn it grey (shape and movement only)").inputs;
+ assert.deepEqual([grey.mask, grey.size], [[grow, 0], [grow, 0]]);
+});
+
+test("the model settings reach the Object Swap Plan", () => {
+ const pruned = pruneObject(graph, false, settings("change"));
+ applyModel(pruned, { ...DEFAULT_MODEL, steps: 9 });
+ assert.equal(node(pruned, "Object Swap Plan (what to change)").inputs.steps, 9);
+ assert.deepEqual(dangling(pruned), []);
+});
diff --git a/workflows/object.api.json b/workflows/object.api.json
new file mode 100644
index 0000000..c659c02
--- /dev/null
+++ b/workflows/object.api.json
@@ -0,0 +1,1109 @@
+{
+ "2": {
+ "inputs": {
+ "image": "apt_vest_reference.png"
+ },
+ "class_type": "LoadImage",
+ "_meta": {
+ "title": "Picture 1",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "3": {
+ "inputs": {
+ "upscale_method": "area",
+ "largest_size": 768,
+ "image": [
+ "2",
+ 0
+ ]
+ },
+ "class_type": "ImageScaleToMaxDimension",
+ "_meta": {
+ "title": "Shrink for the describer",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "4": {
+ "inputs": {
+ "prompt": "Describe the main subject of this picture in one sentence of about 40 words: what it is (an outfit, a hairstyle, an object or a place), its shape, colours, materials, patterns and details. No preamble, and nothing about anything else in the picture.",
+ "max_length": 120,
+ "sampling_mode": "off",
+ "thinking": false,
+ "use_default_template": true,
+ "mtp": "auto",
+ "clip": [
+ "8",
+ 0
+ ],
+ "image": [
+ "3",
+ 0
+ ]
+ },
+ "class_type": "TextGenerate",
+ "_meta": {
+ "title": "Describe picture 1",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "5": {
+ "inputs": {
+ "video": "spiderman_jeangrey_apt.mp4",
+ "force_rate": 24,
+ "custom_width": 0,
+ "custom_height": 0,
+ "frame_load_cap": 0,
+ "skip_first_frames": 0,
+ "select_every_nth": 1,
+ "format": "None"
+ },
+ "class_type": "VHS_LoadVideo",
+ "_meta": {
+ "title": "Source video",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "6": {
+ "inputs": {
+ "start_index": 0,
+ "duration": 2048,
+ "audio": [
+ "5",
+ 2
+ ]
+ },
+ "class_type": "TrimAudioDuration",
+ "_meta": {
+ "title": "Soundtrack (whole video)",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "7": {
+ "inputs": {
+ "mode": "change",
+ "target": "hair",
+ "change_to": "short bright pink hair",
+ "clip_seconds": 6,
+ "overlap_frames": 39,
+ "resolution": "736p",
+ "steps": 6,
+ "seed": 0,
+ "source_frames": [
+ "5",
+ 0
+ ],
+ "picture_1": [
+ "2",
+ 0
+ ],
+ "picture_1_text": [
+ "4",
+ 0
+ ]
+ },
+ "class_type": "H3ObjectSwapPlan",
+ "_meta": {
+ "title": "Object Swap Plan (what to change)",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "8": {
+ "inputs": {
+ "clip_name": "qwen3vl_8b_int8_convrot.safetensors",
+ "type": "stable_diffusion",
+ "device": "default"
+ },
+ "class_type": "CLIPLoader",
+ "_meta": {
+ "title": "Describer: Qwen3-VL 8B",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "9": {
+ "inputs": {
+ "unet_name": "minimax_h3_ref2va_pruned_int8_convrot.safetensors",
+ "weight_dtype": "default"
+ },
+ "class_type": "UNETLoader",
+ "_meta": {
+ "title": "H3 Diffusion Model",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "10": {
+ "inputs": {
+ "lora_name": "minimax_h3_DMAD_4step_full_lora_avg_rank_39_bf16.safetensors",
+ "strength_model": 1,
+ "model": [
+ "9",
+ 0
+ ]
+ },
+ "class_type": "LoraLoaderModelOnly",
+ "_meta": {
+ "title": "DMAD LoRA",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "11": {
+ "inputs": {
+ "attention": "comfy kitchen attention",
+ "model": [
+ "10",
+ 0
+ ]
+ },
+ "class_type": "ModelAttentionBackend",
+ "_meta": {
+ "title": "Comfy Kitchen Attention",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "12": {
+ "inputs": {
+ "shift_video": 12,
+ "shift_audio": 2,
+ "model": [
+ "11",
+ 0
+ ]
+ },
+ "class_type": "MiniMaxH3SigmaShift",
+ "_meta": {
+ "title": "Sigma Shift",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "13": {
+ "inputs": {
+ "clip_name": "qwen3vl_32b_minimax_h3_int4_convrot.safetensors",
+ "type": "minimax",
+ "device": "default"
+ },
+ "class_type": "CLIPLoader",
+ "_meta": {
+ "title": "H3 Text Encoder",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "14": {
+ "inputs": {
+ "vae_name": "minimax_h3_video_vae_int8_convrot.safetensors"
+ },
+ "class_type": "VAELoader",
+ "_meta": {
+ "title": "Video VAE",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "15": {
+ "inputs": {
+ "vae_name": "minimax_h3_audio_vae_fp32.safetensors"
+ },
+ "class_type": "VAELoader",
+ "_meta": {
+ "title": "Audio VAE",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "16": {
+ "inputs": {
+ "sampler_name": "euler"
+ },
+ "class_type": "KSamplerSelect",
+ "_meta": {
+ "title": "Sampler",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "17": {
+ "inputs": {
+ "ckpt_name": "sam3.1_multiplex_fp16.safetensors"
+ },
+ "class_type": "CheckpointLoaderSimple",
+ "_meta": {
+ "title": "SAM 3.1",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "18": {
+ "inputs": {
+ "text": "hair",
+ "clip": [
+ "17",
+ 1
+ ]
+ },
+ "class_type": "CLIPTextEncode",
+ "_meta": {
+ "title": "SAM: what to change",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "19": {
+ "inputs": {
+ "scene_continuity": "Hard picture + protected audio",
+ "audio_profile": "Generate audio"
+ },
+ "class_type": "MiniMaxH3GenerationProfile",
+ "_meta": {
+ "title": "Generation Profile",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "20": {
+ "inputs": {
+ "plan_json": "{\n \"shots\": [\n {\n \"id\": \"intro\",\n \"prompt\": \"Describe the opening shot.\"\n },\n {\n \"id\": \"continuation\",\n \"prompt\": \"Continue the same take.\"\n }\n ]\n}",
+ "run_name": [
+ "7",
+ 3
+ ],
+ "generation_fingerprint": "",
+ "width": [
+ "7",
+ 1
+ ],
+ "height": [
+ "7",
+ 2
+ ],
+ "encode_mode": "video",
+ "crop": "center",
+ "default_duration_seconds": 15,
+ "default_steps": 6,
+ "base_seed": 0,
+ "segment_crf": 16,
+ "video_blend_frames": 0,
+ "chain_policy": [
+ "19",
+ 0
+ ],
+ "plan_json_input": [
+ "7",
+ 0
+ ]
+ },
+ "class_type": "MiniMaxH3ChainPlanModern",
+ "_meta": {
+ "title": "Production Plan (filled by Object Swap Plan)",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "21": {
+ "inputs": {
+ "video_path": "",
+ "audio_path": "",
+ "embedded_audio": "auto",
+ "skip_first_frames": 0,
+ "source_audio": [
+ "6",
+ 0
+ ]
+ },
+ "class_type": "MiniMaxH3SourceTimeline",
+ "_meta": {
+ "title": "Source soundtrack",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "22": {
+ "inputs": {
+ "start_clip": 1,
+ "scene_range": "",
+ "verify_resume_history": true,
+ "plan": [
+ "20",
+ 0
+ ],
+ "source_timeline": [
+ "21",
+ 0
+ ]
+ },
+ "class_type": "MiniMaxH3ChainLoopStart",
+ "_meta": {
+ "title": "Loop Start",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "23": {
+ "inputs": {
+ "align_audio_reference": false,
+ "state": [
+ "22",
+ 1
+ ]
+ },
+ "class_type": "MiniMaxH3ChainCurrent",
+ "_meta": {
+ "title": "Current Clip",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "24": {
+ "inputs": {
+ "prompt": [
+ "39",
+ 0
+ ],
+ "width": [
+ "23",
+ 8
+ ],
+ "height": [
+ "23",
+ 9
+ ],
+ "length": [
+ "23",
+ 6
+ ],
+ "ref_image_size": "match",
+ "clip": [
+ "13",
+ 0
+ ],
+ "vae": [
+ "14",
+ 0
+ ],
+ "audio_vae": [
+ "15",
+ 0
+ ],
+ "ref_images.ref_image_0": [
+ "2",
+ 0
+ ],
+ "ref_videos.ref_video_0": [
+ "35",
+ 0
+ ],
+ "ref_video_audios.ref_video_audio_0": [
+ "23",
+ 12
+ ]
+ },
+ "class_type": "MiniMaxH3ReferenceToVideo",
+ "_meta": {
+ "title": "Reference Conditioning",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "25": {
+ "inputs": {
+ "source_fps": 24,
+ "crop": "center",
+ "state": [
+ "23",
+ 0
+ ],
+ "latent": [
+ "24",
+ 1
+ ],
+ "audio_vae": [
+ "15",
+ 0
+ ],
+ "source_frames": [
+ "5",
+ 0
+ ],
+ "source_audio": [
+ "6",
+ 0
+ ]
+ },
+ "class_type": "MiniMaxH3ContexLoopSourceSlice",
+ "_meta": {
+ "title": "Source clip (frames + audio)",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "26": {
+ "inputs": {
+ "upscale_method": "area",
+ "largest_size": 512,
+ "image": [
+ "5",
+ 0
+ ]
+ },
+ "class_type": "ImageScaleToMaxDimension",
+ "_meta": {
+ "title": "Motion reference video (~512 px)",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "27": {
+ "inputs": {
+ "expression": "round(a * 24)",
+ "values.a": [
+ "23",
+ 10
+ ]
+ },
+ "class_type": "ComfyMathExpression",
+ "_meta": {
+ "title": "Clip start frame",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "28": {
+ "inputs": {
+ "batch_index": [
+ "27",
+ 1
+ ],
+ "length": [
+ "23",
+ 6
+ ],
+ "image": [
+ "26",
+ 0
+ ]
+ },
+ "class_type": "ImageFromBatch",
+ "_meta": {
+ "title": "Motion reference for this clip",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "29": {
+ "inputs": {
+ "upscale_method": "area",
+ "largest_size": 1008,
+ "image": [
+ "5",
+ 0
+ ]
+ },
+ "class_type": "ImageScaleToMaxDimension",
+ "_meta": {
+ "title": "SAM video (1008 px, SAM's own size)",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "30": {
+ "inputs": {
+ "batch_index": [
+ "27",
+ 1
+ ],
+ "length": [
+ "23",
+ 6
+ ],
+ "image": [
+ "29",
+ 0
+ ]
+ },
+ "class_type": "ImageFromBatch",
+ "_meta": {
+ "title": "SAM frames for this clip",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "31": {
+ "inputs": {
+ "noise_seed": [
+ "23",
+ 5
+ ]
+ },
+ "class_type": "RandomNoise",
+ "_meta": {
+ "title": "Clip Seed",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "32": {
+ "inputs": {
+ "detection_threshold": 0.35,
+ "max_objects": 0,
+ "detect_interval": 1,
+ "images": [
+ "30",
+ 0
+ ],
+ "model": [
+ "17",
+ 0
+ ],
+ "conditioning": [
+ "18",
+ 0
+ ]
+ },
+ "class_type": "SAM3_VideoTrack",
+ "_meta": {
+ "title": "SAM 3.1 track it",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "33": {
+ "inputs": {
+ "headroom": 0,
+ "hold_frames": 2,
+ "max_people": 0,
+ "track_data": [
+ "32",
+ 0
+ ]
+ },
+ "class_type": "H3PeopleMask",
+ "_meta": {
+ "title": "Tracked area",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "34": {
+ "inputs": {
+ "headroom": 0,
+ "hold_frames": 1,
+ "max_people": 0,
+ "track_data": [
+ "32",
+ 0
+ ]
+ },
+ "class_type": "H3PeopleMask",
+ "_meta": {
+ "title": "Tracked area, tight (for the grey shape)",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "35": {
+ "inputs": {
+ "blur": 0.04,
+ "face_blur": 0.05,
+ "images": [
+ "28",
+ 0
+ ],
+ "mask": [
+ "34",
+ 0
+ ],
+ "size": [
+ "34",
+ 1
+ ]
+ },
+ "class_type": "H3GreyMannequins",
+ "_meta": {
+ "title": "Turn it grey (shape and movement only)",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "36": {
+ "inputs": {
+ "expand": 20,
+ "incremental_expandrate": 0,
+ "tapered_corners": true,
+ "flip_input": false,
+ "blur_radius": 0,
+ "lerp_alpha": 1,
+ "decay_factor": 1,
+ "fill_holes": true,
+ "mask": [
+ "33",
+ 0
+ ]
+ },
+ "class_type": "GrowMaskWithBlur",
+ "_meta": {
+ "title": "Grow mask",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "37": {
+ "inputs": {
+ "cut_threshold": 40,
+ "images": [
+ "28",
+ 0
+ ],
+ "shot_prompt": [
+ "7",
+ 4
+ ]
+ },
+ "class_type": "H3ClipShots",
+ "_meta": {
+ "title": "Find this clip's cuts",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "38": {
+ "inputs": {
+ "prompt": [
+ "37",
+ 1
+ ],
+ "max_length": 500,
+ "sampling_mode": "off",
+ "thinking": false,
+ "use_default_template": true,
+ "mtp": "auto",
+ "clip": [
+ "8",
+ 0
+ ],
+ "image": [
+ "37",
+ 0
+ ]
+ },
+ "class_type": "TextGenerate",
+ "_meta": {
+ "title": "Write this clip's shot list (Qwen3-VL)",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "39": {
+ "inputs": {
+ "prompt": [
+ "23",
+ 4
+ ],
+ "shots": [
+ "38",
+ 0
+ ]
+ },
+ "class_type": "H3FillShots",
+ "_meta": {
+ "title": "Insert shot list into prompt",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "40": {
+ "inputs": {
+ "source": [
+ "39",
+ 0
+ ]
+ },
+ "class_type": "PreviewAny",
+ "_meta": {
+ "title": "Clip prompt (what H3 gets)",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "41": {
+ "inputs": {
+ "cell_selection": "runtime exact (latent max)",
+ "cell_adjust": 0,
+ "preview_frame": 0,
+ "overlay_opacity": 0.38,
+ "show_grid": true,
+ "show_source_outline": true,
+ "mask_meaning": "white = generate",
+ "image": [
+ "25",
+ 0
+ ],
+ "mask": [
+ "36",
+ 0
+ ]
+ },
+ "class_type": "MiniMaxH3ContexMaskGridPreview",
+ "_meta": {
+ "title": "Mask preview",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "42": {
+ "inputs": {
+ "images": [
+ "41",
+ 1
+ ]
+ },
+ "class_type": "PreviewImage",
+ "_meta": {
+ "title": "Mask preview (white = regenerated)",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "43": {
+ "inputs": {
+ "grow": 0,
+ "keep_audio": true,
+ "megapixels": 0,
+ "vae": [
+ "14",
+ 0
+ ],
+ "images": [
+ "25",
+ 0
+ ],
+ "mask": [
+ "36",
+ 0
+ ],
+ "audio_vae": [
+ "15",
+ 0
+ ],
+ "audio": [
+ "25",
+ 1
+ ]
+ },
+ "class_type": "MiniMaxH3FantasticVideoEditLatent",
+ "_meta": {
+ "title": "Edit latent (source + mask + audio)",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "44": {
+ "inputs": {
+ "mask_meaning": "white = generate",
+ "audio_mode": "preserve source audio",
+ "mask_conversion": "H3 exact (causal/token max)",
+ "target_latent": [
+ "43",
+ 0
+ ],
+ "mask": [
+ "36",
+ 0
+ ]
+ },
+ "class_type": "MiniMaxH3ContexMaskedTarget",
+ "_meta": {
+ "title": "Masked target",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "45": {
+ "inputs": {
+ "state": [
+ "23",
+ 0
+ ],
+ "conditioning": [
+ "24",
+ 0
+ ],
+ "vae": [
+ "14",
+ 0
+ ],
+ "latent": [
+ "44",
+ 0
+ ],
+ "audio_vae": [
+ "15",
+ 0
+ ]
+ },
+ "class_type": "MiniMaxH3ChainContext",
+ "_meta": {
+ "title": "Apply Clip Context",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "46": {
+ "inputs": {
+ "model": [
+ "12",
+ 0
+ ],
+ "conditioning": [
+ "45",
+ 0
+ ]
+ },
+ "class_type": "BasicGuider",
+ "_meta": {
+ "title": "Guider",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "47": {
+ "inputs": {
+ "scheduler": "simple",
+ "steps": [
+ "23",
+ 7
+ ],
+ "denoise": 1,
+ "model": [
+ "12",
+ 0
+ ]
+ },
+ "class_type": "BasicScheduler",
+ "_meta": {
+ "title": "Schedule",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "48": {
+ "inputs": {
+ "noise": [
+ "31",
+ 0
+ ],
+ "guider": [
+ "46",
+ 0
+ ],
+ "sampler": [
+ "16",
+ 0
+ ],
+ "sigmas": [
+ "47",
+ 0
+ ],
+ "latent_image": [
+ "45",
+ 3
+ ]
+ },
+ "class_type": "SamplerCustomAdvanced",
+ "_meta": {
+ "title": "Sample Video + Audio",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "49": {
+ "inputs": {
+ "samples": [
+ "48",
+ 0
+ ],
+ "vae": [
+ "14",
+ 0
+ ]
+ },
+ "class_type": "VAEDecode",
+ "_meta": {
+ "title": "Decode Video",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "50": {
+ "inputs": {
+ "samples": [
+ "48",
+ 0
+ ],
+ "vae": [
+ "15",
+ 0
+ ]
+ },
+ "class_type": "VAEDecodeAudio",
+ "_meta": {
+ "title": "Decode Audio",
+ "cnr_id": "comfy-core",
+ "ver": "0.42.0"
+ }
+ },
+ "51": {
+ "inputs": {
+ "trim_frames": [
+ "45",
+ 1
+ ],
+ "fps": 24,
+ "match_tail": true,
+ "audio_trim_mode": "sync_with_video",
+ "images": [
+ "49",
+ 0
+ ],
+ "audio": [
+ "50",
+ 0
+ ],
+ "state": [
+ "23",
+ 0
+ ]
+ },
+ "class_type": "MiniMaxH3LoopTrim",
+ "_meta": {
+ "title": "Trim Overlap",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "52": {
+ "inputs": {
+ "state": [
+ "23",
+ 0
+ ],
+ "images": [
+ "51",
+ 0
+ ],
+ "sampled_latent": [
+ "48",
+ 0
+ ],
+ "audio": [
+ "51",
+ 1
+ ],
+ "images_with_overlap": [
+ "51",
+ 2
+ ]
+ },
+ "class_type": "MiniMaxH3ChainSegmentSave",
+ "_meta": {
+ "title": "Save Clip + Checkpoint",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "53": {
+ "inputs": {
+ "enabled": false,
+ "play_notification_sound": false,
+ "auto_continue_timeout_minutes": 0,
+ "unload_models_while_waiting": false,
+ "assemble_partial_on_stop": true,
+ "partial_audio_source": "checkpointed",
+ "candidate_count": 1,
+ "review_each_candidate": false,
+ "state": [
+ "23",
+ 0
+ ],
+ "segment": [
+ "52",
+ 0
+ ],
+ "audio": [
+ "51",
+ 1
+ ]
+ },
+ "class_type": "MiniMaxH3ChainReview",
+ "_meta": {
+ "title": "Review (off = no pause)",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "54": {
+ "inputs": {
+ "between_scene_cleanup": "off",
+ "execution_mode": "recursive",
+ "flow": [
+ "22",
+ 0
+ ],
+ "state": [
+ "23",
+ 0
+ ],
+ "images": [
+ "51",
+ 0
+ ],
+ "sampled_latent": [
+ "48",
+ 0
+ ],
+ "segment": [
+ "53",
+ 0
+ ]
+ },
+ "class_type": "MiniMaxH3ChainLoopEnd",
+ "_meta": {
+ "title": "Loop End",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ },
+ "55": {
+ "inputs": {
+ "audio_source": "source",
+ "filename": "edit_%date:yyyy-MM-dd%",
+ "audio_bitrate": 256,
+ "copy_to_output": true,
+ "output_subfolder": "h3_oneclick_edit",
+ "blend_schedule": "plan",
+ "boundary_tone_match": "off",
+ "color_stabilization": "off",
+ "delete_checkpoints_after_assembly": false,
+ "generated_audio_join": "av_overlap",
+ "manifest": [
+ "54",
+ 0
+ ]
+ },
+ "class_type": "MiniMaxH3ChainAssemble",
+ "_meta": {
+ "title": "Final Video",
+ "cnr_id": "comfyui-workflow-encrypt",
+ "ver": "1.0.0"
+ }
+ }
+}
\ No newline at end of file