Insert Images To Batch Indexed
Drop or replace frames at the indices you name
- original_images
- images_to_insert
- IMAGE
You've got a batch and you want to stick some other images into it at specific positions - or overwrite the frames already there. InsertImagesToBatchIndexed does exactly that: you list the indices, hand it the images to place, and pick whether they replace the existing frames or insert between them. It's the manual, type-the-numbers counterpart to the batch-editing family in KJNodes.
This is the one to use when you know the positions yourself. Swap in a fixed first frame, replace a couple of glitchy frames with clean re-rolls, or splice a short insert into the middle of a clip - all by naming where.
How it works
It reads your index string, takes your images_to_insert, and places them into the original batch at those positions. The behavior forks on the mode. In replace mode, the frames at those indices get overwritten - batch length stays the same. In insert mode, the new frames are spliced in between existing ones - the batch gets longer. Same inputs, two genuinely different results, so pick the mode deliberately.
It's a plain, dependency-light utility, which is the KJNodes house style - Kijai's pack is a pile of exactly these "reshape a batch without writing Python" tools.
The inputs and outputs that matter
original_images(IMAGE) - the batch you're editing.images_to_insert(IMAGE) - the frames going in.indexes(STRING, default0, 1, 2, multiline) - the positions, comma-separated, zero-based. The count here should match how many images you're inserting.mode(replace/insert, optional) - overwrite the frames at those indices, or splice new ones in. This is the choice that decides whether your batch length changes.
Output is IMAGE - the edited batch.
Distinguish this from its sibling InsertImageBatchByIndexes, which takes a special INDEXES handoff from the filter node instead of a typed string. This node is the hand-driven one: you type the positions.
How to install it
ComfyUI Manager: search KJNodes for ComfyUI, install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/kijai/ComfyUI-KJNodes
pip install -r ComfyUI-KJNodes/requirements.txt
Restart and it's under KJNodes/image. No models.
Common issues & troubleshooting
Batch length changed when I didn't want it to (or didn't change when I did). That's the mode. replace keeps length constant by overwriting; insert adds frames and grows the batch. If your result is the wrong length, you're on the wrong mode.
Count mismatch. The number of indices should line up with the number of images_to_insert. Three images and two indices is ambiguous - keep them equal.
Index out of range. Zero-based, and in replace mode an index has to point at an existing frame. Asking to replace index 10 in a 10-frame batch (valid 0–9) is off by one. In insert mode you have a bit more latitude about where things land, but the same counting-from-zero rule applies.
"I'm rebuilding a batch after filtering out empty-mask frames." Then you probably want InsertImageBatchByIndexes instead, which consumes the INDEXES output from FilterZeroMasksAndCorrespondingImages directly and keeps the round-trip in sync for you. This node is for when you decide the positions.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| original_images | IMAGE | — | |
| images_to_insert | IMAGE | — | |
| indexes | STRING | 0, 1, 2 | — |
| modeopt | COMBO | 2 options: replace, insert |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |