Replace Img_or_Vid_Bg
The compositor half of background replacement — no model, just alpha math
- foreground_images
- background_images
- IMAGE
- MASK
Background replacement is really two jobs: cut the subject out, then put it on something else. This node is the second half, and the README is explicit about the division of labour - it's "to be used with any background removal node." You supply the cutout, it supplies the compositing.
The "any" is the point. Background removal is the most commoditized operation in the ecosystem by now - BiRefNet ships in ComfyUI core, InspyrenetRembg is a community favourite, rembg has been around since 2020 - and the model choice barely matters to this node. Whatever removal node you have feeding an RGBA image into foreground_images will do. This node never touches a model; it's pure alpha-compositing on CPU.
Mechanically, per frame it: scales the foreground (scale_x/scale_y) and background (bg_scale_x/bg_scale_y) independently, builds a working canvas 3× the size, places the background centered, places the foreground centered with its feet near the bottom of the background, alpha-composites, then crops back to the background's dimensions. The "feet near the bottom" bit is a nice touch - the subject is positioned relative to the bottom of the scene, so a person stands on the ground plane rather than floating mid-frame. It's also batch-aware in the way that matters for video: one background image plus N foreground frames repeats that background across all frames; fewer backgrounds than frames repeats the last one; more truncates.
Inputs that matter
- foreground_images - your cutout(s), RGBA. Can be a batch of frames for video.
- background_images - the new scene(s), one or many.
- x_offset / y_offset - nudge the subject around (pixels, default 0).
- scale_x / scale_y - resize the subject (0.1–10, default 1.0). Scale the person up to loom, down to recede.
- bg_scale_x / bg_scale_y - resize the background independently.
Outputs are IMAGE (the composited batch) and MASK. That mask is an all-zero placeholder - the source literally notes "Assume a default zero mask for simplicity." If you need the subject's actual mask, get it from the removal node upstream.
Installing it
One of eight nodes in ComfyUI-Animation_Nodes_and_Workflows by Isi-dev:
- ComfyUI Manager → search
ComfyUI-Animation_Nodes_and_Workflows→ install, restart. - Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/Isi-dev/ComfyUI-Animation_Nodes_and_Workflows
cd ComfyUI-Animation_Nodes_and_Workflows
pip install -r requirements.txt
torch, opencv-python, numpy, and mediapipe (the last one only matters for the pack's LivePortrait node). No model files, no API key, no GPU.
Common gotchas
- Cropping is real. After scaling, the composite is cropped to the background's size - scale the subject up past the background and you cut their head off. Keep the scaled foreground ≤ background, or budget for the crop.
- Feed it a non-transparent foreground and you get a solid rectangle. The cutout has to come from a removal node (or anything that delivers alpha).
- Hard edges on the subject are a removal-quality problem, not a compositing one - fix it upstream with a better removal pass (BiRefNet-HR for hair, matting weights for genuinely semi-transparent material).
It's a quiet, dependable utility that removes the fiddliest part of compositing - aligning and blending layers - from your workflow. For swapping a person into a new scene across a whole video clip, it's the node you want from this pack.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| foreground_images | IMAGE | — | |
| background_images | IMAGE | — | |
| x_offset | INT | 0-16384–16384 | — |
| y_offset | INT | 0-16384–16384 | — |
| scale_x | FLOAT | 1.00.1–10 | — |
| scale_y | FLOAT | 1.00.1–10 | — |
| bg_scale_x | FLOAT | 1.00.1–10 | — |
| bg_scale_y | FLOAT | 1.00.1–10 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| MASK | MASK | — |