Change Any Objects
Use simple prompt to mask out certain objects within a video, and replace the object using prompt, or optional reference image. Model used: SAM3 + WAN 2.1 VACE inpainting
ワークフローの内部
ソーステンプレートの読み取り専用プレビューです。Cloud で開くと、ノードを確認して変更できます。
Loading the graph
Open full-size workflow preview- 出力
- 動画
- 作成者
- ComfyUI
コードからこのモデルを呼び出す
以下のリクエストでは、Playground と同じ準備済みグラフと設定を使用します。送信ごとに有料実行が開始される場合があります。結果が不明な送信を自動的に再試行しないでください。
What you need
- Runs on
- Comfy Cloud
- キー
- COMFY_API_KEY
- ファイル
- コードによって URL からアップロードされます
有料の Cloud プランとクレジットが必要です。
# Python 3.10+: pip install comfy-sdk==0.4.0
import os
from comfy_sdk import Comfy
api_key = os.environ.get("COMFY_API_KEY", "").strip()
if not api_key: raise RuntimeError("Set COMFY_API_KEY")
os.environ.setdefault("COMFY_BASE_URL", "https://cloud.comfy.org")
client = Comfy(api_key=api_key)
workflow = client.workflows.from_json({
"162": {
"class_type": "INTConstant",
"inputs": {
"value": 1280
},
"_meta": {
"title": "Width"
}
},
"163": {
"class_type": "INTConstant",
"inputs": {
"value": 720
},
"_meta": {
"title": "Height"
}
},
"164": {
"class_type": "VHS_VideoCombine",
"inputs": {
"crf": 19,
"filename_prefix": "VaceControl",
"format": "video/h264-mp4",
"frame_rate": 30,
"images": [
"197",
0
],
"loop_count": 0,
"pingpong": False,
"pix_fmt": "yuv420p",
"save_metadata": True,
"save_output": True,
"trim_to_audio": False
},
"_meta": {
"title": "Video Combine 🎥🅥🅗🅢"
}
},
"165": {
"class_type": "INTConstant",
"inputs": {
"value": 89
},
"_meta": {
"title": "Length"
}
},
"166": {
"class_type": "WanVideoDecode",
"inputs": {
"enable_vae_tiling": False,
"normalization": "default",
"samples": [
"173",
0
],
"tile_stride_x": 144,
"tile_stride_y": 128,
"tile_x": 272,
"tile_y": 272,
"vae": [
"171",
0
]
},
"_meta": {
"title": "WanVideo Decode"
}
},
"167": {
"class_type": "WanVideoTextEncode",
"inputs": {
"device": "gpu",
"force_offload": True,
"model_to_offload": [
"169",
0
],
"negative_prompt": "bad quality, blurry, messy, chaotic",
"positive_prompt": "A chef in a dark industrial kitchen holds a single ripe pomegranate up at chest height toward the camera, slowly turning it in his fingers to show it off. The pomegranate is deep crimson with russet and gold patches on its leathery rind and a small dry crown on top, sitting naturally in his hand with his fingers wrapped around it. He smiles and talks about it while rain streams down the tall steel-framed windows behind him. Cool blue window light falls across the stainless steel counters, and the red fruit glows as the one warm colour in the frame. Natural shadows and reflections on the fruit, consistent size and shape in every frame, realistic texture, smooth natural motion.",
"t5": [
"172",
0
],
"use_disk_cache": False
},
"_meta": {
"title": "WanVideo TextEncode"
}
},
"168": {
"class_type": "WanVideoTorchCompileSettings",
"inputs": {
"allow_unmerged_lora_compile": False,
"backend": "inductor",
"compile_transformer_blocks_only": True,
"dynamic": False,
"dynamo_cache_size_limit": 64,
"dynamo_recompile_limit": 128,
"force_parameter_static_shapes": False,
"fullgraph": False,
"mode": "default"
},
"_meta": {
"title": "WanVideo Torch Compile Settings"
}
},
"169": {
"class_type": "WanVideoModelLoader",
"inputs": {
"attention_mode": "sdpa",
"base_precision": "bf16",
"compile_args": [
"168",
0
],
"load_device": "offload_device",
"lora": [
"181",
0
],
"model": "wan2.1_vace_14B_fp16.safetensors",
"quantization": "disabled",
"rms_norm_function": "default"
},
"_meta": {
"title": "WanVideo Model Loader"
}
},
"171": {
"class_type": "WanVideoVAELoader",
"inputs": {
"model_name": "Wan2_1_VAE_bf16.safetensors",
"precision": "bf16",
"use_cpu_cache": False,
"verbose": False
},
"_meta": {
"title": "WanVideo VAE Loader"
}
},
"172": {
"class_type": "LoadWanVideoT5TextEncoder",
"inputs": {
"load_device": "offload_device",
"model_name": "umt5-xxl-enc-bf16.safetensors",
"precision": "bf16",
"quantization": "disabled"
},
"_meta": {
"title": "WanVideo T5 Text Encoder Loader"
}
},
"173": {
"class_type": "WanVideoSampler",
"inputs": {
"add_noise_to_samples": False,
"batched_cfg": False,
"cfg": 1.0000000000000002,
"denoise_strength": 1,
"end_step": -1,
"experimental_args": [
"174",
0
],
"force_offload": True,
"image_embeds": [
"176",
0
],
"model": [
"169",
0
],
"riflex_freq_index": 0,
"rope_function": "comfy",
"scheduler": "unipc",
"seed": 18,
"shift": 3.0000000000000004,
"slg_args": [
"175",
0
],
"start_step": 0,
"steps": 8,
"text_embeds": [
"167",
0
]
},
"_meta": {
"title": "WanVideo Sampler"
}
},
"174": {
"class_type": "WanVideoExperimentalArgs",
"inputs": {
"bidirectional_sampling": False,
"cfg_zero_star": True,
"fresca_freq_cutoff": 20,
"fresca_scale_high": 1.25,
"fresca_scale_low": 1,
"raag_alpha": 0,
"temporal_score_rescaling": False,
"tsr_k": 0.95,
"tsr_sigma": 1,
"use_fresca": False,
"use_tcfg": False,
"use_zero_init": False,
"video_attention_split_steps": "",
"zero_star_steps": 0
},
"_meta": {
"title": "WanVideo Experimental Args"
}
},
"175": {
"class_type": "WanVideoSLG",
"inputs": {
"blocks": "8",
"end_percent": 0.7000000000000002,
"start_percent": 0.30000000000000004
},
"_meta": {
"title": "WanVideo SLG"
}
},
"176": {
"class_type": "WanVideoVACEEncode",
"inputs": {
"height": [
"163",
0
],
"input_frames": [
"196",
0
],
"input_masks": [
"199",
0
],
"num_frames": [
"165",
0
],
"ref_images": [
"204",
0
],
"strength": 1,
"tiled_vae": False,
"vace_end_percent": 1,
"vace_start_percent": 0,
"vae": [
"171",
0
],
"width": [
"162",
0
]
},
"_meta": {
"title": "WanVideo VACE Encode"
}
},
"181": {
"class_type": "WanVideoLoraSelect",
"inputs": {
"lora": "Wan21_CausVid_14B_T2V_lora_rank32_v2.safetensors",
"low_mem_load": False,
"merge_loras": True,
"strength": 0.7
},
"_meta": {
"title": "WanVideo Lora Select"
}
},
"183": {
"class_type": "SAM3Propagate",
"inputs": {
"direction": "both",
"end_frame": -1,
"offload_model": False,
"sam3_model": [
"192",
0
],
"start_frame": 0,
"video_state": [
"191",
0
]
},
"_meta": {
"title": "SAM3 Propagate"
}
},
"184": {
"class_type": "SAM3VideoOutput",
"inputs": {
"masks": [
"183",
0
],
"obj_id": -1,
"plot_all_masks": True,
"scores": [
"183",
1
],
"video_state": [
"183",
2
]
},
"_meta": {
"title": "SAM3 Video Output"
}
},
"186": {
"class_type": "ImageResize+",
"inputs": {
"condition": "always",
"height": [
"163",
0
],
"image": [
"187",
0
],
"interpolation": "nearest",
"method": "stretch",
"multiple_of": 0,
"width": [
"162",
0
]
},
"_meta": {
"title": "🔧 Image Resize"
}
},
"187": {
"class_type": "VHS_LoadVideo",
"inputs": {
"custom_height": 0,
"custom_width": 0,
"force_rate": 0,
"format": "AnimateDiff",
"frame_load_cap": [
"165",
0
],
"select_every_nth": 1,
"skip_first_frames": 0,
"video": "UPLOADED_video_FILENAME"
},
"_meta": {
"title": "Input Video"
}
},
"191": {
"class_type": "SAM3VideoSegmentation",
"inputs": {
"frame_idx": 0,
"prompt_mode": "text",
"score_threshold": 0.3,
"text_prompt": [
"194",
0
],
"video_frames": [
"186",
0
]
},
"_meta": {
"title": "SAM3 Video Segmentation"
}
},
"192": {
"class_type": "LoadSAM3Model",
"inputs": {
"model_path": "models/sam3/sam3.pt"
},
"_meta": {
"title": "(down)Load SAM3 Model"
}
},
"194": {
"class_type": "TextBox1",
"inputs": {
"text1": "lemon"
},
"_meta": {
"title": "Object Prompt"
}
},
"195": {
"class_type": "ImageConstant",
"inputs": {
"batch_size": [
"165",
0
],
"blue": 1,
"green": 1,
"height": [
"163",
0
],
"red": 1,
"width": [
"162",
0
]
},
"_meta": {
"title": "Image Constant Color (RGB)"
}
},
"196": {
"class_type": "ImageCompositeMasked",
"inputs": {
"destination": [
"186",
0
],
"mask": [
"199",
0
],
"resize_source": False,
"source": [
"195",
0
],
"x": 0,
"y": 0
},
"_meta": {
"title": "Image Composite Masked"
}
},
"197": {
"class_type": "ImageCompositeMasked",
"inputs": {
"destination": [
"186",
0
],
"mask": [
"198",
0
],
"resize_source": False,
"source": [
"166",
0
],
"x": 0,
"y": 0
},
"_meta": {
"title": "Image Composite Masked"
}
},
"198": {
"class_type": "MaskBlur+",
"inputs": {
"amount": 3,
"device": "auto",
"mask": [
"203",
0
]
},
"_meta": {
"title": "🔧 Mask Blur"
}
},
"199": {
"class_type": "MaskBlur+",
"inputs": {
"amount": 3,
"device": "auto",
"mask": [
"203",
0
]
},
"_meta": {
"title": "🔧 Mask Blur"
}
},
"201": {
"class_type": "VHS_VideoCombine",
"inputs": {
"crf": 19,
"filename_prefix": "RotoPreview",
"format": "video/h264-mp4",
"frame_rate": 30,
"images": [
"196",
0
],
"loop_count": 0,
"pingpong": False,
"pix_fmt": "yuv420p",
"save_metadata": True,
"save_output": False,
"trim_to_audio": False
},
"_meta": {
"title": "Output Visualization2"
}
},
"203": {
"class_type": "GrowMaskWithBlur",
"inputs": {
"blur_radius": 0,
"decay_factor": 1,
"expand": 10,
"fill_holes": False,
"flip_input": False,
"incremental_expandrate": 0,
"lerp_alpha": 1,
"mask": [
"184",
0
],
"tapered_corners": True
},
"_meta": {
"title": "Grow Mask With Blur"
}
},
"204": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_reference_FILENAME"
},
"_meta": {
"title": "Load Image"
}
}
})
workflow.set_input("204", "image", client.assets.from_url("https://comfy.org/catalog-media/7284411e-bc60-426f-83a4-401af0db04c6/cc74a266-933e-4da1-aa2e-55f384c955c8"))
workflow.set_input("187", "video", client.assets.from_url("https://comfy.org/catalog-media/d02af599-bed5-4f46-ba0f-e7e1a59270cd/86b7c191-e0f6-42e1-bf85-d0faecb4130f"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)
for output in job.get_outputs("164"):
output.to_file(output.name)例を試す
このワークフローについて
The 'Change Any Objects' workflow in ComfyUI is designed to enable users to seamlessly replace or alter objects within a video using simple text prompts or optional reference images. This workflow leverages advanced inpainting techniques, utilizing models like SAM3 and Wan2.1 VACE, to achieve precise object masking and replacement.
The process begins with loading video inputs and setting up the necessary configurations using nodes like VHS_LoadVideo and WanVideoDecode. The SAM3 model is crucial for video segmentation and object masking, allowing users to specify which objects to alter through intuitive prompts. Once the objects are identified, the Wan2.1 VACE model takes over to inpaint and replace these objects with new content derived from the user's prompts or reference images. This combination of models and nodes provides a powerful tool for video editing, enabling creative transformations without the need for extensive manual editing.
よくある質問
Any object that can be clearly segmented by the SAM3 model can be replaced. The effectiveness depends on the clarity of the object and the quality of the video.
No prior experience is necessary. The workflow is designed to be user-friendly, with intuitive nodes and prompts guiding the process.
This workflow is intended for post-production editing. It processes pre-recorded video files, not live video streams.
The workflow supports common video formats such as MP4 and AVI for both input and output, ensuring compatibility with most video editing software.