KJNodes/latentsgenerated

Get Latent Range From Batch(GetLatentRangeFromBatch)

This node supports processing latent tensors in two common dimensional formats: four-dimensional (B, C, H, W) and five-dimensional (B, C, T, H, W), corresponding to image batches and video frame sequences, respectively.

Get Latent Range From Batch

latents
LATENT
start_index
0
num_frames
1
KJNodes

The Get Latent Range From Batch node supports processing latent tensors in two common dimensional formats: four-dimensional (B, C, H, W) and five-dimensional (B, C, T, H, W), corresponding to image batches and video frame sequences respectively.

The Get Latent Range From Batch node is a tool for extracting specified range data from a batch of latent space (Latent) data. Its core function is to slice a continuous subset from the input batch latent tensor based on the user-defined starting position and quantity. This operation is particularly useful for workflows that need to process specific parts of video sequences or batch images.

Node Function

This node supports processing latent tensors in two common dimensional formats: four-dimensional (B, C, H, W) and five-dimensional (B, C, T, H, W), corresponding to image batches and video frame sequences respectively. Its internal mechanism determines the batch or time dimension size by parsing the shape of the input tensor. Then, based on the provided start index and frame count parameters, it uses slicing operations to precisely extract data within the target range. When a parameter is set to -1, the node automatically calculates the corresponding boundary value.

Node Parameter Description - Get Latent Range From Batch

Connection Inputs (Inputs)

Parameter NameData TypeRequiredDefault ValueValue Range/OptionsDescription
latentsLATENTYes--latents (Input Parameter): Input a batch containing latent tensors. The node will extract data from the specified range within this batch.

Control Parameters (Parameters)

Parameter NameData TypeRequiredDefault ValueValue Range/OptionsDescription
start_indexINTYes0-1 - 4096 (Step: 1)start_index (Input Parameter): Specifies the starting position index for the extraction operation. The valid range is -1 to 4096 with a step of 1. When set to -1, the calculation starts from the end.
num_framesINTYes1-1 - 4096 (Step: 1)num_frames (Input Parameter): Specifies the number of consecutive data (frames) to extract. The valid range is -1 to 4096 with a step of 1. When set to -1, all data from the start index to the end will be extracted.

Output

Parameter NameData TypeDescription
LATENTLATENTLATENT (Output Parameter): Outputs a new batch containing the extracted sub-range latent tensors.

Usage Scenarios

In animation production or video processing workflows, this node can be used to extract key segments from a long sequence for refinement. For example, a user can first use a node to generate a latent video sequence containing multiple frames, then use this node to extract a few frames that require focused adjustment. These frames can then be sent to other nodes for stylization or repair, and finally, the processed segment can be recombined with the original sequence.

Notes

Please note that the start index must be within the valid range of the input latent tensor; otherwise, the node will report an error. For five-dimensional tensors, the slicing operation is performed on the time dimension (T); for four-dimensional tensors, it is performed on the batch dimension (B).

The Get Latent Range From Batch node is from the ComfyUI-KJNodes node package.

Comments

Sign in with GitHub to join the discussion.

Loading comments…