Nodes/ComfyUi-MpiNodes/Mpi Get Image At Index
ComfyUI Node

Mpi Get Image At Index

Pull one frame out of a batch without the IndexError dance

By MadPonyInteractive·Created 11 months ago·Updated 5 days ago· 3
Mpi Get Image At Index
  • images
  • IMAGE
  • INT
index-1

A ComfyUI image "batch" is a tensor with a frame dimension - N images stacked together. Lots of nodes hand you batches: video loaders, multi-frame samplers, grid generators. But plenty of downstream nodes want exactly one. MpiGetImageAtIndex is the two-second answer: point it at a batch, give it an index, get that one image back. Negative indices count from the end, so -1 is the last frame - the default, and the one you'll use most.

How it works

Two inputs: images (an IMAGE batch) and index (an INT, default -1). It indexes the batch with standard Python semantics and returns the chosen image as a single-image batch - the batch dimension is preserved, so whatever you wire it into sees a valid 1-frame IMAGE, not a bare tensor that breaks type expectations. The second output is INT, which just echoes the index you asked for - handy when you want to display or log "this is frame N."

Negative indexing is the headline: -1 gives the last frame, -2 the second-to-last, and so on. That's the common case - "give me the final frame of this video to use as a reference" - which is why -1 is the default.

There's one piece of defensive behavior worth knowing: if the batch is empty, the node returns an execution blocker instead of throwing an IndexError mid-graph. An empty frame dimension is the classic edge case for video nodes, and here it fails cleanly - downstream just doesn't run - rather than killing the whole workflow with a tensor traceback.

The inputs that matter

  • images - the batch. Wire it from a video loader, a sampler output, a batch combiner.
  • index - which frame. Positive from the start (0-based), negative from the end.

Outputs: IMAGE (the picked frame, single-frame batch) and INT (the echoed index).

Where people get burned

Indexing is 0-based from the front but the default is -1, so "the first frame" is 0, not 1 - a classic off-by-one when someone types 1 expecting the first frame and gets the second. And remember it returns a batch of one, not a frame without a batch dimension; some nodes are fine with that, others (like certain compositors) want a raw frame tensor. If you hit a shape complaint downstream, that's the dimension to check.

Install

From the MadPonyInteractive/ComfyUi-MpiNodes pack. ComfyUI Manager → search ComfyUi-MpiNodes (publisher mad-pony-interactive), install, restart. Or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/MadPonyInteractive/ComfyUi-MpiNodes

then restart. Zero dependencies, no model files - it's tensor indexing. The pack is AGPL-3.0 (≤ 1.2.6 MIT) and is the node library behind the author's Cubric Vision app.

The verdict

It's a one-line operation wearing a node costume, but "one line of tensor indexing" is exactly what you don't want to hand-roll in a graph. Every time you've wished you could grab "the last frame" without writing a subgraph, this is the fix. Keep it next to your video loader and you'll wonder how you lived without it.

CategoryMpiNodes/ImgOps

Inputs (2)

NameTypeDefaultDescription
imagesIMAGE
indexINT-1-18446744073709550000–18446744073709550000

Outputs (2)

NameTypeDescription
IMAGEIMAGE
INTINT