ComfyUI Node

Temporal Mask Union

The five-frame fix for flickering video masks

By nomadoor·Created 11 months ago·Updated 11 months ago· 2
Temporal Mask Union
  • mask_batch
  • Mask Batch
radius2
modeor
threshold3

Run a per-frame detector on a video and the masks lie frame by frame. Florence-2 sees the subject in frame 5, loses it in frame 6, finds it again in frame 7. Feed those raw detections straight into a mask-guided edit or video inpainting and you don't get a selection - you get a strobe light. Temporal Mask Union is the smoothing pass between "per-frame detection" and "anything downstream that cares about the whole clip."

The idea is simple: instead of trusting each frame alone, look at its neighbors and merge. For every frame the node opens a window of radius * 2 + 1 frames around it (default radius = 2 means a 5-frame window) and combines them one of two ways, picked by mode:

  • or - a pixel stays active if it was active in any frame in the window. This fills the gaps where the detector blinked and lost the subject for a frame or two. The pack's own demo treats this as the default for good reason.
  • majority - a pixel only survives if at least threshold frames in the window were active (default threshold = 3). Stricter, and it kills genuine one-off flicker instead of patching it, at the cost of eating real short appearances.

Output is a MASK in the same shape you fed in. mask_batch is deliberately flexible: it takes (frames, H, W), (batch, frames, H, W), or even a single (H, W) and hands back whatever dimensionality you gave it. The only inputs that matter are radius, mode, and threshold - the rest is plumbing.

Here's the trap, and it's the one that'll actually bite you: or mode with a big radius is a leak, not a filter. One stray detection and the entire 5-frame window lights up, so the mask swells until it's mushy and your downstream edit starts touching things you didn't want touched. That's why this pack ships a sibling node, Temporal Mask Remove Short Objects, specifically to claw back the blips or invents. Union then prune is the intended pipeline - the example workflow chains them exactly like that.

majority is the other direction and equally easy to overdo: threshold bigger than the window size just clamps to the window (so "threshold 5, radius 2" is really "all five frames must agree"), and at that point short-lived but real objects vanish. A good workflow is usually or for the main pass, then let the cleanup node handle the noise.

Installing is unremarkable and needs nothing heavy: search "ComfyUI Temporal Mask Tools" in ComfyUI Manager, or git clone https://github.com/nomadoor/ComfyUI-Temporal-Mask-Tools into ComfyUI/custom_nodes and restart. No model downloads, no API keys, pure tensor math - this one runs on CPU without complaint and barely touches GPU. Two small gotchas worth knowing: radius = 0 is a passthrough (window of one), and the pack is built on the newer V3 node API, so if the node doesn't show up after install, update ComfyUI before troubleshooting anything else.

Where does it fit in a real graph? Right after per-frame segmentation - Florence-2, or anything that emits a mask sequence - and before any video-aware step: mask-guided inpainting, compositing, region-consistent generation. It's the difference between a selection that holds and one that hums. Small node, but it's the one you'll reach for every time a "stable mask" video workflow is on the table.

CategoryTemporalMask/Operations

Inputs (4)

NameTypeDefaultDescription
mask_batchMASK
radiusINT20–32Half width of the temporal window (frames).
modeCOMBOor'or' unions any active frame; 'majority' requires the threshold count.
thresholdINT31–64Frames within the window that must be active when using majority mode.

Outputs (1)

NameTypeDescription
Mask BatchMASK