Nodes/ComfyUI-RvTools_v2/Keep Calculator
ComfyUI Node

Keep Calculator

How many new frames each pass actually adds

By r-vage·Created about a year ago·Updated 5 months ago· 23
Keep Calculator
    • frames_to_keep
    total_frames16
    context_length8
    overlap_frames4
    image_loop_count1

    Keep Calculator answers the question that Loop Calculator glosses over: of the frames a video pass produces, how many are actually new? In windowed video generation you re-generate a few frames at the start of every pass as overlap - the seam that keeps motion coherent - and only the frames past that overlap are new content worth keeping. This node computes that number so your loop can discard the right amount instead of guessing.

    It's designed as the partner to the pack's Loop Calculator in context-window video workflows (the same technique WAN-era windowed generation made standard: generate a chunk, keep the tail, feed it back, repeat). Loop Calculator tells you how many passes you need; Keep Calculator tells you how many frames to keep out of each pass. Together they turn the fiddly overlap math of long-video generation into two numbers you don't have to compute by hand.

    How it calculates

    The inputs map almost one-to-one onto the loop math:

    • total_frames (INT, default 16) - your target length.
    • context_length (INT, default 8) - frames per pass.
    • overlap_frames (INT, default 4) - frames re-generated as the seam.
    • image_loop_count (INT, default 1) - how many frames you already have committed (the loop iteration's current count).

    The code does: effective stride = context_length - overlap_frames (the new frames per pass), remaining = total_frames - image_loop_count (what's left), and frames_to_keep = min(stride, remaining). The min is the guard: on the final pass you don't keep more frames than are actually still needed. Output is frames_to_keep (INT), with a floor of 0 if things go wrong.

    Note this one takes image_loop_count as a plain integer rather than reading an images tensor - so you're feeding it the loop's counter directly, and it's the caller's job to keep that number in sync with reality.

    Installing it

    Part of ComfyUI-RvTools_v2:

    cd ComfyUI/custom_nodes
    git clone https://github.com/r-vage/ComfyUI-RvTools_v2
    

    Restart ComfyUI or install via ComfyUI Manager (search "RvTools"). No model downloads; dependencies are the standard torch/numpy/Pillow plus opencv-python, pilgram, pynvml, piexif.

    Gotchas

    The README says the pack is no longer maintained, superseded by ComfyUI_Eclipse (same author). Still works fine.

    Two watch-outs. The min-guard means if your image_loop_count already exceeds total_frames, you get 0 - the node assumes you're done, which is correct behavior but looks like a bug if you feed it a stale counter. And keep overlap_frames comfortably below context_length; if the stride comes out at or below zero the math gets weird fast, and you're generating more redundant overlap than new content anyway.

    Category🫦 RvTools II/ Video

    Inputs (4)

    NameTypeDefaultDescription
    total_framesINT161–10000
    context_lengthINT81–32
    overlap_framesINT40–32
    image_loop_countINT11–1000

    Outputs (1)

    NameTypeDescription
    frames_to_keepINT