Nodes/ComfyUI_VideoChunkTools/Wan Chunk Calculator ๐Ÿงฎ
ComfyUI Node

Wan Chunk Calculator ๐Ÿงฎ

Wan Chunk Calculator ๐Ÿงฎ โ€” the 4n+1 arithmetic, done for you

By gregtee2ยทCreated 6 months agoยทUpdated 6 months agoยท 4
Wan Chunk Calculator ๐Ÿงฎ
    • total_frames
    โ—„num_chunks1โ–บ
    โ—„chunk_frames81โ–บ

    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's 4n+1 rule, 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.

    CategoryVideoChunkTools

    Inputs (2)

    NameTypeDefaultDescription
    num_chunksINT11โ€“100Number of chunks you want to generate.
    chunk_framesINT815โ€“241Frames per chunk. Auto-normalized to Wan's 4n+1 rule.

    Outputs (1)

    NameTypeDescription
    total_framesINTโ€”