Modifier n'importe quel objet
Utilisez un prompt simple pour masquer certains objets dans une Vidéo, puis remplacez l'objet à l'aide d'un prompt ou d'une image de référence optionnelle. Modèle utilisé : SAM3 + WAN 2.1 VACE inpainting
Dans le workflow
Un aperçu en lecture seule du modèle source. Ouvrez-le dans Cloud pour explorer les nœuds et apporter des modifications.
Loading the graph
Open full-size workflow previewFichiers de ce workflow
- Sortie
- Vidéo
- Auteur
- ComfyUI
Appelez ce modèle depuis votre code
La requête ci-dessous utilise le même graphe préparé et les mêmes paramètres que le Playground. Chaque envoi peut lancer une exécution payante ; ne relancez pas automatiquement un envoi dont l’issue est inconnue.
What you need
- Runs on
- Comfy Cloud
- Clé
- COMFY_API_KEY
- Vos fichiers
- Importés par le code depuis leurs URL
Nécessite un forfait Cloud payant et des crédits.
# 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)Essayer un exemple
À propos de ce workflow
Le workflow « Changer n’importe quel objet » dans ComfyUI permet de remplacer ou modifier facilement des objets dans une vidéo à l’aide d’invites texte simples ou d’images de référence. Il exploite des techniques avancées d’inpainting, utilisant les modèles SAM3 et Wan2.1 VACE, pour un masquage et un remplacement précis des objets. Le processus commence par le chargement de la vidéo et la configuration via les nœuds VHS_LoadVideo et WanVideoDecode. Le modèle SAM3 est essentiel pour la segmentation vidéo et le masquage des objets, permettant à l’utilisateur de spécifier les objets à modifier via des invites intuitives. Une fois les objets identifiés, le modèle Wan2.1 VACE prend le relais pour inpeindre et remplacer ces objets selon les invites ou images de référence fournies. Cette combinaison de modèles et de nœuds offre un outil puissant d’édition vidéo, permettant des transformations créatives sans retouche manuelle fastidieuse.
Questions-réponses
Tout objet pouvant être clairement segmenté par le modèle SAM3 peut être remplacé. L’efficacité dépend de la clarté de l’objet et de la qualité de la vidéo.
Aucune expérience préalable n’est requise. Le workflow est conçu pour être accessible, avec des nœuds et invites intuitifs.
Ce workflow est destiné à la post-production. Il traite des fichiers vidéo préenregistrés, pas des flux en direct.
Le workflow prend en charge les formats vidéo courants comme MP4 et AVI, assurant la compatibilité avec la plupart des logiciels de montage.