Nodes/ComfyUI-CustomNodePacks/Batch Range (C2C)
ComfyUI Node

Batch Range (C2C)

Image Batch Slice (C2C)

By Code2Collapse·Created 8 months ago·Updated about 8 hours ago· 59
Batch Range (C2C)
  • images
  • images
  • frame_count
  • remainder
  • remainder_count
  • total_frames
  • is_video
◄start0►
◄end-1►
◄step1►
◄moderange►
◄split_index1►
◄split_ratio0.50►
◄frame_index0►

Image Batch Slice (C2C) is the node equivalent of Python's video[start:end:step] - and if you've ever needed to process only frames 10 through 60 of a video batch, or every second frame of a 100-frame sequence, you know the fiddly alternative: a ChainNode, a bunch of math, or loading the video three times. This just does the slice, cleanly, with Python's slice semantics you already half-know.

It's part of the C2C Helpers in ComfyUI-CustomNodePacks, the ~72-node pack from Code2Collapse (Likhith-24, active on r/comfyui). A pack this size needs a "utility drawer," and this is the frame-range drawer.

How it works

You feed it an images batch (a [B,H,W,C] tensor - a video loaded into ComfyUI is just a batch of frames) and three ints:

  • start - first frame, inclusive. Negative counts from the end of the batch.
  • end - exclusive, Python-style: the slice stops before this frame. -1 means "to the end of the batch", which is the default.
  • step - stride. 1 keeps every frame; 2 keeps every second frame (frame decimation for faster testing); 4 keeps every fourth.

Negative values work like Python: start=-30 starts 30 frames from the end, and the node clamps everything into the valid range rather than erroring on out-of-bounds values. Outputs are the sliced images plus frame_count (INT), which is convenient for wiring into downstream logic like save filename prefixes.

It's the same idea as the pack's Frame Range Router (MEC), minus the mask routing - this one is a bare-bones batch-only slice.

The inputs and outputs that matter

  • images - the only required input.
  • start / end / step - the three ints above. The two you'll actually touch: start and end. Leave step at 1 unless you're deliberately decimating.
  • images out - the sliced batch.
  • frame_count (INT) - how many frames you got; wire it into a filename or a counter.

Installing it

Ships inside ComfyUI-CustomNodePacks, no separate repo. ComfyUI Manager → search "CustomNodePacks", or:

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

Pure PyTorch, no extra dependencies, no models, no VRAM. The pack overall wants opencv-python>=4.7.0 and scipy>=1.10.0 for other nodes - add just those if missing (skip the full requirements.txt, which can overwrite ComfyUI's torch). Restart ComfyUI.

Common issues

  • Got fewer frames than expected - check whether you meant end inclusive. It's exclusive. Want frames 0-9? That's start=0, end=10.
  • Empty result - start at or past end, or a step that skips everything. The node clamps instead of erroring, so check frame_count on the output.
  • You only want to view a range, not reshape the batch - this node genuinely slices; the pack's Video Frame Player (MEC) is the in-graph scrubber if your goal is preview instead of processing.

The honest take: it's a one-liner you could write in a custom script node - but you won't, because this exists, is already installed with the pack, and reads exactly like the Python you already know.

Category🐺 C2C/🧰 Core/Helpers

Inputs (8)

NameTypeDefaultDescription
imagesIMAGE—
startINT0-100000–100000Range mode: first frame. Negative counts from the end.
endINT-1-100000–100000Range mode: exclusive end. -1 = end of batch.
stepINT11–1024Range mode: keep every Nth frame.
modeoptCOMBOrangeWhat to pick: a start:end:step range, a split (at a frame index or a fraction), or one frame (first, middle, last or by index).
split_indexoptINT10–100000'split at index': frames before this index go to 'images'.
split_ratiooptFLOAT0.500–1'split at ratio': this fraction of the batch goes to 'images'.
frame_indexoptINT00–999999'frame at index': 0-based, clamped to the last frame.

Outputs (6)

NameTypeDescription
imagesIMAGEThe selected frames (the first part when splitting).
frame_countINTHow many frames 'images' holds.
remainderIMAGESplit modes: the frames after the split point. Empty in the other modes.
remainder_countINTHow many frames 'remainder' holds.
total_framesINTHow many frames came in.
is_videoBOOLEANTrue when more than one frame came in.