add VideoFramePreprocessor
This commit is contained in:
+16
-15
@@ -10,13 +10,13 @@ class VideoFramePreprocessor:
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("IMAGE",)
|
||||
RETURN_NAMES = ("processed_images",)
|
||||
# CHANGED: Added three INT outputs for width, height, and frame_count
|
||||
RETURN_TYPES = ("IMAGE", "INT", "INT", "INT")
|
||||
RETURN_NAMES = ("processed_images", "width", "height", "frame_count")
|
||||
FUNCTION = "process_frames"
|
||||
CATEGORY = "Stand-In" # Placed in a sub-category for organization
|
||||
CATEGORY = "Stand-In"
|
||||
|
||||
def process_frames(self, images: torch.Tensor):
|
||||
# Input tensor shape: (batch_size/frames, height, width, channels)
|
||||
if images.dim() != 4:
|
||||
raise ValueError("Input must be a batch of images (video frames).")
|
||||
|
||||
@@ -24,7 +24,6 @@ class VideoFramePreprocessor:
|
||||
print(f"Original video specs: {total_frames} frames, {original_w}x{original_h}")
|
||||
|
||||
# 1. Trim frame count to be 4n+1
|
||||
# We find the largest number <= total_frames that satisfies the condition.
|
||||
new_total_frames = total_frames - ((total_frames - 1) % 4)
|
||||
|
||||
if new_total_frames != total_frames:
|
||||
@@ -33,29 +32,31 @@ class VideoFramePreprocessor:
|
||||
else:
|
||||
print("Frame count already meets 4n+1 requirement. No trimming needed.")
|
||||
|
||||
# 2. Crop dimensions to the nearest multiple of 8 (rounding down)
|
||||
new_h = (original_h // 8) * 8
|
||||
new_w = (original_w // 8) * 8
|
||||
# 2. Crop dimensions to the nearest multiple of 16 (rounding down)
|
||||
new_h = (original_h // 16) * 16
|
||||
new_w = (original_w // 16) * 16
|
||||
|
||||
if new_h != original_h or new_w != original_w:
|
||||
print(f"Cropping dimensions to a multiple of 8: {original_w}x{original_h} -> {new_w}x{new_h}")
|
||||
print(f"Cropping dimensions to a multiple of 16: {original_w}x{original_h} -> {new_w}x{new_h}")
|
||||
|
||||
# Calculate the amount to remove from each side for a center crop
|
||||
h_to_remove = original_h - new_h
|
||||
w_to_remove = original_w - new_w
|
||||
|
||||
h_start = h_to_remove // 2
|
||||
w_start = w_to_remove // 2
|
||||
|
||||
# Perform the centered crop using tensor slicing
|
||||
processed_images = images[:, h_start : h_start + new_h, w_start : w_start + new_w, :]
|
||||
else:
|
||||
print("Dimensions are already multiples of 8. No cropping needed.")
|
||||
print("Dimensions are already multiples of 16. No cropping needed.")
|
||||
processed_images = images
|
||||
|
||||
print(f"Final video specs: {processed_images.shape[0]} frames, {processed_images.shape[2]}x{processed_images.shape[1]}")
|
||||
# Get final dimensions from the processed tensor
|
||||
final_frames, final_h, final_w, _ = processed_images.shape
|
||||
|
||||
print(f"Final video specs: {final_frames} frames, {final_w}x{final_h}")
|
||||
|
||||
return (processed_images,)
|
||||
# CHANGED: Return the processed images along with the final dimensions
|
||||
return (processed_images, final_w, final_h, final_frames)
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
@@ -64,4 +65,4 @@ NODE_CLASS_MAPPINGS = {
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"VideoFramePreprocessor": "Stand-In Trimmer & Cropper",
|
||||
}
|
||||
}
|
||||
+619
-545
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user