Advanced face swapping for ComfyUI with local ONNX inference - no API required!
cd ComfyUI/custom_nodes
git clone https://github.com/huygiatrng/Facefusion_comfyui.git
cd Facefusion_comfyui
pip install -r requirements.txtRestart ComfyUI. Nodes will appear under FaceFusion and FaceFusion API.
- Add "Load Image" nodes for source (face) and target (body) images
- Add "FF: Advanced Swap Face (Image)" node
- Connect images and set
api_tokento-1(local mode - default) - Choose model:
hyperswap_1c_256(recommended) - Connect to "Preview Image" and run!
First run downloads models (~200MB), then everything runs locally.
- SwapFaceImage - Basic image face swap
- AdvancedSwapFaceImage ⭐ - Full control with all options (recommended)
- AdvancedSwapFaceVideo - Video face swapping with parallel processing
- DeepSwapFaceImage - DeepFaceLive
.dfmmodel support (single images and batches) - FaceSwapApplier - Swap specific detected faces
- FaceDetectorNode - Detect and analyze faces
- FaceDataVisualizer - Debug tool showing detected faces
- PixelBoostNode - Configure pixel boost settings
-1= Local inference (default) ✅ No internet requiredyour_token= API mode (requires internet)
13 models available - All auto-download on first use:
hyperswap_1c_256⭐ Recommended - best quality/speedhyperswap_1a_256,hyperswap_1b_256- HyperSwap variantsghost_1_256,ghost_2_256,ghost_3_256- Apache-2.0 license (commercial OK)hififace_unofficial_256- High fidelity facesinswapper_128_fp16⚡ Fastest for RTX GPUsinswapper_128- Standard InsightFaceblendswap_256- Good blending qualitysimswap_256,simswap_unofficial_512- SimSwap variantsuniface_256- Uniform face handling
256x256- Fast, basic quality512x512⭐ Recommended - good balance768x768- Better quality, slower1024x1024- Best quality, slowest
0.0-1.0- Controls edge blending0.3⭐ Default - natural blending
You can enable multiple mask types at once! Masks are combined to create precise face boundaries.
| Mask Type | Option | Description |
|---|---|---|
| Box | use_box_mask ✅ |
Rectangular mask with blur around face edges (default ON) |
| Occlusion | use_occlusion_mask |
Detects occlusions (hands, hair, objects covering face) - requires face_occluder_model |
| Area | use_area_mask |
Masks specific face areas using landmarks |
| Region | use_region_mask |
Semantic segmentation of face parts - requires face_parser_model |
Comma-separated list of areas:
upper-face- Forehead and upper facelower-face- Chin and jaw areamouth- Mouth region only- Example:
upper-face,lower-face,mouth(default - full face)
Comma-separated list of regions:
skin- Face skin onlyleft-eyebrow,right-eyebrow- Eyebrowsleft-eye,right-eye- Eyesglasses- Glasses areanose- Nosemouth- Mouth areaupper-lip,lower-lip- Lips- Example:
skin,nose,mouth,upper-lip,lower-lip(default)
Edge padding for box mask: top,right,bottom,left
- Example:
5,5,5,5- 5% padding on all sides - Default:
0,0,0,0
| Use Case | Masks | Notes |
|---|---|---|
| Standard swap | Box only ✅ | Fast, good for most cases |
| Hands/objects near face | Box + Occlusion | Preserves hands covering face |
| Precise face boundary | Box + Region | Better edge handling with hair |
| Mouth preservation | Box + Region (skin,nose) |
Keeps original mouth |
| Full quality | Box + Occlusion + Region | Best quality, slower |
one- Single face (use face_position to select)many- All detected facesreference- Match faces similar to reference image
large-small⭐ Biggest face firstleft-right,top-bottom- Spatial sortingbest-worst- By detection confidence
Source Image → Advanced Swap Face ← Target Image → Preview
(api_token: -1)
Source Image → Advanced Swap Face ← Load Image Batch → Preview
(automatically processes all)
Target → Face Detector → Visualize (debug)
↓
Source → Face Swap Applier → Preview
Source Image → Advanced Swap Video ← Target Video
(max_workers: 8)
↓
Save Video
All image swapper nodes automatically detect and handle:
- ✅ Single image (shape: [1, H, W, 3])
- ✅ Batch of images (shape: [N, H, W, 3])
- ✅ Image lists from Load Image Batch nodes
- ✅ Returns same format as input
Example: Feed 10 images → Get 10 swapped images back!
- Create or download a DeepFaceLive-compatible
.dfmmodel. - Place it in
models/deep_swapper/(subfolders are supported). - Restart ComfyUI so the model appears in FF: Deep Swap Face (DFM).
- Use
morphwhen the selected DFM model exposes a morph input. Models without that input safely ignore the value.
DFM models are identity-specific, so this node does not require a source image.
Local image and video swapping now uses a clipped SDR proxy only for ONNX
inference, then applies the swap delta back to the original float tensor.
Negative values and highlights above 1.0 therefore survive unchanged outside
the swapped region instead of wrapping to black during uint8 conversion.
- Model:
inswapper_128_fp16 - Pixel Boost:
256x256or512x512 - GPU with CUDA enabled
- Model:
hyperswap_1c_256orsimswap_unofficial_512 - Pixel Boost:
768x768or1024x1024 - Blur:
0.3-0.5
- Model:
hyperswap_1c_256 - Pixel Boost:
512x512 - Max Workers:
4-8
- Lower
score_thresholdto 0.3-0.4 - Check image quality and lighting
- Ensure face is clearly visible
- Lower
pixel_boost(256×256 or 512×512) - Use smaller model (
inswapper_128_fp16) - Process fewer faces (
mode='one')
- Enable GPU/CUDA
- Use faster model (
inswapper_128_fp16) - Lower pixel boost resolution
- Check internet connection
- Verify disk space (~500MB per model)
- Manual download: https://github.com/facefusion/facefusion-assets/releases/
Models auto-download to: custom_nodes/Facefusion_comfyui/models/
Available models (~100-500MB each):
- hyperswap_1a/1b/1c_256
- inswapper_128, inswapper_128_fp16
- blendswap_256, simswap_256, simswap_unofficial_512
- uniface_256
Face detection: scrfd_2.5g (~3MB), arcface_w600k_r50 (~166MB)
- Start with defaults - They work well for most cases
- Use local mode (api_token: -1) - It's faster and private
- GPU makes a huge difference - 10-50× faster than CPU
- Adjust blur - Higher values (0.4-0.6) for smoother blending
- Match angles - Source and target faces should face similar directions
- Batch processing - Feed multiple images at once, get all results automatically
- Use Load Image Batch - Perfect for processing folders of images
- Hands near face? → Enable
use_occlusion_maskwithface_occluder_model: xseg_1 - Hair blending issues? → Enable
use_region_maskwithface_parser_model: bisenet_resnet_34 - Want original mouth? → Use Region mask with
face_mask_regions: skin,nose,left-eye,right-eye - Processing speed priority? → Use only Box mask (default)
| Feature | Local (api_token: -1) | API (with token) |
|---|---|---|
| Internet | Not required | Required |
| Speed | Fast with GPU | Depends on connection |
| Privacy | Complete | Processed remotely |
| Cost | Free | May have limits/costs |
| Quality | Full pixel boost | Limited options |
Recommendation: Use local mode (default) for best results!
- FaceFusion: https://github.com/facefusion/facefusion
- Models: https://github.com/facefusion/facefusion-assets/releases/
- API: https://facefusion.io (optional)
Respect model licenses:
- InsightFace models: Non-commercial use
- Face swapper models: Check vendor licenses
- Report issues on GitHub
- Check console output for errors
- Enable debug mode by uncommenting print statements in code
Happy Face Swapping! 🎭✨
