Nodes/ComfyUI 1hewNodes/Mask Batch Range
ComfyUI Node

Mask Batch Range

Slice a mask batch with start, step, and a frame budget

By 1hew·Created about a year ago·Updated 7 days ago· 33
Mask Batch Range
  • mask
  • mask
start_index0
step1
num_frame1

When you're working with video-derived masks - a per-frame segmentation batch, a mask per frame of an inpaint sequence - you often want a subset of the batch, sampled a certain way: "every 4th mask," "masks 10 onward," "the first 30." Stock ComfyUI gives you tensor-level slicing in custom Python but nothing clean on the canvas. This node is the mask version of a batch-range slicer, and it's refreshingly simple to use.

It's the mask sibling of the pack's Image Batch Range (both got reshaped in v3.15.0 with the step + num_frame=0 convention), and it does one job: pick a contiguous-ish sample out of a mask batch.

How it works

Three knobs, all straightforward:

  • start_index - where in the batch to start (default 0).
  • step - take every Nth mask (default 1 = all of them from the start point).
  • num_frame - how many masks to take. Default 1. num_frame = 0 is the special case: it means "take everything from the start onward" (respecting step), which is the mode you'll use most for "I want the whole batch sampled."

Internally it's a Python slice: mask[start::step] when num_frame=0, or mask[start:start+step*count:step] when you give it a count. Out-of-range or empty results return an empty mask batch rather than crashing - if you ask for a start past the end, you get an empty output you can then branch on.

Output is a mask batch - a subset, same type as the input, so it chains straight into whatever consumed the full batch.

Where you'd use it

Thinning is the headline use: a 240-mask video batch is a lot to feed through an expensive per-mask pass, so step=4, num_frame=0 gives you every 4th mask for a quick preview pass. The num_frame budget version is for "process only the first 50 masks" or "only this window" when you want a fixed count regardless of the batch's total length. Combined with the pack's Mask Batch Math Ops, you can sample down a batch, collapse it, and feed a single matte into an inpaint - a very common video-mask pipeline.

Installing it

Part of 1hewNodes. ComfyUI Manager → search "ComfyUI 1hewNodes" → install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/1hew/ComfyUI-1hewNodes

Restart ComfyUI. No special dependencies, no model downloads.

Common issues

num_frame=0 semantics are the thing to internalize: it's "all the way to the end," not "zero frames." Set it to 0 by default and you'll almost never hit the empty-batch surprise. Also note it's a range, not a random sample - step=4 gives you evenly spaced masks, not a shuffled subset, which is usually what you want for previews but occasionally not. And like every batch node here, it expects a tensor batch: if your masks arrive as a list, batch them up first.

Category1hewNodes/batch

Inputs (4)

NameTypeDefaultDescription
maskMASK
start_indexINT00–8192
stepINT11–8192
num_frameINT10–8192

Outputs (1)

NameTypeDescription
maskMASK