Workflow d'Échange de Visage
Un workflow ComfyUI pour le rajeunissement et/ou le remplacement de visage combinant masquage IA, transfert d'identité par référence et inpainting pour des résultats naturels et cohérents dans le temps. Conçu pour les VFX, il permet aux artistes de remplacer ou rajeunir rapidement des visages tout en préservant la performance, l'éclairage et l'intégration avec la prise originale.
À propos
Le Workflow d'Échange de Visage dans ComfyUI est un outil sophistiqué destiné aux artistes d'effets visuels qui doivent effectuer du rajeunissement ou des remplacements de visage dans des séquences vidéo. Ce workflow combine masquage IA, transfert d'identité et techniques d'inpainting pour garantir des résultats naturels et cohérents d'une image à l'autre. Des nœuds clés comme WanVideoVAELoader et WanVideoModelLoader servent à charger et gérer les données vidéo, tandis que des nœuds comme DrawMaskOnImage et GrowMask permettent de créer des masques précis pour l'échange de visage. Le workflow intègre également des modèles de détection avancés via OnnxDetectionModelLoader et CLIPVisionLoader pour identifier et manipuler précisément les traits du visage. L'intégration de ces composants assure que le nouveau visage s'intègre parfaitement à la séquence d'origine, en maintenant l'éclairage et la performance.
Ce que vous fournissez
- Lecture du workflow
S’exécute dans ComfyUI. Ce workflow ne peut pas s’exécuter sur cette page. Ouvrez-le dans Comfy Cloud, avec tout déjà chargé, ou téléchargez-le pour votre propre ComfyUI.
Essayer dans CloudEssayer un exemple
Dans le workflow
Un aperçu en lecture seule du graphe de nœuds. Ouvrez-le dans Comfy Cloud ou téléchargez-le pour modifier les nœuds.
Loading the graph
Open full-size workflow previewFichiers de ce workflow
- Auteur
- ComfyUI
Nécessite des nœuds personnalisés
- Lecture du workflow
Utiliser ce workflow depuis du code
Généré à partir du graphe et des entrées du workflow lorsque cela est possible ; sinon, les exemples enregistrés sont affichés. Vérifiez les identifiants et les points de terminaison avant d’exécuter le code, ce qui peut entraîner des frais.
What you need
- Runs on
- Comfy Cloud
- Clé
- COMFY_API_KEY
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({
"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)Questions-réponses
Le workflow prend en charge les formats vidéo courants comme MP4 et AVI. Assurez-vous que votre séquence est compatible avec le nœud WanVideoVAELoader.
Utilisez des images de référence de haute qualité et ajustez soigneusement les paramètres du masque. Les nœuds GrowMask et BlockifyMask permettent d'affiner les bords du masque pour une intégration parfaite.
Oui, le workflow peut traiter plusieurs visages. Utilisez le OnnxDetectionModelLoader pour détecter et gérer chaque visage individuellement.
Le Workflow d'Échange de Visage est optimisé pour la post-production et non pour le temps réel, en raison de ses exigences de calcul.