Wan Chunk Calculator ๐งฎ
Wan Chunk Calculator ๐งฎ โ the 4n+1 arithmetic, done for you
- total_frames
You want a 15-second Wan video. That's 241 frames at 16fps. But you don't generate 241 frames in one go - Wan's native context is 81 frames, so you generate chunks and stitch. Which means you need to know: how many 81-frame chunks does 241 frames actually take, and what total should you type into the sampler? This node is a two-input calculator that answers exactly that.
WanVideoChunkCalculator is the smallest node in the VideoChunkTools pack, and it's honest about it. It does one thing: figure out the total_frames that a given number of chunks produces, accounting for the one-frame overlap between chunks and Wan's 4n+1 frame-count rule.
Why this math is annoying
Here's the trap that's burned everyone who's done Wan chunking by hand. Chunk 2 doesn't add 81 new frames - its first frame duplicates chunk 1's last frame (that's the rolling-reference mechanism, where the next chunk conditions on the previous chunk's final frame). So each chunk after the first contributes chunk_frames โ 1 new frames. On top of that, Wan frames must be 4n+1 (5, 9, 13, ... 81, 85...), because the VAE compresses time ~4x and rounding works out to ((N-1)//4)*4+1. Get either wrong and your clip comes back the wrong length or the end behaves weirdly - a complaint the community has been filing about hand-rolled chunking since before single-node chunkers existed.
The inputs and output
num_chunks- how many chunks you want to generate.chunk_frames- frames per chunk. Auto-normalized to Wan's4n+1rule, so you can type 82 and it quietly uses 81 rather than exploding.
Output: a single total_frames INT, computed as chunk_frames + (num_chunks - 1) * (chunk_frames - 1) with the normalization applied. Wire that straight into the total_frames input of the WanChunkedI2VSampler from the same pack and the two nodes agree by construction.
Who should use it
If you drive the WanChunkedI2VSampler directly with a frame count in mind, you mostly don't need this node - the sampler figures out its own chunk count and trims the overshoot. But if you're building a workflow where you want to decide the number of chunks (say, one per per-chunk prompt you've chained in ChainTextEmbeds, or one per FLF keyframe), this is the node that tells you what total to request. It's also a nice teaching tool: run it with different values once and you'll finally internalize how chunk count and total frames relate.
Installing
cd ComfyUI/custom_nodes
git clone https://github.com/gregtee2/ComfyUI_VideoChunkTools.git
Or search "VideoChunkTools" in ComfyUI Manager, install, restart. Like all the core nodes, it's pure PyTorch arithmetic with no dependencies. Technically it's only "Wan-specific" in the sense that its defaults and the 4n+1 rule target Wan - the math is generally useful for any chunked video pipeline.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| num_chunks | INT | 11โ100 | Number of chunks you want to generate. |
| chunk_frames | INT | 815โ241 | Frames per chunk. Auto-normalized to Wan's 4n+1 rule. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| total_frames | INT | โ |