Nodes/ComfyUI-RvTools_v2/Loop Calculator
ComfyUI Node

Loop Calculator

The arithmetic behind context-window video generation

By r-vage·Created about a year ago·Updated 5 months ago· 23
Loop Calculator
  • images
  • total_loops
total_frames16
context_length8
overlap_frames4

Loop Calculator is a math node that tells you how many generation passes you need to produce a target-length video when your model can only see a limited number of frames at once. Feed it the total frame count you want, the model's context window, how many frames should overlap between passes, and the frames you've already generated - and it hands back the number of additional loops required.

If you've done video in ComfyUI with WAN or similar models, you know the pain this exists for. The model has a hard context limit (WAN 2.x, for example, works with windowed generation around its 3D causal VAE), and long videos don't fit in one pass. The standard technique is sliding-window generation: generate a chunk, keep the tail, feed it back as context, generate the next chunk. Getting the loop count right by hand is exactly the kind of arithmetic you get wrong at 2am - this node does it so your loop structure doesn't.

How it actually calculates

The code is short and worth understanding, because it tells you what the inputs mean:

  • total_frames (INT, default 16) - how many frames you ultimately want.
  • context_length (INT, default 8) - how many frames the model sees per pass.
  • overlap_frames (INT, default 4) - how many frames you deliberately re-generate as the seam between chunks (this is what keeps motion coherent).
  • images (IMAGE) - your current frames so far; the node reads the batch size from this to know how many you already have.

The math: it reads your current frame count off the images input, computes how many frames are still missing, then works out the effective stride (context_length - overlap_frames, floored at 1) - how many new frames each pass actually adds. Loops = ceil(remaining / stride), with a floor of at least 1 and a safe 1 if anything errors. That "reads the frame count from the images" bit is the clever part: the number self-corrects as you feed frames through the loop, so the calculator stays honest on later iterations.

Output is total_loops (INT) - wire it into your loop mechanism's repeat count.

Installing it

Ships in 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 stack plus opencv-python, pilgram, pynvml, piexif.

Gotchas

The pack's README marks it no longer maintained, superseded by ComfyUI_Eclipse (same author). The node still works.

Two things to remember. First, it's a calculator, not a loop driver - it outputs a number, you still have to build the loop that uses it. Second, the images input isn't decorative: if you don't wire in your current frames, the node assumes you have zero and over-reports the loop count. And if your overlap is set larger than your context, the stride clamps to 1, which means lots of tiny, mostly-redundant passes - keep overlap below context_length or you're burning time.

Category🫦 RvTools II/ Video

Inputs (4)

NameTypeDefaultDescription
total_framesINT161–10000
context_lengthINT81–32
overlap_framesINT40–32
imagesIMAGE

Outputs (1)

NameTypeDescription
total_loopsINT