Nodes/ComfyUI Handy Nodes/Get Num Transition Chunks
ComfyUI Node

Get Num Transition Chunks

How Many Chunks Did the Detector Actually Make?

By trashkollector·Created about a year ago·Updated 5 days ago· 3
Get Num Transition Chunks
  • boundary_frames
  • segment_count
  • last_index
◄total_frames0►

The most useful node in a long-video pipeline is often the one that tells you how big the job got. TKTransitionScenesCount - "Get Num Transition Chunks" - takes the boundary list from TKTransitionDetector and gives you back a single number: how many segments that list describes, plus the highest index you're allowed to ask for.

That's it. It counts. And you want it, because everything downstream of scene-based chunking is a loop, and a loop needs its bound from somewhere other than your guess.

Why it earns a slot

Stock ComfyUI has no "length of this list" node. There are primitives for values, there are switches, there are reroutes - but if a node hands you twelve boundary frames, nothing in the core set turns those twelve into the number 12 you can wire into a loop counter or a batch size. People solve this by hardcoding the count, which is exactly the value that changes every time they touch chunk_secs.

So this node is plumbing in the truest sense: it converts a data structure into a scalar the graph can reason about. Wire segment_count into whatever drives your chunk loop, or into a PrimitiveInt that other nodes share, and now the loop follows the detector instead of your memory.

It doubles as a sanity check, which is the part I actually use. Run the detector, look at the number:

  • 1 segment on a five-minute video - detection failed. The detector's cut_z_thresh is too high, its min_scene_seconds swallowed everything, or you fed it frames at the wrong fps.
  • 400 segments on the same video - the opposite problem. The threshold is so twitchy it's flagging camera motion as cuts, and you'll be rendering 400 tiny chunks.
  • A number that matches what you see when you scrub the timeline - you can trust the split, and then you let the render queue run for an hour.

That two-minute check has saved me more wasted compute than any other node in the pack.

How it works

It runs the same boundary normalisation the chunk node does. boundary_frames is a wildcard socket, so it accepts a list of dicts with frame and type, a plain list of ints, a JSON string, or the detector's tuple. The count always treats frame 0 as the first segment start, skips the end marker (that closes the last segment; it doesn't open a new one), and drops anything out of range. Segments are half-open - [0, b0), [b0, b1), last one to the final frame - so a list of n useful boundaries yields n + 1 segments. That's the detail that trips people: the number that comes out is one more than the boundaries going in.

Like its sibling, this node sets INPUT_IS_LIST = True, so the whole boundary list lands in one execution and you get one answer. You get a count, not a list of counts.

Inputs and outputs

  • boundary_frames - the list from TKTransitionDetector. Required, wildcard.
  • total_frames (optional INT, default 0) - a cut-off point. Boundaries at or past this frame are ignored; 0 means no limit. It's the "only chunk the first 600 frames" switch. Useful when you've trimmed the head of a clip and don't want the later boundaries counted, or when you want the count to reflect a range you're actually rendering.
  • segment_count (INT) - total segments. What a loop iterates over.
  • last_index (INT) - segment_count - 1, i.e. the largest index that TKTransitionDetectorChunk will accept without clamping. Wire this one if you're driving index upward and want the loop to stop on the real last chunk rather than grinding an extra pass.

Installing it

Search "Handy Nodes" in ComfyUI Manager, or:

cd ComfyUI/custom_nodes
git clone https://github.com/trashkollector/TKNodes

Restart afterwards. The node lives in the flat TKNodes category, next to Get chunks from Scene Detection - search the canvas for "Num Transition" and you'll land on it.

No models, no GPU. But the pack installs its full requirements.txt regardless: torch/torchvision/torchaudio as >= floors, numpy, pydub (which wants FFmpeg on your PATH) and sherpa-onnx for the speaker nodes you're probably not using. If you hit ModuleNotFoundError: No module named 'cv2', install OpenCV yourself - the pack imports it for its scene analysis but doesn't list it:

cd ComfyUI
python -m pip install opencv-python-headless

Gotchas worth knowing

An empty list still counts 1. Hand it something unparseable and frame 0 always starts a segment, so you get segment_count of 1 and last_index of 0. A loop driven by that runs once and silently renders the whole clip. Not a bug - just why you glance at the number before queueing three hundred renders.

It reads the list, it doesn't re-run detection. Change chunk_secs on the detector and the count updates on the next run, because ComfyUI re-executes this node when its input changes - but if you bypass the detector, this happily counts whatever is left over.

Don't wire it back into the detector. There's a temptation to feed segment_count into something upstream to force a fixed number of chunks. That's the wrong direction; chunk_secs and min_scene_seconds on the detector are what control how many chunks you get. This node reports, it doesn't decide.

Small node, one job, and it's the one that keeps your chunk loop honest.

CategoryTKNodes

Inputs (2)

NameTypeDefaultDescription
boundary_frames*—
total_framesoptINT00–100000000—

Outputs (2)

NameTypeDescription
segment_countINT—
last_indexINT—