ComfyUI Node

Stand-In Background Restorer

Paste the generated face back onto the original video

By WeChatCV·Created 12 months ago·Updated 12 months ago· 158
Stand-In Background Restorer
  • face_processor
  • synth_images
  • orig_images
  • restored_video
confidence_threshold0.50
face_crop_scale3.0
dilation_kernel_size25
feather_amount50
with_necktrue
color_match_enabledtrue
color_match_strength0.75
face_only_modetrue

This is the cleanup node - the one you reach for after your Wan sampler has already produced output, not before. It takes what your model generated and the video you started with, and stitches the two back together so only the face carries the edit.

Here's why that's necessary. If you ran the rest of this Stand-In pipeline with face_only_mode on (the whole reason FaceOnlyModeSwitch exists), you deliberately wanted the identity edit to touch just the face - but a video diffusion model doesn't hand you a clean seam between "the part that changed" and "the part that didn't." Whatever Wan produced is a full frame, background included, and it's almost certainly drifted a little from your original plate even where you didn't want it to. VideoBackgroundRestorer re-detects the face in both the generated output and the original source, crops the generated face back out, and composites it into the untouched original frame - with color matching, so the graft doesn't read as pasted-on.

How it works

synth_images is your model's generated output; orig_images is the original, unedited source. The node runs face detection (via face_processor) on both, uses confidence_threshold and face_crop_scale to find and size the region, softens the seam with dilation_kernel_size and feather_amount, optionally extends the region with with_neck, and - this is the part that actually makes it look convincing - corrects the pasted face's color and lighting to match the original plate via color_match_enabled and color_match_strength. Any time you graft one generation's output onto a different source, tone and lighting drift is the thing that gives it away; that's exactly what color matching here is fighting.

The inputs and outputs that matter

  • face_processor, synth_images, orig_images - the three required inputs. Plug your sampler's decoded output into synth_images and your original (or VideoFramePreprocessor-trimmed) frames into orig_images.
  • color_match_enabled (default true) - leave it on. It's the difference between "obviously composited" and "looks like it was always this way."
  • color_match_strength (0–1, default 0.75) - the one worth touching if the result looks off. Push it toward 1.0 and you risk over-correcting, flattening the generated face's own tone into the original's; the 0.75 default is a reasonable middle ground to back off from if that happens.
  • face_only_mode - make sure this matches whatever you ran upstream on VideoInputPreprocessor; a shared FaceOnlyModeSwitch is the clean way to guarantee that.
  • Output: restored_video - your finished deliverable.

How to install it

cd ComfyUI/custom_nodes
git clone https://github.com/WeChatCV/Stand-In_Preprocessor_ComfyUI.git
cd Stand-In_Preprocessor_ComfyUI
pip install -r requirements.txt

Restart ComfyUI, or search "Stand-In Official Preprocessor ComfyUI Nodes" in ComfyUI Manager.

Common issues & troubleshooting

The composite looks misaligned or shifted. Check that synth_images and orig_images actually share the same frame count and dimensions - if one path went through VideoFramePreprocessor's trim/crop and the other didn't, they've diverged and this node has no way to reconcile that mismatch for you.

The pasted face looks washed out or oddly toned. Back color_match_strength down from the default; too aggressive a correction can flatten the generated face's own lighting into a bad match for the surrounding footage rather than a good one.

Some frames near fast head turns or profile shots look untouched, or worse, only the original plays through. The pack's face detector is working frame by frame with no smoothing described anywhere in the schema - a missed detection on a hard motion frame likely just falls back to the source. Worth spot-checking output around any quick head turns rather than assuming every frame got the same treatment.

Remember this only makes sense downstream of a face_only_mode run. If you generated with the identity conditioning influencing the whole frame rather than just the face, restoring the "original background" here will fight against intentional changes elsewhere in the shot.

CategoryStand-In

Inputs (11)

NameTypeDefaultDescription
face_processorFACE_PROCESSOR
synth_imagesIMAGE
orig_imagesIMAGE
confidence_thresholdFLOAT0.500.1–1
face_crop_scaleFLOAT3.01–10
dilation_kernel_sizeINT250–50
feather_amountINT500–151
with_neckBOOLEANtrue
color_match_enabledBOOLEANtrue
color_match_strengthFLOAT0.750–1
face_only_modeBOOLEANtrue

Outputs (1)

NameTypeDescription
restored_videoIMAGE