Nodes/ComfyUI-YogurtNodes/Replace Image In Batch (Yogurt Nodes)
ComfyUI Node

Replace Image In Batch (Yogurt Nodes)

Swapping one bad frame out of a video batch without the rebuild

By yogurt7771·Created 2 years ago·Updated 9 days ago· 1
Replace Image In Batch (Yogurt Nodes)
  • images
  • image
  • images
index0

Every frame-based pipeline has the same annoyance: 30 frames, 29 great, one with a melted face or a twitching hand, and you either redo the whole batch or write a script. Replace Image In Batch (Yogurt Nodes) is the graph-native middle path. It takes an image batch, replaces the frame at a given index with another image, and hands back the modified batch - one frame swapped, the rest untouched.

The obvious workflow is the repair loop: split a video into frames, run an inpaint or a face-fix on the one bad frame, then stitch that fixed frame back into the batch at its original index before reassembling the video. It also plays nicely with the pack's other batch tools - if you're generating a batch and regenerating just one seed, this is how you slot the retry back in. It's a small node, but it's the difference between "re-ran the whole batch" and "fixed one frame."

How it works

The implementation is careful about edge cases, which is nice given how easy this is to get subtly wrong. It clones the batch, then replaces the frame at index. Negative indices work like Python (-1 is the last frame), and an out-of-range index raises a clear error instead of silently doing nothing. The replacement logic handles batches gracefully: if your replacement input is a batch the same size as the target, it picks the frame at the same index; otherwise it uses the replacement's first frame. It also enforces that the replacement's shape (height/width/channels) matches the frame it's replacing - a mismatched shape errors loudly, because feeding a wrong-shape frame into a video encoder would produce garbage you'd debug for an hour.

The inputs that matter

  • images - the batch to modify.
  • image - the replacement. A single image, or a matching-size batch.
  • index - which frame to replace. 0-based, negative allowed.

One output: images - the modified batch, same size, ready for whatever consumes the original.

Installing it

It's part of ComfyUI-YogurtNodes. Install via ComfyUI Manager (search "ComfyUI-YogurtNodes") or:

cd ComfyUI/custom_nodes
git clone https://github.com/yogurt7771/ComfyUI-YogurtNodes.git
cd ComfyUI-YogurtNodes
pip install -r requirements.txt

Restart ComfyUI; it's under "Yogurt Nodes". Nothing to download.

Where people get burned

The shape check is the thing that bites people who try to be clever: you can't replace a 512×512 frame with a 1024×1024 one - resize it first or the node refuses. Also keep in mind the "same-index" behavior when you feed a replacement batch: it's only honored when sizes match, so if you wired a different-size batch expecting index alignment, you'll silently get the first frame instead. And it's worth stating plainly: this replaces in-memory, so the modified batch only exists as long as the graph has it - save downstream if you need it. For its narrow job it's one of the more trustworthy small nodes in the pack.

CategoryYogurtNodes/Image

Inputs (3)

NameTypeDefaultDescription
imagesIMAGEThe image batch to modify.
imageIMAGEReplacement image. If this is a batch, the index will be used when possible; otherwise the first image is used.
indexINT0Index to replace. Supports negative indices like Python.

Outputs (1)

NameTypeDescription
imagesIMAGE