Nodes/ComfyUI_Swwan/Get Image Range From Batch (Swwan)
ComfyUI Node

Get Image Range From Batch (Swwan)

Slice the frames you actually want

By aining2022·Created 10 months ago·Updated about 18 hours ago· 33
Get Image Range From Batch (Swwan)
  • images
  • masks
  • IMAGE
  • MASK
◄start_index0►
◄num_frames1►

Why a range node is not optional

Once you're doing video, "the batch" stops being a bag of images and starts being a timeline. You rendered 81 frames and you need frames 40–56 to feed the next segment. You want the last 13 frames to hand a video model as its start context. You want to inspect one frame of a 96-frame batch without previewing all of them.

Get Image Range From Batch does exactly that one thing: takes a contiguous run out of a batch. It's KJNodes' node of the same name, re-registered by the Swwan pack, and it takes an IMAGE and a MASK, slicing both with the same indices so a mask stays in sync with its frames.

The inputs

  • start_index - -1 to 4096, default 0. The interesting value is -1: it means "start at the end", specifically max(0, length - num_frames), which is how you grab the last N frames of a batch without doing arithmetic. Any other negative value, or a value past the end of the batch, raises Start index is out of range.
  • num_frames - 1 to 4096, default 1. The count you want from start_index. If you ask for more than exist it stops at the end of the batch rather than erroring, so it silently gives you fewer.
  • images - optional IMAGE.
  • masks - optional MASK.

Both inputs are optional, and that's the one design decision to be careful with. The outputs are always IMAGE and MASK, two sockets. If you only wire masks, the IMAGE output is empty and the next node in line fails with something unhelpful. Wire the one you need and ignore the other output; don't leave yourself guessing which socket is live.

Outputs

IMAGE and MASK, sliced to the same window. Both are ordinary types, so they go anywhere. In the extension pattern this node is the front half: pull the tail of your clip, feed it to the video model as the overlap, generate the next chunk, then hand both to Image Batch Extend With Overlap to stitch them.

Worth knowing: the mask slicing uses start_index after the -1 rewrite, so both outputs always agree on where the window starts. That sounds obvious and it's the kind of thing other implementations get wrong.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/aining2022/ComfyUI_Swwan
cd ComfyUI_Swwan
python -m pip install -r requirements.txt

Manager → ComfyUI Swwan, restart, hard-refresh. No models, no optional dependencies, and it runs in microseconds - it's a slice, not a copy.

Practical notes

This is a plumbing node, and plumbing nodes are where graphs go wrong quietly. Two examples from real use. First, slicing does not renumber anything downstream. Frame 40 of your output is now frame 0, and if a model or node interprets frame index as time, your result is offset by the slice start - usually not what you want when picking a loop point.

Second, ComfyUI caches aggressively, and a start_index you changed by hand is absolutely going to be respected, but if you convert that widget to an input and drive it from a primitive you still control, you'll spend five minutes wondering why the graph "didn't rerun". Change the value, the node reruns, that's the whole rule.

For the "which frames do I actually have?" question, pair this with Get Image Size & Count - it'll tell you the batch length before you slice, which beats guessing and reading an out-of-range traceback.

If you need non-contiguous frames, or specific indices out of order, this is the wrong node: Get Images From Batch Indexed takes a list like 0, 7, 12 instead of a start and a count.

CategorySwwan/Batch

Inputs (4)

NameTypeDefaultDescription
start_indexINT0-1–4096—
num_framesINT11–4096—
imagesoptIMAGE—
masksoptMASK—

Outputs (2)

NameTypeDescription
IMAGEIMAGE—
MASKMASK—