Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Character Swap Studio: H3 Relay segment and mask graphs on your GPU

Claude643a08f34a17
diff --git a/scripts/comfy/build-library.mjs b/scripts/comfy/build-library.mjs
index d74292e9..94a5f3eb 100644
--- a/scripts/comfy/build-library.mjs
+++ b/scripts/comfy/build-library.mjs
@@ -124,6 +124,8 @@ export const BINDING_KEYS = new Set([
'megapixels',
// Genjutsu's Character swap (Originals O5): MiniMax H3 with the h3_character_swap / H3 Relay packs
'quality', 'selection', 'subjectIndex', 'positiveCoords', 'negativeCoords', 'audioGuide', 'useMask', 'windowFrames', 'historyFrames',
+ // Character Swap Studio (o/h3-studio): continuation history from the previous take's master, masks on any frame spliced into a version
+ 'historyVideo', 'historyStart', 'historyLength', 'keyFrame', 'spanFrames', 'tailStart', 'tailFrames', 'prevMask',
]);
const readJson = (p, fallback) => (fs.existsSync(p) ? JSON.parse(fs.readFileSync(p, 'utf8')) : fallback);
diff --git a/scripts/comfy/hand-built/video-character-swap-h3-segment.json b/scripts/comfy/hand-built/video-character-swap-h3-segment.json
new file mode 100644
index 00000000..3994ce04
--- /dev/null
+++ b/scripts/comfy/hand-built/video-character-swap-h3-segment.json
@@ -0,0 +1,892 @@
+{
+ "model": {
+ "class_type": "UNETLoader",
+ "inputs": {
+ "unet_name": "minimax_h3_ref2va_pruned_int8_convrot.safetensors",
+ "weight_dtype": "default"
+ },
+ "_meta": {
+ "title": "UNETLoader"
+ }
+ },
+ "shift": {
+ "class_type": "MiniMaxH3SigmaShift",
+ "inputs": {
+ "model": [
+ "model",
+ 0
+ ],
+ "shift_video": 12.0,
+ "shift_audio": 3.0
+ },
+ "_meta": {
+ "title": "MiniMaxH3SigmaShift"
+ }
+ },
+ "attention": {
+ "class_type": "ModelAttentionBackend",
+ "inputs": {
+ "model": [
+ "shift",
+ 0
+ ],
+ "attention": "comfy kitchen attention"
+ },
+ "_meta": {
+ "title": "ModelAttentionBackend"
+ }
+ },
+ "text": {
+ "class_type": "CLIPLoader",
+ "inputs": {
+ "clip_name": "qwen3vl_32b_minimax_h3_nvfp4_awq.safetensors",
+ "type": "minimax",
+ "device": "default"
+ },
+ "_meta": {
+ "title": "CLIPLoader"
+ }
+ },
+ "text_device": {
+ "class_type": "SelectCLIPDevice",
+ "inputs": {
+ "clip": [
+ "text",
+ 0
+ ],
+ "device": "gpu:0"
+ },
+ "_meta": {
+ "title": "SelectCLIPDevice"
+ }
+ },
+ "text_memory": {
+ "class_type": "H3RelayTextMemory",
+ "inputs": {
+ "clip": [
+ "text_device",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "H3RelayTextMemory"
+ }
+ },
+ "video_vae": {
+ "class_type": "VAELoader",
+ "inputs": {
+ "vae_name": "minimax_h3_video_vae_fp16.safetensors"
+ },
+ "_meta": {
+ "title": "VAELoader"
+ }
+ },
+ "audio_vae": {
+ "class_type": "VAELoader",
+ "inputs": {
+ "vae_name": "minimax_h3_audio_vae_fp32.safetensors"
+ },
+ "_meta": {
+ "title": "VAELoader"
+ }
+ },
+ "turbo": {
+ "class_type": "LoraLoaderModelOnly",
+ "inputs": {
+ "model": [
+ "attention",
+ 0
+ ],
+ "lora_name": "minimax_h3_fl2v_turbo_8step_v1.0_768p_comfyui_bf16.safetensors",
+ "strength_model": 1.0
+ },
+ "_meta": {
+ "title": "LoraLoaderModelOnly"
+ }
+ },
+ "adapter": {
+ "class_type": "LoraLoaderModelOnly",
+ "inputs": {
+ "model": [
+ "turbo",
+ 0
+ ],
+ "lora_name": "h3_character_swap_v1.5.safetensors",
+ "strength_model": 1.0
+ },
+ "_meta": {
+ "title": "LoraLoaderModelOnly"
+ }
+ },
+ "source": {
+ "class_type": "LoadVideo",
+ "inputs": {
+ "file": "source.mp4"
+ },
+ "_meta": {
+ "title": "LoadVideo"
+ }
+ },
+ "trim": {
+ "class_type": "Video Slice",
+ "inputs": {
+ "video": [
+ "source",
+ 0
+ ],
+ "start_time": 0,
+ "duration": 5.0,
+ "strict_duration": false
+ },
+ "_meta": {
+ "title": "The chosen part"
+ }
+ },
+ "prepare": {
+ "class_type": "H3RelayPrepareSource",
+ "inputs": {
+ "video": [
+ "trim",
+ 0
+ ],
+ "resolution": "768",
+ "duration_seconds": 5.0,
+ "missing_audio": "silence"
+ },
+ "_meta": {
+ "title": "H3RelayPrepareSource"
+ }
+ },
+ "dimensions": {
+ "class_type": "GetImageSize",
+ "inputs": {
+ "image": [
+ "prepare",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "GetImageSize"
+ }
+ },
+ "reference": {
+ "class_type": "LoadImage",
+ "inputs": {
+ "image": "reference.png"
+ },
+ "_meta": {
+ "title": "LoadImage"
+ }
+ },
+ "sam": {
+ "class_type": "CheckpointLoaderSimple",
+ "inputs": {
+ "ckpt_name": "sam3.1_multiplex_fp16.safetensors"
+ },
+ "_meta": {
+ "title": "CheckpointLoaderSimple"
+ }
+ },
+ "subject": {
+ "class_type": "CLIPTextEncode",
+ "inputs": {
+ "clip": [
+ "sam",
+ 1
+ ],
+ "text": "person"
+ },
+ "_meta": {
+ "title": "CLIPTextEncode"
+ }
+ },
+ "first_frame": {
+ "class_type": "ImageFromBatch",
+ "inputs": {
+ "image": [
+ "prepare",
+ 0
+ ],
+ "batch_index": 0,
+ "length": 1
+ },
+ "_meta": {
+ "title": "ImageFromBatch"
+ }
+ },
+ "detect": {
+ "class_type": "SAM3_Detect",
+ "inputs": {
+ "model": [
+ "sam",
+ 0
+ ],
+ "image": [
+ "first_frame",
+ 0
+ ],
+ "conditioning": [
+ "subject",
+ 0
+ ],
+ "threshold": 0.35,
+ "refine_iterations": 2,
+ "individual_masks": true,
+ "positive_coords": "",
+ "negative_coords": ""
+ },
+ "_meta": {
+ "title": "SAM3_Detect"
+ }
+ },
+ "select": {
+ "class_type": "H3RelaySelectMask",
+ "inputs": {
+ "masks": [
+ "detect",
+ 0
+ ],
+ "selection": "largest",
+ "index": 0
+ },
+ "_meta": {
+ "title": "H3RelaySelectMask"
+ }
+ },
+ "track": {
+ "class_type": "SAM3_VideoTrack",
+ "inputs": {
+ "model": [
+ "sam",
+ 0
+ ],
+ "images": [
+ "prepare",
+ 0
+ ],
+ "initial_mask": [
+ "select",
+ 0
+ ],
+ "conditioning": [
+ "subject",
+ 0
+ ],
+ "detection_threshold": 0.5,
+ "max_objects": 1,
+ "detect_interval": 1
+ },
+ "_meta": {
+ "title": "SAM3_VideoTrack"
+ }
+ },
+ "mask": {
+ "class_type": "SAM3_TrackToMask",
+ "inputs": {
+ "track_data": [
+ "track",
+ 0
+ ],
+ "object_indices": ""
+ },
+ "_meta": {
+ "title": "SAM3_TrackToMask"
+ }
+ },
+ "recover": {
+ "class_type": "H3RelayRecoverMasks",
+ "inputs": {
+ "masks": [
+ "mask",
+ 0
+ ],
+ "images": [
+ "prepare",
+ 0
+ ],
+ "source_frames": [
+ "prepare",
+ 5
+ ],
+ "model": [
+ "sam",
+ 0
+ ],
+ "conditioning": [
+ "subject",
+ 0
+ ],
+ "selection": [
+ "select",
+ 1
+ ],
+ "recover_empty_frames": true
+ },
+ "_meta": {
+ "title": "H3RelayRecoverMasks"
+ }
+ },
+ "expand_mask": {
+ "class_type": "H3RelayExpandMask",
+ "inputs": {
+ "masks": [
+ "recover",
+ 0
+ ],
+ "images": [
+ "prepare",
+ 0
+ ],
+ "source_frames": [
+ "prepare",
+ 5
+ ],
+ "expansion_px": 64
+ },
+ "_meta": {
+ "title": "H3RelayExpandMask"
+ }
+ },
+ "plan": {
+ "class_type": "H3RelayWindowPlan",
+ "inputs": {
+ "source_frames": [
+ "prepare",
+ 5
+ ],
+ "window_frames": "124",
+ "history_frames": "18",
+ "seed": 904239,
+ "schedule": "segment",
+ "seed_mode": "fixed",
+ "seed_overrides": "{}",
+ "initial_history": [
+ "history_fit",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "Plan source-aligned windows"
+ }
+ },
+ "start": {
+ "class_type": "StartLoop",
+ "inputs": {
+ "mode": "simple",
+ "mode.num_iterations": [
+ "plan",
+ 2
+ ],
+ "cache_iterations": false
+ },
+ "_meta": {
+ "title": "Native loop · one H3 window"
+ }
+ },
+ "window": {
+ "class_type": "H3RelayWindowInputs",
+ "inputs": {
+ "source": [
+ "prepare",
+ 0
+ ],
+ "window": [
+ "plan",
+ 3
+ ],
+ "iteration_index": [
+ "start",
+ 0
+ ],
+ "previous": [
+ "start",
+ 4
+ ],
+ "reference_history": true,
+ "fps": 24.0,
+ "resize_anchor": true,
+ "history_audio_mode": "source",
+ "source_audio": [
+ "prepare",
+ 1
+ ],
+ "mask": [
+ "expand_mask",
+ 0
+ ],
+ "anchor": [
+ "anchor_image",
+ 0
+ ],
+ "initial_history": [
+ "history_fit",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "H3RelayWindowInputs"
+ }
+ },
+ "reference_conditioning": {
+ "class_type": "MiniMaxH3ReferenceToVideo",
+ "inputs": {
+ "clip": [
+ "text_memory",
+ 0
+ ],
+ "prompt": "Replace the selected person in <Video 1> with the character in <Picture 1>. Preserve the source performance, scene and audio timing.",
+ "width": [
+ "dimensions",
+ 0
+ ],
+ "height": [
+ "dimensions",
+ 1
+ ],
+ "length": [
+ "window",
+ 8
+ ],
+ "ref_image_size": "match",
+ "ref_videos.ref_video_0": [
+ "window",
+ 5
+ ],
+ "ref_images.ref_image_0": [
+ "reference",
+ 0
+ ],
+ "vae": [
+ "video_vae",
+ 0
+ ],
+ "audio_vae": [
+ "audio_vae",
+ 0
+ ],
+ "ref_audios.ref_audio_0": [
+ "window",
+ 6
+ ],
+ "ref_images.ref_image_1": [
+ "window",
+ 11
+ ]
+ },
+ "_meta": {
+ "title": "Native H3 reference conditioning"
+ }
+ },
+ "history": {
+ "class_type": "H3RelayApplyHistory",
+ "inputs": {
+ "positive": [
+ "reference_conditioning",
+ 0
+ ],
+ "latent": [
+ "reference_conditioning",
+ 1
+ ],
+ "vae": [
+ "video_vae",
+ 0
+ ],
+ "audio_vae": [
+ "audio_vae",
+ 0
+ ],
+ "frames": [
+ "window",
+ 3
+ ],
+ "history_frames": [
+ "window",
+ 7
+ ],
+ "first_frame_guide": true,
+ "target_audio_guide": true,
+ "audio": [
+ "window",
+ 4
+ ]
+ },
+ "_meta": {
+ "title": "H3RelayApplyHistory"
+ }
+ },
+ "encode_source": {
+ "class_type": "VAEEncode",
+ "inputs": {
+ "pixels": [
+ "window",
+ 0
+ ],
+ "vae": [
+ "video_vae",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "VAEEncode"
+ }
+ },
+ "edit_mask": {
+ "class_type": "H3RelayApplyEditMask",
+ "inputs": {
+ "latent": [
+ "history",
+ 1
+ ],
+ "source_latent": [
+ "encode_source",
+ 0
+ ],
+ "mask": [
+ "window",
+ 1
+ ]
+ },
+ "_meta": {
+ "title": "H3RelayApplyEditMask"
+ }
+ },
+ "guide": {
+ "class_type": "MiniMaxH3AddGuide",
+ "inputs": {
+ "positive": [
+ "history",
+ 0
+ ],
+ "latent": [
+ "edit_mask",
+ 0
+ ],
+ "frame_idx": 0,
+ "audio_vae": [
+ "audio_vae",
+ 0
+ ],
+ "audio": [
+ "window",
+ 2
+ ]
+ },
+ "_meta": {
+ "title": "Native target guide"
+ }
+ },
+ "sampling_memory": {
+ "class_type": "H3RelaySamplingMemory",
+ "inputs": {
+ "model": [
+ "adapter",
+ 0
+ ],
+ "latent": [
+ "edit_mask",
+ 0
+ ],
+ "conditioning": [
+ "guide",
+ 0
+ ],
+ "activation_memory_gib": 17.0
+ },
+ "_meta": {
+ "title": "H3RelaySamplingMemory"
+ }
+ },
+ "noise": {
+ "class_type": "RandomNoise",
+ "inputs": {
+ "noise_seed": [
+ "window",
+ 10
+ ]
+ },
+ "_meta": {
+ "title": "RandomNoise"
+ }
+ },
+ "guider": {
+ "class_type": "CFGGuider",
+ "inputs": {
+ "model": [
+ "sampling_memory",
+ 0
+ ],
+ "positive": [
+ "guide",
+ 0
+ ],
+ "negative": [
+ "guide",
+ 0
+ ],
+ "cfg": 1.0
+ },
+ "_meta": {
+ "title": "CFGGuider"
+ }
+ },
+ "sampler": {
+ "class_type": "KSamplerSelect",
+ "inputs": {
+ "sampler_name": "er_sde"
+ },
+ "_meta": {
+ "title": "KSamplerSelect"
+ }
+ },
+ "schedule": {
+ "class_type": "BasicScheduler",
+ "inputs": {
+ "model": [
+ "adapter",
+ 0
+ ],
+ "scheduler": "normal",
+ "steps": 8,
+ "denoise": 1.0
+ },
+ "_meta": {
+ "title": "BasicScheduler"
+ }
+ },
+ "sample": {
+ "class_type": "SamplerCustomAdvanced",
+ "inputs": {
+ "noise": [
+ "noise",
+ 0
+ ],
+ "guider": [
+ "guider",
+ 0
+ ],
+ "sampler": [
+ "sampler",
+ 0
+ ],
+ "sigmas": [
+ "schedule",
+ 0
+ ],
+ "latent_image": [
+ "edit_mask",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "SamplerCustomAdvanced"
+ }
+ },
+ "separate": {
+ "class_type": "LTXVSeparateAVLatent",
+ "inputs": {
+ "av_latent": [
+ "sample",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "LTXVSeparateAVLatent"
+ }
+ },
+ "decode": {
+ "class_type": "VAEDecode",
+ "inputs": {
+ "samples": [
+ "separate",
+ 0
+ ],
+ "vae": [
+ "video_vae",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "VAEDecode"
+ }
+ },
+ "append": {
+ "class_type": "H3RelayAppendWindow",
+ "inputs": {
+ "frames": [
+ "decode",
+ 0
+ ],
+ "window": [
+ "window",
+ 12
+ ],
+ "previous": [
+ "start",
+ 4
+ ],
+ "initial_history": [
+ "history_fit",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "H3RelayAppendWindow"
+ }
+ },
+ "end": {
+ "class_type": "EndLoop",
+ "inputs": {
+ "output_value": [
+ "append",
+ 0
+ ],
+ "next_iteration_value": [
+ "append",
+ 0
+ ],
+ "accumulate": false
+ },
+ "_meta": {
+ "title": "EndLoop"
+ }
+ },
+ "finish": {
+ "class_type": "H3RelayFinishWindows",
+ "inputs": {
+ "state": [
+ "end",
+ 0
+ ],
+ "audio_mode": "source",
+ "source_audio": [
+ "prepare",
+ 1
+ ]
+ },
+ "_meta": {
+ "title": "H3RelayFinishWindows"
+ }
+ },
+ "video": {
+ "class_type": "CreateVideo",
+ "inputs": {
+ "images": [
+ "finish",
+ 0
+ ],
+ "fps": [
+ "finish",
+ 2
+ ],
+ "audio": [
+ "finish",
+ 1
+ ]
+ },
+ "_meta": {
+ "title": "CreateVideo"
+ }
+ },
+ "save": {
+ "class_type": "SaveVideo",
+ "inputs": {
+ "video": [
+ "video",
+ 0
+ ],
+ "filename_prefix": "fuobe/character-swap-segment",
+ "format": "mp4",
+ "format.codec": "h264",
+ "format.codec.encoding": "re-encode",
+ "format.codec.encoding.crf": 16
+ },
+ "_meta": {
+ "title": "SaveVideo"
+ }
+ },
+ "anchor_image": {
+ "class_type": "LoadImage",
+ "inputs": {
+ "image": "anchor.png"
+ },
+ "_meta": {
+ "title": "Anchor (Picture 2, or 3 after the boundary)"
+ }
+ },
+ "history_source": {
+ "class_type": "LoadVideo",
+ "inputs": {
+ "file": "history.mkv"
+ },
+ "_meta": {
+ "title": "Previous take (lossless master)"
+ }
+ },
+ "history_components": {
+ "class_type": "GetVideoComponents",
+ "inputs": {
+ "video": [
+ "history_source",
+ 0
+ ]
+ }
+ },
+ "history_tail": {
+ "class_type": "ImageFromBatch",
+ "inputs": {
+ "image": [
+ "history_components",
+ 0
+ ],
+ "batch_index": 106,
+ "length": 18
+ },
+ "_meta": {
+ "title": "Its last frames"
+ }
+ },
+ "history_fit": {
+ "class_type": "ImageScale",
+ "inputs": {
+ "image": [
+ "history_tail",
+ 0
+ ],
+ "upscale_method": "lanczos",
+ "width": [
+ "dimensions",
+ 0
+ ],
+ "height": [
+ "dimensions",
+ 1
+ ],
+ "crop": "center"
+ },
+ "_meta": {
+ "title": "History at the canvas size"
+ }
+ },
+ "save_master": {
+ "class_type": "VHS_VideoCombine",
+ "inputs": {
+ "images": [
+ "finish",
+ 0
+ ],
+ "frame_rate": 24,
+ "loop_count": 0,
+ "filename_prefix": "fuobe/character-swap-master",
+ "format": "video/ffv1-mkv",
+ "pingpong": false,
+ "save_output": true,
+ "pix_fmt": "rgba64le",
+ "save_metadata": false,
+ "trim_to_audio": false
+ },
+ "_meta": {
+ "title": "Lossless master (FFV1)"
+ }
+ }
+}
\ No newline at end of file
diff --git a/scripts/comfy/hand-built/video-mask-h3-relay.json b/scripts/comfy/hand-built/video-mask-h3-relay.json
new file mode 100644
index 00000000..1048d618
--- /dev/null
+++ b/scripts/comfy/hand-built/video-mask-h3-relay.json
@@ -0,0 +1,336 @@
+{
+ "source": {
+ "class_type": "LoadVideo",
+ "inputs": {
+ "file": "source.mp4"
+ },
+ "_meta": {
+ "title": "LoadVideo"
+ }
+ },
+ "trim": {
+ "class_type": "Video Slice",
+ "inputs": {
+ "video": [
+ "source",
+ 0
+ ],
+ "start_time": 0,
+ "duration": 5.0,
+ "strict_duration": false
+ },
+ "_meta": {
+ "title": "The chosen part"
+ }
+ },
+ "prepare": {
+ "class_type": "H3RelayPrepareSource",
+ "inputs": {
+ "video": [
+ "trim",
+ 0
+ ],
+ "resolution": "768",
+ "duration_seconds": 5.0,
+ "missing_audio": "silence"
+ },
+ "_meta": {
+ "title": "H3RelayPrepareSource"
+ }
+ },
+ "dimensions": {
+ "class_type": "GetImageSize",
+ "inputs": {
+ "image": [
+ "prepare",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "GetImageSize"
+ }
+ },
+ "sam": {
+ "class_type": "CheckpointLoaderSimple",
+ "inputs": {
+ "ckpt_name": "sam3.1_multiplex_fp16.safetensors"
+ },
+ "_meta": {
+ "title": "CheckpointLoaderSimple"
+ }
+ },
+ "subject": {
+ "class_type": "CLIPTextEncode",
+ "inputs": {
+ "clip": [
+ "sam",
+ 1
+ ],
+ "text": "person"
+ },
+ "_meta": {
+ "title": "CLIPTextEncode"
+ }
+ },
+ "key_frame": {
+ "class_type": "ImageFromBatch",
+ "inputs": {
+ "image": [
+ "prepare",
+ 0
+ ],
+ "batch_index": 0,
+ "length": 1
+ },
+ "_meta": {
+ "title": "The frame you clicked"
+ }
+ },
+ "detect": {
+ "class_type": "SAM3_Detect",
+ "inputs": {
+ "model": [
+ "sam",
+ 0
+ ],
+ "image": [
+ "key_frame",
+ 0
+ ],
+ "conditioning": [
+ "subject",
+ 0
+ ],
+ "threshold": 0.35,
+ "refine_iterations": 2,
+ "individual_masks": true,
+ "positive_coords": "",
+ "negative_coords": ""
+ },
+ "_meta": {
+ "title": "SAM3_Detect"
+ }
+ },
+ "select": {
+ "class_type": "H3RelaySelectMask",
+ "inputs": {
+ "masks": [
+ "detect",
+ 0
+ ],
+ "selection": "largest",
+ "index": 0
+ },
+ "_meta": {
+ "title": "H3RelaySelectMask"
+ }
+ },
+ "span": {
+ "class_type": "ImageFromBatch",
+ "inputs": {
+ "image": [
+ "prepare",
+ 0
+ ],
+ "batch_index": 0,
+ "length": 120
+ },
+ "_meta": {
+ "title": "Frames to track"
+ }
+ },
+ "track": {
+ "class_type": "SAM3_VideoTrack",
+ "inputs": {
+ "model": [
+ "sam",
+ 0
+ ],
+ "images": [
+ "span",
+ 0
+ ],
+ "initial_mask": [
+ "select",
+ 0
+ ],
+ "conditioning": [
+ "subject",
+ 0
+ ],
+ "detection_threshold": 0.5,
+ "max_objects": 1,
+ "detect_interval": 1
+ },
+ "_meta": {
+ "title": "SAM3_VideoTrack"
+ }
+ },
+ "mask": {
+ "class_type": "SAM3_TrackToMask",
+ "inputs": {
+ "track_data": [
+ "track",
+ 0
+ ],
+ "object_indices": ""
+ },
+ "_meta": {
+ "title": "SAM3_TrackToMask"
+ }
+ },
+ "recover": {
+ "class_type": "H3RelayRecoverMasks",
+ "inputs": {
+ "masks": [
+ "mask",
+ 0
+ ],
+ "images": [
+ "span",
+ 0
+ ],
+ "source_frames": 120,
+ "model": [
+ "sam",
+ 0
+ ],
+ "conditioning": [
+ "subject",
+ 0
+ ],
+ "selection": [
+ "select",
+ 1
+ ],
+ "recover_empty_frames": true
+ },
+ "_meta": {
+ "title": "H3RelayRecoverMasks"
+ }
+ },
+ "new_images": {
+ "class_type": "MaskToImage",
+ "inputs": {
+ "mask": [
+ "recover",
+ 0
+ ]
+ }
+ },
+ "prev_source": {
+ "class_type": "LoadVideo",
+ "inputs": {
+ "file": "previous-mask.mp4"
+ },
+ "_meta": {
+ "title": "The mask it corrects"
+ }
+ },
+ "prev_frames": {
+ "class_type": "GetVideoComponents",
+ "inputs": {
+ "video": [
+ "prev_source",
+ 0
+ ]
+ }
+ },
+ "prev_fit": {
+ "class_type": "ImageScale",
+ "inputs": {
+ "image": [
+ "prev_frames",
+ 0
+ ],
+ "upscale_method": "nearest-exact",
+ "width": [
+ "dimensions",
+ 0
+ ],
+ "height": [
+ "dimensions",
+ 1
+ ],
+ "crop": "center"
+ }
+ },
+ "head": {
+ "class_type": "ImageFromBatch",
+ "inputs": {
+ "image": [
+ "prev_fit",
+ 0
+ ],
+ "batch_index": 0,
+ "length": 1
+ },
+ "_meta": {
+ "title": "Before the new part"
+ }
+ },
+ "tail": {
+ "class_type": "ImageFromBatch",
+ "inputs": {
+ "image": [
+ "prev_fit",
+ 0
+ ],
+ "batch_index": 2,
+ "length": 1
+ },
+ "_meta": {
+ "title": "After the new part"
+ }
+ },
+ "join_head": {
+ "class_type": "ImageBatch",
+ "inputs": {
+ "image1": [
+ "head",
+ 0
+ ],
+ "image2": [
+ "new_images",
+ 0
+ ]
+ }
+ },
+ "join_tail": {
+ "class_type": "ImageBatch",
+ "inputs": {
+ "image1": [
+ "join_head",
+ 0
+ ],
+ "image2": [
+ "tail",
+ 0
+ ]
+ }
+ },
+ "video": {
+ "class_type": "CreateVideo",
+ "inputs": {
+ "images": [
+ "join_tail",
+ 0
+ ],
+ "fps": 24.0
+ }
+ },
+ "save": {
+ "class_type": "SaveVideo",
+ "inputs": {
+ "video": [
+ "video",
+ 0
+ ],
+ "filename_prefix": "fuobe/character-swap-mask",
+ "format": "mp4",
+ "format.codec": "h264",
+ "format.codec.encoding": "re-encode",
+ "format.codec.encoding.crf": 10
+ }
+ }
+}
\ No newline at end of file
diff --git a/scripts/comfy/library.spec.mjs b/scripts/comfy/library.spec.mjs
index d485362f..0e6a5d91 100644
--- a/scripts/comfy/library.spec.mjs
+++ b/scripts/comfy/library.spec.mjs
@@ -2887,6 +2887,66 @@ export const SPEC = [
'Needs the h3-relay pack (H3_RELAY=1) and FFmpeg. Not validated here: the pack is not installed on this server.',
},
+ // Character Swap Studio (o/h3-studio; docs/research/openjutsu-6.md §4.2): Akatz Labs' H3 Character Swap workbench for whole
+ // clips. A segment is one H3 Relay 2.0 pass ("segment" schedule) over its frames plus the history before it; the
+ // previous take's lossless master supplies that history (Akatz's continuation masters), the approved mask replaces
+ // SAM's own when there is one, and an anchor is Picture 2 (Picture 3 after the boundary). The mask graph is the same
+ // SAM 3.1 chain on any frame of a shot, spliced into the version it corrects.
+ {
+ id: 'video-character-swap-h3-segment',
+ title: 'Character Swap Studio segment: one H3 Relay 2.0 pass with the approved mask, an anchor and the previous take\'s lossless master as history (h3-relay pack)',
+ capability: 'video-character-swap',
+ handBuilt: 'hand-built/video-character-swap-h3-segment.json',
+ packs: ['h3-relay'],
+ modelUrls: { 'sam3.1_multiplex_fp16.safetensors': 'https://huggingface.co/Comfy-Org/sam3.1/resolve/7bb8374780a725b4353ed31f3a9395c9742b5621/checkpoints/sam3.1_multiplex_fp16.safetensors' },
+ optionalModels: ['h3_character_swap_pro4500_1000.safetensors'],
+ bindings: {
+ video: [b('source', 'file')], image: [b('reference', 'image')], image2: [b('anchor_image', 'image')],
+ startTime: [b('trim', 'start_time')], duration: [b('trim', 'duration'), b('prepare', 'duration_seconds')], quality: [b('prepare', 'resolution')],
+ prompt: [b('reference_conditioning', 'prompt')], seed: [b('plan', 'seed')], steps: [b('schedule', 'steps')], cfg: [b('guider', 'cfg')], audioGuide: [b('history', 'target_audio_guide')],
+ maskPrompt: [b('subject', 'text')], selection: [b('select', 'selection')], subjectIndex: [b('select', 'index')], maskGrow: [b('expand_mask', 'expansion_px')],
+ positiveCoords: [b('detect', 'positive_coords')], negativeCoords: [b('detect', 'negative_coords')],
+ windowFrames: [b('plan', 'window_frames')], historyFrames: [b('plan', 'history_frames')],
+ historyVideo: [b('history_source', 'file')], historyStart: [b('history_tail', 'batch_index')], historyLength: [b('history_tail', 'length')],
+ lora: [b('adapter', 'lora_name')], loraStrength: [b('adapter', 'strength_model')], filenamePrefix: [b('save', 'filename_prefix'), b('save_master', 'filename_prefix')],
+ },
+ outputs: [{ node: 'save', kind: 'video' }, { node: 'save_master', kind: 'video', role: 'master' }],
+ defaults: { quality: '768', maskPrompt: 'person', selection: 'largest', subjectIndex: 0, maskGrow: 64, audioGuide: true, windowFrames: '124', historyFrames: '18', lora: 'h3_character_swap_v1.5.safetensors' },
+ limits: { maxDurationSec: 30, maxFrames: 703 },
+ vramGb: 24,
+ license: 'MiniMax H3 Community License (H3 Ref2VA, its video and audio VAEs, the packaged Qwen3-VL text encoder, Akatz Labs\' Character Swap LoRA): territory EXCLUDES the US, the EU, the UK and South Korea; commercial use above US$20M yearly revenue needs MiniMax\'s written authorization; show "MiniMax H3" on the product\'s interface; no outputs used to improve other AI models · Qwen3-VL-32B base Apache-2.0 · SAM 3.1 under Meta\'s SAM License (commercial use allowed under its terms) · FL2V Turbo LoRA Apache-2.0 at the pinned revision · H3 Relay nodes GPL-3.0 (Sendy Software LLC and contributors; vendored Context Loop and Spectrum GPL-3.0); the graph is built from H3 Relay\'s example workflow (GPL-3.0 repository)',
+ notes:
+ 'One segment of Character Swap Studio on your GPU, built from video-character-swap-h3-relay: the window plan runs H3 Relay\'s "segment" schedule (one pass, at most 362 frames with its continuation boundary). ' +
+ 'video = the clip at 24 fps (oss-fit-clip), startTime / duration = the segment and the history frames before it (the app starts half a frame early and runs a quarter frame long, so Trim Video and PrepareVideo keep exactly those frames), image = the character, image2 = the anchor (absent: the provider deletes it, unlinks the window\'s anchor, drops Picture 2 and the first-frame guide unless there is history). ' +
+ 'historyVideo = the previous take\'s lossless master (save_master, 16-bit FFV1), historyStart / historyLength = its last frames, which become initial_history on the plan, the window and the append (Akatz\'s H3RelayLoadHistory route, with frames instead of an NPZ); absent: the provider deletes that branch. With history and an anchor the anchor is Picture 3 (the window\'s anchor output is then the generated boundary). ' +
+ 'The approved mask (params.extra.maskVideo, a whole-shot mask at 24 fps from video-mask-h3-relay) is added by the provider: Trim Video at maskStart for the same duration, fitted to the canvas, red channel to a mask, into the expansion instead of SAM\'s own chain; useMask false bypasses the edit mask (the whole frame is regenerated). ' +
+ 'Outputs: the segment (H.264) and its lossless master (role master) for the next segment. Needs the h3-relay pack (H3_RELAY=1), VideoHelperSuite and FFmpeg. Not validated here: the pack is not installed on this server.',
+ },
+ {
+ id: 'video-mask-h3-relay',
+ title: 'Character Swap Studio mask: SAM 3.1 finds the person on any frame of a shot (words, largest / leftmost / rightmost / #n, or clicks), follows them to the end of the shot or redoes one frame, spliced into the mask it corrects (h3-relay pack)',
+ capability: 'person-mask',
+ handBuilt: 'hand-built/video-mask-h3-relay.json',
+ packs: ['h3-relay'],
+ modelUrls: { 'sam3.1_multiplex_fp16.safetensors': 'https://huggingface.co/Comfy-Org/sam3.1/resolve/7bb8374780a725b4353ed31f3a9395c9742b5621/checkpoints/sam3.1_multiplex_fp16.safetensors' },
+ bindings: {
+ video: [b('source', 'file')], startTime: [b('trim', 'start_time')], duration: [b('trim', 'duration'), b('prepare', 'duration_seconds')], quality: [b('prepare', 'resolution')],
+ maskPrompt: [b('subject', 'text')], selection: [b('select', 'selection')], subjectIndex: [b('select', 'index')],
+ positiveCoords: [b('detect', 'positive_coords')], negativeCoords: [b('detect', 'negative_coords')],
+ keyFrame: [b('key_frame', 'batch_index'), b('span', 'batch_index'), b('head', 'length')], spanFrames: [b('span', 'length'), b('recover', 'source_frames')],
+ tailStart: [b('tail', 'batch_index')], tailFrames: [b('tail', 'length')], prevMask: [b('prev_source', 'file')],
+ filenamePrefix: [b('save', 'filename_prefix')],
+ },
+ outputs: [{ node: 'save', kind: 'video', role: 'matte' }],
+ defaults: { quality: '768', maskPrompt: 'person', selection: 'largest', subjectIndex: 0, keyFrame: 0, spanFrames: 120 },
+ limits: { maxDurationSec: 150, maxFrames: 3592 },
+ vramGb: 6,
+ license: 'SAM 3.1 under Meta\'s SAM License (commercial use allowed under its terms) · H3 Relay nodes GPL-3.0 (Sendy Software LLC and contributors)',
+ notes:
+ 'Who to swap in one shot, as a black-and-white mask video at H3\'s canvas size and 24 fps (white = the person): the shot is prepared like a segment (H3 Relay\'s PrepareSource), SAM 3.1 detects on frame keyFrame from the words (maskPrompt) and the clicks (positiveCoords / negativeCoords, moved into the canvas by the provider; a click makes its detection first, so selection becomes index 0), H3RelaySelectMask picks largest / leftmost / rightmost / #n as the swap graphs do, SAM 3.1 tracks it for spanFrames (the rest of the shot for Track shot, 1 for Update frame) and recovers empty frames. ' +
+ 'prevMask = the version it corrects: its frames before (head) and after (tail) the new part are spliced around it; without one the provider links the new part straight to the video (and puts blank frames before a track that starts mid-shot). Akatz Labs\' app does the same with its own nodes (mask versions, Update frame, Track shot). Needs the h3-relay pack. Not validated here: the pack is not installed on this server.',
+ },
+
// ---- Faceless "Frame by frame": Ken Burns over a still ------------------------------
{
id: 'kenburns-still',
diff --git a/scripts/comfy/validation-state.json b/scripts/comfy/validation-state.json
index 350e4e70..623e6595 100644
--- a/scripts/comfy/validation-state.json
+++ b/scripts/comfy/validation-state.json
@@ -587,6 +587,12 @@
"error": "HTTP 400: missing_node_type: Node 'H3RelayAppendWindow' not found. The custom node may not be installed. (Node ID '#append')",
"at": "2026-10-27T04:10:39.895Z"
},
+ "video-character-swap-h3-segment": {
+ "sha256": "876118b7908f3f831f4232a4cdad10235d15b736af835c84b60234a384226f4e",
+ "validated": false,
+ "error": "HTTP 400: missing_node_type: Node 'H3RelayAppendWindow' not found. The custom node may not be installed. (Node ID '#append')",
+ "at": "2026-10-27T11:01:36.134Z"
+ },
"video-concat-2": {
"sha256": "3d08966f5a3c2da662dc112df537ad4245bcd5dbb90e0451a0beb5c54d8db581",
"validated": true,
@@ -713,6 +719,12 @@
"error": null,
"at": "2026-10-23T00:12:21.209Z"
},
+ "video-mask-h3-relay": {
+ "sha256": "d5a3fc7046010b54ea070f45acc325602ed5ab5dbe403040e4d6591949084c84",
+ "validated": false,
+ "error": "HTTP 400: missing_node_type: Node 'H3RelayPrepareSource' not found. The custom node may not be installed. (Node ID '#prepare')",
+ "at": "2026-10-27T11:01:36.148Z"
+ },
"video-mux-audio": {
"sha256": "68af795bae0c0e89749819173916044e4024a6ce3035f830b48c80e0b6899181",
"validated": true,
diff --git a/src/lib/catalog/character-swap.ts b/src/lib/catalog/character-swap.ts
index c57d79be..1797cdef 100644
--- a/src/lib/catalog/character-swap.ts
+++ b/src/lib/catalog/character-swap.ts
@@ -101,8 +101,8 @@ export const TURBO_LORA: LoraRef = {
licence: { commercial: true, hostedOk: true, snapshotDate: "2026-10-27", name: "Apache-2.0" },
};
-/** The ComfyUI workflows of the Character swap. */
-export const H3_WORKFLOWS = ["video-character-swap-h3", "video-character-swap-h3-relay"] as const;
+/** The ComfyUI workflows of the Character swap (and Character Swap Studio's one-pass segment, on H3 Relay). */
+export const H3_WORKFLOWS = ["video-character-swap-h3", "video-character-swap-h3-relay", "video-character-swap-h3-segment"] as const;
/** Remove object's "Remove a person (H3)": H3 Relay's Person Removal graph (docs/research/openjutsu-6.md §4.4). */
export const H3_REMOVAL_WORKFLOW = "video-person-remove-h3-relay";
diff --git a/src/lib/catalog/models.ts b/src/lib/catalog/models.ts
index 7f314839..109d56ba 100644
--- a/src/lib/catalog/models.ts
+++ b/src/lib/catalog/models.ts
@@ -708,6 +708,31 @@ const open: ModelDef[] = [
routes: [comfy("remove-object", "video-person-remove-h3-relay", "H3 Relay Person Removal: the person painted green, 22-frame windows with 18 of history from the clean first frame (image), 12 steps, silent")],
options: { seed: true, maxImages: 1 },
}),
+ // Character Swap Studio (/character-swap, o/h3-studio): Akatz Labs' workbench for whole clips. A segment is one H3 Relay
+ // pass (its approved mask, anchor and the previous take's lossless master as history); a mask is SAM 3.1 on any frame
+ // of a shot, spliced into the version it corrects. Both run through the studio, not the composer.
+ o({
+ id: "oss-h3-swap-segment",
+ name: "H3 Character Swap · studio segment",
+ vendor: "MiniMax × Akatz Labs",
+ family: "minimax-h3",
+ kind: "video",
+ tagline: "One Character Swap Studio segment: a single H3 Relay pass with the approved mask, an anchor and the previous take's lossless master as history · 24 GB GPU with offloading, 48 GB+ advised",
+ routes: [comfy("video-swap", "video-character-swap-h3-segment", "H3 Relay segment schedule; saves the segment and its 16-bit FFV1 master")],
+ options: { seed: true, resolutions: ["480p", "768p"], maxImages: 2 },
+ hidden: true,
+ }),
+ o({
+ id: "oss-h3-person-mask",
+ name: "SAM 3.1 person mask · H3 Relay",
+ vendor: "Meta × Akatz Labs",
+ family: "sam",
+ kind: "video",
+ tagline: "Who to swap in a shot: SAM 3.1 finds them on any frame (words, largest / leftmost / rightmost / #n, or clicks) and follows them; corrections splice into the mask",
+ routes: [comfy("bg-remove-video", "video-mask-h3-relay", "a black-and-white mask video at H3's canvas size, 24 fps")],
+ options: { keepsNamed: true, matteOutputs: ["matte"] },
+ hidden: true,
+ }),
o({
id: "oss-qwen-relight",
name: "Qwen-Image-Edit Relight",
diff --git a/src/lib/comfy.ts b/src/lib/comfy.ts
index 02968f8d..60b72013 100644
--- a/src/lib/comfy.ts
+++ b/src/lib/comfy.ts
@@ -64,7 +64,8 @@ export interface ManifestOutput {
* Round 4: OCR "lines" (JSON, boxes 0–1000) and the "frame" the model saw, an EXR sequence's "frames", a whole-"scene" GLB and its
* "depth" map, a Gaussian "splat", a reference video's style "brief"; a painted eraser's last tracked "mask" (handed to the next
* window), and a matte graph's "cutout" (transparent video) and "matte" (black and white) videos. A "preview" is the clip shown
- * for an EXR export (the frames ride along zipped).
+ * for an EXR export (the frames ride along zipped). A "master" is a lossless copy a later job continues from (Character Swap
+ * Studio's segment, 16-bit FFV1).
*/
role?:
| "cues"
@@ -85,7 +86,8 @@ export interface ManifestOutput {
| "mask"
| "cutout"
| "matte"
- | "preview";
+ | "preview"
+ | "master";
}
export interface ManifestWorkflow {
diff --git a/src/lib/swap-studio-graphs.ts b/src/lib/swap-studio-graphs.ts
new file mode 100644
index 00000000..d5af28bf
--- /dev/null
+++ b/src/lib/swap-studio-graphs.ts
@@ -0,0 +1,96 @@
+/**
+ * Character Swap Studio's two ComfyUI graphs, rewritten per job (pure, so the tests run them on the real files). The
+ * graphs carry every branch a job can use, connected; a job that has no anchor, no history or no version to correct
+ * loses those branches here, and the branches a job adds (the approved mask, the anchor as Picture 3, blank frames
+ * before a mask that starts mid-shot) are inserted here. See video-character-swap-h3-segment and video-mask-h3-relay
+ * in scripts/comfy/library.spec.mjs.
+ */
+import { cloneWorkflow, dropUnused, type ComfyWorkflow } from "./comfy";
+
+const isLink = (v: unknown): v is [string, number] => Array.isArray(v) && v.length === 2 && typeof v[0] === "string" && typeof v[1] === "number";
+
+export interface SegmentGraphOptions {
+ /** An anchor image went in (image2). */
+ anchor: boolean;
+ /** The previous take's master went in (historyVideo). */
+ history: boolean;
+ /** With history and an anchor: the anchor is Picture 3, after the generated boundary. */
+ anchorAfterHistory?: boolean;
+ /** The approved mask: its ComfyUI input name, where the segment starts in it (seconds) and how long it is. */
+ mask?: { file: string; start: number; duration: number } | null;
+ /** Masked generation off: the whole frame is regenerated (the edit mask is bypassed). */
+ useMask: boolean;
+ /** Output nodes (never dropped). */
+ outputs: string[];
+}
+
+/**
+ * One segment's graph: without history the plan, the window and the append lose their initial history (and its
+ * loader goes); without an anchor and without history Picture 2 and the first-frame guide go too (the window's anchor
+ * would otherwise be the clip's own first frame). With both, the anchor moves to Picture 3 at the canvas size and the
+ * window's anchor output is the boundary. An approved mask replaces SAM's chain; masked generation off bypasses the
+ * edit mask and SAM altogether.
+ */
+export function segmentGraph(wf: ComfyWorkflow, o: SegmentGraphOptions): ComfyWorkflow {
+ const out = cloneWorkflow(wf);
+ if (!o.history) for (const id of ["plan", "window", "append"]) if (out[id]) delete out[id].inputs.initial_history;
+ const anchor = o.anchor && !!out.anchor_image;
+ const cond = out.reference_conditioning?.inputs;
+ if (cond) {
+ if (!anchor && !o.history) {
+ delete cond["ref_images.ref_image_1"];
+ if (out.history) out.history.inputs.first_frame_guide = false;
+ } else if (anchor && o.history && o.anchorAfterHistory) {
+ out.anchor_fit = { class_type: "ImageScale", inputs: { image: ["anchor_image", 0], upscale_method: "lanczos", width: ["dimensions", 0], height: ["dimensions", 1], crop: "center" }, _meta: { title: "Anchor (Picture 3) at the canvas size" } };
+ cond["ref_images.ref_image_2"] = ["anchor_fit", 0];
+ if (out.window) delete out.window.inputs.anchor;
+ }
+ }
+ if (!o.useMask) {
+ // Readers of the edit mask read its latent instead, and nothing asks SAM for a mask.
+ const src = out.edit_mask?.inputs.latent;
+ if (isLink(src)) {
+ for (const n of Object.values(out)) for (const [k, v] of Object.entries(n.inputs)) if (isLink(v) && v[0] === "edit_mask") n.inputs[k] = [...src];
+ delete out.edit_mask;
+ }
+ if (out.window) delete out.window.inputs.mask;
+ } else if (o.mask && out.expand_mask) {
+ out.mask_source = { class_type: "LoadVideo", inputs: { file: o.mask.file }, _meta: { title: "Approved mask (the shot)" } };
+ out.mask_trim = { class_type: "Video Slice", inputs: { video: ["mask_source", 0], start_time: o.mask.start, duration: o.mask.duration, strict_duration: false } };
+ out.mask_components = { class_type: "GetVideoComponents", inputs: { video: ["mask_trim", 0] } };
+ out.mask_fit = { class_type: "ImageScale", inputs: { image: ["mask_components", 0], upscale_method: "nearest-exact", width: ["dimensions", 0], height: ["dimensions", 1], crop: "center" } };
+ out.mask_channel = { class_type: "ImageToMask", inputs: { image: ["mask_fit", 0], channel: "red" } };
+ out.expand_mask.inputs.masks = ["mask_channel", 0];
+ }
+ return dropUnused(out, o.outputs);
+}
+
+export interface MaskGraphOptions {
+ /** Frames of the corrected version before the new part (0: none). */
+ head: number;
+ /** Frames of it after the new part (0: none). */
+ tail: number;
+ /** A version to correct went in (prevMask). */
+ prev: boolean;
+ outputs: string[];
+}
+
+/**
+ * A mask job's graph: the new part alone, or spliced between the corrected version's frames before and after it.
+ * A track that starts mid-shot with nothing to correct gets blank frames before it (no person: generating those frames
+ * would stop with "SAM lost the selected person", as Akatz's empty frames block rendering).
+ */
+export function maskGraph(wf: ComfyWorkflow, o: MaskGraphOptions): ComfyWorkflow {
+ const out = cloneWorkflow(wf);
+ const head = o.head > 0;
+ const tail = o.tail > 0 && o.prev;
+ if (head && !o.prev) {
+ out.head_blank = { class_type: "EmptyImage", inputs: { width: ["dimensions", 0], height: ["dimensions", 1], batch_size: o.head, color: 0 }, _meta: { title: "Before the new part (no mask yet)" } };
+ if (out.join_head) out.join_head.inputs.image1 = ["head_blank", 0];
+ }
+ const before = head ? "join_head" : "new_images";
+ if (tail) {
+ if (out.join_tail) out.join_tail.inputs.image1 = [before, 0];
+ } else if (out.video) out.video.inputs.images = [before, 0];
+ return dropUnused(out, o.outputs);
+}
diff --git a/src/server/providers/comfyui.ts b/src/server/providers/comfyui.ts
index 222b0c1a..e1d89ee2 100644
--- a/src/server/providers/comfyui.ts
+++ b/src/server/providers/comfyui.ts
@@ -43,6 +43,8 @@ import { exportValues, exrWorkflow, framesPerPass, hdrColorSpace, upscaleShortSi
import { guessKind } from "@/lib/catalog/payload";
import { loraByFile, needsToken } from "@/lib/catalog/loras";
import { CHARACTER_SWAP, packResolution, samCoords, swapPrompt, SWAP_LORAS, windowPlan } from "@/lib/catalog/character-swap";
+import { STUDIO_WORKFLOWS } from "@/lib/catalog/swap-studio-plan";
+import { maskGraph, segmentGraph, type MaskGraphOptions, type SegmentGraphOptions } from "@/lib/swap-studio-graphs";
import { getMaker, makerPrompt, OPEN_TARGET_PROBLEM, ORIGINALS, swapTarget } from "@/lib/catalog/genjutsu";
import { CLICK_OPEN_PROBLEM, HAND_OFF, REMOVE_SCENE, targetPhrase } from "@/lib/catalog/remove-object";
import type { GenInput, MediaKind, ModelRoute, Operation } from "@/lib/catalog/types";
@@ -939,6 +941,61 @@ export async function prepareWorkflow(endpointTemplate: string, input: GenInput,
// No words: Openjutsu's instruction, with the anchor sentence only when the anchor goes in (the graph's own text names it).
if (!(typeof values.prompt === "string" && values.prompt.trim())) values.prompt = swapPrompt({ engine: "open", anchor: !!b.image2 && !dropAnchor });
}
+ // Character Swap Studio's segment (one H3 Relay pass): the previous take's master as history, the approved mask in
+ // place of SAM's, the anchor after the boundary, masked generation off. Branches it doesn't use go after binding.
+ // Media inputs a studio job leaves out on purpose (their branches go after binding).
+ const studioLeft: string[] = [];
+ let studioSegment: Omit<SegmentGraphOptions, "outputs"> | null = null;
+ if (manifest.id === STUDIO_WORKFLOWS.segment) {
+ const history = typeof extra.historyVideo === "string" && !!extra.historyVideo;
+ if (!history) {
+ studioLeft.push("historyVideo");
+ for (const k of ["historyVideo", "historyStart", "historyLength"]) delete extra[k];
+ } else {
+ const start = Number(extra.historyStart);
+ const length = Number(extra.historyLength);
+ if (!Number.isInteger(start) || start < 0 || !Number.isInteger(length) || length < 1) throw new ProviderError("The continuation history needs the previous take's frame count");
+ }
+ const maskFile = typeof extra.maskVideo === "string" && extra.maskVideo ? extra.maskVideo : null;
+ const span = input.endTime !== undefined ? Math.max(0, input.endTime - start) : Number(values.duration ?? 0);
+ studioSegment = {
+ anchor: !dropAnchor,
+ history,
+ anchorAfterHistory: extra.anchorAfterHistory === true,
+ mask: maskFile ? { file: maskFile, start: Math.max(0, Number(extra.maskStart ?? 0)), duration: span } : null,
+ useMask: extra.useMask !== false,
+ };
+ for (const k of ["maskVideo", "maskStart", "anchorAfterHistory", "useMask"]) delete extra[k];
+ }
+ // Character Swap Studio's mask: who to swap on one frame of a shot (words, a selection or clicks moved into H3's
+ // canvas), followed for spanFrames, spliced into the version it corrects (prevMask).
+ let studioMask: Omit<MaskGraphOptions, "outputs"> | null = null;
+ if (manifest.id === STUDIO_WORKFLOWS.mask) {
+ values.quality = packResolution(input.resolution);
+ const words = (typeof extra.maskPrompt === "string" && extra.maskPrompt.trim()) || input.prompt?.trim() || "person";
+ values.maskPrompt = words.slice(0, 120);
+ delete extra.maskPrompt;
+ if (input.points?.length) {
+ if (!clip?.width || !clip.height) throw new ProviderError("Couldn't read the clip's size to place your clicks — pick who to swap instead");
+ const [pos, neg] = samCoords(input.points, { width: clip.width, height: clip.height }, input.resolution);
+ values.positiveCoords = pos;
+ values.negativeCoords = neg;
+ extra.selection = "index";
+ extra.subjectIndex = 0;
+ }
+ const keyFrame = Math.max(0, Math.round(Number(extra.keyFrame ?? 0)));
+ const shotFrames = Math.round(Number(extra.shotFrames ?? 0));
+ const spanFrames = Math.max(1, Math.round(Number(extra.spanFrames ?? shotFrames - keyFrame)));
+ if (!(shotFrames > 0) || keyFrame + spanFrames > shotFrames) throw new ProviderError("The mask's frames don't fit in the shot — reload and try again");
+ const prev = typeof extra.prevMask === "string" && !!extra.prevMask;
+ if (!prev) {
+ studioLeft.push("prevMask");
+ delete extra.prevMask;
+ }
+ Object.assign(extra, { keyFrame, spanFrames, tailStart: keyFrame + spanFrames, tailFrames: Math.max(1, shotFrames - keyFrame - spanFrames) });
+ delete extra.shotFrames;
+ studioMask = { head: keyFrame, tail: shotFrames - keyFrame - spanFrames, prev };
+ }
// Genjutsu's Object swap: SAM 3.1 follows what goes (params.extra.maskPrompt, or the "replace … with" part of the prompt,
// as Genjutsu sends it), the reference comes in, the prompt describes the result. Insert: the painted spot and the
// reference, the prompt says what appears there. Neither graph takes clicked points.
@@ -988,7 +1045,7 @@ export async function prepareWorkflow(endpointTemplate: string, input: GenInput,
// Reference images the user left out: dropped from a FLUX.2 reference chain, else the previous image
// again where that's harmless (style boards, multi-reference edits), else a clear "add …" message.
let graph = workflow;
- const left: string[] = [];
+ const left: string[] = [...studioLeft];
// A side nobody photographed is left out (its cut-out and crop with it); the front is needed.
if (rules.views) {
for (const k of IMAGE_SLOTS.slice(1)) {
@@ -1041,6 +1098,8 @@ export async function prepareWorkflow(endpointTemplate: string, input: GenInput,
if (dropAnchor) wf = withoutAnchor(wf, b.image2![0].node);
// LoRA "none": the swap LoRA's loader is linked out (H3 runs with the Turbo LoRA alone).
if (dropSwapLora && b.lora?.length === 1) wf = bypassNode(wf, b.lora[0].node, "model", outputIds);
+ if (studioSegment) wf = segmentGraph(wf, { ...studioSegment, outputs: outputIds });
+ if (studioMask) wf = maskGraph(wf, { ...studioMask, outputs: outputIds });
// FPS Boost to a lower rate, or one the clip divides into: no interpolation, only every n-th frame.
if (finish.bypassInterpolation) {
const id = Object.keys(wf).find((k) => wf[k].class_type === "FrameInterpolate");
diff --git a/tests/comfy-library-4.test.ts b/tests/comfy-library-4.test.ts
index 59165f39..201bcf75 100644
--- a/tests/comfy-library-4.test.ts
+++ b/tests/comfy-library-4.test.ts
@@ -58,6 +58,8 @@ const ROLES: NonNullable<ManifestOutput["role"]>[] = [
"cues", "transcript", "language", "layers", "sheet", "tiles", "first-frame", "turntable", "lines", "frame", "frames", "scene", "depth", "splat", "brief", "preview",
// remove-object package: the painted eraser's hand-off mask, the matte graphs' two videos.
"mask", "cutout", "matte",
+ // Character Swap Studio: a segment's lossless master, which the next segment continues from.
+ "master",
];
describe("round-4 ComfyUI workflows", () => {
@@ -84,7 +86,13 @@ describe("round-4 ComfyUI workflows", () => {
expect(new Set(manifest.workflows.map((w) => w.id)).size).toBe(manifest.workflows.length);
// Only the MiniMax H3 graphs wait on node packs this server doesn't have (h3_character_swap, H3 Relay): never
// installed here, so their /prompt check names a missing node (tests/comfy-character-swap.test.ts).
- expect(manifest.workflows.filter((w) => !w.validated).map((w) => w.id)).toEqual(["video-character-swap-h3", "video-character-swap-h3-relay", "video-person-remove-h3-relay"]);
+ expect(manifest.workflows.filter((w) => !w.validated).map((w) => w.id)).toEqual([
+ "video-character-swap-h3",
+ "video-character-swap-h3-relay",
+ "video-person-remove-h3-relay",
+ "video-character-swap-h3-segment",
+ "video-mask-h3-relay",
+ ]);
for (const w of manifest.workflows) for (const o of w.outputs) if (o.role) expect(ROLES, `${w.id} ${o.role}`).toContain(o.role);
});
diff --git a/tests/comfy-swap-studio.test.ts b/tests/comfy-swap-studio.test.ts
new file mode 100644
index 00000000..f6b673e0
--- /dev/null
+++ b/tests/comfy-swap-studio.test.ts
@@ -0,0 +1,187 @@
+import fs from "node:fs";
+import os from "node:os";
+import path from "node:path";
+import { afterAll, describe, expect, it } from "vitest";
+import type { ComfyWorkflow, Manifest } from "@/lib/comfy";
+import { getModel } from "@/lib/catalog";
+import { graphLoras, H3_WORKFLOWS, SWAP_LORAS, TURBO_LORA } from "@/lib/catalog/character-swap";
+import { STUDIO_MODELS, STUDIO_WORKFLOWS } from "@/lib/catalog/swap-studio-plan";
+import type { GenInput, Operation } from "@/lib/catalog/types";
+import type { MediaInfo } from "@/lib/media-probe";
+
+// Character Swap Studio's two ComfyUI graphs (H3 Relay 2.0), bound for real by the provider on the library files.
+const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "fuobe-swap-studio-comfy-"));
+process.env.FUOBE_DATA_DIR = tmp;
+process.env.COMFYUI_URL = "http://comfy.test:8188";
+const { prepareWorkflow } = await import("@/server/providers/comfyui");
+afterAll(() => fs.rmSync(tmp, { recursive: true, force: true }));
+
+const dir = path.join(process.cwd(), "workflows/comfyui");
+const manifest = JSON.parse(fs.readFileSync(path.join(dir, "manifest.json"), "utf8")) as Manifest;
+const subset = JSON.parse(fs.readFileSync(path.join(dir, "object_info.subset.json"), "utf8")) as Record<string, unknown>;
+const entry = (id: string) => manifest.workflows.find((w) => w.id === id)!;
+const file = (id: string) => JSON.parse(fs.readFileSync(path.join(dir, `${id}.json`), "utf8")) as ComfyWorkflow;
+
+const clip: MediaInfo = { container: "mp4", hasVideo: true, hasAudio: true, duration: 20, videoDuration: 20, width: 1920, height: 1080, fps: 24, frames: 480 };
+const prepare = (id: string, input: Partial<GenInput>, op: Operation) =>
+ prepareWorkflow(id, { video: "clip.mp4", ...input } as GenInput, { generationId: "g1", op, upload: async (_d, _t, name) => `up_${name}`, media: (n) => (n === "clip.mp4" ? clip : undefined) });
+const at = (wf: ComfyWorkflow, node: string, input: string) => wf[node]?.inputs[input];
+const SEG = STUDIO_WORKFLOWS.segment;
+const MASK = STUDIO_WORKFLOWS.mask;
+const SAM_CHAIN = ["sam", "subject", "first_frame", "detect", "select", "track", "mask", "recover"];
+
+describe("the studio's graphs in the library", () => {
+ it("are what the studio's models run, on H3 Relay", () => {
+ expect(getModel(STUDIO_MODELS.open.swap)!.routes[0]).toMatchObject({ provider: "comfyui", endpoint: SEG, op: "video-swap" });
+ expect(getModel(STUDIO_MODELS.open.mask)!.routes[0]).toMatchObject({ provider: "comfyui", endpoint: MASK, op: "bg-remove-video" });
+ expect(getModel(STUDIO_MODELS.open.swap)!.hidden).toBe(true);
+ expect(entry(SEG).customNodes.map((c) => c.name)).toEqual(expect.arrayContaining(["h3-relay", "ComfyUI-VideoHelperSuite"]));
+ expect(entry(MASK).customNodes.map((c) => c.name)).toEqual(["h3-relay"]);
+ expect(entry(SEG).outputs).toEqual([{ node: "save", kind: "video" }, { node: "save_master", kind: "video", role: "master" }]);
+ expect(entry(MASK).outputs).toEqual([{ node: "save", kind: "video", role: "matte" }]);
+ // The swap's weights, pinned, with their sizes.
+ for (const m of entry(SEG).models) {
+ expect(m.url, m.file).toMatch(/^https:\/\/huggingface\.co\/[^/]+\/[^/]+\/resolve\/[0-9a-f]{40}\//);
+ expect(m.sizeGb, m.file).toBeGreaterThan(0);
+ }
+ expect(entry(SEG).license).toMatch(/territory EXCLUDES the US, the EU, the UK and South Korea/);
+ expect(entry(MASK).license).toMatch(/SAM License/);
+ });
+
+ it("use core nodes this server has and H3 Relay's, which it doesn't: /prompt names one", () => {
+ for (const id of [SEG, MASK]) {
+ for (const c of new Set(Object.values(file(id)).map((n) => n.class_type))) {
+ expect(Object.hasOwn(subset, c), c).toBe(true);
+ if (/^H3Relay/.test(c)) expect(subset[c], c).toBeNull();
+ else expect(subset[c], c).not.toBeNull();
+ }
+ expect(entry(id).validated).toBe(false);
+ expect((entry(id) as { validationError?: string }).validationError).toMatch(/missing_node_type: Node 'H3Relay/);
+ }
+ });
+
+ it("downloads the swap and Turbo LoRAs before a segment runs", () => {
+ expect(H3_WORKFLOWS).toContain(SEG);
+ expect(graphLoras(SEG, {}).map((l) => l.file)).toEqual([TURBO_LORA.file, SWAP_LORAS["v1.5"].file]);
+ expect(graphLoras(SEG, { lora: "none" }).map((l) => l.file)).toEqual([TURBO_LORA.file]);
+ expect(graphLoras(MASK, {})).toEqual([]);
+ });
+});
+
+describe("a segment through the provider", () => {
+ const base = { prompt: "Replace only the selected person in <Video 1>.", images: ["hero.png"], startTime: 0, endTime: 120.25 / 24, resolution: "768p", seed: 9 };
+
+ it("starts fresh without an anchor: no history, no Picture 2, no first-frame guide; SAM picks who", async () => {
+ const { workflow: wf } = await prepare(SEG, { ...base, extra: { selection: "rightmost", subjectIndex: 0, maskPrompt: "person", maskGrow: 32 } }, "video-swap");
+ expect(at(wf, "plan", "schedule")).toBe("segment");
+ for (const id of ["plan", "window", "append"]) expect(at(wf, id, "initial_history")).toBeUndefined();
+ for (const id of ["history_source", "history_components", "history_tail", "history_fit", "anchor_image"]) expect(wf[id], id).toBeUndefined();
+ expect(at(wf, "reference_conditioning", "ref_images.ref_image_1")).toBeUndefined();
+ expect(at(wf, "history", "first_frame_guide")).toBe(false);
+ expect(at(wf, "select", "selection")).toBe("rightmost");
+ expect(at(wf, "expand_mask", "expansion_px")).toBe(32);
+ expect(at(wf, "prepare", "resolution")).toBe("768");
+ expect(at(wf, "trim", "duration")).toBeCloseTo(120.25 / 24, 9);
+ expect(at(wf, "prepare", "duration_seconds")).toBeCloseTo(120.25 / 24, 9);
+ expect(at(wf, "save_master", "format")).toBe("video/ffv1-mkv");
+ expect(at(wf, "save_master", "filename_prefix")).toBe("fuobe/g1");
+ for (const id of SAM_CHAIN) expect(wf[id], id).toBeDefined();
+ });
+
+ it("an anchor is Picture 2 through the window and guides the first frame", async () => {
+ const { workflow: wf } = await prepare(SEG, { ...base, images: ["hero.png", "anchor.png"] }, "video-swap");
+ expect(at(wf, "anchor_image", "image")).toBe("anchor.png");
+ expect(at(wf, "window", "anchor")).toEqual(["anchor_image", 0]);
+ expect(at(wf, "reference_conditioning", "ref_images.ref_image_1")).toEqual(["window", 11]);
+ expect(at(wf, "history", "first_frame_guide")).toBe(true);
+ });
+
+ it("continues from the previous take's master, the anchor after the boundary as Picture 3", async () => {
+ // (The studio sends the master's /api/files URL; the provider uploads it and binds the name it gets.)
+ const { workflow: wf } = await prepare(SEG, { ...base, images: ["hero.png", "anchor.png"], extra: { historyVideo: "up_master.mkv", historyStart: 106, historyLength: 18, anchorAfterHistory: true } }, "video-swap");
+ for (const id of ["plan", "window", "append"]) expect(at(wf, id, "initial_history")).toEqual(["history_fit", 0]);
+ expect(at(wf, "history_tail", "batch_index")).toBe(106);
+ expect(at(wf, "history_tail", "length")).toBe(18);
+ expect(at(wf, "reference_conditioning", "ref_images.ref_image_1")).toEqual(["window", 11]);
+ expect(at(wf, "reference_conditioning", "ref_images.ref_image_2")).toEqual(["anchor_fit", 0]);
+ expect(at(wf, "anchor_fit", "image")).toEqual(["anchor_image", 0]);
+ expect(at(wf, "window", "anchor")).toBeUndefined();
+ expect(at(wf, "history", "first_frame_guide")).toBe(true);
+ await expect(prepare(SEG, { ...base, extra: { historyVideo: "up_master.mkv", historyStart: -1, historyLength: 18 } }, "video-swap")).rejects.toThrow(/frame count/);
+ });
+
+ it("the approved mask replaces SAM's chain, trimmed like the segment", async () => {
+ const { workflow: wf } = await prepare(SEG, { ...base, startTime: 105.5 / 24, endTime: (105.5 + 141.25) / 24, extra: { maskVideo: "up_mask.mp4", maskStart: 105.5 / 24 } }, "video-swap");
+ expect(at(wf, "mask_source", "file")).toBe("up_mask.mp4");
+ expect(at(wf, "mask_trim", "start_time")).toBeCloseTo(105.5 / 24, 9);
+ expect(at(wf, "mask_trim", "duration")).toBeCloseTo(141.25 / 24, 9);
+ expect(at(wf, "mask_fit", "width")).toEqual(["dimensions", 0]);
+ expect(at(wf, "expand_mask", "masks")).toEqual(["mask_channel", 0]);
+ for (const id of SAM_CHAIN) expect(wf[id], id).toBeUndefined();
+ });
+
+ it("masked generation off regenerates the whole frame: no edit mask, no SAM", async () => {
+ const { workflow: wf } = await prepare(SEG, { ...base, extra: { useMask: false } }, "video-swap");
+ expect(wf.edit_mask).toBeUndefined();
+ expect(at(wf, "guide", "latent")).toEqual(["history", 1]);
+ expect(at(wf, "sample", "latent_image")).toEqual(["history", 1]);
+ expect(at(wf, "window", "mask")).toBeUndefined();
+ for (const id of [...SAM_CHAIN, "expand_mask"]) expect(wf[id], id).toBeUndefined();
+ });
+
+ it("the swap LoRA's release, or none", async () => {
+ const v1 = await prepare(SEG, { ...base, extra: { lora: "v1" } }, "video-swap");
+ expect(at(v1.workflow, "adapter", "lora_name")).toBe(SWAP_LORAS.v1.file);
+ const none = await prepare(SEG, { ...base, extra: { lora: "none" } }, "video-swap");
+ expect(none.workflow.adapter).toBeUndefined();
+ expect(at(none.workflow, "sampling_memory", "model")).toEqual(["turbo", 0]);
+ });
+});
+
+describe("a mask through the provider", () => {
+ const base = { startTime: 119.5 / 24, endTime: (119.5 + 240.25) / 24, resolution: "768p" };
+
+ it("tracks the whole shot from its first frame: the new part alone", async () => {
+ const { workflow: wf } = await prepare(MASK, { ...base, prompt: "person", extra: { keyFrame: 0, spanFrames: 240, shotFrames: 240, selection: "largest", subjectIndex: 0 } }, "bg-remove-video");
+ expect(at(wf, "video", "images")).toEqual(["new_images", 0]);
+ for (const id of ["prev_source", "prev_frames", "prev_fit", "head", "tail", "join_head", "join_tail", "head_blank"]) expect(wf[id], id).toBeUndefined();
+ expect(at(wf, "key_frame", "batch_index")).toBe(0);
+ expect(at(wf, "span", "length")).toBe(240);
+ expect(at(wf, "recover", "source_frames")).toBe(240);
+ expect(at(wf, "subject", "text")).toBe("person");
+ expect(at(wf, "prepare", "resolution")).toBe("768");
+ });
+
+ it("redoes one clicked frame inside the version it corrects", async () => {
+ const { workflow: wf } = await prepare(
+ MASK,
+ { ...base, points: [{ x: 960, y: 540, label: "positive" }, { x: 100, y: 100, label: "negative" }], extra: { keyFrame: 30, spanFrames: 1, shotFrames: 240, prevMask: "up_prev.mp4", maskPrompt: "the man in the hat" } },
+ "bg-remove-video",
+ );
+ expect(at(wf, "prev_source", "file")).toBe("up_prev.mp4");
+ expect(at(wf, "head", "length")).toBe(30);
+ expect(at(wf, "tail", "batch_index")).toBe(31);
+ expect(at(wf, "tail", "length")).toBe(209);
+ expect(at(wf, "join_head", "image1")).toEqual(["head", 0]);
+ expect(at(wf, "join_tail", "image1")).toEqual(["join_head", 0]);
+ expect(at(wf, "video", "images")).toEqual(["join_tail", 0]);
+ // The click is the person: SAM's first detection; the points are in H3's 1 MP canvas.
+ expect(at(wf, "select", "selection")).toBe("index");
+ expect(at(wf, "select", "index")).toBe(0);
+ expect(JSON.parse(String(at(wf, "detect", "positive_coords")))).toHaveLength(1);
+ expect(JSON.parse(String(at(wf, "detect", "negative_coords")))).toHaveLength(1);
+ expect(at(wf, "subject", "text")).toBe("the man in the hat");
+ });
+
+ it("tracks from a later frame: the corrected version before it, or blank frames when there is none", async () => {
+ const after = await prepare(MASK, { ...base, extra: { keyFrame: 100, spanFrames: 140, shotFrames: 240, prevMask: "up_prev.mp4" } }, "bg-remove-video");
+ expect(at(after.workflow, "video", "images")).toEqual(["join_head", 0]);
+ expect(after.workflow.tail).toBeUndefined();
+ const blank = await prepare(MASK, { ...base, extra: { keyFrame: 100, spanFrames: 140, shotFrames: 240 } }, "bg-remove-video");
+ expect(at(blank.workflow, "head_blank", "batch_size")).toBe(100);
+ expect(at(blank.workflow, "join_head", "image1")).toEqual(["head_blank", 0]);
+ expect(at(blank.workflow, "video", "images")).toEqual(["join_head", 0]);
+ expect(blank.workflow.prev_source).toBeUndefined();
+ await expect(prepare(MASK, { ...base, extra: { keyFrame: 200, spanFrames: 100, shotFrames: 240 } }, "bg-remove-video")).rejects.toThrow(/don't fit in the shot/);
+ });
+});
diff --git a/workflows/comfyui/manifest.json b/workflows/comfyui/manifest.json
index 59264e32..088b9e51 100644
--- a/workflows/comfyui/manifest.json
+++ b/workflows/comfyui/manifest.json
@@ -1,6 +1,6 @@
{
"version": 1,
- "generatedAt": "2026-10-27T09:34:34.799Z",
+ "generatedAt": "2026-10-27T11:01:23.799Z",
"comfyuiCommit": "fc04da91b2ab12f99e4716371a7e4f98ac982597",
"comfyuiVersion": "0.41.0",
"workflowTemplatesVersion": "0.11.86",
@@ -13628,6 +13628,425 @@
"notes": "H3 Relay's toolkit H3-Person-Removal.api.json at e2a7665b (Akatz Labs' tool ships the same file). Changed: the clean first frame goes through an ImageScale (centre crop) to the video's exact size, so an edit that came back a little larger or smaller still fits; SAM 3.1's words default to \"person\"; the save prefix. video = the part already fitted to 24 fps on the 32-pixel grid (oss-fit-clip), image = the clean first frame (the app makes it with Qwen-Image-Edit from the part's first frame). 22-frame windows with 18 of history, 12 steps, er_sde / simple, CFG 1, LoRA 1.0, mask grown 5 px, seed 904234 by default (Akatz's settings). The output is silent: the app puts the clip's sound back. Needs the h3-relay pack (H3_RELAY=1) and FFmpeg. Not validated here: the pack is not installed on this server.",
"validationError": "HTTP 400: missing_node_type: Node 'H3RelayAppendWindow' not found. The custom node may not be installed. (Node ID '#append')"
},
+ {
+ "id": "video-character-swap-h3-segment",
+ "title": "Character Swap Studio segment: one H3 Relay 2.0 pass with the approved mask, an anchor and the previous take's lossless master as history (h3-relay pack)",
+ "capability": "video-character-swap",
+ "file": "video-character-swap-h3-segment.json",
+ "source": "hand-built (scripts/comfy/hand-built/video-character-swap-h3-segment.json)",
+ "bindings": {
+ "video": [
+ {
+ "node": "source",
+ "input": "file"
+ }
+ ],
+ "image": [
+ {
+ "node": "reference",
+ "input": "image"
+ }
+ ],
+ "image2": [
+ {
+ "node": "anchor_image",
+ "input": "image"
+ }
+ ],
+ "startTime": [
+ {
+ "node": "trim",
+ "input": "start_time"
+ }
+ ],
+ "duration": [
+ {
+ "node": "trim",
+ "input": "duration"
+ },
+ {
+ "node": "prepare",
+ "input": "duration_seconds"
+ }
+ ],
+ "quality": [
+ {
+ "node": "prepare",
+ "input": "resolution"
+ }
+ ],
+ "prompt": [
+ {
+ "node": "reference_conditioning",
+ "input": "prompt"
+ }
+ ],
+ "seed": [
+ {
+ "node": "plan",
+ "input": "seed"
+ }
+ ],
+ "steps": [
+ {
+ "node": "schedule",
+ "input": "steps"
+ }
+ ],
+ "cfg": [
+ {
+ "node": "guider",
+ "input": "cfg"
+ }
+ ],
+ "audioGuide": [
+ {
+ "node": "history",
+ "input": "target_audio_guide"
+ }
+ ],
+ "maskPrompt": [
+ {
+ "node": "subject",
+ "input": "text"
+ }
+ ],
+ "selection": [
+ {
+ "node": "select",
+ "input": "selection"
+ }
+ ],
+ "subjectIndex": [
+ {
+ "node": "select",
+ "input": "index"
+ }
+ ],
+ "maskGrow": [
+ {
+ "node": "expand_mask",
+ "input": "expansion_px"
+ }
+ ],
+ "positiveCoords": [
+ {
+ "node": "detect",
+ "input": "positive_coords"
+ }
+ ],
+ "negativeCoords": [
+ {
+ "node": "detect",
+ "input": "negative_coords"
+ }
+ ],
+ "windowFrames": [
+ {
+ "node": "plan",
+ "input": "window_frames"
+ }
+ ],
+ "historyFrames": [
+ {
+ "node": "plan",
+ "input": "history_frames"
+ }
+ ],
+ "historyVideo": [
+ {
+ "node": "history_source",
+ "input": "file"
+ }
+ ],
+ "historyStart": [
+ {
+ "node": "history_tail",
+ "input": "batch_index"
+ }
+ ],
+ "historyLength": [
+ {
+ "node": "history_tail",
+ "input": "length"
+ }
+ ],
+ "lora": [
+ {
+ "node": "adapter",
+ "input": "lora_name"
+ }
+ ],
+ "loraStrength": [
+ {
+ "node": "adapter",
+ "input": "strength_model"
+ }
+ ],
+ "filenamePrefix": [
+ {
+ "node": "save",
+ "input": "filename_prefix"
+ },
+ {
+ "node": "save_master",
+ "input": "filename_prefix"
+ }
+ ]
+ },
+ "outputs": [
+ {
+ "node": "save",
+ "kind": "video"
+ },
+ {
+ "node": "save_master",
+ "kind": "video",
+ "role": "master"
+ }
+ ],
+ "defaults": {
+ "steps": 8,
+ "cfg": 1,
+ "duration": 5,
+ "loraStrength": 1,
+ "startTime": 0,
+ "maskGrow": 64,
+ "quality": "768",
+ "maskPrompt": "person",
+ "selection": "largest",
+ "subjectIndex": 0,
+ "audioGuide": true,
+ "windowFrames": "124",
+ "historyFrames": "18",
+ "lora": "h3_character_swap_v1.5.safetensors"
+ },
+ "limits": {
+ "maxDurationSec": 30,
+ "maxFrames": 703
+ },
+ "models": [
+ {
+ "file": "h3_character_swap_v1.5.safetensors",
+ "folder": "loras",
+ "url": "https://huggingface.co/akatz-ai/MiniMax-H3-Character-Swap-LoRA/resolve/d06323b7c8e70e97cdab48b78a1e05f786c8cba9/h3_character_swap_v1.5.safetensors",
+ "sizeGb": 0.16
+ },
+ {
+ "file": "minimax_h3_audio_vae_fp32.safetensors",
+ "folder": "vae",
+ "url": "https://huggingface.co/Comfy-Org/MiniMax-H3/resolve/1c41cfca8ebba91d0af792a05c5761fb2c3a7975/vae/minimax_h3_audio_vae_fp32.safetensors",
+ "sizeGb": 0.61
+ },
+ {
+ "file": "minimax_h3_ref2va_pruned_int8_convrot.safetensors",
+ "folder": "diffusion_models",
+ "url": "https://huggingface.co/Comfy-Org/MiniMax-H3/resolve/1c41cfca8ebba91d0af792a05c5761fb2c3a7975/diffusion_models/minimax_h3_ref2va_pruned_int8_convrot.safetensors",
+ "sizeGb": 20.97
+ },
+ {
+ "file": "sam3.1_multiplex_fp16.safetensors",
+ "folder": "checkpoints",
+ "url": "https://huggingface.co/Comfy-Org/sam3.1/resolve/7bb8374780a725b4353ed31f3a9395c9742b5621/checkpoints/sam3.1_multiplex_fp16.safetensors",
+ "sizeGb": 1.75
+ },
+ {
+ "file": "qwen3vl_32b_minimax_h3_nvfp4_awq.safetensors",
+ "folder": "text_encoders",
+ "url": "https://huggingface.co/Comfy-Org/MiniMax-H3/resolve/1c41cfca8ebba91d0af792a05c5761fb2c3a7975/text_encoders/qwen3vl_32b_minimax_h3_nvfp4_awq.safetensors",
+ "sizeGb": 15.69
+ },
+ {
+ "file": "minimax_h3_fl2v_turbo_8step_v1.0_768p_comfyui_bf16.safetensors",
+ "folder": "loras",
+ "url": "https://huggingface.co/lightx2v/Minimax-h3-Turbo/resolve/3ec17a324ced54151364f24f8b5fb6bf7e26414f/minimax_h3_fl2v_turbo_8step_v1.0_768p_comfyui_bf16.safetensors",
+ "sizeGb": 1.96
+ },
+ {
+ "file": "minimax_h3_video_vae_fp16.safetensors",
+ "folder": "vae",
+ "url": "https://huggingface.co/Comfy-Org/MiniMax-H3/resolve/1c41cfca8ebba91d0af792a05c5761fb2c3a7975/vae/minimax_h3_video_vae_fp16.safetensors",
+ "sizeGb": 5.21
+ },
+ {
+ "file": "h3_character_swap_pro4500_1000.safetensors",
+ "folder": "loras",
+ "url": "https://huggingface.co/akatz-ai/MiniMax-H3-Character-Swap-LoRA/resolve/a665bb7e3bb9804e487d2925f67744f554c8ad49/h3_character_swap_pro4500_1000.safetensors",
+ "sizeGb": 0.16,
+ "optional": true
+ }
+ ],
+ "customNodes": [
+ {
+ "name": "ComfyUI-VideoHelperSuite",
+ "repo": "https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite"
+ },
+ {
+ "name": "h3-relay",
+ "repo": "https://github.com/akatz-ai/h3-relay/tree/e2a7665b6eb8ea37a88c0de2c9c6b69a8f7c9220"
+ }
+ ],
+ "vramGb": 24,
+ "license": "MiniMax H3 Community License (H3 Ref2VA, its video and audio VAEs, the packaged Qwen3-VL text encoder, Akatz Labs' Character Swap LoRA): territory EXCLUDES the US, the EU, the UK and South Korea; commercial use above US$20M yearly revenue needs MiniMax's written authorization; show \"MiniMax H3\" on the product's interface; no outputs used to improve other AI models · Qwen3-VL-32B base Apache-2.0 · SAM 3.1 under Meta's SAM License (commercial use allowed under its terms) · FL2V Turbo LoRA Apache-2.0 at the pinned revision · H3 Relay nodes GPL-3.0 (Sendy Software LLC and contributors; vendored Context Loop and Spectrum GPL-3.0); the graph is built from H3 Relay's example workflow (GPL-3.0 repository)",
+ "validated": false,
+ "notes": "One segment of Character Swap Studio on your GPU, built from video-character-swap-h3-relay: the window plan runs H3 Relay's \"segment\" schedule (one pass, at most 362 frames with its continuation boundary). video = the clip at 24 fps (oss-fit-clip), startTime / duration = the segment and the history frames before it (the app starts half a frame early and runs a quarter frame long, so Trim Video and PrepareVideo keep exactly those frames), image = the character, image2 = the anchor (absent: the provider deletes it, unlinks the window's anchor, drops Picture 2 and the first-frame guide unless there is history). historyVideo = the previous take's lossless master (save_master, 16-bit FFV1), historyStart / historyLength = its last frames, which become initial_history on the plan, the window and the append (Akatz's H3RelayLoadHistory route, with frames instead of an NPZ); absent: the provider deletes that branch. With history and an anchor the anchor is Picture 3 (the window's anchor output is then the generated boundary). The approved mask (params.extra.maskVideo, a whole-shot mask at 24 fps from video-mask-h3-relay) is added by the provider: Trim Video at maskStart for the same duration, fitted to the canvas, red channel to a mask, into the expansion instead of SAM's own chain; useMask false bypasses the edit mask (the whole frame is regenerated). Outputs: the segment (H.264) and its lossless master (role master) for the next segment. Needs the h3-relay pack (H3_RELAY=1), VideoHelperSuite and FFmpeg. Not validated here: the pack is not installed on this server.",
+ "validationError": "HTTP 400: missing_node_type: Node 'H3RelayAppendWindow' not found. The custom node may not be installed. (Node ID '#append')"
+ },
+ {
+ "id": "video-mask-h3-relay",
+ "title": "Character Swap Studio mask: SAM 3.1 finds the person on any frame of a shot (words, largest / leftmost / rightmost / #n, or clicks), follows them to the end of the shot or redoes one frame, spliced into the mask it corrects (h3-relay pack)",
+ "capability": "person-mask",
+ "file": "video-mask-h3-relay.json",
+ "source": "hand-built (scripts/comfy/hand-built/video-mask-h3-relay.json)",
+ "bindings": {
+ "video": [
+ {
+ "node": "source",
+ "input": "file"
+ }
+ ],
+ "startTime": [
+ {
+ "node": "trim",
+ "input": "start_time"
+ }
+ ],
+ "duration": [
+ {
+ "node": "trim",
+ "input": "duration"
+ },
+ {
+ "node": "prepare",
+ "input": "duration_seconds"
+ }
+ ],
+ "quality": [
+ {
+ "node": "prepare",
+ "input": "resolution"
+ }
+ ],
+ "maskPrompt": [
+ {
+ "node": "subject",
+ "input": "text"
+ }
+ ],
+ "selection": [
+ {
+ "node": "select",
+ "input": "selection"
+ }
+ ],
+ "subjectIndex": [
+ {
+ "node": "select",
+ "input": "index"
+ }
+ ],
+ "positiveCoords": [
+ {
+ "node": "detect",
+ "input": "positive_coords"
+ }
+ ],
+ "negativeCoords": [
+ {
+ "node": "detect",
+ "input": "negative_coords"
+ }
+ ],
+ "keyFrame": [
+ {
+ "node": "key_frame",
+ "input": "batch_index"
+ },
+ {
+ "node": "span",
+ "input": "batch_index"
+ },
+ {
+ "node": "head",
+ "input": "length"
+ }
+ ],
+ "spanFrames": [
+ {
+ "node": "span",
+ "input": "length"
+ },
+ {
+ "node": "recover",
+ "input": "source_frames"
+ }
+ ],
+ "tailStart": [
+ {
+ "node": "tail",
+ "input": "batch_index"
+ }
+ ],
+ "tailFrames": [
+ {
+ "node": "tail",
+ "input": "length"
+ }
+ ],
+ "prevMask": [
+ {
+ "node": "prev_source",
+ "input": "file"
+ }
+ ],
+ "filenamePrefix": [
+ {
+ "node": "save",
+ "input": "filename_prefix"
+ }
+ ]
+ },
+ "outputs": [
+ {
+ "node": "save",
+ "kind": "video",
+ "role": "matte"
+ }
+ ],
+ "defaults": {
+ "duration": 5,
+ "startTime": 0,
+ "quality": "768",
+ "maskPrompt": "person",
+ "selection": "largest",
+ "subjectIndex": 0,
+ "keyFrame": 0,
+ "spanFrames": 120
+ },
+ "limits": {
+ "maxDurationSec": 150,
+ "maxFrames": 3592
+ },
+ "models": [
+ {
+ "file": "sam3.1_multiplex_fp16.safetensors",
+ "folder": "checkpoints",
+ "url": "https://huggingface.co/Comfy-Org/sam3.1/resolve/7bb8374780a725b4353ed31f3a9395c9742b5621/checkpoints/sam3.1_multiplex_fp16.safetensors",
+ "sizeGb": 1.75
+ }
+ ],
+ "customNodes": [
+ {
+ "name": "h3-relay",
+ "repo": "https://github.com/akatz-ai/h3-relay/tree/e2a7665b6eb8ea37a88c0de2c9c6b69a8f7c9220"
+ }
+ ],
+ "vramGb": 6,
+ "license": "SAM 3.1 under Meta's SAM License (commercial use allowed under its terms) · H3 Relay nodes GPL-3.0 (Sendy Software LLC and contributors)",
+ "validated": false,
+ "notes": "Who to swap in one shot, as a black-and-white mask video at H3's canvas size and 24 fps (white = the person): the shot is prepared like a segment (H3 Relay's PrepareSource), SAM 3.1 detects on frame keyFrame from the words (maskPrompt) and the clicks (positiveCoords / negativeCoords, moved into the canvas by the provider; a click makes its detection first, so selection becomes index 0), H3RelaySelectMask picks largest / leftmost / rightmost / #n as the swap graphs do, SAM 3.1 tracks it for spanFrames (the rest of the shot for Track shot, 1 for Update frame) and recovers empty frames. prevMask = the version it corrects: its frames before (head) and after (tail) the new part are spliced around it; without one the provider links the new part straight to the video (and puts blank frames before a track that starts mid-shot). Akatz Labs' app does the same with its own nodes (mask versions, Update frame, Track shot). Needs the h3-relay pack. Not validated here: the pack is not installed on this server.",
+ "validationError": "HTTP 400: missing_node_type: Node 'H3RelayPrepareSource' not found. The custom node may not be installed. (Node ID '#prepare')"
+ },
{
"id": "kenburns-still",
"title": "Ken Burns pan and zoom over a still for N seconds at F fps (core loops, chunk-encoded, no model)",
diff --git a/workflows/comfyui/video-character-swap-h3-segment.json b/workflows/comfyui/video-character-swap-h3-segment.json
new file mode 100644
index 00000000..dd03f857
--- /dev/null
+++ b/workflows/comfyui/video-character-swap-h3-segment.json
@@ -0,0 +1,892 @@
+{
+ "adapter": {
+ "class_type": "LoraLoaderModelOnly",
+ "inputs": {
+ "model": [
+ "turbo",
+ 0
+ ],
+ "lora_name": "h3_character_swap_v1.5.safetensors",
+ "strength_model": 1
+ },
+ "_meta": {
+ "title": "LoraLoaderModelOnly"
+ }
+ },
+ "anchor_image": {
+ "class_type": "LoadImage",
+ "inputs": {
+ "image": "anchor.png"
+ },
+ "_meta": {
+ "title": "Anchor (Picture 2, or 3 after the boundary)"
+ }
+ },
+ "append": {
+ "class_type": "H3RelayAppendWindow",
+ "inputs": {
+ "frames": [
+ "decode",
+ 0
+ ],
+ "window": [
+ "window",
+ 12
+ ],
+ "previous": [
+ "start",
+ 4
+ ],
+ "initial_history": [
+ "history_fit",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "H3RelayAppendWindow"
+ }
+ },
+ "attention": {
+ "class_type": "ModelAttentionBackend",
+ "inputs": {
+ "model": [
+ "shift",
+ 0
+ ],
+ "attention": "comfy kitchen attention"
+ },
+ "_meta": {
+ "title": "ModelAttentionBackend"
+ }
+ },
+ "audio_vae": {
+ "class_type": "VAELoader",
+ "inputs": {
+ "vae_name": "minimax_h3_audio_vae_fp32.safetensors"
+ },
+ "_meta": {
+ "title": "VAELoader"
+ }
+ },
+ "decode": {
+ "class_type": "VAEDecode",
+ "inputs": {
+ "samples": [
+ "separate",
+ 0
+ ],
+ "vae": [
+ "video_vae",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "VAEDecode"
+ }
+ },
+ "detect": {
+ "class_type": "SAM3_Detect",
+ "inputs": {
+ "model": [
+ "sam",
+ 0
+ ],
+ "image": [
+ "first_frame",
+ 0
+ ],
+ "conditioning": [
+ "subject",
+ 0
+ ],
+ "threshold": 0.35,
+ "refine_iterations": 2,
+ "individual_masks": true,
+ "positive_coords": "",
+ "negative_coords": ""
+ },
+ "_meta": {
+ "title": "SAM3_Detect"
+ }
+ },
+ "dimensions": {
+ "class_type": "GetImageSize",
+ "inputs": {
+ "image": [
+ "prepare",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "GetImageSize"
+ }
+ },
+ "edit_mask": {
+ "class_type": "H3RelayApplyEditMask",
+ "inputs": {
+ "latent": [
+ "history",
+ 1
+ ],
+ "source_latent": [
+ "encode_source",
+ 0
+ ],
+ "mask": [
+ "window",
+ 1
+ ]
+ },
+ "_meta": {
+ "title": "H3RelayApplyEditMask"
+ }
+ },
+ "encode_source": {
+ "class_type": "VAEEncode",
+ "inputs": {
+ "pixels": [
+ "window",
+ 0
+ ],
+ "vae": [
+ "video_vae",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "VAEEncode"
+ }
+ },
+ "end": {
+ "class_type": "EndLoop",
+ "inputs": {
+ "output_value": [
+ "append",
+ 0
+ ],
+ "next_iteration_value": [
+ "append",
+ 0
+ ],
+ "accumulate": false
+ },
+ "_meta": {
+ "title": "EndLoop"
+ }
+ },
+ "expand_mask": {
+ "class_type": "H3RelayExpandMask",
+ "inputs": {
+ "masks": [
+ "recover",
+ 0
+ ],
+ "images": [
+ "prepare",
+ 0
+ ],
+ "source_frames": [
+ "prepare",
+ 5
+ ],
+ "expansion_px": 64
+ },
+ "_meta": {
+ "title": "H3RelayExpandMask"
+ }
+ },
+ "finish": {
+ "class_type": "H3RelayFinishWindows",
+ "inputs": {
+ "state": [
+ "end",
+ 0
+ ],
+ "audio_mode": "source",
+ "source_audio": [
+ "prepare",
+ 1
+ ]
+ },
+ "_meta": {
+ "title": "H3RelayFinishWindows"
+ }
+ },
+ "first_frame": {
+ "class_type": "ImageFromBatch",
+ "inputs": {
+ "image": [
+ "prepare",
+ 0
+ ],
+ "batch_index": 0,
+ "length": 1
+ },
+ "_meta": {
+ "title": "ImageFromBatch"
+ }
+ },
+ "guide": {
+ "class_type": "MiniMaxH3AddGuide",
+ "inputs": {
+ "positive": [
+ "history",
+ 0
+ ],
+ "latent": [
+ "edit_mask",
+ 0
+ ],
+ "frame_idx": 0,
+ "audio_vae": [
+ "audio_vae",
+ 0
+ ],
+ "audio": [
+ "window",
+ 2
+ ]
+ },
+ "_meta": {
+ "title": "Native target guide"
+ }
+ },
+ "guider": {
+ "class_type": "CFGGuider",
+ "inputs": {
+ "model": [
+ "sampling_memory",
+ 0
+ ],
+ "positive": [
+ "guide",
+ 0
+ ],
+ "negative": [
+ "guide",
+ 0
+ ],
+ "cfg": 1
+ },
+ "_meta": {
+ "title": "CFGGuider"
+ }
+ },
+ "history": {
+ "class_type": "H3RelayApplyHistory",
+ "inputs": {
+ "positive": [
+ "reference_conditioning",
+ 0
+ ],
+ "latent": [
+ "reference_conditioning",
+ 1
+ ],
+ "vae": [
+ "video_vae",
+ 0
+ ],
+ "audio_vae": [
+ "audio_vae",
+ 0
+ ],
+ "frames": [
+ "window",
+ 3
+ ],
+ "history_frames": [
+ "window",
+ 7
+ ],
+ "first_frame_guide": true,
+ "target_audio_guide": true,
+ "audio": [
+ "window",
+ 4
+ ]
+ },
+ "_meta": {
+ "title": "H3RelayApplyHistory"
+ }
+ },
+ "history_components": {
+ "class_type": "GetVideoComponents",
+ "inputs": {
+ "video": [
+ "history_source",
+ 0
+ ]
+ }
+ },
+ "history_fit": {
+ "class_type": "ImageScale",
+ "inputs": {
+ "image": [
+ "history_tail",
+ 0
+ ],
+ "upscale_method": "lanczos",
+ "width": [
+ "dimensions",
+ 0
+ ],
+ "height": [
+ "dimensions",
+ 1
+ ],
+ "crop": "center"
+ },
+ "_meta": {
+ "title": "History at the canvas size"
+ }
+ },
+ "history_source": {
+ "class_type": "LoadVideo",
+ "inputs": {
+ "file": "history.mkv"
+ },
+ "_meta": {
+ "title": "Previous take (lossless master)"
+ }
+ },
+ "history_tail": {
+ "class_type": "ImageFromBatch",
+ "inputs": {
+ "image": [
+ "history_components",
+ 0
+ ],
+ "batch_index": 106,
+ "length": 18
+ },
+ "_meta": {
+ "title": "Its last frames"
+ }
+ },
+ "mask": {
+ "class_type": "SAM3_TrackToMask",
+ "inputs": {
+ "track_data": [
+ "track",
+ 0
+ ],
+ "object_indices": ""
+ },
+ "_meta": {
+ "title": "SAM3_TrackToMask"
+ }
+ },
+ "model": {
+ "class_type": "UNETLoader",
+ "inputs": {
+ "unet_name": "minimax_h3_ref2va_pruned_int8_convrot.safetensors",
+ "weight_dtype": "default"
+ },
+ "_meta": {
+ "title": "UNETLoader"
+ }
+ },
+ "noise": {
+ "class_type": "RandomNoise",
+ "inputs": {
+ "noise_seed": [
+ "window",
+ 10
+ ]
+ },
+ "_meta": {
+ "title": "RandomNoise"
+ }
+ },
+ "plan": {
+ "class_type": "H3RelayWindowPlan",
+ "inputs": {
+ "source_frames": [
+ "prepare",
+ 5
+ ],
+ "window_frames": "124",
+ "history_frames": "18",
+ "seed": 904239,
+ "schedule": "segment",
+ "seed_mode": "fixed",
+ "seed_overrides": "{}",
+ "initial_history": [
+ "history_fit",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "Plan source-aligned windows"
+ }
+ },
+ "prepare": {
+ "class_type": "H3RelayPrepareSource",
+ "inputs": {
+ "video": [
+ "trim",
+ 0
+ ],
+ "resolution": "768",
+ "duration_seconds": 5,
+ "missing_audio": "silence"
+ },
+ "_meta": {
+ "title": "H3RelayPrepareSource"
+ }
+ },
+ "recover": {
+ "class_type": "H3RelayRecoverMasks",
+ "inputs": {
+ "masks": [
+ "mask",
+ 0
+ ],
+ "images": [
+ "prepare",
+ 0
+ ],
+ "source_frames": [
+ "prepare",
+ 5
+ ],
+ "model": [
+ "sam",
+ 0
+ ],
+ "conditioning": [
+ "subject",
+ 0
+ ],
+ "selection": [
+ "select",
+ 1
+ ],
+ "recover_empty_frames": true
+ },
+ "_meta": {
+ "title": "H3RelayRecoverMasks"
+ }
+ },
+ "reference": {
+ "class_type": "LoadImage",
+ "inputs": {
+ "image": "reference.png"
+ },
+ "_meta": {
+ "title": "LoadImage"
+ }
+ },
+ "reference_conditioning": {
+ "class_type": "MiniMaxH3ReferenceToVideo",
+ "inputs": {
+ "clip": [
+ "text_memory",
+ 0
+ ],
+ "prompt": "Replace the selected person in <Video 1> with the character in <Picture 1>. Preserve the source performance, scene and audio timing.",
+ "width": [
+ "dimensions",
+ 0
+ ],
+ "height": [
+ "dimensions",
+ 1
+ ],
+ "length": [
+ "window",
+ 8
+ ],
+ "ref_image_size": "match",
+ "ref_videos.ref_video_0": [
+ "window",
+ 5
+ ],
+ "ref_images.ref_image_0": [
+ "reference",
+ 0
+ ],
+ "vae": [
+ "video_vae",
+ 0
+ ],
+ "audio_vae": [
+ "audio_vae",
+ 0
+ ],
+ "ref_audios.ref_audio_0": [
+ "window",
+ 6
+ ],
+ "ref_images.ref_image_1": [
+ "window",
+ 11
+ ]
+ },
+ "_meta": {
+ "title": "Native H3 reference conditioning"
+ }
+ },
+ "sam": {
+ "class_type": "CheckpointLoaderSimple",
+ "inputs": {
+ "ckpt_name": "sam3.1_multiplex_fp16.safetensors"
+ },
+ "_meta": {
+ "title": "CheckpointLoaderSimple"
+ }
+ },
+ "sample": {
+ "class_type": "SamplerCustomAdvanced",
+ "inputs": {
+ "noise": [
+ "noise",
+ 0
+ ],
+ "guider": [
+ "guider",
+ 0
+ ],
+ "sampler": [
+ "sampler",
+ 0
+ ],
+ "sigmas": [
+ "schedule",
+ 0
+ ],
+ "latent_image": [
+ "edit_mask",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "SamplerCustomAdvanced"
+ }
+ },
+ "sampler": {
+ "class_type": "KSamplerSelect",
+ "inputs": {
+ "sampler_name": "er_sde"
+ },
+ "_meta": {
+ "title": "KSamplerSelect"
+ }
+ },
+ "sampling_memory": {
+ "class_type": "H3RelaySamplingMemory",
+ "inputs": {
+ "model": [
+ "adapter",
+ 0
+ ],
+ "latent": [
+ "edit_mask",
+ 0
+ ],
+ "conditioning": [
+ "guide",
+ 0
+ ],
+ "activation_memory_gib": 17
+ },
+ "_meta": {
+ "title": "H3RelaySamplingMemory"
+ }
+ },
+ "save": {
+ "class_type": "SaveVideo",
+ "inputs": {
+ "video": [
+ "video",
+ 0
+ ],
+ "filename_prefix": "fuobe/video-character-swap-h3-segment",
+ "format": "mp4",
+ "format.codec": "h264",
+ "format.codec.encoding": "re-encode",
+ "format.codec.encoding.crf": 16
+ },
+ "_meta": {
+ "title": "SaveVideo"
+ }
+ },
+ "save_master": {
+ "class_type": "VHS_VideoCombine",
+ "inputs": {
+ "images": [
+ "finish",
+ 0
+ ],
+ "frame_rate": 24,
+ "loop_count": 0,
+ "filename_prefix": "fuobe/video-character-swap-h3-segment",
+ "format": "video/ffv1-mkv",
+ "pingpong": false,
+ "save_output": true,
+ "pix_fmt": "rgba64le",
+ "save_metadata": false,
+ "trim_to_audio": false
+ },
+ "_meta": {
+ "title": "Lossless master (FFV1)"
+ }
+ },
+ "schedule": {
+ "class_type": "BasicScheduler",
+ "inputs": {
+ "model": [
+ "adapter",
+ 0
+ ],
+ "scheduler": "normal",
+ "steps": 8,
+ "denoise": 1
+ },
+ "_meta": {
+ "title": "BasicScheduler"
+ }
+ },
+ "select": {
+ "class_type": "H3RelaySelectMask",
+ "inputs": {
+ "masks": [
+ "detect",
+ 0
+ ],
+ "selection": "largest",
+ "index": 0
+ },
+ "_meta": {
+ "title": "H3RelaySelectMask"
+ }
+ },
+ "separate": {
+ "class_type": "LTXVSeparateAVLatent",
+ "inputs": {
+ "av_latent": [
+ "sample",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "LTXVSeparateAVLatent"
+ }
+ },
+ "shift": {
+ "class_type": "MiniMaxH3SigmaShift",
+ "inputs": {
+ "model": [
+ "model",
+ 0
+ ],
+ "shift_video": 12,
+ "shift_audio": 3
+ },
+ "_meta": {
+ "title": "MiniMaxH3SigmaShift"
+ }
+ },
+ "source": {
+ "class_type": "LoadVideo",
+ "inputs": {
+ "file": "source.mp4"
+ },
+ "_meta": {
+ "title": "LoadVideo"
+ }
+ },
+ "start": {
+ "class_type": "StartLoop",
+ "inputs": {
+ "mode": "simple",
+ "mode.num_iterations": [
+ "plan",
+ 2
+ ],
+ "cache_iterations": false
+ },
+ "_meta": {
+ "title": "Native loop · one H3 window"
+ }
+ },
+ "subject": {
+ "class_type": "CLIPTextEncode",
+ "inputs": {
+ "clip": [
+ "sam",
+ 1
+ ],
+ "text": "person"
+ },
+ "_meta": {
+ "title": "CLIPTextEncode"
+ }
+ },
+ "text": {
+ "class_type": "CLIPLoader",
+ "inputs": {
+ "clip_name": "qwen3vl_32b_minimax_h3_nvfp4_awq.safetensors",
+ "type": "minimax",
+ "device": "default"
+ },
+ "_meta": {
+ "title": "CLIPLoader"
+ }
+ },
+ "text_device": {
+ "class_type": "SelectCLIPDevice",
+ "inputs": {
+ "clip": [
+ "text",
+ 0
+ ],
+ "device": "gpu:0"
+ },
+ "_meta": {
+ "title": "SelectCLIPDevice"
+ }
+ },
+ "text_memory": {
+ "class_type": "H3RelayTextMemory",
+ "inputs": {
+ "clip": [
+ "text_device",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "H3RelayTextMemory"
+ }
+ },
+ "track": {
+ "class_type": "SAM3_VideoTrack",
+ "inputs": {
+ "model": [
+ "sam",
+ 0
+ ],
+ "images": [
+ "prepare",
+ 0
+ ],
+ "initial_mask": [
+ "select",
+ 0
+ ],
+ "conditioning": [
+ "subject",
+ 0
+ ],
+ "detection_threshold": 0.5,
+ "max_objects": 1,
+ "detect_interval": 1
+ },
+ "_meta": {
+ "title": "SAM3_VideoTrack"
+ }
+ },
+ "trim": {
+ "class_type": "Video Slice",
+ "inputs": {
+ "video": [
+ "source",
+ 0
+ ],
+ "start_time": 0,
+ "duration": 5,
+ "strict_duration": false
+ },
+ "_meta": {
+ "title": "The chosen part"
+ }
+ },
+ "turbo": {
+ "class_type": "LoraLoaderModelOnly",
+ "inputs": {
+ "model": [
+ "attention",
+ 0
+ ],
+ "lora_name": "minimax_h3_fl2v_turbo_8step_v1.0_768p_comfyui_bf16.safetensors",
+ "strength_model": 1
+ },
+ "_meta": {
+ "title": "LoraLoaderModelOnly"
+ }
+ },
+ "video": {
+ "class_type": "CreateVideo",
+ "inputs": {
+ "images": [
+ "finish",
+ 0
+ ],
+ "fps": [
+ "finish",
+ 2
+ ],
+ "audio": [
+ "finish",
+ 1
+ ]
+ },
+ "_meta": {
+ "title": "CreateVideo"
+ }
+ },
+ "video_vae": {
+ "class_type": "VAELoader",
+ "inputs": {
+ "vae_name": "minimax_h3_video_vae_fp16.safetensors"
+ },
+ "_meta": {
+ "title": "VAELoader"
+ }
+ },
+ "window": {
+ "class_type": "H3RelayWindowInputs",
+ "inputs": {
+ "source": [
+ "prepare",
+ 0
+ ],
+ "window": [
+ "plan",
+ 3
+ ],
+ "iteration_index": [
+ "start",
+ 0
+ ],
+ "previous": [
+ "start",
+ 4
+ ],
+ "reference_history": true,
+ "fps": 24,
+ "resize_anchor": true,
+ "history_audio_mode": "source",
+ "source_audio": [
+ "prepare",
+ 1
+ ],
+ "mask": [
+ "expand_mask",
+ 0
+ ],
+ "anchor": [
+ "anchor_image",
+ 0
+ ],
+ "initial_history": [
+ "history_fit",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "H3RelayWindowInputs"
+ }
+ }
+}
diff --git a/workflows/comfyui/video-mask-h3-relay.json b/workflows/comfyui/video-mask-h3-relay.json
new file mode 100644
index 00000000..9380d223
--- /dev/null
+++ b/workflows/comfyui/video-mask-h3-relay.json
@@ -0,0 +1,336 @@
+{
+ "detect": {
+ "class_type": "SAM3_Detect",
+ "inputs": {
+ "model": [
+ "sam",
+ 0
+ ],
+ "image": [
+ "key_frame",
+ 0
+ ],
+ "conditioning": [
+ "subject",
+ 0
+ ],
+ "threshold": 0.35,
+ "refine_iterations": 2,
+ "individual_masks": true,
+ "positive_coords": "",
+ "negative_coords": ""
+ },
+ "_meta": {
+ "title": "SAM3_Detect"
+ }
+ },
+ "dimensions": {
+ "class_type": "GetImageSize",
+ "inputs": {
+ "image": [
+ "prepare",
+ 0
+ ]
+ },
+ "_meta": {
+ "title": "GetImageSize"
+ }
+ },
+ "head": {
+ "class_type": "ImageFromBatch",
+ "inputs": {
+ "image": [
+ "prev_fit",
+ 0
+ ],
+ "batch_index": 0,
+ "length": 1
+ },
+ "_meta": {
+ "title": "Before the new part"
+ }
+ },
+ "join_head": {
+ "class_type": "ImageBatch",
+ "inputs": {
+ "image1": [
+ "head",
+ 0
+ ],
+ "image2": [
+ "new_images",
+ 0
+ ]
+ }
+ },
+ "join_tail": {
+ "class_type": "ImageBatch",
+ "inputs": {
+ "image1": [
+ "join_head",
+ 0
+ ],
+ "image2": [
+ "tail",
+ 0
+ ]
+ }
+ },
+ "key_frame": {
+ "class_type": "ImageFromBatch",
+ "inputs": {
+ "image": [
+ "prepare",
+ 0
+ ],
+ "batch_index": 0,
+ "length": 1
+ },
+ "_meta": {
+ "title": "The frame you clicked"
+ }
+ },
+ "mask": {
+ "class_type": "SAM3_TrackToMask",
+ "inputs": {
+ "track_data": [
+ "track",
+ 0
+ ],
+ "object_indices": ""
+ },
+ "_meta": {
+ "title": "SAM3_TrackToMask"
+ }
+ },
+ "new_images": {
+ "class_type": "MaskToImage",
+ "inputs": {
+ "mask": [
+ "recover",
+ 0
+ ]
+ }
+ },
+ "prepare": {
+ "class_type": "H3RelayPrepareSource",
+ "inputs": {
+ "video": [
+ "trim",
+ 0
+ ],
+ "resolution": "768",
+ "duration_seconds": 5,
+ "missing_audio": "silence"
+ },
+ "_meta": {
+ "title": "H3RelayPrepareSource"
+ }
+ },
+ "prev_fit": {
+ "class_type": "ImageScale",
+ "inputs": {
+ "image": [
+ "prev_frames",
+ 0
+ ],
+ "upscale_method": "nearest-exact",
+ "width": [
+ "dimensions",
+ 0
+ ],
+ "height": [
+ "dimensions",
+ 1
+ ],
+ "crop": "center"
+ }
+ },
+ "prev_frames": {
+ "class_type": "GetVideoComponents",
+ "inputs": {
+ "video": [
+ "prev_source",
+ 0
+ ]
+ }
+ },
+ "prev_source": {
+ "class_type": "LoadVideo",
+ "inputs": {
+ "file": "previous-mask.mp4"
+ },
+ "_meta": {
+ "title": "The mask it corrects"
+ }
+ },
+ "recover": {
+ "class_type": "H3RelayRecoverMasks",
+ "inputs": {
+ "masks": [
+ "mask",
+ 0
+ ],
+ "images": [
+ "span",
+ 0
+ ],
+ "source_frames": 120,
+ "model": [
+ "sam",
+ 0
+ ],
+ "conditioning": [
+ "subject",
+ 0
+ ],
+ "selection": [
+ "select",
+ 1
+ ],
+ "recover_empty_frames": true
+ },
+ "_meta": {
+ "title": "H3RelayRecoverMasks"
+ }
+ },
+ "sam": {
+ "class_type": "CheckpointLoaderSimple",
+ "inputs": {
+ "ckpt_name": "sam3.1_multiplex_fp16.safetensors"
+ },
+ "_meta": {
+ "title": "CheckpointLoaderSimple"
+ }
+ },
+ "save": {
+ "class_type": "SaveVideo",
+ "inputs": {
+ "video": [
+ "video",
+ 0
+ ],
+ "filename_prefix": "fuobe/video-mask-h3-relay",
+ "format": "mp4",
+ "format.codec": "h264",
+ "format.codec.encoding": "re-encode",
+ "format.codec.encoding.crf": 10
+ }
+ },
+ "select": {
+ "class_type": "H3RelaySelectMask",
+ "inputs": {
+ "masks": [
+ "detect",
+ 0
+ ],
+ "selection": "largest",
+ "index": 0
+ },
+ "_meta": {
+ "title": "H3RelaySelectMask"
+ }
+ },
+ "source": {
+ "class_type": "LoadVideo",
+ "inputs": {
+ "file": "source.mp4"
+ },
+ "_meta": {
+ "title": "LoadVideo"
+ }
+ },
+ "span": {
+ "class_type": "ImageFromBatch",
+ "inputs": {
+ "image": [
+ "prepare",
+ 0
+ ],
+ "batch_index": 0,
+ "length": 120
+ },
+ "_meta": {
+ "title": "Frames to track"
+ }
+ },
+ "subject": {
+ "class_type": "CLIPTextEncode",
+ "inputs": {
+ "clip": [
+ "sam",
+ 1
+ ],
+ "text": "person"
+ },
+ "_meta": {
+ "title": "CLIPTextEncode"
+ }
+ },
+ "tail": {
+ "class_type": "ImageFromBatch",
+ "inputs": {
+ "image": [
+ "prev_fit",
+ 0
+ ],
+ "batch_index": 2,
+ "length": 1
+ },
+ "_meta": {
+ "title": "After the new part"
+ }
+ },
+ "track": {
+ "class_type": "SAM3_VideoTrack",
+ "inputs": {
+ "model": [
+ "sam",
+ 0
+ ],
+ "images": [
+ "span",
+ 0
+ ],
+ "initial_mask": [
+ "select",
+ 0
+ ],
+ "conditioning": [
+ "subject",
+ 0
+ ],
+ "detection_threshold": 0.5,
+ "max_objects": 1,
+ "detect_interval": 1
+ },
+ "_meta": {
+ "title": "SAM3_VideoTrack"
+ }
+ },
+ "trim": {
+ "class_type": "Video Slice",
+ "inputs": {
+ "video": [
+ "source",
+ 0
+ ],
+ "start_time": 0,
+ "duration": 5,
+ "strict_duration": false
+ },
+ "_meta": {
+ "title": "The chosen part"
+ }
+ },
+ "video": {
+ "class_type": "CreateVideo",
+ "inputs": {
+ "images": [
+ "join_tail",
+ 0
+ ],
+ "fps": 24
+ }
+ }
+}