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 the workflow build scripts (#17)
mixbaga3b0f7effd91
diff --git a/README.md b/README.mdindex 7391dd3..92240e6 100644--- a/README.md+++ b/README.md@@ -9,7 +9,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`.-- **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 `user/default/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`.+- **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@@ -82,7 +82,7 @@ On Windows, double-click `start_openjutsu.bat` (ComfyUI must be running, or star`.env.local` sets `COMFY_BASE_URL=http://127.0.0.1:8189`. Leave `COMFY_API_KEY` empty for a local proxy. The base model and LoRA pickers read ComfyUI's model lists from `COMFYUI_URL` (default `http://127.0.0.1:8188`); without it they become text fields.-Uploads are limited to 512 MB total per request, including reference pictures. One upload/submission is accepted at a time per app process; other tabs can retry once it finishes. Generation continues in ComfyUI independently.+Uploads are limited to 512 MB total per request, including reference pictures. Uploads are streamed to a temporary folder, and up to three can arrive at once per app process; a fourth is asked to retry shortly. After a job ends, its uploads are removed from comfy-api-proxy, but the files stay in ComfyUI's `input/` folder. Generation continues in ComfyUI independently.A 6 s clip at 480p takes about 6–13 minutes on a 4060 Ti, most of it in H3 sampling. 736p is the default; 1080p is about 2.5× slower than 736p and needs much more memory. Custom sets an exact width × height from 256 to 2048 px a side (rounded to 32); the video is scaled and centre-cropped to that shape first. It needs the `short_edge` input of the H3 Swap Plan nodes in comfyui-h3-oneclick-swap.@@ -124,13 +124,13 @@ Each clip, SAM 3.1 tracks everyone at 1008 px (its own working size), and H3 Peo`workflows/mask.api.json` is the mask check: the same SAM, People Mask and grow settings over the whole video, with the mask tinted over the frames next to the mannequin, saved as an MP4.-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.+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 `workflows/build/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.+The swap workflows are built by the scripts in `workflows/build/`: `oneclick_single_build.js` (Simple), `oneclick_advanced_build.js` (Advanced; set `globalThis.H3_MAX_QUALITY = true` first for One pass per person), `oneclick_object_build.js` and `oneclick_control_build.js`. To rebuild one, open ComfyUI in the browser with an empty workflow tab (each script clears the active tab), run `const app = window.comfyAPI.app.app;` in the developer console, paste the script, enable its optional groups (hat fix, No lip-sync) where the export needs them, export **Workflow (API)** and replace the matching `workflows/*.api.json`. Fix faces is written by `python workflows/build/openjutsu_face_build.py`. If node ids change, update `NODES` in `lib/simple.ts`. `npm test` checks the pruning against the exports.## Deploy on the Comfy Developer Platformdiff --git a/lib/advanced.ts b/lib/advanced.tsindex 03917e4..8467ef2 100644--- a/lib/advanced.ts+++ b/lib/advanced.ts@@ -1,7 +1,7 @@// Advanced motion transfer: 1-4 characters, SAM tracks labelled by role, only the labelled people regenerated.// workflows/advanced.api.json (one pass) and advanced_maxq.api.json (one pass per person, 2 characters) are exported// with every picture, the hat fix and No lip-sync enabled; each request prunes what it does not use. Nodes are found by title, as-// the builder (ComfyUI user/default/oneclick_advanced_build.js) names them.+// the builder (workflows/build/oneclick_advanced_build.js) names them.import { MARGINS, dropNoLipSync, isLink, setMotionSize, setResolution, type ApiGraph, type Margin, type MotionSize, type Resolution } from "./simple.ts";export const MAX_CHARACTERS = 4;diff --git a/lib/control.ts b/lib/control.tsindex f5aadcf..7ea692a 100644--- a/lib/control.ts+++ b/lib/control.ts@@ -1,6 +1,6 @@// ControlNet picture swap: the whole frame, the main person and the setting, comes from the picture. A depth video of only// the main person (SAM 3.1 + Depth Anything V2) holds the framing, camera and poses through the H3 Fun ControlNet Union 2.0.-// workflows/control.api.json is exported (ComfyUI user/default/oneclick_control_build.js) with No lip-sync on; nodes are found by title.+// workflows/control.api.json is exported (workflows/build/oneclick_control_build.js) with No lip-sync on; nodes are found by title.import { nodeByTitle } from "./advanced.ts";import { dropNoLipSync, setResolution, setSection, type ApiGraph, type Resolution, type Section } from "./simple.ts";diff --git a/lib/face.ts b/lib/face.tsindex 08f0fa1..b738121 100644--- a/lib/face.ts+++ b/lib/face.ts@@ -1,6 +1,6 @@// Fix faces: post-processing for a finished video. The face of the person in the picture is regenerated by H3 in// independent overlapping chunks, crossfaded and pasted back; faces that already fill the frame are left alone.-// workflows/face.api.json is written by ComfyUI user/default/openjutsu_face_build.py with Follow the mouth on;+// workflows/face.api.json is written by workflows/build/openjutsu_face_build.py with Follow the mouth on;// each request prunes it. Nodes are found by title.import { nodeByTitle } from "./advanced.ts";import type { ApiGraph } from "./simple.ts";diff --git a/lib/object.ts b/lib/object.tsindex 0526c49..3638c6c 100644--- a/lib/object.ts+++ b/lib/object.ts@@ -1,5 +1,5 @@// 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;+// workflows/object.api.json is exported (workflows/build/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, setResolution, type ApiGraph, type MotionSize, type Resolution } from "./simple.ts";diff --git a/lib/simple.ts b/lib/simple.tsindex f006d50..6a9bcb0 100644--- a/lib/simple.ts+++ b/lib/simple.ts@@ -117,7 +117,7 @@ function maskSettings(source: ApiGraph, hatFix: boolean, margin: Margin, target:return graph;}-// The No lip-sync nodes, titled the same in every swap export (ComfyUI user/default/oneclick_*_build.js).+// The No lip-sync nodes, titled the same in every swap export (workflows/build/oneclick_*_build.js).const MUTE = /^Mute the (clip|reference) audio H3 hears$/;const NO_LIP_SYNC = /^(No lip-sync in the prompt|SAM: faces|SAM 3\.1 track faces|Faces \(shown on the mannequins?\))$/;diff --git a/workflows/build/oneclick_advanced_build.js b/workflows/build/oneclick_advanced_build.jsnew file mode 100644index 0000000..af2f3b9--- /dev/null+++ b/workflows/build/oneclick_advanced_build.js@@ -0,0 +1,349 @@+// Advanced motion transfer: SAM tracks labelled by role (Qwen3-VL), only the labelled people regenerated.+// Builds "H3 One-Click Advanced Swap (DMAD 6 step)". Set globalThis.H3_MAX_QUALITY = true before running it+// to build the max-quality variant instead: one H3 pass per person (Pictures 1 and 2), pass 2 editing pass 1's output.+// It clears the active tab, so run it in a fresh tab.+const MAX_QUALITY = globalThis.H3_MAX_QUALITY === true;+const g = app.graph;+g.clear();+const made = [];+let curGroup = null;+function add(type, title, pos, widgets = {}, mode = 0) {+ const n = LiteGraph.createNode(type);+ if (!n) throw new Error("no node " + type);+ if (title) n.title = title;+ n.pos = pos;+ g.add(n);+ for (const [k, v] of Object.entries(widgets)) {+ const w = /^\d+$/.test(k) ? n.widgets[+k] : n.widgets.find(w => w.name === k);+ if (!w) throw new Error(type + " has no widget " + k);+ w.value = v;+ w.callback?.(v, app.canvas, n);+ }+ n.mode = mode;+ made.push(n);+ curGroup?.members.push(n);+ return n;+}+function link(a, out, b, inp) {+ const o = typeof out === "number" ? out : a.outputs.findIndex(x => x.name === out);+ const i = b.inputs.findIndex(x => x.name === inp);+ if (o < 0 || i < 0) throw new Error(`link ${a.type}.${out} -> ${b.type}.${inp}`);+ a.connect(o, b, i);+}+function group(title, x, y, w, h, color) {+ const gr = new LiteGraph.LGraphGroup(title);+ gr.pos = [x, y]; gr.size = [w, h];+ if (color) gr.color = color;+ g.add(gr);+ gr.members = [];+ curGroup = gr;+ return gr;+}++const PIC = "Describe the person in this picture for a casting sheet, in one sentence of about 40 words: apparent age and gender, hair, facial hair, skin tone, build, and their complete outfit including footwear. No preamble, no background.";+const PEOPLE = "These are frames from one video, in time order. List the people who appear most, up to four, the person with the most screen time first. Write one numbered line per person: first their role in the video in two to four words, without gender, that stays true in every shot, then \" - \" and how they look, like \"1. the guitarist - tall man with a grey beard in a denim jacket\". Each person appears once. Output only the list.";+const GEN_OFF = {sampling_mode: "off"};+const PICTURES = MAX_QUALITY ? 2 : 4;++// ---------------- 1 · UPLOAD ----------------+const note = add("MarkdownNote", "START HERE", [40, 60], {0:+`# One-click advanced swap (H3)${MAX_QUALITY ? " - max quality" : ""}++1. **Picture 1, Picture 2** - drop a photo per character.${MAX_QUALITY ? "" : " Pictures 3-4 are optional; turn their groups on with the **ON / OFF** switches, in order."}+2. **Source video** - upload the video. Its camera, cuts, motion and soundtrack are kept.+3. Press **Run**.++The graph then, per ~6 s clip:+- tracks every person with SAM 3.1 and shows each track, once per shot, to Qwen3-VL 8B, which says which picture's role it is (or "other"),+- regenerates only the people with a picture; extras and passers-by stay untouched,+- writes the shot list from frames where each labelled person is outlined in their subject's colour, so the prompt names the same people the masks do.+${MAX_QUALITY ? "- runs H3 once per person: pass 1 replaces Subject 1 with Picture 1, pass 2 replaces Subject 2 in pass 1's result with Picture 2 (about 2x the time).\n" : ""}+**Who becomes who:** type one line per picture in **roles**, for example:+\`\`\`+the singer+the drummer+\`\`\`+Name the role or position, not the clothes. You can add how they look after " - " (\`the drummer - man in a black cap\`); that only helps the labeller and never reaches H3. Blank roles use the auto-detected people.++**Check the labels:** "Track labels" and "Who is each track" show what Qwen decided for each clip.+**New take:** change **seed**. **Faster test:** set **resolution** to 480p. **Hats:** turn on **OPTIONAL - Hat fix** to also replace hats worn by the labelled people.+**Not singing along:** if the soundtrack has vocals but the people do not sing or talk, turn on **OPTIONAL - No lip-sync** so the new people do not lip-sync the song (about 30 s extra per clip).`});+note.size = [500, 900];++const pics = [], picTexts = [];+const files = ["", "", "example.png", "example.png"];+for (let i = 0; i < PICTURES; i++) {+ const x = 580 + i * 380;+ const title = i < 2 ? `Picture ${i + 1}` : `OPTIONAL - Picture ${i + 1}`;+ group(title, x - 20, 0, 360, 960, i < 2 ? "#3f789e" : "#88a");+ const load = add("LoadImage", `Picture ${i + 1}`, [x, 60], {image: files[i]}, i < 2 ? 0 : 4);+ load.size = [320, 420];+ const scale = add("ImageScaleToMaxDimension", "Shrink for the describer", [x, 520], {upscale_method: "area", largest_size: 768}, i < 2 ? 0 : 4);+ const gen = add("TextGenerate", `Describe picture ${i + 1}`, [x, 640], {prompt: PIC, max_length: 120, ...GEN_OFF}, i < 2 ? 0 : 4);+ gen.size = [320, 260];+ link(load, 0, scale, "image");+ link(scale, 0, gen, "image");+ pics.push(load); picTexts.push(gen);+}++const vx = 2100;+group("Source video", vx - 20, 0, 420, 1580, "#3f789e");+const video = add("VHS_LoadVideo", "Source video (people get replaced)", [vx, 60], {video: "", force_rate: 24, format: "None"});+video.size = [380, 560];+const soundtrack = add("TrimAudioDuration", "Soundtrack (whole video)", [vx, 650], {start_index: 0, duration: 36000});+link(video, "audio", soundtrack, "audio");+const nth = add("VHS_SelectEveryNthImage", "One frame every 2 s", [vx, 700], {select_every_nth: 48, skip_first_images: 24});+const first20 = add("ImageFromBatch", "At most 20 frames", [vx, 800], {batch_index: 0, length: 20});+const vscale = add("ImageScaleToMaxDimension", "Shrink for the describer", [vx, 920], {upscale_method: "area", largest_size: 640});+const people = add("TextGenerate", "Who is in the video", [vx, 1020], {prompt: PEOPLE, max_length: 160, ...GEN_OFF});+people.size = [380, 240];+link(video, "IMAGE", nth, "images");+link(nth, 0, first20, "image");+link(first20, 0, vscale, "image");+link(vscale, 0, people, "image");++// ---------------- 2 · SETTINGS ----------------+const sx = 2560;+group("SETTINGS (optional)", sx - 20, 0, 460, 1300, "#a1309b");+const swapPlan = add("H3AdvancedSwapPlan", "Swap Plan (roles, seed, size)", [sx, 60], {seed: 0, control_after_generate: "fixed"});+swapPlan.size = [420, 460];+const bypass = add("Fast Groups Bypasser (rgthree)", "ON / OFF SWITCHES", [sx, 560]);+Object.assign(bypass.properties, {matchTitle: "OPTIONAL", sort: "position"});+bypass.size = [420, 160];+const qwen = add("CLIPLoader", "Describer: Qwen3-VL 8B", [sx, 800], {clip_name: "qwen3vl_8b_int8_convrot.safetensors", type: "stable_diffusion"});+qwen.size = [420, 110];+const qwenFree = add("Note", "", [sx, 960], {0: "The describer reads your pictures and the video once (about 40 s), then per clip labels the tracks (about 10 s) and writes a shot list (about 20 s)."});+qwenFree.size = [420, 80];++link(video, "IMAGE", swapPlan, "source_frames");+pics.forEach((p, i) => link(p, 0, swapPlan, `picture_${i + 1}`));+picTexts.forEach((t, i) => link(t, 0, swapPlan, `picture_${i + 1}_text`));+link(people, 0, swapPlan, "video_people");+for (const t of [...picTexts, people]) link(qwen, 0, t, "clip");++// ---------------- 3 · ENGINE ----------------+const ex = 3100;+group("ENGINE - no need to touch", ex - 20, 0, 3300, 1900, "#444");+const unet = add("UNETLoader", "H3 Diffusion Model", [ex, 60], {unet_name: "minimax_h3_ref2va_pruned_int8_convrot.safetensors"});+const lora = add("LoraLoaderModelOnly", "DMAD LoRA", [ex, 200], {lora_name: "minimax_h3_DMAD_4step_full_lora_avg_rank_39_bf16.safetensors", strength_model: 1.0});+const attn = add("ModelAttentionBackend", "Comfy Kitchen Attention", [ex, 340], {0: "comfy kitchen attention"});+const shift = add("MiniMaxH3SigmaShift", "Sigma Shift", [ex, 440], {0: 12, 1: 2});+const te = add("CLIPLoader", "H3 Text Encoder", [ex, 560], {clip_name: "qwen3vl_32b_minimax_h3_int4_convrot.safetensors", type: "minimax"});+const vae = add("VAELoader", "Video VAE", [ex, 700], {vae_name: "minimax_h3_video_vae_int8_convrot.safetensors"});+const avae = add("VAELoader", "Audio VAE", [ex, 800], {vae_name: "minimax_h3_audio_vae_fp32.safetensors"});+const sampler = add("KSamplerSelect", "Sampler", [ex, 900], {sampler_name: "euler"});+const sam = add("CheckpointLoaderSimple", "SAM 3.1", [ex, 1000], {ckpt_name: "sam3.1_multiplex_fp16.safetensors"});+const samText = add("CLIPTextEncode", "SAM: what to replace", [ex, 1140], {text: "person"});+samText.size = [320, 100];+link(unet, 0, lora, "model");+link(lora, 0, attn, "model");+link(attn, 0, shift, "model");+link(sam, 1, samText, "clip");++const lx = ex + 400;+const profile = add("MiniMaxH3GenerationProfile", "Generation Profile", [lx, 60], {scene_continuity: "Hard picture + protected audio", audio_profile: "Generate audio"});+const plan = add("MiniMaxH3ChainPlanModern", "Production Plan (filled by Swap Plan)", [lx, 220], {crop: "center", default_steps: 6, segment_crf: 16, run_name: ""});+plan.size = [360, 500];+const timeline = add("MiniMaxH3SourceTimeline", "Source soundtrack", [lx, 760]);+const start = add("MiniMaxH3ChainLoopStart", "Loop Start", [lx, 960]);+const cur = add("MiniMaxH3ChainCurrent", "Current Clip", [lx, 1160]);+link(profile, 0, plan, "chain_policy");+link(swapPlan, "plan_json", plan, "plan_json_input");+link(swapPlan, "width", plan, "width");+link(swapPlan, "height", plan, "height");+link(swapPlan, "run_name", plan, "run_name");+link(soundtrack, 0, timeline, "source_audio");+link(plan, 0, start, "plan");+link(timeline, 0, start, "source_timeline");+link(start, "state", cur, "state");++// per clip: track, label the tracks by role, cut lists+const tx = lx + 420;+const clipStart = add("ComfyMathExpression", "Clip start frame", [tx, 60], {0: "round(a * 24)"});+const motionAll = add("ImageScaleToMaxDimension", "Motion reference video (~512 px)", [vx, 1340], {upscale_method: "area", largest_size: 512});+const motion = add("ImageFromBatch", "Motion reference for this clip", [tx, 160], {batch_index: 0, length: 141});+const samAll = add("ImageScaleToMaxDimension", "SAM video (1008 px, SAM's own size)", [vx, 1460], {upscale_method: "area", largest_size: 1008});+const samClip = add("ImageFromBatch", "SAM frames for this clip", [tx, 260], {batch_index: 0, length: 141});+const track = add("SAM3_VideoTrack", "SAM 3.1 track every person", [tx, 360], {detection_threshold: 0.35, max_objects: 0, detect_interval: 1});+const crops = add("H3TrackCrops", "Show each track per shot", [tx, 520], {cut_threshold: 40});+const roles = add("H3TrackRoles", "Who is each track (Qwen3-VL)", [tx, 640]);+const labelPrev = add("PreviewAny", "Track labels", [tx, 960]);+const cropPrev = add("PreviewImage", "Who is each track (what Qwen saw)", [tx, 1100]);+cropPrev.size = [360, 300];+const outline = add("H3RoleMask", "Labelled people (outlined for the shot list)", [tx, 1340], {headroom: 0, hold_frames: 0, subject: 0});+const shotFrames = add("H3ClipShots", "Find this clip's cuts", [tx, 1460], {cut_threshold: 40});+const shotGen = add("TextGenerate", "Write this clip's shot list (Qwen3-VL)", [tx, 1560], {max_length: 500, ...GEN_OFF});+shotGen.size = [360, 200];+link(video, "IMAGE", motionAll, "image");+link(motionAll, 0, motion, "image");+link(cur, "audio_start", clipStart, "values.a");+link(clipStart, 1, motion, "batch_index");+link(cur, "length", motion, "length");+link(video, "IMAGE", samAll, "image");+link(samAll, 0, samClip, "image"); link(clipStart, 1, samClip, "batch_index"); link(cur, "length", samClip, "length");+link(samClip, 0, track, "images"); link(sam, 0, track, "model"); link(samText, 0, track, "conditioning");+link(track, 0, crops, "track_data"); link(samClip, 0, crops, "images"); link(swapPlan, "people", crops, "people");+link(qwen, 0, roles, "clip"); link(crops, "crops", roles, "crops"); link(crops, "segments", roles, "segments");+link(roles, 0, labelPrev, "source");+link(crops, "crops", cropPrev, "images");+link(track, 0, outline, "track_data"); link(roles, 0, outline, "labels");+link(motion, 0, shotFrames, "images"); link(outline, "role_map", shotFrames, "role_map");+link(swapPlan, "shot_prompt", shotFrames, "shot_prompt");+link(shotFrames, 0, shotGen, "image");+link(qwen, 0, shotGen, "clip");+link(shotFrames, 1, shotGen, "prompt");++const engineGroup = curGroup;+const hatGroup = group("OPTIONAL - Hat fix (also mask hats of the labelled people)", 540, 1000, 400, 760, "#88a");+const hatText = add("CLIPTextEncode", "SAM: hats", [600, 1060], {text: "hat"}, 4);+hatText.size = [320, 100];+const hatTrack = add("SAM3_VideoTrack", "SAM 3.1 track hats", [600, 1200], {detection_threshold: 0.35, max_objects: 0, detect_interval: 1}, 4);+const hatMask = add("SAM3_TrackToMask", "All hats", [600, 1400], {object_indices: ""}, 4);+link(sam, 1, hatText, "clip");+link(samClip, 0, hatTrack, "images"); link(sam, 0, hatTrack, "model"); link(hatText, 0, hatTrack, "conditioning");+link(hatTrack, 0, hatMask, "track_data");+group("OPTIONAL - No lip-sync (they don't sing along)", 40, 1000, 460, 760, "#88a");+const noLip = add("PrimitiveBoolean", "No lip-sync in the prompt", [100, 1060], {value: true}, 4);+const faceText = add("CLIPTextEncode", "SAM: faces", [100, 1160], {text: "face"}, 4);+faceText.size = [320, 100];+const faceTrack = add("SAM3_VideoTrack", "SAM 3.1 track faces", [100, 1300], {detection_threshold: 0.2, max_objects: 0, detect_interval: 1}, 4);+const faces = add("H3PeopleMask", "Faces (shown on the mannequins)", [100, 1500], {headroom: 0, hold_frames: 0, max_people: 0}, 4);+const muteClip = add("AudioAdjustVolume", "Mute the clip audio H3 hears", [100, 1640], {volume: -100}, 4);+const muteRef = add("AudioAdjustVolume", "Mute the reference audio H3 hears", [100, 1740], {volume: -100}, 4);+link(noLip, 0, swapPlan, "no_lip_sync");+link(sam, 1, faceText, "clip");+link(samClip, 0, faceTrack, "images"); link(sam, 0, faceTrack, "model"); link(faceText, 0, faceTrack, "conditioning");+link(faceTrack, 0, faces, "track_data");+link(soundtrack, 0, muteClip, "audio");+link(cur, "source_audio_slice", muteRef, "audio");+curGroup = engineGroup;++const src = add("MiniMaxH3ContexLoopSourceSlice", "Source clip (frames + audio)", [lx, 1360], {source_fps: 24, crop: "center"});+const noise = add("RandomNoise", "Clip Seed", [lx, 1560], {control_after_generate: "fixed"});+link(cur, "state", src, "state");+link(avae, 0, src, "audio_vae");+link(video, "IMAGE", src, "source_frames"); link(muteClip, 0, src, "source_audio");+link(cur, "noise_seed", noise, "noise_seed");++// One H3 pass: masks the labelled people (or only `subject`), hides them as grey figures in `motionIn`,+// and regenerates them in `frames` (null = the source clip).+function pass(x, subject, frames, motionIn, label) {+ const hatY = 1500 + (subject || 0) * 300;+ const toMask = add("H3RoleMask", `${label}: labelled people (+ headroom)`, [x, 60], {headroom: 0.1, hold_frames: 2, subject: subject || 0});+ const body = add("H3RoleMask", `${label}: labelled people, no headroom (mannequin)`, [x, 220], {headroom: 0, hold_frames: 1, subject: subject || 0});+ const grow = add("GrowMaskWithBlur", `${label}: grow mask (~4% of the frame)`, [x, 380], {expand: 40, incremental_expandrate: 0, tapered_corners: true, flip_input: false, blur_radius: 0, lerp_alpha: 1, decay_factor: 1, fill_holes: true});+ const mannequins = add("H3GreyMannequins", `${label}: hide them (grey mannequins)`, [x, 640], {blur: 0.04});+ link(track, 0, toMask, "track_data"); link(roles, 0, toMask, "labels");+ link(track, 0, body, "track_data"); link(roles, 0, body, "labels");+ curGroup = hatGroup;+ const hatNear = add("GrowMaskWithBlur", `${label}: hat search area (person + 60 px)`, [600, hatY], {expand: 60, incremental_expandrate: 0, tapered_corners: true, flip_input: false, blur_radius: 0, lerp_alpha: 1, decay_factor: 1, fill_holes: true}, 4);+ const hatOwn = add("MaskComposite", `${label}: only their hats`, [600, hatY + 100], {x: 0, y: 0, operation: "multiply"}, 4);+ const hatAdd = add("MaskComposite", `${label}: people + hats`, [600, hatY + 200], {x: 0, y: 0, operation: "add"}, 4);+ curGroup = engineGroup;+ link(toMask, 0, hatNear, "mask");+ link(hatMask, 0, hatOwn, "destination"); link(hatNear, 0, hatOwn, "source");+ link(toMask, 0, hatAdd, "destination"); link(hatOwn, 0, hatAdd, "source");+ link(hatAdd, 0, grow, "mask");+ link(motionIn, 0, mannequins, "images"); link(body, "mask", mannequins, "mask"); link(body, "size", mannequins, "size");+ link(faces, 0, mannequins, "faces"); link(faces, 1, mannequins, "face_size");++ const ref = add("MiniMaxH3ReferenceToVideo", `${label}: reference conditioning`, [x + 420, 60], {ref_image_size: "match"});+ ref.size = [360, 300];+ const fill = add("H3FillShots", `${label}: insert shot list into prompt`, [x + 420, 420]);+ const promptPrev = add("PreviewAny", `${label}: clip prompt (what H3 gets)`, [x + 420, 520]);+ if (subject) {+ const subjectPrompt = add("H3SubjectPrompt", `${label}: prompt for Subject ${subject} only`, [x + 420, 340], {subject});+ link(swapPlan, "subject_prompts", subjectPrompt, "subject_prompts"); link(cur, "clip_index", subjectPrompt, "clip_index");+ link(subjectPrompt, 0, fill, "prompt");+ link(pics[subject - 1], 0, ref, "ref_images.ref_image_0");+ } else {+ link(cur, "prompt", fill, "prompt");+ link(outline, "role_map", fill, "role_map");+ pics.forEach((p, i) => link(p, 0, ref, `ref_images.ref_image_${i}`));+ }+ link(shotGen, 0, fill, "shots");+ link(fill, 0, promptPrev, "source");+ link(te, 0, ref, "clip"); link(vae, 0, ref, "vae"); link(avae, 0, ref, "audio_vae");+ link(fill, 0, ref, "prompt"); link(cur, "width", ref, "width"); link(cur, "height", ref, "height"); link(cur, "length", ref, "length");+ link(mannequins, 0, ref, "ref_videos.ref_video_0");+ link(muteRef, 0, ref, "ref_video_audios.ref_video_audio_0");++ const edit = add("MiniMaxH3FantasticVideoEditLatent", `${label}: edit latent (source + mask + audio)`, [x + 420, 640], {grow: 0, keep_audio: true, megapixels: 0});+ const masked = add("MiniMaxH3ContexMaskedTarget", `${label}: masked target`, [x + 420, 840], {mask_meaning: "white = generate", audio_mode: "preserve source audio"});+ const ctx = add("MiniMaxH3ChainContext", `${label}: apply clip context`, [x + 420, 1020]);+ link(vae, 0, edit, "vae"); link(grow, 0, edit, "mask");+ link(avae, 0, edit, "audio_vae"); link(src, "scene_audio", edit, "audio");+ if (frames) link(frames, 0, edit, "images"); else link(src, "scene_frames", edit, "images");+ link(edit, 0, masked, "target_latent"); link(grow, 0, masked, "mask");+ link(cur, "state", ctx, "state"); link(ref, 0, ctx, "conditioning"); link(vae, 0, ctx, "vae");+ link(masked, 0, ctx, "latent"); link(avae, 0, ctx, "audio_vae");++ const guider = add("BasicGuider", `${label}: guider`, [x + 840, 60]);+ const sched = add("BasicScheduler", `${label}: schedule`, [x + 840, 160], {scheduler: "simple", denoise: 1});+ const sca = add("SamplerCustomAdvanced", `${label}: sample video + audio`, [x + 840, 320]);+ const dec = add("VAEDecode", `${label}: decode video`, [x + 840, 520]);+ link(shift, 0, guider, "model"); link(ctx, 0, guider, "conditioning");+ link(shift, 0, sched, "model"); link(cur, "steps", sched, "steps");+ link(noise, 0, sca, "noise"); link(guider, 0, sca, "guider"); link(sampler, 0, sca, "sampler");+ link(sched, 0, sca, "sigmas"); link(ctx, 3, sca, "latent_image");+ link(sca, 0, dec, "samples"); link(vae, 0, dec, "vae");+ return {grow, ctx, sca, dec, ref};+}++const px = tx + 420;+let last, maskShown;+if (MAX_QUALITY) {+ const a = pass(px, 1, null, motion, "Pass 1");+ const motion2 = add("ImageScaleToMaxDimension", "Pass 2: motion reference from pass 1 (~512 px)", [px + 1260, 760], {upscale_method: "area", largest_size: 512});+ link(a.dec, 0, motion2, "image");+ last = pass(px + 1680, 2, a.dec, motion2, "Pass 2");+ link(a.ref, 1, src, "latent");+ maskShown = a.grow;+} else {+ last = pass(px, 0, null, motion, "Swap");+ link(last.ref, 1, src, "latent");+ maskShown = last.grow;+}++const mx = px + (MAX_QUALITY ? 2940 : 1260);+const gridPrev = add("MiniMaxH3ContexMaskGridPreview", "Mask preview", [mx, 60]);+const prevImg = add("PreviewImage", "Mask preview (white = regenerated)", [mx, 420]);+prevImg.size = [360, 300];+link(src, "scene_frames", gridPrev, "image"); link(maskShown, 0, gridPrev, "mask");+link(gridPrev, "grid_preview", prevImg, "images");++const kx = mx + 420;+const deca = add("VAEDecodeAudio", "Decode Audio", [kx, 60]);+const trim = add("MiniMaxH3LoopTrim", "Trim Overlap", [kx, 160], {trim_frames: 0, fps: 24, match_tail: true, audio_trim_mode: "sync_with_video"});+link(last.sca, 0, deca, "samples"); link(avae, 0, deca, "vae");+link(last.dec, 0, trim, "images"); link(last.ctx, 1, trim, "trim_frames"); link(deca, 0, trim, "audio"); link(cur, "state", trim, "state");++const ox = kx + 400;+const save = add("MiniMaxH3ChainSegmentSave", "Save Clip + Checkpoint", [ox, 60]);+const review = add("MiniMaxH3ChainReview", "Review (off = no pause)", [ox, 260], {enabled: false});+const end = add("MiniMaxH3ChainLoopEnd", "Loop End", [ox, 600], {between_scene_cleanup: "off", execution_mode: "recursive"});+const asm = add("MiniMaxH3ChainAssemble", "Final Video", [ox, 800], {audio_source: "source", filename: "advanced_swap_%date:yyyy-MM-dd%", copy_to_output: true, output_subfolder: "h3_oneclick_swap"});+link(cur, "state", save, "state"); link(trim, 0, save, "images"); link(last.sca, 0, save, "sampled_latent");+link(trim, 1, save, "audio"); link(trim, 2, save, "images_with_overlap");+link(cur, "state", review, "state"); link(save, 0, review, "segment"); link(trim, 1, review, "audio");+link(start, "flow", end, "flow"); link(cur, "state", end, "state"); link(trim, 0, end, "images");+link(last.sca, 0, end, "sampled_latent"); link(review, 0, end, "segment");+link(end, 0, asm, "manifest");++// stack each column by real node height, then fit groups around their nodes+const cols = {};+for (const n of made) (cols[n.pos[0]] ??= []).push(n);+for (const col of Object.values(cols)) {+ col.sort((a, b) => a.pos[1] - b.pos[1]);+ let y = col[0].pos[1];+ for (const n of col) { n.pos[1] = y; y += n.size[1] + LiteGraph.NODE_TITLE_HEIGHT + 30; }+}+for (const gr of g._groups) {+ const inside = gr.members;+ if (!inside.length) continue;+ const bottom = Math.max(...inside.map(n => n.pos[1] + n.size[1]));+ const right = Math.max(...inside.map(n => n.pos[0] + n.size[0]));+ gr.size = [Math.max(gr.size[0], right - gr.pos[0] + 20), bottom - gr.pos[1] + 30];+}+app.graph.setDirtyCanvas(true, true);+JSON.stringify({maxQuality: MAX_QUALITY, nodes: g._nodes.length, links: Object.keys(g.links).length ?? g.links.size});diff --git a/workflows/build/oneclick_control_build.js b/workflows/build/oneclick_control_build.jsnew file mode 100644index 0000000..eb0a261--- /dev/null+++ b/workflows/build/oneclick_control_build.js@@ -0,0 +1,278 @@+const g = app.graph;+g.clear();+const made = [];+let curGroup = null;+function add(type, title, pos, widgets = {}, mode = 0) {+ const n = LiteGraph.createNode(type);+ if (!n) throw new Error("no node " + type);+ if (title) n.title = title;+ n.pos = pos;+ g.add(n);+ for (const [k, v] of Object.entries(widgets)) {+ const w = /^\d+$/.test(k) ? n.widgets[+k] : n.widgets.find(w => w.name === k);+ if (!w) throw new Error(type + " has no widget " + k);+ w.value = v;+ w.callback?.(v, app.canvas, n);+ }+ n.mode = mode;+ made.push(n);+ curGroup?.members.push(n);+ return n;+}+function link(a, out, b, inp) {+ const o = typeof out === "number" ? out : a.outputs.findIndex(x => x.name === out);+ const i = b.inputs.findIndex(x => x.name === inp);+ if (o < 0 || i < 0) throw new Error(`link ${a.type}.${out} -> ${b.type}.${inp}`);+ a.connect(o, b, i);+}+function group(title, x, y, w, h, color) {+ const gr = new LiteGraph.LGraphGroup(title);+ gr.pos = [x, y]; gr.size = [w, h];+ if (color) gr.color = color;+ g.add(gr);+ gr.members = [];+ curGroup = gr;+ return gr;+}++const PIC = "Describe the person in this picture for a casting sheet, in one sentence of about 40 words: apparent age and gender, hair, facial hair, skin tone, build, and their complete outfit including footwear. No preamble, no background.";+const PEOPLE = "These are frames from one video, in time order. List the people who appear most, up to four, the person with the most screen time first. Write one numbered line per person: first their role in the video in two to four words, without gender, that stays true in every shot, then \" - \" and how they look, like \"1. the guitarist - tall man with a grey beard in a denim jacket\". Each person appears once. Output only the list.";+const GEN_OFF = {sampling_mode: "off"};++// ---------------- 1 · UPLOAD ----------------+const note = add("MarkdownNote", "START HERE", [40, 60], {0:+`# One-click picture swap with ControlNet (H3)++1. **Picture** - drop a photo of your character in the place they should be.+2. **Source video** - upload the video. Its main person (the one on screen most) becomes the person in the picture, and the whole setting becomes the picture's; the framing, camera movement, motion and soundtrack are kept.+3. Press **Run**.++That's it. The graph then:+- describes your picture and the people in the video, and writes a shot list per clip (Qwen3-VL 8B, local),+- splits the video into ~6 s clips that overlap by 39 frames,+- tracks the main person with SAM 3.1 and makes a depth video of only them (Depth Anything V2),+- regenerates the whole frame from the picture, held to that depth by the H3 Fun ControlNet Union 2.0 (DMAD, 6 steps),+- joins the clips with the original audio.++The final MP4 lands in **output/h3_oneclick_swap/**. Each clip is saved as it finishes, so a crash resumes where it stopped when you press Run again with the same inputs.++Everyone else in the video is dropped: the picture's setting and its people replace the whole background.+**New take:** change **seed**. **Faster test:** set **resolution** to 480p.+**Not singing along:** if the soundtrack has vocals but the person does not sing or talk, turn on **OPTIONAL - No lip-sync** so the new person does not lip-sync the song.`});+note.size = [500, 860];++const pics = [], picTexts = [];+const files = [""];+for (let i = 0; i < 1; i++) {+ const x = 580 + i * 380;+ const title = i === 0 ? "Picture 1" : `OPTIONAL - Picture ${i + 1}`;+ group(title, x - 20, 0, 360, 960, i === 0 ? "#3f789e" : "#88a");+ const load = add("LoadImage", `Picture ${i + 1}`, [x, 60], {image: files[i]}, i < 2 ? 0 : 4);+ load.size = [320, 420];+ const scale = add("ImageScaleToMaxDimension", "Shrink for the describer", [x, 520], {upscale_method: "area", largest_size: 768}, i < 2 ? 0 : 4);+ const gen = add("TextGenerate", `Describe picture ${i + 1}`, [x, 640], {prompt: PIC, max_length: 120, ...GEN_OFF}, i < 2 ? 0 : 4);+ gen.size = [320, 260];+ link(load, 0, scale, "image");+ link(scale, 0, gen, "image");+ pics.push(load); picTexts.push(gen);+}++const vx = 2100;+group("Source video", vx - 20, 0, 420, 1580, "#3f789e");+const video = add("VHS_LoadVideo", "Source video (people get replaced)", [vx, 60], {video: "", force_rate: 24, format: "None"});+video.size = [380, 560];+const soundtrack = add("TrimAudioDuration", "Soundtrack (whole video)", [vx, 650], {start_index: 0, duration: 36000});+link(video, "audio", soundtrack, "audio");+const nth = add("VHS_SelectEveryNthImage", "One frame every 2 s", [vx, 700], {select_every_nth: 48, skip_first_images: 24});+const first20 = add("ImageFromBatch", "At most 20 frames", [vx, 800], {batch_index: 0, length: 20});+const vscale = add("ImageScaleToMaxDimension", "Shrink for the describer", [vx, 920], {upscale_method: "area", largest_size: 640});+const people = add("TextGenerate", "Who is in the video", [vx, 1020], {prompt: PEOPLE, max_length: 160, ...GEN_OFF});+people.size = [380, 240];+link(video, "IMAGE", nth, "images");+link(nth, 0, first20, "image");+link(first20, 0, vscale, "image");+link(vscale, 0, people, "image");++// ---------------- 2 · SETTINGS ----------------+const sx = 2560;+group("SETTINGS (optional)", sx - 20, 0, 460, 1300, "#a1309b");+const swapPlan = add("H3PictureSwapPlan", "Swap Plan (roles, seed, size)", [sx, 60], {seed: 0, control_after_generate: "fixed"});+swapPlan.size = [420, 420];+const bypass = add("Fast Groups Bypasser (rgthree)", "ON / OFF SWITCHES", [sx, 560]);+Object.assign(bypass.properties, {matchTitle: "OPTIONAL", sort: "position"});+bypass.size = [420, 160];+const qwen = add("CLIPLoader", "Describer: Qwen3-VL 8B", [sx, 800], {clip_name: "qwen3vl_8b_int8_convrot.safetensors", type: "stable_diffusion"});+qwen.size = [420, 110];+const qwenFree = add("Note", "", [sx, 960], {0: "The describer reads your pictures and the video once (about 40 s), then writes a shot list for every clip (about 20 s each)."});+qwenFree.size = [420, 80];++link(video, "IMAGE", swapPlan, "source_frames");+pics.forEach((p, i) => link(p, 0, swapPlan, `picture_${i + 1}`));+picTexts.forEach((t, i) => link(t, 0, swapPlan, `picture_${i + 1}_text`));+link(people, 0, swapPlan, "video_people");+for (const t of [...picTexts, people]) link(qwen, 0, t, "clip");++// ---------------- 3 · ENGINE ----------------+const ex = 3100;+group("ENGINE - no need to touch", ex - 20, 0, 2900, 1900, "#444");+const unet = add("UNETLoader", "H3 Diffusion Model", [ex, 60], {unet_name: "minimax_h3_ref2va_pruned_int8_convrot.safetensors"});+const lora = add("LoraLoaderModelOnly", "DMAD LoRA", [ex, 200], {lora_name: "minimax_h3_DMAD_4step_full_lora_avg_rank_39_bf16.safetensors", strength_model: 1.0});+const attn = add("ModelAttentionBackend", "Comfy Kitchen Attention", [ex, 340], {0: "comfy kitchen attention"});+const shift = add("MiniMaxH3SigmaShift", "Sigma Shift", [ex, 440], {0: 12, 1: 2});+const te = add("CLIPLoader", "H3 Text Encoder", [ex, 560], {clip_name: "qwen3vl_32b_minimax_h3_int4_convrot.safetensors", type: "minimax"});+const vae = add("VAELoader", "Video VAE", [ex, 700], {vae_name: "minimax_h3_video_vae_int8_convrot.safetensors"});+const avae = add("VAELoader", "Audio VAE", [ex, 800], {vae_name: "minimax_h3_audio_vae_fp32.safetensors"});+const sampler = add("KSamplerSelect", "Sampler", [ex, 900], {sampler_name: "euler"});+const sam = add("CheckpointLoaderSimple", "SAM 3.1", [ex, 1000], {ckpt_name: "sam3.1_multiplex_fp16.safetensors"});+const samText = add("CLIPTextEncode", "SAM: what to replace", [ex, 1140], {text: "person"});+samText.size = [320, 100];+link(unet, 0, lora, "model");+link(lora, 0, attn, "model");+link(attn, 0, shift, "model");+link(sam, 1, samText, "clip");++const lx = ex + 400;+const profile = add("MiniMaxH3GenerationProfile", "Generation Profile", [lx, 60], {scene_continuity: "Hard picture + protected audio", audio_profile: "Generate audio"});+const plan = add("MiniMaxH3ChainPlanModern", "Production Plan (filled by Swap Plan)", [lx, 220], {crop: "center", default_steps: 6, segment_crf: 16, run_name: ""});+plan.size = [360, 500];+const timeline = add("MiniMaxH3SourceTimeline", "Source soundtrack", [lx, 760]);+const start = add("MiniMaxH3ChainLoopStart", "Loop Start", [lx, 960]);+const cur = add("MiniMaxH3ChainCurrent", "Current Clip", [lx, 1160]);+link(profile, 0, plan, "chain_policy");+link(swapPlan, "plan_json", plan, "plan_json_input");+link(swapPlan, "width", plan, "width");+link(swapPlan, "height", plan, "height");+link(swapPlan, "run_name", plan, "run_name");+link(soundtrack, 0, timeline, "source_audio");+link(plan, 0, start, "plan");+link(timeline, 0, start, "source_timeline");+link(start, "state", cur, "state");++const cx = lx + 420;+const ref = add("MiniMaxH3ReferenceToVideo", "Reference Conditioning", [cx, 60], {ref_image_size: "match"});+ref.size = [360, 300];+const src = add("MiniMaxH3ContexLoopSourceSlice", "Source clip (frames + audio)", [cx, 420], {source_fps: 24, crop: "center"});+const motionAll = add("ImageScaleToMaxDimension", "Shot list frames (~512 px)", [vx, 1340], {upscale_method: "area", largest_size: 512});+const clipStart = add("ComfyMathExpression", "Clip start frame", [cx, 640], {0: "round(a * 24)"});+const motion = add("ImageFromBatch", "Shot list frames for this clip", [cx, 740], {batch_index: 0, length: 141});+const samAll = add("ImageScaleToMaxDimension", "SAM video (1008 px, SAM's own size)", [vx, 1460], {upscale_method: "area", largest_size: 1008});+const samClip = add("ImageFromBatch", "SAM frames for this clip", [cx, 820], {batch_index: 0, length: 141});+const noise = add("RandomNoise", "Clip Seed", [cx, 760], {control_after_generate: "fixed"});+const track = add("SAM3_VideoTrack", "SAM 3.1 track every person", [cx, 900], {detection_threshold: 0.35, max_objects: 0, detect_interval: 1});+const body = add("H3PeopleMask", "Main person, no headroom (for the depth)", [cx, 1060], {headroom: 0, hold_frames: 1, max_people: 1});+const bodyImg = add("MaskToImage", "Main person mask as image", [cx, 1160]);+const depth = add("DepthAnythingV2Preprocessor", "Depth of this clip (Depth Anything V2)", [cx, 1260], {ckpt_name: "depth_anything_v2_vitb.pth", resolution: 512});+const personDepth = add("ImageBlend", "Depth of the main person only (control video)", [cx, 1360], {blend_factor: 1.0, blend_mode: "multiply"});+const whole = add("SolidMask", "Whole frame (regenerate everything)", [cx, 1460], {value: 1.0});++link(te, 0, ref, "clip"); link(vae, 0, ref, "vae"); link(avae, 0, ref, "audio_vae");+const shotFrames = add("H3ClipShots", "Find this clip's cuts", [cx, 1500], {cut_threshold: 40});+const shotGen = add("TextGenerate", "Write this clip's shot list (Qwen3-VL)", [cx, 1600], {max_length: 500, ...GEN_OFF});+shotGen.size = [360, 200];+const fill = add("H3FillShots", "Insert shot list into prompt", [cx, 1850]);+const promptPrev = add("PreviewAny", "Clip prompt (what H3 gets)", [cx, 1950]);+link(motion, 0, shotFrames, "images");+link(swapPlan, "shot_prompt", shotFrames, "shot_prompt");+link(shotFrames, 0, shotGen, "image");+link(qwen, 0, shotGen, "clip");+link(shotFrames, 1, shotGen, "prompt");+link(cur, "prompt", fill, "prompt");+link(shotGen, 0, fill, "shots");+link(fill, 0, promptPrev, "source");+link(fill, 0, ref, "prompt"); link(cur, "width", ref, "width"); link(cur, "height", ref, "height"); link(cur, "length", ref, "length");+link(pics[0], 0, ref, "ref_images.ref_image_0");+link(cur, "state", src, "state");+link(ref, 1, src, "latent"); link(avae, 0, src, "audio_vae");+link(video, "IMAGE", src, "source_frames");+link(video, "IMAGE", motionAll, "image");+link(motionAll, 0, motion, "image");+link(cur, "audio_start", clipStart, "values.a");+link(clipStart, 1, motion, "batch_index");+link(cur, "length", motion, "length");+link(cur, "width", whole, "width"); link(cur, "height", whole, "height");++link(cur, "noise_seed", noise, "noise_seed");+link(video, "IMAGE", samAll, "image");+link(samAll, 0, samClip, "image"); link(clipStart, 1, samClip, "batch_index"); link(cur, "length", samClip, "length");+link(samClip, 0, track, "images"); link(sam, 0, track, "model"); link(samText, 0, track, "conditioning");+link(track, 0, body, "track_data");+link(body, 0, bodyImg, "mask");+link(samClip, 0, depth, "image");+link(depth, 0, personDepth, "image1"); link(bodyImg, 0, personDepth, "image2");++const mx = cx + 420;+const funPatch = add("ModelPatchLoader", "H3 Fun ControlNet Union 2.0", [mx, 60], {name: "minimax_h3_fun_controlnet_union_2.0_pruned_int8_convrot.safetensors"});+const fun = add("MiniMaxH3FunControlNetApply", "Apply ControlNet (person depth)", [mx, 180], {strength: 1.0});+const depthPrev = add("PreviewImage", "Control video (person depth)", [mx, 420]);+depthPrev.size = [360, 300];+const edit = add("MiniMaxH3FantasticVideoEditLatent", "Edit latent (source + mask + audio)", [mx, 760], {grow: 0, keep_audio: true, megapixels: 0});+const masked = add("MiniMaxH3ContexMaskedTarget", "Masked target", [mx, 960], {mask_meaning: "white = generate", audio_mode: "preserve source audio"});+const ctx = add("MiniMaxH3ChainContext", "Apply Clip Context", [mx, 1140]);+link(shift, 0, fun, "model"); link(funPatch, 0, fun, "model_patch"); link(vae, 0, fun, "vae"); link(personDepth, 0, fun, "control_video");+link(personDepth, 0, depthPrev, "images");+link(vae, 0, edit, "vae"); link(src, "scene_frames", edit, "images"); link(whole, 0, edit, "mask");+link(avae, 0, edit, "audio_vae"); link(src, "scene_audio", edit, "audio");+link(edit, 0, masked, "target_latent"); link(whole, 0, masked, "mask");+link(cur, "state", ctx, "state"); link(ref, 0, ctx, "conditioning"); link(vae, 0, ctx, "vae");+link(masked, 0, ctx, "latent"); link(avae, 0, ctx, "audio_vae");++const kx = mx + 420;+const guider = add("BasicGuider", "Guider", [kx, 60]);+const sched = add("BasicScheduler", "Schedule", [kx, 160], {scheduler: "simple", denoise: 1});+const sca = add("SamplerCustomAdvanced", "Sample Video + Audio", [kx, 320]);+const dec = add("VAEDecode", "Decode Video", [kx, 520]);+const deca = add("VAEDecodeAudio", "Decode Audio", [kx, 620]);+const trim = add("MiniMaxH3LoopTrim", "Trim Overlap", [kx, 720], {trim_frames: 0, fps: 24, match_tail: true, audio_trim_mode: "sync_with_video"});+// With the ControlNet on, H3 draws the first frame or two as the picture itself; later clips trim them with their overlap.+const frame2 = add("ImageFromBatch", "Frame 2", [kx, 920], {batch_index: 2, length: 1});+const twice = add("RepeatImageBatch", "Frame 2 as frames 0 and 1 (they show the picture)", [kx, 1020], {amount: 2});+const rest = add("ImageFromBatch", "Frame 2 to the end", [kx, 1120], {batch_index: 2, length: 4096});+const held = add("BatchImagesNode", "Clip with frames 0 and 1 replaced", [kx, 1220]);+link(fun, 0, guider, "model"); link(ctx, 0, guider, "conditioning");+link(fun, 0, sched, "model"); link(cur, "steps", sched, "steps");+link(noise, 0, sca, "noise"); link(guider, 0, sca, "guider"); link(sampler, 0, sca, "sampler");+link(sched, 0, sca, "sigmas"); link(ctx, 3, sca, "latent_image");+link(sca, 0, dec, "samples"); link(vae, 0, dec, "vae");+link(sca, 0, deca, "samples"); link(avae, 0, deca, "vae");+link(dec, 0, frame2, "image"); link(frame2, 0, twice, "image"); link(dec, 0, rest, "image");+link(twice, 0, held, "images.image0"); link(rest, 0, held, "images.image1");+link(held, 0, trim, "images"); link(ctx, 1, trim, "trim_frames"); link(deca, 0, trim, "audio"); link(cur, "state", trim, "state");++const ox = kx + 400;+const save = add("MiniMaxH3ChainSegmentSave", "Save Clip + Checkpoint", [ox, 60]);+const review = add("MiniMaxH3ChainReview", "Review (off = no pause)", [ox, 260], {enabled: false});+const end = add("MiniMaxH3ChainLoopEnd", "Loop End", [ox, 600], {between_scene_cleanup: "off", execution_mode: "recursive"});+const asm = add("MiniMaxH3ChainAssemble", "Final Video", [ox, 800], {audio_source: "source", filename: "swap_%date:yyyy-MM-dd%", copy_to_output: true, output_subfolder: "h3_oneclick_swap"});+link(cur, "state", save, "state"); link(trim, 0, save, "images"); link(sca, 0, save, "sampled_latent");+link(trim, 1, save, "audio"); link(trim, 2, save, "images_with_overlap");+link(cur, "state", review, "state"); link(save, 0, review, "segment"); link(trim, 1, review, "audio");+link(start, "flow", end, "flow"); link(cur, "state", end, "state"); link(trim, 0, end, "images");+link(sca, 0, end, "sampled_latent"); link(review, 0, end, "segment");+link(end, 0, asm, "manifest");++// optional pieces added last keep the node ids above stable for the Openjutsu export+group("OPTIONAL - No lip-sync (they don't sing along)", 40, 1000, 460, 560, "#88a");+const noLip = add("PrimitiveBoolean", "No lip-sync in the prompt", [100, 1060], {value: true}, 4);+const muteClip = add("AudioAdjustVolume", "Mute the clip audio H3 hears", [100, 1160], {volume: -100}, 4);+const muteRef = add("AudioAdjustVolume", "Mute the reference audio H3 hears", [100, 1260], {volume: -100}, 4);+link(noLip, 0, swapPlan, "no_lip_sync");+link(soundtrack, 0, muteClip, "audio"); link(muteClip, 0, src, "source_audio");+link(cur, "source_audio_slice", muteRef, "audio"); link(muteRef, 0, ref, "ref_audios.ref_audio_0");++// stack each column by real node height, then fit groups around their nodes+const cols = {};+for (const n of made) (cols[n.pos[0]] ??= []).push(n);+for (const col of Object.values(cols)) {+ col.sort((a, b) => a.pos[1] - b.pos[1]);+ let y = col[0].pos[1];+ for (const n of col) { n.pos[1] = y; y += n.size[1] + LiteGraph.NODE_TITLE_HEIGHT + 30; }+}+for (const gr of g._groups) {+ const inside = gr.members;+ if (!inside.length) continue;+ const bottom = Math.max(...inside.map(n => n.pos[1] + n.size[1]));+ const right = Math.max(...inside.map(n => n.pos[0] + n.size[0]));+ gr.size = [Math.max(gr.size[0], right - gr.pos[0] + 20), bottom - gr.pos[1] + 30];+}+app.graph.setDirtyCanvas(true, true);+JSON.stringify({nodes: g._nodes.length, links: Object.keys(g.links).length ?? g.links.size});diff --git a/workflows/build/oneclick_object_build.js b/workflows/build/oneclick_object_build.jsnew file mode 100644index 0000000..5071ac2--- /dev/null+++ b/workflows/build/oneclick_object_build.js@@ -0,0 +1,233 @@+const g = app.graph;+g.clear();+const made = [];+let curGroup = null;+function add(type, title, pos, widgets = {}, mode = 0) {+ const n = LiteGraph.createNode(type);+ if (!n) throw new Error("no node " + type);+ if (title) n.title = title;+ n.pos = pos;+ g.add(n);+ for (const [k, v] of Object.entries(widgets)) {+ const w = /^\d+$/.test(k) ? n.widgets[+k] : n.widgets.find(w => w.name === k);+ if (!w) throw new Error(type + " has no widget " + k);+ w.value = v;+ w.callback?.(v, app.canvas, n);+ }+ n.mode = mode;+ made.push(n);+ curGroup?.members.push(n);+ return n;+}+function link(a, out, b, inp) {+ const o = typeof out === "number" ? out : a.outputs.findIndex(x => x.name === out);+ const i = b.inputs.findIndex(x => x.name === inp);+ if (o < 0 || i < 0) throw new Error(`link ${a.type}.${out} -> ${b.type}.${inp}`);+ a.connect(o, b, i);+}+function group(title, x, y, w, h, color) {+ const gr = new LiteGraph.LGraphGroup(title);+ gr.pos = [x, y]; gr.size = [w, h];+ if (color) gr.color = color;+ g.add(gr);+ gr.members = [];+ curGroup = gr;+ return gr;+}++const PIC = "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.";+const GEN_OFF = {sampling_mode: "off"};++// ---------------- 1 · UPLOAD ----------------+const note = add("MarkdownNote", "START HERE", [40, 60], {0:+`# One-click object swap (H3)++1. **Source video** - upload the video.+2. **Object Swap Plan** - pick a **mode** and say what:+ - **change**: **target** is what changes (\`hair\`, \`jacket\`, \`car\`, or several: \`hair, top\`), **change_to** what it becomes (\`short bright pink hair\`).+ - **remove**: **target** is what disappears; **change_to** can say what shows instead.+ - **background**: **target** is what stays (\`person\`), **change_to** the new place.+3. **Picture** (optional, change and background) - an outfit, hairstyle, product or place to copy. Bypass the Picture group to go without one.+4. Press **Run**.++Only the tracked area is regenerated (DMAD, 6 steps); everything else, the camera, cuts, motion and soundtrack are kept. The final MP4 lands in **output/h3_oneclick_edit/**.++**change:** with **keep_outline** on (default) the grey shape keeps the real face, hands and arm motion but also the old outline. To let the outline change (long hair to a bob, pants to a skirt), turn it off and delete the two Reference Conditioning ref video inputs (Openjutsu does this for you).+**remove:** delete the two ref video inputs too; the grey shape would come back as a grey object.+**background:** turn on **flip_input** in Grow mask and wire it into the mannequin's mask and size (Openjutsu does this for you).`});+note.size = [500, 860];++const px = 580;+group("Picture 1", px - 20, 0, 360, 960, "#3f789e");+const pic = add("LoadImage", "Picture 1", [px, 60], {image: ""});+pic.size = [320, 420];+const picScale = add("ImageScaleToMaxDimension", "Shrink for the describer", [px, 520], {upscale_method: "area", largest_size: 768});+const picText = add("TextGenerate", "Describe picture 1", [px, 640], {prompt: PIC, max_length: 120, ...GEN_OFF});+picText.size = [320, 260];+link(pic, 0, picScale, "image");+link(picScale, 0, picText, "image");++const vx = 1000;+group("Source video", vx - 20, 0, 420, 1580, "#3f789e");+const video = add("VHS_LoadVideo", "Source video", [vx, 60], {video: "", force_rate: 24, format: "None"});+video.size = [380, 560];+const soundtrack = add("TrimAudioDuration", "Soundtrack (whole video)", [vx, 650], {start_index: 0, duration: 36000});+link(video, "audio", soundtrack, "audio");++// ---------------- 2 · SETTINGS ----------------+const sx = 1460;+group("SETTINGS", sx - 20, 0, 460, 1300, "#a1309b");+const objPlan = add("H3ObjectSwapPlan", "Object Swap Plan (what to change)", [sx, 60], {mode: "change", target: "hair", change_to: "short bright pink hair", seed: 0, control_after_generate: "fixed"});+objPlan.size = [420, 460];+const qwen = add("CLIPLoader", "Describer: Qwen3-VL 8B", [sx, 800], {clip_name: "qwen3vl_8b_int8_convrot.safetensors", type: "stable_diffusion"});+qwen.size = [420, 110];+link(video, "IMAGE", objPlan, "source_frames");+link(pic, 0, objPlan, "picture_1");+link(picText, 0, objPlan, "picture_1_text");+link(qwen, 0, picText, "clip");++// ---------------- 3 · ENGINE ----------------+const ex = 2000;+group("ENGINE - no need to touch", ex - 20, 0, 2900, 1900, "#444");+const unet = add("UNETLoader", "H3 Diffusion Model", [ex, 60], {unet_name: "minimax_h3_ref2va_pruned_int8_convrot.safetensors"});+const lora = add("LoraLoaderModelOnly", "DMAD LoRA", [ex, 200], {lora_name: "minimax_h3_DMAD_4step_full_lora_avg_rank_39_bf16.safetensors", strength_model: 1.0});+const attn = add("ModelAttentionBackend", "Comfy Kitchen Attention", [ex, 340], {0: "comfy kitchen attention"});+const shift = add("MiniMaxH3SigmaShift", "Sigma Shift", [ex, 440], {0: 12, 1: 2});+const te = add("CLIPLoader", "H3 Text Encoder", [ex, 560], {clip_name: "qwen3vl_32b_minimax_h3_int4_convrot.safetensors", type: "minimax"});+const vae = add("VAELoader", "Video VAE", [ex, 700], {vae_name: "minimax_h3_video_vae_int8_convrot.safetensors"});+const avae = add("VAELoader", "Audio VAE", [ex, 800], {vae_name: "minimax_h3_audio_vae_fp32.safetensors"});+const sampler = add("KSamplerSelect", "Sampler", [ex, 900], {sampler_name: "euler"});+const sam = add("CheckpointLoaderSimple", "SAM 3.1", [ex, 1000], {ckpt_name: "sam3.1_multiplex_fp16.safetensors"});+const samText = add("CLIPTextEncode", "SAM: what to change", [ex, 1140], {text: "hair"});+samText.size = [320, 100];+link(unet, 0, lora, "model");+link(lora, 0, attn, "model");+link(attn, 0, shift, "model");+link(sam, 1, samText, "clip");++const lx = ex + 400;+const profile = add("MiniMaxH3GenerationProfile", "Generation Profile", [lx, 60], {scene_continuity: "Hard picture + protected audio", audio_profile: "Generate audio"});+const plan = add("MiniMaxH3ChainPlanModern", "Production Plan (filled by Object Swap Plan)", [lx, 220], {crop: "center", default_steps: 6, segment_crf: 16, run_name: ""});+plan.size = [360, 500];+const timeline = add("MiniMaxH3SourceTimeline", "Source soundtrack", [lx, 760]);+const start = add("MiniMaxH3ChainLoopStart", "Loop Start", [lx, 960]);+const cur = add("MiniMaxH3ChainCurrent", "Current Clip", [lx, 1160]);+link(profile, 0, plan, "chain_policy");+link(objPlan, "plan_json", plan, "plan_json_input");+link(objPlan, "width", plan, "width");+link(objPlan, "height", plan, "height");+link(objPlan, "run_name", plan, "run_name");+link(soundtrack, 0, timeline, "source_audio");+link(plan, 0, start, "plan");+link(timeline, 0, start, "source_timeline");+link(start, "state", cur, "state");++const cx = lx + 420;+const ref = add("MiniMaxH3ReferenceToVideo", "Reference Conditioning", [cx, 60], {ref_image_size: "match"});+ref.size = [360, 300];+const src = add("MiniMaxH3ContexLoopSourceSlice", "Source clip (frames + audio)", [cx, 420], {source_fps: 24, crop: "center"});+const motionAll = add("ImageScaleToMaxDimension", "Motion reference video (~512 px)", [vx, 1340], {upscale_method: "area", largest_size: 512});+const clipStart = add("ComfyMathExpression", "Clip start frame", [cx, 640], {0: "round(a * 24)"});+const motion = add("ImageFromBatch", "Motion reference for this clip", [cx, 740], {batch_index: 0, length: 141});+const samAll = add("ImageScaleToMaxDimension", "SAM video (1008 px, SAM's own size)", [vx, 1460], {upscale_method: "area", largest_size: 1008});+const samClip = add("ImageFromBatch", "SAM frames for this clip", [cx, 820], {batch_index: 0, length: 141});+const noise = add("RandomNoise", "Clip Seed", [cx, 760], {control_after_generate: "fixed"});+const track = add("SAM3_VideoTrack", "SAM 3.1 track it", [cx, 900], {detection_threshold: 0.35, max_objects: 0, detect_interval: 1});+const toMask = add("H3PeopleMask", "Tracked area", [cx, 1060], {headroom: 0, hold_frames: 2, max_people: 0});+const tight = add("H3PeopleMask", "Tracked area, tight (for the grey shape)", [cx, 1260], {headroom: 0, hold_frames: 1, max_people: 0});+const mannequins = add("H3GreyMannequins", "Turn it grey (shape and movement only)", [cx, 1360], {blur: 0.04});+const grow = add("GrowMaskWithBlur", "Grow mask", [cx, 1160], {expand: 20, incremental_expandrate: 0, tapered_corners: true, flip_input: false, blur_radius: 0, lerp_alpha: 1, decay_factor: 1, fill_holes: true});++link(te, 0, ref, "clip"); link(vae, 0, ref, "vae"); link(avae, 0, ref, "audio_vae");+const shotFrames = add("H3ClipShots", "Find this clip's cuts", [cx, 1500], {cut_threshold: 40});+const shotGen = add("TextGenerate", "Write this clip's shot list (Qwen3-VL)", [cx, 1600], {max_length: 500, ...GEN_OFF});+shotGen.size = [360, 200];+const fill = add("H3FillShots", "Insert shot list into prompt", [cx, 1850]);+const promptPrev = add("PreviewAny", "Clip prompt (what H3 gets)", [cx, 1950]);+link(motion, 0, shotFrames, "images");+link(objPlan, "shot_prompt", shotFrames, "shot_prompt");+link(shotFrames, 0, shotGen, "image");+link(qwen, 0, shotGen, "clip");+link(shotFrames, 1, shotGen, "prompt");+link(cur, "prompt", fill, "prompt");+link(shotGen, 0, fill, "shots");+link(fill, 0, promptPrev, "source");+link(fill, 0, ref, "prompt"); link(cur, "width", ref, "width"); link(cur, "height", ref, "height"); link(cur, "length", ref, "length");+link(pic, 0, ref, "ref_images.ref_image_0");+link(cur, "state", src, "state");+link(ref, 1, src, "latent"); link(avae, 0, src, "audio_vae");+link(video, "IMAGE", src, "source_frames"); link(soundtrack, 0, src, "source_audio");+link(video, "IMAGE", motionAll, "image");+link(motionAll, 0, motion, "image");+link(cur, "audio_start", clipStart, "values.a");+link(clipStart, 1, motion, "batch_index");+link(cur, "length", motion, "length");+link(mannequins, 0, ref, "ref_videos.ref_video_0");+link(cur, "source_audio_slice", ref, "ref_video_audios.ref_video_audio_0");+link(cur, "noise_seed", noise, "noise_seed");+link(video, "IMAGE", samAll, "image");+link(samAll, 0, samClip, "image"); link(clipStart, 1, samClip, "batch_index"); link(cur, "length", samClip, "length");+link(samClip, 0, track, "images"); link(sam, 0, track, "model"); link(samText, 0, track, "conditioning");+link(track, 0, toMask, "track_data"); link(track, 0, tight, "track_data");+link(toMask, 0, grow, "mask");+link(motion, 0, mannequins, "images"); link(tight, 0, mannequins, "mask"); link(tight, 1, mannequins, "size");++const mx = cx + 420;+const gridPrev = add("MiniMaxH3ContexMaskGridPreview", "Mask preview", [mx, 60]);+const prevImg = add("PreviewImage", "Mask preview (white = regenerated)", [mx, 420]);+prevImg.size = [360, 300];+const edit = add("MiniMaxH3FantasticVideoEditLatent", "Edit latent (source + mask + audio)", [mx, 760], {grow: 0, keep_audio: true, megapixels: 0});+const masked = add("MiniMaxH3ContexMaskedTarget", "Masked target", [mx, 960], {mask_meaning: "white = generate", audio_mode: "preserve source audio"});+const ctx = add("MiniMaxH3ChainContext", "Apply Clip Context", [mx, 1140]);+link(src, "scene_frames", gridPrev, "image"); link(grow, 0, gridPrev, "mask");+link(gridPrev, "grid_preview", prevImg, "images");+link(vae, 0, edit, "vae"); link(src, "scene_frames", edit, "images"); link(grow, 0, edit, "mask");+link(avae, 0, edit, "audio_vae"); link(src, "scene_audio", edit, "audio");+link(edit, 0, masked, "target_latent"); link(grow, 0, masked, "mask");+link(cur, "state", ctx, "state"); link(ref, 0, ctx, "conditioning"); link(vae, 0, ctx, "vae");+link(masked, 0, ctx, "latent"); link(avae, 0, ctx, "audio_vae");++const kx = mx + 420;+const guider = add("BasicGuider", "Guider", [kx, 60]);+const sched = add("BasicScheduler", "Schedule", [kx, 160], {scheduler: "simple", denoise: 1});+const sca = add("SamplerCustomAdvanced", "Sample Video + Audio", [kx, 320]);+const dec = add("VAEDecode", "Decode Video", [kx, 520]);+const deca = add("VAEDecodeAudio", "Decode Audio", [kx, 620]);+const trim = add("MiniMaxH3LoopTrim", "Trim Overlap", [kx, 720], {trim_frames: 0, fps: 24, match_tail: true, audio_trim_mode: "sync_with_video"});+link(shift, 0, guider, "model"); link(ctx, 0, guider, "conditioning");+link(shift, 0, sched, "model"); link(cur, "steps", sched, "steps");+link(noise, 0, sca, "noise"); link(guider, 0, sca, "guider"); link(sampler, 0, sca, "sampler");+link(sched, 0, sca, "sigmas"); link(ctx, 3, sca, "latent_image");+link(sca, 0, dec, "samples"); link(vae, 0, dec, "vae");+link(sca, 0, deca, "samples"); link(avae, 0, deca, "vae");+link(dec, 0, trim, "images"); link(ctx, 1, trim, "trim_frames"); link(deca, 0, trim, "audio"); link(cur, "state", trim, "state");++const ox = kx + 400;+const save = add("MiniMaxH3ChainSegmentSave", "Save Clip + Checkpoint", [ox, 60]);+const review = add("MiniMaxH3ChainReview", "Review (off = no pause)", [ox, 260], {enabled: false});+const end = add("MiniMaxH3ChainLoopEnd", "Loop End", [ox, 600], {between_scene_cleanup: "off", execution_mode: "recursive"});+const asm = add("MiniMaxH3ChainAssemble", "Final Video", [ox, 800], {audio_source: "source", filename: "edit_%date:yyyy-MM-dd%", copy_to_output: true, output_subfolder: "h3_oneclick_edit"});+link(cur, "state", save, "state"); link(trim, 0, save, "images"); link(sca, 0, save, "sampled_latent");+link(trim, 1, save, "audio"); link(trim, 2, save, "images_with_overlap");+link(cur, "state", review, "state"); link(save, 0, review, "segment"); link(trim, 1, review, "audio");+link(start, "flow", end, "flow"); link(cur, "state", end, "state"); link(trim, 0, end, "images");+link(sca, 0, end, "sampled_latent"); link(review, 0, end, "segment");+link(end, 0, asm, "manifest");++// stack each column by real node height, then fit groups around their nodes+const cols = {};+for (const n of made) (cols[n.pos[0]] ??= []).push(n);+for (const col of Object.values(cols)) {+ col.sort((a, b) => a.pos[1] - b.pos[1]);+ let y = col[0].pos[1];+ for (const n of col) { n.pos[1] = y; y += n.size[1] + LiteGraph.NODE_TITLE_HEIGHT + 30; }+}+for (const gr of g._groups) {+ const inside = gr.members;+ if (!inside.length) continue;+ const bottom = Math.max(...inside.map(n => n.pos[1] + n.size[1]));+ const right = Math.max(...inside.map(n => n.pos[0] + n.size[0]));+ gr.size = [Math.max(gr.size[0], right - gr.pos[0] + 20), bottom - gr.pos[1] + 30];+}+app.graph.setDirtyCanvas(true, true);+JSON.stringify({nodes: g._nodes.length, links: Object.keys(g.links).length ?? g.links.size});diff --git a/workflows/build/oneclick_single_build.js b/workflows/build/oneclick_single_build.jsnew file mode 100644index 0000000..5a53bc6--- /dev/null+++ b/workflows/build/oneclick_single_build.js@@ -0,0 +1,293 @@+const g = app.graph;+g.clear();+const made = [];+let curGroup = null;+function add(type, title, pos, widgets = {}, mode = 0) {+ const n = LiteGraph.createNode(type);+ if (!n) throw new Error("no node " + type);+ if (title) n.title = title;+ n.pos = pos;+ g.add(n);+ for (const [k, v] of Object.entries(widgets)) {+ const w = /^\d+$/.test(k) ? n.widgets[+k] : n.widgets.find(w => w.name === k);+ if (!w) throw new Error(type + " has no widget " + k);+ w.value = v;+ w.callback?.(v, app.canvas, n);+ }+ n.mode = mode;+ made.push(n);+ curGroup?.members.push(n);+ return n;+}+function link(a, out, b, inp) {+ const o = typeof out === "number" ? out : a.outputs.findIndex(x => x.name === out);+ const i = b.inputs.findIndex(x => x.name === inp);+ if (o < 0 || i < 0) throw new Error(`link ${a.type}.${out} -> ${b.type}.${inp}`);+ a.connect(o, b, i);+}+function group(title, x, y, w, h, color) {+ const gr = new LiteGraph.LGraphGroup(title);+ gr.pos = [x, y]; gr.size = [w, h];+ if (color) gr.color = color;+ g.add(gr);+ gr.members = [];+ curGroup = gr;+ return gr;+}++const PIC = "Describe the person in this picture for a casting sheet, in one sentence of about 40 words: apparent age and gender, hair, facial hair, skin tone, build, and their complete outfit including footwear. No preamble, no background.";+const PEOPLE = "These are frames from one video, in time order. List the people who appear most, up to four, the person with the most screen time first. Write one numbered line per person: first their role in the video in two to four words, without gender, that stays true in every shot, then \" - \" and how they look, like \"1. the guitarist - tall man with a grey beard in a denim jacket\". Each person appears once. Output only the list.";+const GEN_OFF = {sampling_mode: "off"};++// ---------------- 1 · UPLOAD ----------------+const note = add("MarkdownNote", "START HERE", [40, 60], {0:+`# One-click single swap (H3)++1. **Picture** - drop the photo of your character.+2. **Source video** - upload the video. Its main person (the one on screen most) is replaced; everyone else, the camera, cuts, motion and soundtrack are kept.+3. Press **Run**.++That's it. The graph then:+- describes your pictures and the people in the video, and writes a shot list per clip (Qwen3-VL 8B, local),+- splits the video into ~6 s clips that overlap by 39 frames,+- tracks the main person with SAM 3.1 and regenerates only them (DMAD, 6 steps),+- joins the clips with the original audio.++The final MP4 lands in **output/h3_oneclick_swap/**. Each clip is saved as it finishes, so a crash resumes where it stopped when you press Run again with the same inputs.++**Who is replaced:** the person who covers the most of the frame over each clip. **roles** can name them for the prompt (\`the singer\`); name the role, not the clothes (clothes words leak into the result).+**New take:** change **seed**. **Faster test:** set **resolution** to 480p.++**Hats:** if the person wears a hat, turn on **OPTIONAL - Hat fix** so the hat is replaced too (about 45 s extra per clip).+**Not singing along:** if the soundtrack has vocals but the person does not sing or talk, turn on **OPTIONAL - No lip-sync** so the new person does not lip-sync the song (about 30 s extra per clip).`});+note.size = [500, 860];++const pics = [], picTexts = [];+const files = [""];+for (let i = 0; i < 1; i++) {+ const x = 580 + i * 380;+ const title = i === 0 ? "Picture 1" : `OPTIONAL - Picture ${i + 1}`;+ group(title, x - 20, 0, 360, 960, i === 0 ? "#3f789e" : "#88a");+ const load = add("LoadImage", `Picture ${i + 1}`, [x, 60], {image: files[i]}, i < 2 ? 0 : 4);+ load.size = [320, 420];+ const scale = add("ImageScaleToMaxDimension", "Shrink for the describer", [x, 520], {upscale_method: "area", largest_size: 768}, i < 2 ? 0 : 4);+ const gen = add("TextGenerate", `Describe picture ${i + 1}`, [x, 640], {prompt: PIC, max_length: 120, ...GEN_OFF}, i < 2 ? 0 : 4);+ gen.size = [320, 260];+ link(load, 0, scale, "image");+ link(scale, 0, gen, "image");+ pics.push(load); picTexts.push(gen);+}++const vx = 2100;+group("Source video", vx - 20, 0, 420, 1580, "#3f789e");+const video = add("VHS_LoadVideo", "Source video (people get replaced)", [vx, 60], {video: "", force_rate: 24, format: "None"});+video.size = [380, 560];+const soundtrack = add("TrimAudioDuration", "Soundtrack (whole video)", [vx, 650], {start_index: 0, duration: 36000});+link(video, "audio", soundtrack, "audio");+const nth = add("VHS_SelectEveryNthImage", "One frame every 2 s", [vx, 700], {select_every_nth: 48, skip_first_images: 24});+const first20 = add("ImageFromBatch", "At most 20 frames", [vx, 800], {batch_index: 0, length: 20});+const vscale = add("ImageScaleToMaxDimension", "Shrink for the describer", [vx, 920], {upscale_method: "area", largest_size: 640});+const people = add("TextGenerate", "Who is in the video", [vx, 1020], {prompt: PEOPLE, max_length: 160, ...GEN_OFF});+people.size = [380, 240];+link(video, "IMAGE", nth, "images");+link(nth, 0, first20, "image");+link(first20, 0, vscale, "image");+link(vscale, 0, people, "image");++// ---------------- 2 · SETTINGS ----------------+const sx = 2560;+group("SETTINGS (optional)", sx - 20, 0, 460, 1300, "#a1309b");+const swapPlan = add("H3OneClickSwapPlan", "Swap Plan (roles, seed, size)", [sx, 60], {seed: 0, control_after_generate: "fixed"});+swapPlan.size = [420, 420];+const bypass = add("Fast Groups Bypasser (rgthree)", "ON / OFF SWITCHES", [sx, 560]);+Object.assign(bypass.properties, {matchTitle: "OPTIONAL", sort: "position"});+bypass.size = [420, 160];+const qwen = add("CLIPLoader", "Describer: Qwen3-VL 8B", [sx, 800], {clip_name: "qwen3vl_8b_int8_convrot.safetensors", type: "stable_diffusion"});+qwen.size = [420, 110];+const qwenFree = add("Note", "", [sx, 960], {0: "The describer reads your pictures and the video once (about 40 s), then writes a shot list for every clip (about 20 s each)."});+qwenFree.size = [420, 80];++link(video, "IMAGE", swapPlan, "source_frames");+pics.forEach((p, i) => link(p, 0, swapPlan, `picture_${i + 1}`));+picTexts.forEach((t, i) => link(t, 0, swapPlan, `picture_${i + 1}_text`));+link(people, 0, swapPlan, "video_people");+for (const t of [...picTexts, people]) link(qwen, 0, t, "clip");++// ---------------- 3 · ENGINE ----------------+const ex = 3100;+group("ENGINE - no need to touch", ex - 20, 0, 2900, 1900, "#444");+const unet = add("UNETLoader", "H3 Diffusion Model", [ex, 60], {unet_name: "minimax_h3_ref2va_pruned_int8_convrot.safetensors"});+const lora = add("LoraLoaderModelOnly", "DMAD LoRA", [ex, 200], {lora_name: "minimax_h3_DMAD_4step_full_lora_avg_rank_39_bf16.safetensors", strength_model: 1.0});+const attn = add("ModelAttentionBackend", "Comfy Kitchen Attention", [ex, 340], {0: "comfy kitchen attention"});+const shift = add("MiniMaxH3SigmaShift", "Sigma Shift", [ex, 440], {0: 12, 1: 2});+const te = add("CLIPLoader", "H3 Text Encoder", [ex, 560], {clip_name: "qwen3vl_32b_minimax_h3_int4_convrot.safetensors", type: "minimax"});+const vae = add("VAELoader", "Video VAE", [ex, 700], {vae_name: "minimax_h3_video_vae_int8_convrot.safetensors"});+const avae = add("VAELoader", "Audio VAE", [ex, 800], {vae_name: "minimax_h3_audio_vae_fp32.safetensors"});+const sampler = add("KSamplerSelect", "Sampler", [ex, 900], {sampler_name: "euler"});+const sam = add("CheckpointLoaderSimple", "SAM 3.1", [ex, 1000], {ckpt_name: "sam3.1_multiplex_fp16.safetensors"});+const samText = add("CLIPTextEncode", "SAM: what to replace", [ex, 1140], {text: "person"});+samText.size = [320, 100];+link(unet, 0, lora, "model");+link(lora, 0, attn, "model");+link(attn, 0, shift, "model");+link(sam, 1, samText, "clip");++const lx = ex + 400;+const profile = add("MiniMaxH3GenerationProfile", "Generation Profile", [lx, 60], {scene_continuity: "Hard picture + protected audio", audio_profile: "Generate audio"});+const plan = add("MiniMaxH3ChainPlanModern", "Production Plan (filled by Swap Plan)", [lx, 220], {crop: "center", default_steps: 6, segment_crf: 16, run_name: ""});+plan.size = [360, 500];+const timeline = add("MiniMaxH3SourceTimeline", "Source soundtrack", [lx, 760]);+const start = add("MiniMaxH3ChainLoopStart", "Loop Start", [lx, 960]);+const cur = add("MiniMaxH3ChainCurrent", "Current Clip", [lx, 1160]);+link(profile, 0, plan, "chain_policy");+link(swapPlan, "plan_json", plan, "plan_json_input");+link(swapPlan, "width", plan, "width");+link(swapPlan, "height", plan, "height");+link(swapPlan, "run_name", plan, "run_name");+link(soundtrack, 0, timeline, "source_audio");+link(plan, 0, start, "plan");+link(timeline, 0, start, "source_timeline");+link(start, "state", cur, "state");++const cx = lx + 420;+const ref = add("MiniMaxH3ReferenceToVideo", "Reference Conditioning", [cx, 60], {ref_image_size: "match"});+ref.size = [360, 300];+const src = add("MiniMaxH3ContexLoopSourceSlice", "Source clip (frames + audio)", [cx, 420], {source_fps: 24, crop: "center"});+const motionAll = add("ImageScaleToMaxDimension", "Motion reference video (~512 px)", [vx, 1340], {upscale_method: "area", largest_size: 512});+const clipStart = add("ComfyMathExpression", "Clip start frame", [cx, 640], {0: "round(a * 24)"});+const motion = add("ImageFromBatch", "Motion reference for this clip", [cx, 740], {batch_index: 0, length: 141});+const samAll = add("ImageScaleToMaxDimension", "SAM video (1008 px, SAM's own size)", [vx, 1460], {upscale_method: "area", largest_size: 1008});+const samClip = add("ImageFromBatch", "SAM frames for this clip", [cx, 820], {batch_index: 0, length: 141});+const noise = add("RandomNoise", "Clip Seed", [cx, 760], {control_after_generate: "fixed"});+const track = add("SAM3_VideoTrack", "SAM 3.1 track every person", [cx, 900], {detection_threshold: 0.35, max_objects: 0, detect_interval: 1});+const toMask = add("H3PeopleMask", "Main person (+ headroom)", [cx, 1060], {headroom: 0.1, hold_frames: 2, max_people: 1});+const body = add("H3PeopleMask", "Main person, no headroom (for the mannequin)", [cx, 1260], {headroom: 0, hold_frames: 1, max_people: 1});+const mannequins = add("H3GreyMannequins", "Hide the main person (grey mannequin)", [cx, 1360], {blur: 0.04});+const grow = add("GrowMaskWithBlur", "Grow mask (~4% of the frame)", [cx, 1160], {expand: 40, incremental_expandrate: 0, tapered_corners: true, flip_input: false, blur_radius: 0, lerp_alpha: 1, decay_factor: 1, fill_holes: true});++link(te, 0, ref, "clip"); link(vae, 0, ref, "vae"); link(avae, 0, ref, "audio_vae");+const shotFrames = add("H3ClipShots", "Find this clip's cuts", [cx, 1500], {cut_threshold: 40});+const shotGen = add("TextGenerate", "Write this clip's shot list (Qwen3-VL)", [cx, 1600], {max_length: 500, ...GEN_OFF});+shotGen.size = [360, 200];+const fill = add("H3FillShots", "Insert shot list into prompt", [cx, 1850]);+const promptPrev = add("PreviewAny", "Clip prompt (what H3 gets)", [cx, 1950]);+link(motion, 0, shotFrames, "images");+link(swapPlan, "shot_prompt", shotFrames, "shot_prompt");+link(shotFrames, 0, shotGen, "image");+link(qwen, 0, shotGen, "clip");+link(shotFrames, 1, shotGen, "prompt");+link(cur, "prompt", fill, "prompt");+link(shotGen, 0, fill, "shots");+link(fill, 0, promptPrev, "source");+link(fill, 0, ref, "prompt"); link(cur, "width", ref, "width"); link(cur, "height", ref, "height"); link(cur, "length", ref, "length");+link(pics[0], 0, ref, "ref_images.ref_image_0");+link(cur, "state", src, "state");+link(ref, 1, src, "latent"); link(avae, 0, src, "audio_vae");+link(video, "IMAGE", src, "source_frames");+link(video, "IMAGE", motionAll, "image");+link(motionAll, 0, motion, "image");+link(cur, "audio_start", clipStart, "values.a");+link(clipStart, 1, motion, "batch_index");+link(cur, "length", motion, "length");+link(mannequins, 0, ref, "ref_videos.ref_video_0");++link(cur, "noise_seed", noise, "noise_seed");+link(video, "IMAGE", samAll, "image");+link(samAll, 0, samClip, "image"); link(clipStart, 1, samClip, "batch_index"); link(cur, "length", samClip, "length");+link(samClip, 0, track, "images"); link(sam, 0, track, "model"); link(samText, 0, track, "conditioning");+link(track, 0, toMask, "track_data"); link(track, 0, body, "track_data");+const engineGroup = curGroup;+group("OPTIONAL - Hat fix (also mask hats)", 540, 1000, 400, 760, "#88a");+const hatText = add("CLIPTextEncode", "SAM: hats", [600, 1060], {text: "hat"}, 4);+hatText.size = [320, 100];+const hatTrack = add("SAM3_VideoTrack", "SAM 3.1 track hats", [600, 1200], {detection_threshold: 0.35, max_objects: 0, detect_interval: 1}, 4);+const hatMask = add("SAM3_TrackToMask", "All hats", [600, 1400], {object_indices: ""}, 4);+const hatNear = add("GrowMaskWithBlur", "Hat search area (person + 60 px)", [600, 1500], {expand: 60, incremental_expandrate: 0, tapered_corners: true, flip_input: false, blur_radius: 0, lerp_alpha: 1, decay_factor: 1, fill_holes: true}, 4);+const hatOwn = add("MaskComposite", "Only the main person's hat", [600, 1600], {x: 0, y: 0, operation: "multiply"}, 4);+const hatAdd = add("MaskComposite", "People + hats", [600, 1700], {x: 0, y: 0, operation: "add"}, 4);+link(sam, 1, hatText, "clip");+link(samClip, 0, hatTrack, "images"); link(sam, 0, hatTrack, "model"); link(hatText, 0, hatTrack, "conditioning");+link(hatTrack, 0, hatMask, "track_data");+link(toMask, 0, hatNear, "mask");+link(hatMask, 0, hatOwn, "destination"); link(hatNear, 0, hatOwn, "source");+link(toMask, 0, hatAdd, "destination"); link(hatOwn, 0, hatAdd, "source");+link(hatAdd, 0, grow, "mask");+curGroup = engineGroup;+link(motion, 0, mannequins, "images"); link(body, 0, mannequins, "mask"); link(body, 1, mannequins, "size");++const mx = cx + 420;+const gridPrev = add("MiniMaxH3ContexMaskGridPreview", "Mask preview", [mx, 60]);+const prevImg = add("PreviewImage", "Mask preview (white = regenerated)", [mx, 420]);+prevImg.size = [360, 300];+const edit = add("MiniMaxH3FantasticVideoEditLatent", "Edit latent (source + mask + audio)", [mx, 760], {grow: 0, keep_audio: true, megapixels: 0});+const masked = add("MiniMaxH3ContexMaskedTarget", "Masked target", [mx, 960], {mask_meaning: "white = generate", audio_mode: "preserve source audio"});+const ctx = add("MiniMaxH3ChainContext", "Apply Clip Context", [mx, 1140]);+link(src, "scene_frames", gridPrev, "image"); link(grow, 0, gridPrev, "mask");+link(gridPrev, "grid_preview", prevImg, "images");+link(vae, 0, edit, "vae"); link(src, "scene_frames", edit, "images"); link(grow, 0, edit, "mask");+link(avae, 0, edit, "audio_vae"); link(src, "scene_audio", edit, "audio");+link(edit, 0, masked, "target_latent"); link(grow, 0, masked, "mask");+link(cur, "state", ctx, "state"); link(ref, 0, ctx, "conditioning"); link(vae, 0, ctx, "vae");+link(masked, 0, ctx, "latent"); link(avae, 0, ctx, "audio_vae");++const kx = mx + 420;+const guider = add("BasicGuider", "Guider", [kx, 60]);+const sched = add("BasicScheduler", "Schedule", [kx, 160], {scheduler: "simple", denoise: 1});+const sca = add("SamplerCustomAdvanced", "Sample Video + Audio", [kx, 320]);+const dec = add("VAEDecode", "Decode Video", [kx, 520]);+const deca = add("VAEDecodeAudio", "Decode Audio", [kx, 620]);+const trim = add("MiniMaxH3LoopTrim", "Trim Overlap", [kx, 720], {trim_frames: 0, fps: 24, match_tail: true, audio_trim_mode: "sync_with_video"});+link(shift, 0, guider, "model"); link(ctx, 0, guider, "conditioning");+link(shift, 0, sched, "model"); link(cur, "steps", sched, "steps");+link(noise, 0, sca, "noise"); link(guider, 0, sca, "guider"); link(sampler, 0, sca, "sampler");+link(sched, 0, sca, "sigmas"); link(ctx, 3, sca, "latent_image");+link(sca, 0, dec, "samples"); link(vae, 0, dec, "vae");+link(sca, 0, deca, "samples"); link(avae, 0, deca, "vae");+link(dec, 0, trim, "images"); link(ctx, 1, trim, "trim_frames"); link(deca, 0, trim, "audio"); link(cur, "state", trim, "state");++const ox = kx + 400;+const save = add("MiniMaxH3ChainSegmentSave", "Save Clip + Checkpoint", [ox, 60]);+const review = add("MiniMaxH3ChainReview", "Review (off = no pause)", [ox, 260], {enabled: false});+const end = add("MiniMaxH3ChainLoopEnd", "Loop End", [ox, 600], {between_scene_cleanup: "off", execution_mode: "recursive"});+const asm = add("MiniMaxH3ChainAssemble", "Final Video", [ox, 800], {audio_source: "source", filename: "swap_%date:yyyy-MM-dd%", copy_to_output: true, output_subfolder: "h3_oneclick_swap"});+link(cur, "state", save, "state"); link(trim, 0, save, "images"); link(sca, 0, save, "sampled_latent");+link(trim, 1, save, "audio"); link(trim, 2, save, "images_with_overlap");+link(cur, "state", review, "state"); link(save, 0, review, "segment"); link(trim, 1, review, "audio");+link(start, "flow", end, "flow"); link(cur, "state", end, "state"); link(trim, 0, end, "images");+link(sca, 0, end, "sampled_latent"); link(review, 0, end, "segment");+link(end, 0, asm, "manifest");++// optional pieces added last keep the node ids above stable for the Openjutsu export+group("OPTIONAL - No lip-sync (they don't sing along)", 40, 1000, 460, 760, "#88a");+const noLip = add("PrimitiveBoolean", "No lip-sync in the prompt", [100, 1060], {value: true}, 4);+const faceText = add("CLIPTextEncode", "SAM: faces", [100, 1160], {text: "face"}, 4);+faceText.size = [320, 100];+const faceTrack = add("SAM3_VideoTrack", "SAM 3.1 track faces", [100, 1300], {detection_threshold: 0.2, max_objects: 0, detect_interval: 1}, 4);+const faces = add("H3PeopleMask", "Faces (shown on the mannequin)", [100, 1500], {headroom: 0, hold_frames: 0, max_people: 0}, 4);+const muteClip = add("AudioAdjustVolume", "Mute the clip audio H3 hears", [100, 1640], {volume: -100}, 4);+const muteRef = add("AudioAdjustVolume", "Mute the reference audio H3 hears", [100, 1740], {volume: -100}, 4);+link(noLip, 0, swapPlan, "no_lip_sync");+link(sam, 1, faceText, "clip");+link(samClip, 0, faceTrack, "images"); link(sam, 0, faceTrack, "model"); link(faceText, 0, faceTrack, "conditioning");+link(faceTrack, 0, faces, "track_data");+link(faces, 0, mannequins, "faces"); link(faces, 1, mannequins, "face_size");+link(soundtrack, 0, muteClip, "audio"); link(muteClip, 0, src, "source_audio");+link(cur, "source_audio_slice", muteRef, "audio"); link(muteRef, 0, ref, "ref_video_audios.ref_video_audio_0");++// stack each column by real node height, then fit groups around their nodes+const cols = {};+for (const n of made) (cols[n.pos[0]] ??= []).push(n);+for (const col of Object.values(cols)) {+ col.sort((a, b) => a.pos[1] - b.pos[1]);+ let y = col[0].pos[1];+ for (const n of col) { n.pos[1] = y; y += n.size[1] + LiteGraph.NODE_TITLE_HEIGHT + 30; }+}+for (const gr of g._groups) {+ const inside = gr.members;+ if (!inside.length) continue;+ const bottom = Math.max(...inside.map(n => n.pos[1] + n.size[1]));+ const right = Math.max(...inside.map(n => n.pos[0] + n.size[0]));+ gr.size = [Math.max(gr.size[0], right - gr.pos[0] + 20), bottom - gr.pos[1] + 30];+}+app.graph.setDirtyCanvas(true, true);+JSON.stringify({nodes: g._nodes.length, links: Object.keys(g.links).length ?? g.links.size});diff --git a/workflows/build/openjutsu_face_build.py b/workflows/build/openjutsu_face_build.pynew file mode 100644index 0000000..9df824d--- /dev/null+++ b/workflows/build/openjutsu_face_build.py@@ -0,0 +1,71 @@+"""Writes workflows/face.api.json, the Openjutsu Fix faces workflow, with Follow the mouth on.++The face of the person in Picture 1 is tracked and cropped over the whole video, its edit mask regenerated by H3 in+independent overlapping chunks (H3 Face Fix Chunks), crossfaded back (H3 Face Fix Join) and pasted onto the video.+Needs ComfyUI-H3-FaceRefine (track, SAM face masks, stitch) and Impact Pack (SAMLoader).+usage: python openjutsu_face_build.py [video picture] with names in ComfyUI input/ also queues a test run+"""+import json, sys, urllib.request+from pathlib import Path++g = {}+def node(i, cls, title, **inputs):+ g[i] = {"inputs": inputs, "class_type": cls, "_meta": {"title": title}}+ return [i, 0]++node("1", "VHS_LoadVideo", "Video to fix", video="", force_rate=24, custom_width=0, custom_height=0, frame_load_cap=0,+ skip_first_frames=0, select_every_nth=1, format="None")+node("2", "LoadImage", "Picture 1", image="")+node("3", "ImageScaleToMaxDimension", "Shrink for the describer", upscale_method="area", largest_size=768, image=["2", 0])+node("4", "CLIPLoader", "Describer: Qwen3-VL 8B", clip_name="qwen3vl_8b_int8_convrot.safetensors", type="stable_diffusion", device="default")+node("5", "TextGenerate", "Describe the face in picture 1",+ prompt="Describe this person's face for a casting sheet, in one sentence of about 30 words: apparent age and gender, face shape, skin tone, "+ "eyebrows, facial hair and any glasses. No preamble, no clothing, no background.",+ max_length=90, sampling_mode="off", thinking=False, use_default_template=True, mtp="auto", clip=["4", 0], image=["3", 0])+track = dict(detector="bbox\\face_yolov8m.pt", confidence=0.35, crop_factor=2.5, canvas_width=512, canvas_height=512, canvas_mode="manual",+ smooth_window=21, size_smooth_window=51, smooth_method="gaussian", size_mode="per_frame", identity_track=True,+ identity_threshold=0.28, select="largest", fallback_head_frac=0.5)+node("6", "H3FaceTrackCrop", "Track + crop the face", images=["1", 0], identity_reference=["2", 0],+ fallback_detector="segm\\person_yolov8m-seg.pt", **track)+node("7", "H3FaceTrackCrop", "Face from picture 1", images=["2", 0], fallback_detector="none", **track)+node("8", "SAMLoader", "SAM (face masks)", model_name="sam_vit_b_01ec64.pth", device_mode="AUTO")+# H3 regenerates a little more than is pasted back, so the paste edge lands inside regenerated pixels+node("9", "H3FaceMaskSAM", "Face mask (regenerated)", crops=["6", 0], sam_model=["8", 0], transform=["6", 1], threshold=0.93, dilation=24, temporal_smooth=5)+node("10", "H3FaceMaskSAM", "Face mask (pasted back)", crops=["6", 0], sam_model=["8", 0], transform=["6", 1], threshold=0.93, dilation=8, temporal_smooth=5)+node("11", "ImageBlur", "Blurred face (follow the mouth)", image=["6", 0], blur_radius=9, sigma=3.0)+node("12", "H3FaceChunks", "Face Fix Chunks", crops=["6", 0], masks=["9", 0], audio=["1", 2], transform=["6", 1], chunk_seconds=6.5,+ skip_faces_above=0.2, follow_mouth=["11", 0], picture_text=["5", 0])+node("13", "UNETLoader", "H3 Diffusion Model", unet_name="minimax_h3_ref2va_pruned_int8_convrot.safetensors", weight_dtype="default")+node("14", "LoraLoaderModelOnly", "DMAD LoRA", lora_name="minimax_h3_DMAD_4step_full_lora_avg_rank_39_bf16.safetensors", strength_model=1, model=["13", 0])+node("15", "ModelAttentionBackend", "Comfy Kitchen Attention", attention="comfy kitchen attention", model=["14", 0])+node("16", "CLIPLoader", "H3 Text Encoder", clip_name="qwen3vl_32b_minimax_h3_int4_convrot.safetensors", type="minimax", device="default")+node("17", "VAELoader", "Video VAE", vae_name="minimax_h3_video_vae_int8_convrot.safetensors")+node("18", "VAELoader", "Audio VAE", vae_name="minimax_h3_audio_vae_fp32.safetensors")+node("19", "MiniMaxH3FantasticVideoEditLatent", "Edit latent (face + audio)", grow=0, keep_audio=True, megapixels=0, vae=["17", 0],+ images=["12", 0], mask=["12", 1], audio_vae=["18", 0], audio=["12", 3])+node("20", "MiniMaxH3ContexMaskedTarget", "Masked target", mask_meaning="white = generate", audio_mode="preserve source audio",+ mask_conversion="H3 exact (causal/token max)", target_latent=["19", 0], mask=["12", 1])+node("21", "MiniMaxH3ReferenceToVideo", "Reference Conditioning", prompt=["12", 4], width=["19", 1], height=["19", 2], length=["19", 3],+ ref_image_size="match", clip=["16", 0], vae=["17", 0], audio_vae=["18", 0],+ **{"ref_images.ref_image_0": ["7", 0], "ref_videos.ref_video_0": ["12", 2]})+node("22", "BasicGuider", "Guider", model=["15", 0], conditioning=["21", 0])+node("23", "KSamplerSelect", "Sampler", sampler_name="euler")+node("24", "RandomNoise", "Seed", noise_seed=0)+node("25", "BasicScheduler", "Schedule", scheduler="simple", steps=6, denoise=1, model=["15", 0])+node("26", "SamplerCustomAdvanced", "Sample face", noise=["24", 0], guider=["22", 0], sampler=["23", 0], sigmas=["25", 0], latent_image=["20", 0])+node("27", "VAEDecode", "Decode face", samples=["26", 0], vae=["17", 0])+node("28", "H3FaceJoin", "Face Fix Join", images=["27", 0], plan=["12", 5], crops=["6", 0], transform=["6", 1])+node("29", "H3FaceStitch", "Paste the face back", paste_region="face_only", mask_dilation=0, feather=8, colour_match=1.0, blend=1.0,+ undetected_frames="fade_out", feather_scales_with_crop=False, base_images=["1", 0], refined_crops=["28", 0], transform=["28", 1], masks=["10", 0])+node("30", "VHS_VideoCombine", "Fixed video", frame_rate=24, loop_count=0, filename_prefix="openjutsu_face/face", format="video/h264-mp4",+ pix_fmt="yuv420p", crf=16, save_metadata=False, trim_to_audio=False, pingpong=False, save_output=True, images=["29", 0], audio=["1", 2])++with open(Path(__file__).resolve().parent.parent / "face.api.json", "w", encoding="utf-8") as f:+ json.dump(g, f, indent=2)+ f.write("\n")+print("wrote face.api.json,", len(g), "nodes")++if len(sys.argv) == 3:+ g["1"]["inputs"]["video"], g["2"]["inputs"]["image"] = sys.argv[1], sys.argv[2]+ r = urllib.request.urlopen(urllib.request.Request("http://127.0.0.1:8188/prompt", json.dumps({"prompt": g}).encode(), {"content-type": "application/json"}))+ print(r.read().decode())