Flujo de Trabajo de Intercambio de Rostros
Un flujo de trabajo de ComfyUI para rejuvenecimiento y/o reemplazo de rostros que combina enmascaramiento impulsado por IA, transferencia de identidad basada en referencia y inpainting para producir resultados naturales y consistentes en el tiempo. Diseñado para VFX, permite a los artistas intercambiar o rejuvenecer rostros rápidamente mientras se preserva la actuación, la iluminación y la integración con el material original.
Acerca de
El Flujo de Trabajo de Intercambio de Rostros en ComfyUI es una herramienta sofisticada diseñada para artistas de efectos visuales que necesitan realizar rejuvenecimiento o reemplazo de rostros en material de video. Este flujo de trabajo combina enmascaramiento impulsado por IA, transferencia de identidad y técnicas de inpainting para ofrecer resultados naturales y consistentes entre fotogramas. Nodos clave como WanVideoVAELoader y WanVideoModelLoader se utilizan para cargar y gestionar datos de video, mientras que nodos como DrawMaskOnImage y GrowMask ayudan a crear máscaras precisas para el intercambio de rostros. El flujo de trabajo también incorpora modelos avanzados de detección a través de OnnxDetectionModelLoader y CLIPVisionLoader para identificar y manipular características faciales con precisión. Al integrar estos componentes, el flujo de trabajo asegura que el nuevo rostro se mezcle perfectamente con el material original, manteniendo matices de iluminación y actuación.
Lo que proporcionas
- Leyendo el flujo de trabajo
Se ejecuta en ComfyUI. Este flujo de trabajo no puede ejecutarse en esta página. Ábrelo en Comfy Cloud con todo cargado o descárgalo para tu propio ComfyUI.
Probar en CloudProbar un ejemplo
Dentro del flujo de trabajo
Una vista previa de solo lectura del gráfico de nodos. Ábrelo en Comfy Cloud o descárgalo para editar los nodos.
Loading the graph
Open full-size workflow previewArchivos de este flujo de trabajo
- Autor
- ComfyUI
Requiere nodos personalizados
- Leyendo el flujo de trabajo
Usa este flujo de trabajo desde código
Se genera a partir del gráfico y las entradas del flujo de trabajo cuando es posible; de lo contrario, se muestran ejemplos almacenados. Revisa las credenciales y los endpoints antes de ejecutar el código, ya que puede generar cargos.
What you need
- Runs on
- Comfy Cloud
- Clave
- COMFY_API_KEY
Requiere un plan de pago de Cloud y 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)Preguntas y respuestas
El flujo de trabajo admite formatos de video comunes como MP4 y AVI. Asegúrate de que tu material sea compatible con el nodo WanVideoVAELoader.
Usa imágenes de referencia de alta calidad y ajusta cuidadosamente la configuración de la máscara. Los nodos GrowMask y BlockifyMask pueden ayudar a refinar los bordes de la máscara para una mezcla perfecta.
Sí, el flujo de trabajo puede procesar múltiples rostros. Usa el nodo OnnxDetectionModelLoader para detectar y gestionar cada rostro individualmente.
El Flujo de Trabajo de Intercambio de Rostros está optimizado para postproducción en lugar de aplicaciones en tiempo real debido a sus requerimientos computacionales.