Alterar Qualquer Objeto
Use um prompt simples para mascarar certos objetos dentro de um Vídeo e substitua o objeto usando um prompt ou uma imagem de referência opcional. Modelo usado: SAM3 + WAN 2.1 VACE inpainting
Dentro do workflow
Uma prévia somente leitura do modelo de origem. Abra-o no Cloud para explorar os nós e fazer alterações.
Loading the graph
Open full-size workflow previewArquivos neste workflow
- Saída
- Vídeo
- Autor
- ComfyUI
Chame este modelo pelo seu código
A solicitação abaixo usa o mesmo grafo e as mesmas configurações preparadas no Playground. Cada envio pode iniciar uma execução paga; não tente novamente automaticamente um envio cujo resultado seja desconhecido.
What you need
- Runs on
- Comfy Cloud
- Chave
- COMFY_API_KEY
- Seus arquivos
- Enviados pelo código a partir de suas URLs
Requer um plano pago do Cloud e créditos.
# 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)Experimente um exemplo
Sobre este fluxo de trabalho
O fluxo de trabalho 'Trocar Qualquer Objeto' no ComfyUI permite substituir ou alterar objetos em um vídeo usando prompts de texto simples ou imagens de referência opcionais. Este fluxo utiliza técnicas avançadas de inpainting, empregando modelos como SAM3 e Wan2.1 VACE para mascaramento e substituição precisa de objetos. O processo começa com o carregamento do vídeo e configuração dos nós necessários, como VHS_LoadVideo e WanVideoDecode. O modelo SAM3 é essencial para segmentação e mascaramento de objetos, permitindo ao usuário especificar quais objetos alterar por meio de prompts intuitivos. Após a identificação, o modelo Wan2.1 VACE realiza o inpainting e substitui os objetos com novos conteúdos derivados dos prompts ou imagens de referência do usuário. Essa combinação de modelos e nós oferece uma ferramenta poderosa para edição de vídeo, possibilitando transformações criativas sem necessidade de edição manual extensa.
Perguntas e respostas
Qualquer objeto que possa ser claramente segmentado pelo modelo SAM3 pode ser substituído. A eficácia depende da clareza do objeto e da qualidade do vídeo.
Não é necessário ter experiência prévia. O fluxo foi projetado para ser fácil de usar, com nós e prompts intuitivos guiando o processo.
Este fluxo é destinado à edição pós-produção. Ele processa arquivos de vídeo gravados, não transmissões ao vivo.
O fluxo suporta formatos comuns como MP4 e AVI tanto para entrada quanto para saída, garantindo compatibilidade com a maioria dos softwares de edição de vídeo.
Workflows relacionados
- SSAM3
SAM3 - Remover Fundo via Prompt
- Seedance 2.5
Change a video’s background
- LTX-2.3
Remove an object from a video
- LTX-2.3
Expand a video’s frame
- SSCAIL-2
Replace a character in a video
- SSeedVR2
Upscale a video
- LTX-2.3
Restore archival footage
- Nó parceiro
AI on the Lot 2026_LTX-2.3_IC LoRA (Union Control)
- Wan2.2, Z-Image-Turbo
AIrt MAchIne
- Topaz
Ampliar vídeo: Topaz Starlight Precise 2.5
- NNó parceiro
Beeble SwitchX: Edição de Vídeo
- BRIA
Bria: Remover Fundo de Vídeo