ScalarMaskBlend
Blend two video batches with a one-number-per-frame mask (the VRAM-free compositor)
- a
- b
- mask
- IMAGE
ScalarMaskBlend is the node you reach for when you need to mix two video batches frame-by-frame, but the only thing telling you how much to mix is one number per frame. The canonical case: compositing a LatentSync lip-sync result back onto your original video. The name isn't marketing - the "scalar" is the whole point. It's the only custom node I can think of where feeding a 1x1 mask is the feature, not a mistake.
The pack is a single tiny file, no dependencies, no model downloads. Someone hit a real problem in a lip-sync workflow and shipped a fix instead of a framework.
What it actually does
You give it two image batches and a mask. It collapses each mask frame down to a single scalar weight w by taking the mean over the height and width, then blends:
output = a * (1 - w) + b * w
Read that carefully, because people get the polarity backwards. A mask value of 0 gives you a (the LatentSync output, say); a value of 1 gives you b (the original frames). Everything between is a linear crossfade. So a per-frame mask around 0.2 means "mostly the lip-sync frames, nudged toward the original" - which is exactly the setting you want when LatentSync nukes the background but nails the mouth.
The VRAM angle is what makes this worth having. In a video pipeline you're holding hundreds of frames at full resolution. If your mask is just a per-frame confidence or coverage number, upscaling it to full res to do a proper mask blend burns memory for zero benefit. Here the mask never leaves 1x1 if you don't want it to. LatentSync itself is a ByteDance open release and a regular in the talking-head corner of the ComfyUI ecosystem, and this node is squarely aimed at that crowd - the README literally names it as the expected use.
The inputs that matter
a(IMAGE) - usually the LatentSync output.b(IMAGE) - usually the original video frames.mask(MASK) - per-frame mask,1x1or any size. Only its per-frame mean matters. A single-frame mask gets repeated across the whole batch automatically.length_mode- what happens when the batches don't have the same number of frames.trim_to_min(default) truncates everything to the shortest batch, silently dropping frames off the end.match_a/match_bpick a target length and pad the short ones instead.pad_mode- only used when padding.repeat_lastholds the final frame,loopcycles from frame zero.clamp_mask(default on) - clamps weights to[0, 1], so out-of-range mask values can't overbrighten or invert the blend.
The output is a single IMAGE batch, same size as the inputs, ready to feed a VAE decode or a Video Combine node.
Where people get burned
The big trap: if you feed a full-resolution mask expecting per-pixel blending, you're not getting it. The mean of a face-shaped mask over a full frame is a tiny number, so the blend barely lets a through and you'll stare at output that looks almost like the original and wonder why the node is broken. That's not a bug - it's the wrong tool. ScalarMaskBlend is for the case where one number per frame is genuinely what you want. If you need spatial blending (face region replaced, background preserved), use a proper per-pixel mask composite instead.
Second gotcha: trim_to_min is the default, and it will happily cut frames off the end of a longer batch. If your sync and your original are off by a frame or two, you'll get a clip that ends early with no warning. If the lengths matter, set length_mode to match_a or match_b and let repeat_last hold the last frame.
Third: mismatched dtypes are handled by casting everything to a's device and dtype, and an empty batch raises RuntimeError: Empty batch after alignment. - both fine in normal use, just not things that fail gracefully mid-workflow.
Installing it
ComfyUI Manager: search "Scalar Mask Blend" and install the comfyui-scalar-mask-blend pack, then restart. Or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/Notimefornuts/comfyui-scalar-mask-blend
Then restart ComfyUI. No requirements.txt, no pip install step, no models - it only uses torch, which ComfyUI already ships. It shows up under the video category in the node menu.
It's a small, very new pack with basically no community footprint yet, so don't expect a troubleshooting forum. What you get is one focused node that does one thing, does it cheaply, and is small enough that reading its whole source takes about a minute if you want to be sure what you're running.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| a | IMAGE | — | |
| b | IMAGE | — | |
| mask | MASK | — | |
| length_mode | COMBO | 3 options: trim_to_min, match_a, match_b | |
| pad_mode | COMBO | 2 options: repeat_last, loop | |
| clamp_mask | BOOLEAN | true | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |