-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathBatchThief.py
64 lines (53 loc) · 1.96 KB
/
BatchThief.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import torch
import numpy as np
class BatchThief:
def __init__(self):
self.type = "BatchThief"
self.output_node = True
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"images": ("IMAGE",),
"start_frame": ("INT", {
"default": 0,
"min": 0,
"max": 999, # Arbitrary limit, can be adjusted
"step": 1
}),
"end_frame": ("INT", {
"default": 1,
"min": 0,
"max": 999, # Arbitrary limit, can be adjusted
"step": 1
})
}
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "steal_frames"
CATEGORY = "image/batch"
def steal_frames(self, images, start_frame, end_frame):
# Check if we have a batch of images
if len(images.shape) < 4 or images.shape[0] <= 1:
print("Warning: BatchThief node requires a batch of multiple images")
return (images,)
# Get batch size
batch_size = images.shape[0]
# Validate and adjust frame indices
start_frame = min(max(0, start_frame), batch_size - 1)
end_frame = min(max(start_frame, end_frame), batch_size)
# Extract the specified range of frames
stolen_frames = images[start_frame:end_frame]
# If the range is empty (start_frame >= end_frame), return an empty batch
if stolen_frames.shape[0] == 0:
print("Warning: Selected frame range is empty")
# Return a single empty frame to maintain tensor structure
return (images[:1],)
return (stolen_frames,)
# This is required for ComfyUI to recognize and load the node
NODE_CLASS_MAPPINGS = {
"BatchThief": BatchThief
}
NODE_DISPLAY_NAME_MAPPINGS = {
"BatchThief": "Batch Thief"
}