Nodes/ComfyUI-xiaozhuguang/小珠光批次计数
ComfyUI Node

小珠光批次计数

The node that makes conditional workflows possible

By xiaozhuguang·Created 2 months ago·Updated a day ago· 56
小珠光批次计数
  • 批次
  • 整数

Every conditional workflow has the same hidden dependency: somewhere, you need to know how much stuff is in a batch. How many frames did that video loader actually return? Is this latent a single image or a batch of eight? 小珠光批次计数 (Xiaozhuguang Batch Count) answers exactly that - it takes one input of any type and outputs the count as an integer. It's the 小珠光 take on comfyui_essentials' "Batch Count" node, which is a flattering thing to copy.

It lives in the plumbing layer, not the pixel layer - the part of ComfyUI that turns your graph into a small program. You reach for it when a downstream choice depends on how much data came through: pad a short frame batch up to a fixed length, branch on "did the loader return anything at all," or display a count to your human self while debugging.

How it works

The input is a wildcard (*), so anything can plug in, and the node figures out what "count" means for that type:

  • a tensor (IMAGE, LATENT samples, etc.) → the shape[0] batch dimension
  • a LATENT dict → the batch dimension of its samples tensor
  • a list or dict → its length

That's the whole logic, and it's robust because it ducks the type system entirely. It also declares an IS_CHANGED that hashes the batch contents, so it stays honest with ComfyUI's cache - if the batch changes, the count re-runs.

The input and output

  • 批次 (Batch) - any single wire: IMAGE, MASK, LATENT, a list, whatever.
  • 整数 (Integer) - the count out, ready to feed an INT input or a compare node.

It's about as close to a leaf node as ComfyUI gets: one in, one out, no settings.

A realistic use

Wire a video loader's frames into it, take the count, and feed it to the pack's CompareDataBlock with "less than" and a threshold - now you've got a data gate that only passes when the video is long enough. Or pair the count with DuplicateFirstFrame (the pack's frame-optimizer) to know exactly how many frames you had before padding, so you can strip them later with FrameExtract. Simple as it is, it's the difference between a graph that guesses and one that knows.

Install

Part of ComfyUI-xiaozhuguang - Manager (search "ComfyUI-xiaozhuguang"), or:

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

Restart. No dependencies beyond what ComfyUI already ships; this node is pure torch + Python.

Gotcha

The one thing that trips people: a tensor's batch dimension is shape[0], so an IMAGE that's really "one image with 4 frames" counts as 4, not 1. That's usually exactly what you want for video logic, but if you're counting "how many separate images," make sure the input is actually a list rather than a batched tensor - otherwise your conditional is doing math on the wrong number.

Categoryxiaozhuguang

Inputs (1)

NameTypeDefaultDescription
批次*

Outputs (1)

NameTypeDescription
整数INT