影片換臉
最佳的開源影片換臉工作流程。上傳一段驅動影片與角色臉部照片。此 LTX 2.3 lora 由 @Alissonerdx 訓練。
工作流程內部
來源範本的唯讀預覽。請在 Cloud 中開啟,以探索節點並進行變更。
Loading the graph
Open full-size workflow preview從您的程式碼呼叫此模型
以下請求使用與 Playground 相同的已準備節點圖和設定。每次提交都可能啟動付費執行;若提交結果不明,請勿自動重試提交。
What you need
- Runs on
- Comfy Cloud
- 金鑰
- COMFY_API_KEY
- 您的檔案
- 由程式碼透過其 URL 上傳
需要付費 Cloud 方案與點數。
# 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({
"269": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_face_image_FILENAME"
},
"_meta": {
"title": "Load Face Reference"
}
},
"341": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/LTX_2.3_ia2v",
"format": "auto",
"format.codec": "auto",
"video": [
"408",
0
]
},
"_meta": {
"title": "Final Video"
}
},
"345": {
"class_type": "VHS_LoadVideo",
"inputs": {
"custom_height": 0,
"custom_width": 0,
"force_rate": [
"358",
0
],
"format": "AnimateDiff",
"frame_load_cap": [
"627",
1
],
"select_every_nth": 1,
"skip_first_frames": 0,
"video": "UPLOADED_video_FILENAME"
},
"_meta": {
"title": "Load Video"
}
},
"358": {
"class_type": "PrimitiveFloat",
"inputs": {
"value": 24
},
"_meta": {
"title": "FPS"
}
},
"360": {
"class_type": "ReservedRegionFrameComposer",
"inputs": {
"chroma_b": 0,
"chroma_g": 255,
"chroma_r": 0,
"face_align_cross": "center",
"face_align_main": "center",
"face_distribution": "all_faces_every_frame",
"face_gap_px": 12,
"face_images": [
"269",
0
],
"face_padding_px": 12,
"face_scale_pct": 100,
"frames": [
"361",
0
],
"interval_frames": 12,
"overflow_mode": "loop",
"region_position": "left",
"region_size_px": 256,
"stack_direction": "auto"
},
"_meta": {
"title": "Reserved Region Frame Composer"
}
},
"361": {
"class_type": "ImageResizeKJv2",
"inputs": {
"crop_position": "center",
"device": "cpu",
"divisible_by": 32,
"height": [
"362",
0
],
"image": [
"345",
0
],
"keep_proportion": "resize",
"pad_color": "0, 0, 0",
"upscale_method": "lanczos",
"width": [
"362",
0
]
},
"_meta": {
"title": "Resize Image v2"
}
},
"362": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 1280
},
"_meta": {
"title": "Base Resolution (Largest Size)"
}
},
"365": {
"class_type": "VHS_VideoCombine",
"inputs": {
"audio": [
"345",
2
],
"crf": 19,
"filename_prefix": "comparison",
"format": "video/h264-mp4",
"frame_rate": [
"358",
0
],
"images": [
"360",
0
],
"loop_count": 0,
"pingpong": False,
"pix_fmt": "yuv420p",
"save_metadata": True,
"save_output": True,
"trim_to_audio": False
},
"_meta": {
"title": "Control Video Preview"
}
},
"408": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"345",
2
],
"bit_depth": 8,
"codec": "none",
"color_space": "sRGB",
"fps": [
"358",
0
],
"images": [
"641:545",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"427": {
"class_type": "PrimitiveFloat",
"inputs": {
"value": 5
},
"_meta": {
"title": "Duration (Seconds)"
}
},
"559": {
"class_type": "VHS_VideoCombine",
"inputs": {
"audio": [
"345",
2
],
"crf": 19,
"filename_prefix": "comparison",
"format": "video/h264-mp4",
"frame_rate": [
"358",
0
],
"images": [
"560",
0
],
"loop_count": 0,
"pingpong": False,
"pix_fmt": "yuv420p",
"save_metadata": True,
"save_output": True,
"trim_to_audio": False
},
"_meta": {
"title": "Video Combine Comparison"
}
},
"560": {
"class_type": "ImageConcanate",
"inputs": {
"direction": "right",
"image1": [
"360",
0
],
"image2": [
"641:545",
0
],
"match_image_size": True
},
"_meta": {
"title": "ImageConcanate"
}
},
"627": {
"class_type": "ComfyMathExpression",
"inputs": {
"expression": "((a * b) // 8) * 8 + 1",
"values.a": [
"427",
0
],
"values.b": [
"358",
0
]
},
"_meta": {
"title": "Total Frames"
}
},
"641:377": {
"class_type": "RandomNoise",
"inputs": {
"noise_seed": 48738923203162
},
"_meta": {
"title": "RandomNoise"
}
},
"641:382": {
"class_type": "SamplerCustomAdvanced",
"inputs": {
"guider": [
"641:396",
0
],
"latent_image": [
"641:416",
0
],
"noise": [
"641:377",
0
],
"sampler": [
"641:386",
0
],
"sigmas": [
"641:575",
0
]
},
"_meta": {
"title": "SamplerCustomAdvanced"
}
},
"641:383": {
"class_type": "LTXVCropGuides",
"inputs": {
"latent": [
"641:392",
0
],
"negative": [
"641:440",
1
],
"positive": [
"641:440",
0
]
},
"_meta": {
"title": "LTXVCropGuides"
}
},
"641:386": {
"class_type": "KSamplerSelect",
"inputs": {
"sampler_name": "euler_ancestral_cfg_pp"
},
"_meta": {
"title": "KSamplerSelect"
}
},
"641:390": {
"class_type": "LTXVConditioning",
"inputs": {
"frame_rate": [
"358",
0
],
"negative": [
"641:395",
0
],
"positive": [
"641:481",
0
]
},
"_meta": {
"title": "LTXVConditioning"
}
},
"641:392": {
"class_type": "LTXVSeparateAVLatent",
"inputs": {
"av_latent": [
"641:382",
0
]
},
"_meta": {
"title": "Separate AV Latent"
}
},
"641:395": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"641:477",
0
],
"text": ""
},
"_meta": {
"title": "CLIP Text Encode (Negative Prompt)"
}
},
"641:396": {
"class_type": "CFGGuider",
"inputs": {
"cfg": 1,
"model": [
"641:573",
0
],
"negative": [
"641:440",
1
],
"positive": [
"641:440",
0
]
},
"_meta": {
"title": "CFG Guider"
}
},
"641:400": {
"class_type": "SolidMask",
"inputs": {
"height": [
"641:471",
1
],
"value": 0,
"width": [
"641:471",
0
]
},
"_meta": {
"title": "Create Solid Mask"
}
},
"641:414": {
"class_type": "TrimAudioDuration",
"inputs": {
"audio": [
"345",
2
],
"duration": [
"427",
0
],
"start_index": 0
},
"_meta": {
"title": "Trim Audio Duration"
}
},
"641:415": {
"class_type": "LTXVAudioVAEEncode",
"inputs": {
"audio": [
"641:414",
0
],
"audio_vae": [
"641:480",
0
]
},
"_meta": {
"title": "LTXV Audio VAE Encode"
}
},
"641:416": {
"class_type": "LTXVConcatAVLatent",
"inputs": {
"audio_latent": [
"641:417",
0
],
"video_latent": [
"641:440",
2
]
},
"_meta": {
"title": "Concat AV Latent"
}
},
"641:417": {
"class_type": "SetLatentNoiseMask",
"inputs": {
"mask": [
"641:400",
0
],
"samples": [
"641:415",
0
]
},
"_meta": {
"title": "Set Latent Noise Mask"
}
},
"641:418": {
"class_type": "LatentUpscaleModelLoader",
"inputs": {
"model_name": "ltx-2.3-spatial-upscaler-x2-1.1.safetensors"
},
"_meta": {
"title": "Load Latent Upscale Model"
}
},
"641:440": {
"class_type": "LTXVAddGuideMulti",
"inputs": {
"latent": [
"641:443",
0
],
"negative": [
"641:390",
1
],
"num_guides": "1",
"num_guides.frame_idx_1": 0,
"num_guides.image_1": [
"360",
0
],
"num_guides.strength_1": 1,
"positive": [
"641:390",
0
],
"vae": [
"641:479",
0
]
},
"_meta": {
"title": "LTXVAddGuideMulti"
}
},
"641:443": {
"class_type": "VAEEncode",
"inputs": {
"pixels": [
"360",
0
],
"vae": [
"641:479",
0
]
},
"_meta": {
"title": "VAE Encode"
}
},
"641:471": {
"class_type": "GetImageSize",
"inputs": {
"image": [
"360",
0
]
},
"_meta": {
"title": "Get Image Size"
}
},
"641:477": {
"class_type": "DualCLIPLoader",
"inputs": {
"clip_name1": "gemma_3_12B_it_fp8_scaled.safetensors",
"clip_name2": "ltx-2.3_text_projection_bf16.safetensors",
"device": "default",
"type": "ltxv"
},
"_meta": {
"title": "Load CLIP (Dual)"
}
},
"641:478": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "ltx-2.3-22b-distilled_transformer_only_fp8_input_scaled_v3.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"641:479": {
"class_type": "VAELoaderKJ",
"inputs": {
"device": "main_device",
"vae_name": "LTX23_video_vae_bf16.safetensors",
"weight_dtype": "bf16"
},
"_meta": {
"title": "VAELoader KJ"
}
},
"641:480": {
"class_type": "VAELoaderKJ",
"inputs": {
"device": "main_device",
"vae_name": "LTX23_audio_vae_bf16.safetensors",
"weight_dtype": "bf16"
},
"_meta": {
"title": "VAELoader KJ"
}
},
"641:481": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"641:477",
0
],
"text": [
"641:498",
0
]
},
"_meta": {
"title": "Encode Positive"
}
},
"641:498": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "The young woman with long, wavy ginger hair, a densely freckled face, blue-green eyes and pale, natural skin is standing on a sunlit golf fairway, looking into the camera. Her copper waves fall from under a deep purple leather bucket hat onto the shoulders of a white Swiss-dot high-collared blouse, and she wears brown leather gloves. She lifts the golf driver off her shoulders, swings it once in a relaxed half-arc, rests it on one shoulder, laughs and speaks while the camera arcs around her and pushes in to a close-up. Bright midday sun, deep-blue sky, pine trees softly blurred behind her. Her freckles and features stay sharp and consistent in every frame, with realistic lip movement. Photorealistic, natural skin texture."
},
"_meta": {
"title": "Positive Prompt"
}
},
"641:545": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"641:383",
2
],
"vae": [
"641:479",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"641:573": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "ltx23-head_swap_v3_rank_adaptive_fro_098.safetensors",
"model": [
"641:478",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"641:575": {
"class_type": "BasicScheduler",
"inputs": {
"denoise": 1,
"model": [
"641:573",
0
],
"scheduler": "bong_tangent",
"steps": 8
},
"_meta": {
"title": "BasicScheduler"
}
}
})
workflow.set_input("269", "image", client.assets.from_url("https://comfy.org/catalog-media/97f668e5-901f-42b2-961d-47039cfd6a2c/fa2b20ed-2ba6-4783-b676-ddc358244949"))
workflow.set_input("345", "video", client.assets.from_url("https://comfy.org/catalog-media/e5e95c05-0dbc-49f8-b6a6-b03e20a06e4a/9e76d5e9-b473-4d3b-98ec-4ac4c4249071"))
# 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("341"):
output.to_file(output.name)
for output in job.get_outputs("559"):
output.to_file(output.name)試試範例
關於此工作流程
此 ComfyUI 工作流程會進行影片換臉:將單張參考人臉套用到驅動影片的每一幀,並重新合成為最終片段。流程以 VHS_LoadVideo 將來源影片解碼為影格,並用 LoadImage 載入參考人臉。自訂換臉節點(dc72113f-8276-4a5a-af12-85d6bec89ed5)使用由 @Alissonerdx 訓練的 LTX 2.3 LoRA 來完成臉部轉換。PrimitiveFloat 與 PrimitiveInt 節點提供關鍵控制(例如效果強度、區域大小或幀步進),而 ImageResizeKJv2 則用於對齊參考人臉比例以符合目標畫面。
為了穩定結果並保留背景,工作流程會用 ReservedRegionFrameComposer 將生成的人臉合成回每張原始影格。此節點可讓你定義固定的「保留」人臉區域,並用羽化邊緣進行融合,降低時間上的抖動並保留髮絲、光線與場景動作。ComfyMathExpression 用於推導動態數值(例如依影片解析度計算區域大小),讓設定能隨載入內容同步。品質檢查方面,ImageConcanate 可拼出原始 vs. 換臉影格的並排預覽。最後,處理後影格會用 VHS_VideoCombine 或 CreateVideo 編碼成影片,並以 SaveVideo 輸出。
問答
請安裝 Video Helper Suite(提供 VHS_LoadVideo 與 VHS_VideoCombine),並將 @Alissonerdx 的 LTX 2.3 LoRA 放到 ComfyUI/models/loras。自訂換臉節點(dc72113f-8276-4a5a-af12-85d6bec89ed5)會在推論時套用 LoRA,因此你不需要在此模板中手動加入取樣器。
讓 ReservedRegionFrameComposer 的區域穩定地覆蓋目標人臉,並提高羽化以取得更平滑的邊緣。使用高品質、正面且光線與驅動影片相近的參考圖。避免激進的跳幀;逐幀處理可獲得較好的時間一致性。
可以。將影格流程交由 VHS_VideoCombine,並在節點設定中啟用或提供原始音訊(若你的節點配置支援)。如果你的 ComfyUI 環境無法在節點內混音,請先輸出影片,再在剪輯軟體中加回音訊。
調整 ReservedRegionFrameComposer 的區域大小/位置,並用 ImageResizeKJv2 重新縮放參考人臉。利用 PrimitiveFloat/PrimitiveInt 控制項(以及提供時的 ComfyMathExpression)讓區域與影片解析度成比例,並在輸出前先預覽短片段確認。