File size: 1,365 Bytes
47b0045
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# LTX Duration -> Frames
# Drop this file into ComfyUI/custom_nodes/ and restart ComfyUI.
# Converts a duration in seconds to a valid LTX 2.3 frame count,
# snapped to 8n+1 (latent temporal compression requirement). No duration cap.
# Outputs fps as both INT and FLOAT so one node drives every consumer.

class LTXDurationToFrames:
    @classmethod
    def INPUT_TYPES(cls):
        return {
            "required": {
                "duration_seconds": ("FLOAT", {"default": 10.0, "min": 0.5, "max": 120.0, "step": 0.1}),
                "fps": ("INT", {"default": 25, "min": 1, "max": 60}),
            }
        }

    RETURN_TYPES = ("INT", "INT", "FLOAT", "FLOAT")
    RETURN_NAMES = ("frames", "fps_int", "fps_float", "actual_seconds")
    FUNCTION = "calc"
    CATEGORY = "LTX"

    def calc(self, duration_seconds, fps):
        raw = duration_seconds * fps
        n = round((raw - 1) / 8.0)
        frames = int(8 * n + 1)
        if frames < 9:
            frames = 9
        actual = frames / float(fps)
        print("[LTXDurationToFrames] %.1fs @ %dfps -> %d frames (%.2fs actual)"
              % (duration_seconds, fps, frames, actual))
        return (frames, int(fps), float(fps), actual)


NODE_CLASS_MAPPINGS = {"LTXDurationToFrames": LTXDurationToFrames}
NODE_DISPLAY_NAME_MAPPINGS = {"LTXDurationToFrames": "LTX Duration to Frames (seconds)"}