Nodes/ComfyUI-VideoHelperSuite/Select Every Nth Mask πŸŽ₯πŸ…₯πŸ…—πŸ…’
ComfyUI Node Runs on cloud

Select Every Nth Mask πŸŽ₯πŸ…₯πŸ…—πŸ…’

Select Every Nth Mask

By KosinkadinkΒ·Created 3 years agoΒ·Updated 3 months agoΒ· 1,727
Select Every Nth Mask πŸŽ₯πŸ…₯πŸ…—πŸ…’
  • mask
  • MASK
  • count
β—„select_every_nth1β–Ί
β—„skip_first_masks0β–Ί

Select Every Nth Mask thins out a stack of masks, keeping one for every interval you set and throwing the rest away. Set the interval to 3 and you keep masks 0, 3, 6, 9… and drop everything in between. It's the frame-decimation node, but for the mask track of a video workflow.

Masks in ComfyUI travel as batches just like images and latents - one mask per frame when you're doing per-frame masking (inpainting a moving subject, driving a regional prompt across a clip, feeding an animated matte to a ControlNet). Sometimes you have far more mask frames than you need, or you want to sample the sequence down to match a lower frame rate elsewhere. That's this node's job.

Why you'd reach for it

Two honest reasons. One, you're building at a reduced frame rate - maybe generating at 8fps AnimateDiff-style while your source mask sequence is 24fps - and you need to keep every third mask so the counts line up. Two, you're processing a long sequence in chunks and want to hand each chunk a different slice.

That second use is where skip_first_masks earns its keep: it applies before the every-nth thinning, so two copies of this node with different skip values will carve the same mask stack into interleaved groups. Skip 0 keeps 0,3,6…; skip 1 keeps 1,4,7…; skip 2 keeps 2,5,8… - three non-overlapping passes over one sequence.

Inputs and outputs

  • mask (MASK) - the input mask stack.
  • select_every_nth (INT, default 1) - the interval. 1 means keep everything (no skipping); 2 keeps every other; and so on.
  • skip_first_masks (INT, default 0) - how many masks to drop from the front before the interval logic kicks in.

Outputs:

  • MASK - the thinned stack.
  • count (INT) - how many masks came out, handy for wiring into whatever consumes the result.

The two settings you'll actually touch are select_every_nth and, if you're doing the interleaved-groups trick, skip_first_masks.

Installing it

comfy.icu already bundles VideoHelperSuite - no install step.

Locally: ComfyUI Manager β†’ search ComfyUI-VideoHelperSuite β†’ install β†’ restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite

and restart ComfyUI.

Common issues

The thing that bites: this node changes your frame count, and if the mask stack no longer matches the image or latent stack it's supposed to line up with, downstream nodes will either error or silently misalign your masks to the wrong frames. After thinning masks, thin the images the same way (there's a Select Every Nth for images too) or you'll get a mask that's one frame off for the whole clip. Use the count output to sanity-check both sides match.

And remember select_every_nth = 1 is a no-op - if nothing's being dropped, that's why. If the node's missing from the menu entirely, it's the pack failing to import; check the startup log and reinstall through Manager.

CategoryVideo Helper Suite πŸŽ₯πŸ…₯πŸ…—πŸ…’/mask

Inputs (3)

NameTypeDefaultDescription
maskMASKβ€”
select_every_nthINT11–9007199254740991β€”
skip_first_masksINT00–9007199254740991β€”

Outputs (2)

NameTypeDescription
MASKMASKβ€”
countINTβ€”