image composite masked one bye one
Compositing video batches without blowing your VRAM
- destination
- source
- mask
- IMAGE
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- resizesourceto matchdestinationif they differ in size.resize_source_mode- the actual interpolation algorithm used for that resize:nearest,bilinear,bicubic,area, ornearest-exact. This is exposed here in a way the siblingWithSwitchnode doesn't bother with -nearest/nearest-exactfor hard-edged content like masks,bilinear/bicubicfor smoother photographic footage,areawhen 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.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| destination | IMAGE | — | |
| source | IMAGE | — | |
| x | INT | 00–16384 | — |
| y | INT | 00–16384 | — |
| resize_source | BOOLEAN | false | — |
| resize_source_mode | COMBO | 5 options: nearest, bilinear, bicubic, area, nearest-exact | |
| maskopt | MASK | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |