Nodes/KJNodes for ComfyUI/Get Mask Size & Count
ComfyUI Node Runs on cloud

Get Mask Size & Count

The inline sanity check for mask batches

By kijai·Created 3 years ago·Updated about 14 hours ago· 2,930
Get Mask Size & Count
  • mask
  • mask
  • width
  • height
  • count

Small node, genuinely useful habit. You drop it inline on a mask connection and it tells you three things about that mask - width, height, and how many are in the batch - while passing the mask straight through untouched. That's it. But if you've ever built a video mask workflow and gotten silently wrong output because your mask batch had 1 frame when you thought it had 81, this is the node that would have saved you twenty minutes of confusion.

It lives in KJNodes, kijai's utility pack, right next to its sibling Get Image Size & Count. Both exist for the same reason: ComfyUI hides tensor shapes from you, and half of debugging a graph is figuring out what's actually flowing through a wire.

How it works

A mask in ComfyUI is a tensor with a batch dimension - a stack of one or more frames, each width × height. This node reads those numbers off the tensor and surfaces them as values you can see on the node face and, if you want, wire onward. Crucially it doesn't modify anything: the mask output is the exact same mask you fed in, so you can splice this into an existing connection without changing behavior. It's a probe, not a transform.

The inputs and outputs that matter

There's one input - mask - and four outputs:

  • mask - the passthrough, identical to the input. Route your existing wire through it.
  • width / height - the mask dimensions as integers. Feed them into a resize, a crop, or any node that wants to match the mask's size.
  • count - the batch size. This is the one you actually came for on video work: it's the number of frames in the mask batch.

The count output is the tell for the classic bug. If you built a mask from a single image but expected it to cover a whole video, count reads 1 and you know instantly your mask never got batched to the frame length.

Installing it

ComfyUI Manager → search KJNodes for ComfyUI → install → restart. Manual route: cd ComfyUI/custom_nodes && git clone https://github.com/kijai/ComfyUI-KJNodes, then pip install -r ComfyUI-KJNodes/requirements.txt, and restart. Nothing heavy to download - this is pure inspection, no model behind it.

Where it actually helps

  • Frame-count mismatches. Video masks that quietly collapse to one frame are a top cause of "why is only the first frame masked." Watch count.
  • Feeding downstream sizing. Instead of typing dimensions into a resize node by hand, wire width/height out of here so the graph stays correct when you change resolution upstream.
  • It's a no-op you can leave in. Because the mask passes through unchanged, there's no reason to rip it out once a graph works - it's just a readout. The only "cost" is a node on your canvas.
CategoryKJNodes/masking

Inputs (1)

NameTypeDefaultDescription
maskMASK

Outputs (4)

NameTypeDescription
maskMASK
widthINT
heightINT
countINT