forked from filliptm/ComfyUI_Fill-Nodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fl_image_duration_sync.py
36 lines (29 loc) · 1.18 KB
/
fl_image_duration_sync.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
import numpy as np
import torch
from PIL import Image, ImageOps
class FL_ImageDurationSync:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"images": ("IMAGE", {}),
"frame_count": ("INT", {"default": 30}),
"bpm": ("INT", {"default": 120}),
"fps": ("INT", {"default": 30}),
"bars": ("FLOAT", {"default": 4.0, "step": 0.05}),
}
}
RETURN_TYPES = ("IMAGE", "INT")
RETURN_NAMES = ("output_images", "hold_frames")
FUNCTION = "sync_image_to_duration"
CATEGORY = "🏵️Fill Nodes"
def sync_image_to_duration(self, images, bpm, frame_count, bars, fps):
# Calculate the duration of each bar in seconds
bar_duration = 60 / bpm * 4
# Calculate the total duration in seconds
total_duration = bar_duration * bars
# Calculate the number of frames to hold the image
hold_frames = int(total_duration * fps)
# Repeat the image for the calculated number of frames
output_images = images.repeat(hold_frames, 1, 1, 1)
return (output_images, hold_frames)