Selects a range of frames from the video latent. Args: samples (dict): Video latent dictionary start_index (int): Starting frame index (supports negative indexing) end_index (int): Ending frame index (supports negative indexing) Returns:
(self, samples: dict, start_index: int, end_index: int)
| 47 | ) |
| 48 | |
| 49 | def select_latents(self, samples: dict, start_index: int, end_index: int) -> tuple: |
| 50 | """ |
| 51 | Selects a range of frames from the video latent. |
| 52 | |
| 53 | Args: |
| 54 | samples (dict): Video latent dictionary |
| 55 | start_index (int): Starting frame index (supports negative indexing) |
| 56 | end_index (int): Ending frame index (supports negative indexing) |
| 57 | |
| 58 | Returns: |
| 59 | tuple: Contains modified latent dictionary with selected frames |
| 60 | |
| 61 | Raises: |
| 62 | ValueError: If indices are invalid |
| 63 | """ |
| 64 | try: |
| 65 | s = samples.copy() |
| 66 | video_latent = s["samples"] |
| 67 | batch, channels, frames, height, width = video_latent.shape |
| 68 | |
| 69 | # Handle negative indices |
| 70 | start_idx = frames + start_index if start_index < 0 else start_index |
| 71 | end_idx = frames + end_index if end_index < 0 else end_index |
| 72 | |
| 73 | # Validate and clamp indices |
| 74 | start_idx = max(0, min(start_idx, frames - 1)) |
| 75 | end_idx = max(0, min(end_idx, frames - 1)) |
| 76 | if start_idx > end_idx: |
| 77 | start_idx = min(start_idx, end_idx) |
| 78 | |
| 79 | # Select frames while maintaining 5D format |
| 80 | s["samples"] = video_latent[:, :, start_idx : end_idx + 1, :, :] |
| 81 | |
| 82 | # Handle noise mask if present |
| 83 | if "noise_mask" in s and s["noise_mask"] is not None: |
| 84 | s["noise_mask"] = s["noise_mask"][:, :, start_idx : end_idx + 1, :, :] |
| 85 | |
| 86 | return (s,) |
| 87 | |
| 88 | except Exception as e: |
| 89 | print(f"[LTXVSelectLatents] Error: {str(e)}") |
| 90 | raise |
| 91 | |
| 92 | |
| 93 | @comfy_node(name="LTXVAddLatents") |
no outgoing calls
no test coverage detected