Nodes/Suplex Misc ComfyUI Nodes/Video Segment Calculator
ComfyUI Node

Video Segment Calculator

The frame math for slicing a long video into chunks

By saftle·Created 2 years ago·Updated 8 months ago· 3
Video Segment Calculator
    • frame_load_cap
    • skip_first_frames
    • force_rate
    • start_time
    • end_time
    duration30
    frame_rate25.0
    index0
    overlap_frames0
    precise_timingtrue

    Processing a long video through ComfyUI almost always means slicing it into segments: load chunk 1, process, save, load chunk 2... and the boring arithmetic of "which frames does segment N start and end at" is exactly where people produce overlapping or gappy segments by hand. Video Segment Calculator does that math and hands you the numbers ready to plug into a frame-based video loader. You decide the segment length; it decides the frames.

    The outputs map straight onto what video-loading nodes actually want. frame_load_cap and skip_first_frames are the two parameters a VHS-style (VideoHelperSuite) Load Video node takes to pull a window out of a long clip. start_time and end_time are the precise seconds for audio trimmers or anything that works in time rather than frames. force_rate is just your frame rate passed through for loaders that want it restated. Nothing gets loaded here - it's pure calculation, so it's free to run and trivially fast.

    How it works

    The math is simple and, usefully, defensively written:

    frames_per_segment = math.ceil(duration * frame_rate)
    skip_first_frames = max(0, index * frames_per_segment - overlap_frames)
    start_time = skip_first_frames / frame_rate
    end_time = (skip_first_frames + frames_per_segment) / frame_rate
    

    The ceil on frames per segment prevents gaps between segments. The max(0, ...) keeps segment 1 from going negative when you add overlap. And precise_timing (default true) keeps full float precision in the time outputs - flip it off to round to two decimals if your audio trimmer chokes on long decimal tails.

    Inputs and outputs

    • duration - segment length in seconds (tooltip: "Duration of each segment in seconds").
    • frame_rate - the video's FPS.
    • index - which segment you want, 0-based. Segment 0 is the first.
    • overlap_frames - optional frames of overlap with the previous segment (0–10), handy for smooth blending at cut points.
    • precise_timing - keep decimal precision (default true) or round times.

    Outputs, in order: frame_load_cap, skip_first_frames, force_rate, start_time, end_time.

    The README's example is the clearest picture: duration 45s at 30fps, index 2 → frame_load_cap=1350, skip_first_frames=2700, start_time=90.0, end_time=135.0. For a two-minute video in 45-second chunks, that's the third chunk, seconds 90–135, computed correctly the first time.

    Where people get tripped up

    index is 0-based - the first segment is index 0 with a skip of 0, and the natural instinct to start at 1 gives you a missing first segment. Also note overlap_frames only kicks in from segment 1 onward; segment 0 always starts at frame 0, which is correct behavior but worth knowing if you're testing overlap with segment 0 and seeing nothing happen. And remember it computes numbers only - you still have to feed them to a loader that honors frame_load_cap/skip_first_frames; if your loader doesn't expose those, this node's frame outputs aren't going to help you.

    Install

    Standard for this pack: ComfyUI Manager → search "uber_comfy_nodes" ("Suplex Misc ComfyUI Nodes") → install → restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/saftle/uber_comfy_nodes
    

    Restart, find it under Uber Comfy. Dependencies are Pillow, numpy, psutil and pynvml - nothing video-specific to download.

    CategoryUber Comfy

    Inputs (5)

    NameTypeDefaultDescription
    durationFLOAT301–3600Duration of each segment in seconds
    frame_rateFLOAT25.01–120Frame rate of the video
    indexINT00–1000Current segment index (0-based)
    overlap_framesoptINT00–10Number of frames to overlap between segments
    precise_timingoptBOOLEANtrueUse precise decimal timing for audio trimming

    Outputs (5)

    NameTypeDescription
    frame_load_capINT
    skip_first_framesINT
    force_rateFLOAT
    start_timeFLOAT
    end_timeFLOAT