Nodes/zhangp365/ComfyUI-utils-nodes/image composite masked one bye one
ComfyUI Node

image composite masked one bye one

Compositing video batches without blowing your VRAM

By zhangp365·Created 2 years ago·Updated 5 months ago· 134
image composite masked one bye one
  • destination
  • source
  • mask
  • IMAGE
x0
y0
resize_sourcefalse
resize_source_mode

Same job as stock ImageCompositeMasked - paste source onto destination through a mask - but processed one frame at a time instead of as a single batch tensor. If you've ever run a compositing step on a video-length image batch and watched your VRAM usage spike right at that node, this is the fix.

Why batch compositing gets expensive

Stock ImageCompositeMasked operates on the whole batch tensor at once - destination, source, and mask all held in memory simultaneously for every frame. That's fine at a handful of images. At video length - 81 frames, 121 frames, whatever your clip is - holding all of that in memory at the same time is where a lot of "worked fine on stills, OOMs on video" reports come from. This node loops over the batch frame by frame instead, compositing each one and releasing it before moving to the next. You trade a bit of wall-clock speed for a peak memory footprint that doesn't scale with your batch size the same way.

It's the direct counterpart to the "paste back without touching the VAE" discipline that makes ImageCompositeMasked the standard tool for inpainting in the first place - this node keeps that discipline intact for video, where the naive batch version would otherwise force you to either downsize your clip or upgrade your GPU.

Inputs and outputs

  • destination / source - your base and pasted-in image batches.
  • x / y - placement offset, up to 16384.
  • resize_source - resize source to match destination if they differ in size.
  • resize_source_mode - the actual interpolation algorithm used for that resize: nearest, bilinear, bicubic, area, or nearest-exact. This is exposed here in a way the sibling WithSwitch node doesn't bother with - nearest/nearest-exact for hard-edged content like masks, bilinear/bicubic for smoother photographic footage, area when you're downscaling.
  • mask (optional) - same masking behavior as the stock node.

Output: IMAGE, the composited batch.

Note what's not here: no enabled toggle. That's deliberately the other node's job - this one exists purely for the memory optimization, not for A/B bypassing.

Installing it

ComfyUI Manager: search "ComfyUI-utils-nodes." Or:

cd ComfyUI/custom_nodes
git clone https://github.com/zhangp365/ComfyUI-utils-nodes

Restart ComfyUI. No model weights or extra Python packages involved - it's pure tensor-op glue.

When to actually reach for this one

If you're compositing a handful of still images, use the regular ImageCompositeMaskedWithSwitch or the plain stock node - the per-frame loop here adds overhead you don't need at small batch sizes. Reach for this specifically when your batch is video-length and you're seeing memory pressure at the composite step, not before. And if you're still hitting VRAM limits even with this node, the next thing to check is whether resize_source is forced on unnecessarily - resizing every frame of a large batch is real work too, so only enable it if source and destination genuinely don't match.

Categoryutils/image

Inputs (7)

NameTypeDefaultDescription
destinationIMAGE
sourceIMAGE
xINT00–16384
yINT00–16384
resize_sourceBOOLEANfalse
resize_source_modeCOMBO5 options: nearest, bilinear, bicubic, area, nearest-exact
maskoptMASK

Outputs (1)

NameTypeDescription
IMAGEIMAGE