Workflow de Troca de Rosto
Um workflow do ComfyUI para rejuvenescimento e/ou substituição de rosto que combina mascaramento orientado por IA, transferência de identidade baseada em referência e inpainting para produzir resultados naturais e consistentes ao longo do tempo. Projetado para uso em VFX, ele permite que artistas troquem ou rejuveneçam rostos rapidamente, preservando performance, iluminação e integração com o plate original.
Sobre
O Fluxo de Troca de Rosto no ComfyUI é uma ferramenta sofisticada projetada para artistas de efeitos visuais que precisam realizar rejuvenescimento ou substituição de rostos em vídeos. Este fluxo combina mascaramento por IA, transferência de identidade e técnicas de inpainting para entregar resultados naturais e consistentes entre os quadros. Nós-chave como WanVideoVAELoader e WanVideoModelLoader são usados para carregar e gerenciar dados de vídeo, enquanto nós como DrawMaskOnImage e GrowMask ajudam a criar máscaras precisas para a troca de rosto. O fluxo também incorpora modelos avançados de detecção por meio do OnnxDetectionModelLoader e CLIPVisionLoader para identificar e manipular características faciais com precisão. Ao integrar esses componentes, o fluxo garante que o novo rosto se misture perfeitamente ao vídeo original, mantendo nuances de iluminação e performance.
O que você fornece
- Lendo o fluxo de trabalho
É executado no ComfyUI. Este fluxo de trabalho não pode ser executado nesta página. Abra-o no Comfy Cloud com tudo carregado ou baixe-o para usar no seu próprio ComfyUI.
Experimentar no CloudExperimente um exemplo
Dentro do workflow
Uma prévia somente leitura do gráfico de nós. Abra-o no Comfy Cloud ou faça o download para editar os nós.
Loading the graph
Open full-size workflow previewArquivos neste workflow
- Autor
- ComfyUI
Requer nós personalizados
- Lendo o fluxo de trabalho
Use este fluxo de trabalho a partir do código
Gerado a partir do grafo e das entradas do fluxo de trabalho quando possível; caso contrário, são exibidos exemplos armazenados. Revise as credenciais e os endpoints antes de executar o código, pois isso pode gerar cobranças.
What you need
- Runs on
- Comfy Cloud
- Chave
- COMFY_API_KEY
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({
"38": {
"class_type": "WanVideoVAELoader",
"inputs": {
"model_name": "Wan2_1_VAE_fp32.safetensors",
"precision": "fp32",
"use_cpu_cache": False,
"verbose": False
},
"_meta": {
"title": "WanVideo VAE Loader"
}
},
"195": {
"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"
}
},
"891": {
"class_type": "WanVideoLoraSelectMulti",
"inputs": {
"lora_0": "WanAnimate_relight_lora_fp16.safetensors",
"lora_1": "lightx2v_I2V_14B_480p_cfg_step_distill_rank64_bf16.safetensors",
"lora_2": "none",
"lora_3": "none",
"lora_4": "none",
"low_mem_load": False,
"merge_loras": False,
"strength_0": 1,
"strength_1": 1,
"strength_2": 1,
"strength_3": 1,
"strength_4": 1
},
"_meta": {
"title": "WanVideo Lora Select Multi"
}
},
"899": {
"class_type": "LoadImage",
"inputs": {
"image": "27e8b5aa2f2631d728cbaca117fe57ae2297a085a2d356d1a3f1438a7e8dadea.png"
},
"_meta": {
"title": "Load Image"
}
},
"900": {
"class_type": "ImageResizeKJv2",
"inputs": {
"crop_position": "top",
"device": "cpu",
"divisible_by": 16,
"height": [
"1099",
4
],
"image": [
"899",
0
],
"keep_proportion": "crop",
"pad_color": "0, 0, 0",
"upscale_method": "lanczos",
"width": [
"1099",
3
]
},
"_meta": {
"title": "Resize Image v2"
}
},
"911": {
"class_type": "VHS_VideoCombine",
"inputs": {
"crf": 19,
"filename_prefix": "WanVideo2_1_T2V",
"format": "video/h264-mp4",
"frame_rate": [
"1099",
0
],
"images": [
"912",
0
],
"loop_count": 0,
"pingpong": False,
"pix_fmt": "yuv420p",
"save_metadata": True,
"save_output": False,
"trim_to_audio": False
},
"_meta": {
"title": "Video Combine 🎥🅥🅗🅢"
}
},
"912": {
"class_type": "DrawMaskOnImage",
"inputs": {
"color": "0,0,0",
"device": "cpu",
"image": [
"1098",
0
],
"mask": [
"914",
0
]
},
"_meta": {
"title": "Draw Mask On Image"
}
},
"913": {
"class_type": "GrowMask",
"inputs": {
"expand": 300,
"mask": [
"1293",
0
],
"tapered_corners": False
},
"_meta": {
"title": "Grow Mask"
}
},
"914": {
"class_type": "BlockifyMask",
"inputs": {
"block_size": 8,
"device": "cpu",
"masks": [
"913",
0
]
},
"_meta": {
"title": "Blockify Mask"
}
},
"926": {
"class_type": "VHS_VideoCombine",
"inputs": {
"crf": 19,
"filename_prefix": "WanVideo2_1_T2V",
"format": "video/h264-mp4",
"frame_rate": [
"1099",
0
],
"images": [
"1036",
1
],
"loop_count": 0,
"pingpong": False,
"pix_fmt": "yuv420p",
"save_metadata": True,
"save_output": False,
"trim_to_audio": False
},
"_meta": {
"title": "Video Combine 🎥🅥🅗🅢"
}
},
"935": {
"class_type": "CLIPVisionLoader",
"inputs": {
"clip_name": "clip_vision_h.safetensors"
},
"_meta": {
"title": "Load CLIP Vision"
}
},
"936": {
"class_type": "WanVideoClipVisionEncode",
"inputs": {
"clip_vision": [
"935",
0
],
"combine_embeds": "average",
"crop": "center",
"force_offload": True,
"image_1": [
"900",
0
],
"ratio": 0.5,
"strength_1": 1,
"strength_2": 1,
"tiles": 0
},
"_meta": {
"title": "WanVideo ClipVision Encode"
}
},
"951": {
"class_type": "WanVideoAnimateEmbeds",
"inputs": {
"bg_images": [
"912",
0
],
"clip_embeds": [
"936",
0
],
"colormatch": "hm-mvgd-hm",
"face_images": [
"1036",
1
],
"face_strength": 1,
"force_offload": False,
"frame_window_size": [
"1099",
1
],
"height": [
"1099",
4
],
"mask": [
"914",
0
],
"num_frames": [
"1099",
1
],
"pose_images": [
"1035",
0
],
"pose_strength": 1,
"ref_images": [
"900",
0
],
"tiled_vae": False,
"vae": [
"38",
0
],
"width": [
"1099",
3
]
},
"_meta": {
"title": "WanVideo Animate Embeds"
}
},
"953": {
"class_type": "WanVideoSampler",
"inputs": {
"add_noise_to_samples": False,
"batched_cfg": False,
"cfg": 1,
"denoise_strength": 1,
"end_step": -1,
"force_offload": True,
"image_embeds": [
"951",
0
],
"model": [
"979",
0
],
"riflex_freq_index": 0,
"rope_function": "comfy",
"scheduler": "dpm++_sde/beta",
"seed": 65346457346,
"shift": 6,
"start_step": 0,
"steps": 8,
"text_embeds": [
"982",
0
]
},
"_meta": {
"title": "WanVideo Sampler"
}
},
"954": {
"class_type": "WanVideoDecode",
"inputs": {
"enable_vae_tiling": False,
"normalization": "default",
"samples": [
"953",
0
],
"tile_stride_x": 144,
"tile_stride_y": 128,
"tile_x": 272,
"tile_y": 272,
"vae": [
"38",
0
]
},
"_meta": {
"title": "WanVideo Decode"
}
},
"979": {
"class_type": "WanVideoModelLoader",
"inputs": {
"attention_mode": "sdpa",
"base_precision": "fp16_fast",
"compile_args": [
"195",
0
],
"load_device": "offload_device",
"lora": [
"891",
0
],
"model": "Wan2_2-Animate-14B_fp8_scaled_e4m3fn_KJ_v2.safetensors",
"quantization": "disabled",
"rms_norm_function": "default"
},
"_meta": {
"title": "WanVideo Model Loader"
}
},
"982": {
"class_type": "WanVideoTextEncodeCached",
"inputs": {
"device": "gpu",
"model_name": "umt5-xxl-enc-bf16.safetensors",
"negative_prompt": "色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走",
"positive_prompt": "A young man with short, dark brown hair sits in a dimly lit room, his gaze steady on the camera. He is wearing an olive green button-up shirt that appears slightly worn but neat. His skin has a natural tan tone, and he looks calm yet thoughtful. He has no wrinkles and looks very youthful. Not old.",
"precision": "bf16",
"quantization": "disabled",
"use_disk_cache": False
},
"_meta": {
"title": "WanVideo TextEncode Cached"
}
},
"1034": {
"class_type": "OnnxDetectionModelLoader",
"inputs": {
"onnx_device": "CUDAExecutionProvider",
"vitpose_model": "vitpose-l-wholebody.onnx",
"yolo_model": "yolov10m.onnx"
},
"_meta": {
"title": "ONNX Detection Model Loader"
}
},
"1035": {
"class_type": "DrawViTPose",
"inputs": {
"body_stick_width": -1,
"draw_head": True,
"hand_stick_width": -1,
"height": [
"1099",
4
],
"pose_data": [
"1036",
0
],
"retarget_padding": 16,
"width": [
"1099",
3
]
},
"_meta": {
"title": "Draw ViT Pose"
}
},
"1036": {
"class_type": "PoseAndFaceDetection",
"inputs": {
"face_padding": 0,
"height": [
"1099",
4
],
"images": [
"1098",
0
],
"model": [
"1034",
0
],
"width": [
"1099",
3
]
},
"_meta": {
"title": "Pose and Face Detection"
}
},
"1037": {
"class_type": "VHS_VideoCombine",
"inputs": {
"crf": 19,
"filename_prefix": "WanVideo2_1_T2V",
"format": "video/h264-mp4",
"frame_rate": [
"1099",
0
],
"images": [
"1035",
0
],
"loop_count": 0,
"pingpong": False,
"pix_fmt": "yuv420p",
"save_metadata": True,
"save_output": False,
"trim_to_audio": False
},
"_meta": {
"title": "Video Combine 🎥🅥🅗🅢"
}
},
"1098": {
"class_type": "VHS_LoadVideoFFmpeg",
"inputs": {
"custom_height": [
"1288",
0
],
"custom_width": [
"1287",
0
],
"force_rate": 0,
"format": "Wan",
"frame_load_cap": 0,
"start_time": 0,
"video": "dacaa9337be45cb55ba8e804af52574ff18a96c7e20e40757558d116b54fe1e6.mp4"
},
"_meta": {
"title": "Load Video FFmpeg (Upload) 🎥🅥🅗🅢"
}
},
"1099": {
"class_type": "VHS_VideoInfoLoaded",
"inputs": {
"video_info": [
"1098",
3
]
},
"_meta": {
"title": "Video Info (Loaded) 🎥🅥🅗🅢"
}
},
"1201": {
"class_type": "AILab_QwenVL",
"inputs": {
"attention_mode": "sdpa",
"custom_prompt": "describe this image as if its a 5 second long video. Include a detail description of the person and their features and hair and age. ",
"image": [
"900",
0
],
"keep_model_loaded": False,
"max_tokens": 512,
"model_name": "Qwen3-VL-2B-Instruct",
"preset_prompt": "🖼️ Detailed Description",
"quantization": "None (FP16)",
"seed": 2074003516
},
"_meta": {
"title": "QwenVL"
}
},
"1287": {
"class_type": "INTConstant",
"inputs": {
"value": 1920
},
"_meta": {
"title": "Width"
}
},
"1288": {
"class_type": "INTConstant",
"inputs": {
"value": 1088
},
"_meta": {
"title": "Height"
}
},
"1289": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"1201",
0
]
},
"_meta": {
"title": "Preview as Text"
}
},
"1290": {
"class_type": "DownloadAndLoadFlorence2Model",
"inputs": {
"attention": "sdpa",
"convert_to_safetensors": False,
"model": "microsoft/Florence-2-large",
"precision": "fp16"
},
"_meta": {
"title": "DownloadAndLoadFlorence2Model"
}
},
"1291": {
"class_type": "Florence2Run",
"inputs": {
"do_sample": True,
"fill_mask": True,
"florence2_model": [
"1290",
0
],
"image": [
"1098",
0
],
"keep_model_loaded": False,
"max_new_tokens": 1024,
"num_beams": 3,
"output_mask_select": "",
"seed": 3228786869,
"task": "caption_to_phrase_grounding",
"text_input": "Face, Head"
},
"_meta": {
"title": "Florence2Run"
}
},
"1292": {
"class_type": "Florence2toCoordinates",
"inputs": {
"batch": True,
"data": [
"1291",
3
],
"index": "0"
},
"_meta": {
"title": "Florence2 Coordinates"
}
},
"1293": {
"class_type": "Sam2Segmentation",
"inputs": {
"bboxes": [
"1292",
1
],
"image": [
"1295",
0
],
"individual_objects": True,
"keep_model_loaded": True,
"sam2_model": [
"1294",
0
]
},
"_meta": {
"title": "Sam2Segmentation"
}
},
"1294": {
"class_type": "DownloadAndLoadSAM2Model",
"inputs": {
"device": "cuda",
"model": "sam2_hiera_base_plus.safetensors",
"precision": "bf16",
"segmentor": "single_image"
},
"_meta": {
"title": "(Down)Load SAM2Model"
}
},
"1295": {
"class_type": "GetImageSizeAndCount",
"inputs": {
"image": [
"1098",
0
]
},
"_meta": {
"title": "Get Image Size & Count"
}
},
"1298": {
"class_type": "VHS_VideoCombine",
"inputs": {
"audio": [
"1098",
2
],
"crf": 22,
"filename_prefix": "FaceSwap",
"format": "video/h265-mp4",
"frame_rate": [
"1099",
0
],
"images": [
"954",
0
],
"loop_count": 0,
"pingpong": False,
"pix_fmt": "yuv420p10le",
"save_metadata": True,
"save_output": True
},
"_meta": {
"title": "Video Combine 🎥🅥🅗🅢"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)Perguntas e respostas
O fluxo suporta formatos comuns como MP4 e AVI. Certifique-se de que seu vídeo seja compatível com o nó WanVideoVAELoader.
Use imagens de referência de alta qualidade e ajuste cuidadosamente as configurações da máscara. Os nós GrowMask e BlockifyMask ajudam a refinar as bordas da máscara para uma fusão perfeita.
Sim, o fluxo pode processar múltiplos rostos. Use o OnnxDetectionModelLoader para detectar e gerenciar cada rosto individualmente.
O Fluxo de Troca de Rosto é otimizado para pós-produção, não para aplicações em tempo real, devido aos requisitos computacionais.
Workflows relacionados
- Nano Banana Pro, Gemini3 Pro Image Preview, Google
Create a character turnaround
- Qwen-Image-Edit
Change a material
- Qwen-Image-Edit
See your subject from a new angle
- Flux.2 Dev, Flux
Create a product mockup
- Nano Banana Pro
Try an outfit on a character
- Seedream
Put your product in a new scene
- SSeedVR2
Upscale and restore detail
- Nano Banana Pro
Sharpen a product photo
- Topaz
Upscale an illustration
- HHitPaw
Restore portrait detail
- FLUX.1 Fill
Edit a selected region
- FLUX.1 Fill
Extend an image’s borders