Latent From Batch
Slice latents like frames — and it knows video latents are 5D
- samples
- LATENT
The latent equivalent of slicing an image batch - but with one crucial difference that's easy to miss: video latents are 5D tensors, with the frame dimension in a different place than an image batch's. Nifty Latent From Batch handles both, which is exactly why you'd reach for it over hand-rolling the slice in a math node.
Feed it a samples LATENT, a start index, and a length, and it returns the slice you asked for. Same spirit as Nifty Image From Batch, but the index semantics have a couple of quirks worth knowing:
- batch_index - positive counts from the start, negative from the end (
-1= last latent). Same as images. - length - this one's the oddball.
0= "all the way to the end." Positive = read a fixed count in the direction of the index. Negative = trim that many off the opposite end - solength = -1withbatch_index = 0gives you "everything except the last one."
Output: LATENT - the sliced samples, with the samples tensor truncated along the frame/time axis.
The 4D vs 5D thing
This is the whole reason the node exists beyond convenience. A 4D latent is an image batch: shape [batch, channels, h, w]. A 5D latent is a video: [batch, channels, frames, h, w] - the frame count lives on axis 2, not axis 0. The node detects the rank and slices the right axis, so you don't have to remember which dimension means what. Wire up a 5D WAN or LTX video latent and the slicing just works; that alone is worth having it.
Where you'll use it
- Trim the start of a generated video - drop the unstable first frames before VAE decode.
- Preview mid-generation - pull one latent from the middle, decode it, check the vibe.
- Loop construction - grab the tail and re-feed it, the video-analog of the image tail trick.
For the "just give me the end" case, Nifty Last Latent From Batch is the one-input shortcut - same 4D/5D awareness, no index math.
Install
Nifty Nodes, standard: ComfyUI Manager → search "Nifty Nodes", or
cd ComfyUI/custom_nodes
git clone https://github.com/Stibo/comfyui-nifty-nodes
Restart ComfyUI, keep ComfyUI current (v3 API). No extra dependencies - pure tensor slicing with rank detection.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| samples | LATENT | Input latent batch to slice from. | |
| batch_index | INT | 0-4096–4096 | Positive values count from the beginning. Negative values count from the end (-1 = last latent etc.). |
| length | INT | 0-4096–4096 | 0 = all. Positive values read a fixed amount in the selected direction. Negative values trim from the opposite end (-1 = everything except the last latent etc.). |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LATENT | LATENT | — |