Get Image or Mask Range From Batch
Slice frames out of a batch
- images
- masks
- IMAGE
- MASK
You loaded a 120-frame video and you only want frames 30 through 60. Or you generated a big batch and want to pull out just the middle chunk. GetImageRangeFromBatch is the slicer for exactly that. Give it a start point and a length, and it returns that contiguous range out of a batch of images or masks. If you work with video in ComfyUI, this is bread-and-butter - trimming clips, isolating a segment, grabbing the last frame to use as a seed for the next generation.
How it works
A batch is just an ordered stack of images (or mask frames). This node takes a slice of that stack - like frames[start : start + num] - and hands back the sub-batch. Nothing is resampled or altered; you get the original frames, just fewer of them.
The inputs
- start_index - where the slice begins (0 is the first frame). It accepts -1, which counts from the end, so you can grab the tail of a sequence without knowing its exact length.
- num_frames - how many frames to take from the start point. Default 1 (a single frame), up to the batch length.
Then two optional inputs - images and masks - because the node works on either. Wire in a batch of images, a batch of masks, or both, and they get sliced together with the same range. The outputs mirror that: IMAGE and MASK.
Why it's handy for video
Video work in ComfyUI is mostly juggling batches of frames, and you constantly need pieces of them. Trim off a bad first second. Feed only the last frame of one clip into the next as an init image for continuity. Split a long sequence into chunks your VRAM can handle. Pull a specific window to inspect or re-process. All of that is a start index and a length, which is precisely this node. It's the counterpart to concatenation: one builds sequences, this one cuts them.
Installing KJNodes
In ComfyUI Manager, search "KJNodes for ComfyUI" in the Custom Nodes Manager, install, restart. Manual: cd ComfyUI/custom_nodes && git clone https://github.com/kijai/ComfyUI-KJNodes, then pip install -r ComfyUI-KJNodes/requirements.txt (portable: python_embeded\python.exe -m pip install -r ComfyUI\custom_nodes\ComfyUI-KJNodes\requirements.txt), then restart. No models required.
Watch out for
Off-by-one thinking is the usual source of confusion. start_index is zero-based, so frame "one" is index 0. And if you ask for more frames than actually remain after your start point - start at 100 in a 110-frame batch and request 30 - you'll get whatever's left, not an error padding out to 30. If your output is shorter than you expected, check that your start plus length doesn't run off the end.
Also make sure you're actually feeding it a batch. A single image on the wire is a batch of one, and slicing that does very little. This node earns its keep when there are many frames to choose from.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| start_index | INT | 0-1–4096 | — |
| num_frames | INT | 11–4096 | — |
| imagesopt | IMAGE | — | |
| masksopt | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| MASK | MASK | — |