WAN Frame Calculator
Round any frame count to WAN's n×4+1 pattern
- wan_frames
WAN doesn't accept arbitrary frame counts. Because its VAE compresses time by roughly 4x, only counts of the form 4n+1 - 1, 5, 9, 13, 17, 21, and so on - round-trip cleanly through encode and decode. Ask for anything else and it gets corrected somewhere in the pipeline whether you planned for it or not, which is exactly why people occasionally end up staring at a clip that came back a frame or two short of what they asked for. WAN Frame Calculator does that rounding on purpose, up front, instead of letting it happen implicitly downstream.
Why this constraint exists
It comes straight from how the Wan VAE handles time: N input frames become roughly ((N - 1) // 4) + 1 latents, and decoding those latents back out gives you (latents - 1) * 4 + 1 frames - which only equals your original N when N was already a valid 4n+1 number to begin with. Every other value gets silently reshaped by that arithmetic. This node just runs the correction in the direction you choose, before you commit to a generation.
The inputs and outputs that matter
frame_count(1–10000, default 1) - the frame count you actually want.rounding_mode-nearest,max, ormin.nearestsnaps to whichever valid 4n+1 value is closest, up or down.maxalways rounds up to the next valid value - use this when you need at least your target length and can't afford to come up short.minalways rounds down - use this when going over your target is the worse outcome, say a hard duration cap you can't exceed.
Output: wan_frames - the corrected, WAN-valid frame count, ready to wire straight into whatever length parameter your sampler or frame-count input expects.
How it fits with the rest of the pack
This is the simplest piece of a small cluster of frame-math nodes in this pack. WAN Frames to Add & Cut builds on the same constraint when you're adjusting an existing clip's length toward a target rather than picking a fresh count from scratch, and SCAIL Pose Frames applies the identical 4n+1 rule specifically to blank inpaint frame counts in a SCAIL loop.
How to install it
Search "Link Comfy Nodes" in ComfyUI Manager and install from there. Or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/Mister-Link/link-comfy-nodes
pip install -r link-comfy-nodes/requirements.txt
Restart ComfyUI. Pure integer math - no extra dependencies for this node specifically.
Common issues & troubleshooting
Skipping this node and hand-typing a frame count elsewhere. That's the actual failure mode in practice - a WAN run coming back a couple frames off from what you requested, or erroring outright, is usually this constraint biting you somewhere you didn't route through this node first.
Needing an exact count that isn't 4n+1-shaped. If you have a hard sync requirement to existing footage at a frame count that doesn't fit the pattern, remember that rounding is happening somewhere in the pipeline regardless of whether you use this node. Better to control where and how with min/max/nearest here than let WAN's own internals decide silently.
Picking nearest when you actually need a floor or ceiling. nearest is the right default for casual use, but if your workflow depends on never going under (or never going over) a specific length, switch to max or min explicitly rather than relying on nearest-rounding to happen to land the way you want.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| frame_count | INT | 11–10000 | — |
| rounding_mode | COMBO | nearest | 3 options: nearest, max, min |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| wan_frames | INT | — |