Get Latents From Batch Indexed
Pick specific latents out of a batch by index
- latents
- LATENT
This is the latent-space twin of GetImagesFromBatchIndexed. You've got a batch of latents and you want specific ones - index 0, 5, 12 - pulled out into a new batch, in the order you list. Where the image version works on decoded pictures, this one works on the raw latents, which matters when you want to select frames before spending a VAE decode, or when you're juggling video latents mid-pipeline.
Working on latents instead of images is the whole reason to use this rather than its image sibling: latents are cheaper to move around, and you often want to slice them while they're still in the sampler's world.
How it works
You give it a latent batch and a list of indices; it returns those latents as a new batch. Same explicit, out-of-order, duplicate-friendly selection as the image version - 2, 0, 1 reorders, listing an index twice duplicates it.
The one extra wrinkle is latent_format, and it exists because video latents aren't shaped like image latents. An image latent batch is BCHW (batch, channels, height, width). Video latents carry a time dimension, so they come as BTCHW or BCTHW depending on the model. The node needs to know which layout it's looking at to index the right axis - pick the frames, not accidentally the channels.
The inputs and outputs that matter
latents(LATENT) - the batch to pick from.indexes(STRING, default0, 1, 2, multiline) - the positions you want, zero-based, comma-separated. Order is preserved.latent_format(BCHW/BTCHW/BCTHW) - the layout of your latents. This is the setting that bites. Plain image latents areBCHW; video latents are one of the temporal formats. Get it wrong and you're indexing the wrong dimension.
Output is LATENT - the selected latents as a new batch, ready to decode or feed onward.
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/latents. No model downloads; the pack keeps deps minimal.
Common issues & troubleshooting
Garbage or wrong-shaped output. Almost always latent_format. If you're selecting frames from a video latent but left it on BCHW, the node indexes the wrong axis and you get nonsense (or the wrong count). Match the format to your model's latent layout - video models generally want BTCHW or BCTHW; check which by what your loader produces.
Index out of range. Zero-based, same as everywhere. A batch of N latents has valid indices 0 through N-1. For video, "how many latents" is the temporal count, which is not the same as your final frame count (video VAEs compress several frames per latent) - so don't assume 60 output frames means 60 latents to index.
"Should I do this before or after decode?" Before, when you can - selecting latents and then decoding only the ones you kept saves the VAE work on frames you're discarding. If you already have images, use GetImagesFromBatchIndexed instead; no point re-encoding.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| latents | LATENT | — | |
| indexes | STRING | 0, 1, 2 | — |
| latent_format | COMBO | BCHW | 3 options: BCHW, BTCHW, BCTHW |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LATENT | LATENT | — |