PainterFrameMath
PainterFrameMath for Video Frame Counts
- aligned_frame
If you've ever typed 97 into a Wan sampler's length box because the model refused 96, you already know what this node does. PainterFrameMath takes any frame count and bumps it up to the next number that video models in the 4n+1 family will actually accept. It's a one-trick utility, and the trick is one you'll hit constantly once you start chaining clips.
The context matters. Video diffusion models like Wan run their frames through a temporal VAE that compresses time roughly 4x, so valid lengths aren't arbitrary - they're 4n+1. That's why every Wan workflow you download uses 81, 97, 121, or 161 frames instead of round numbers. Get it wrong and you either get a silent truncation (the Wan VAE turns 111 frames into 28 latents and decodes back to 109 - the well-documented "4n+1 trap" of hand-chaining chunks) or an outright error. This node exists so you stop doing that arithmetic by hand.
How it works
The math is four lines. It computes (frame_number - 1) % 4; if the remainder is zero the number is already valid and passes through unchanged, otherwise it adds 4 - remainder to round up to the next 4n+1. So 120→121, 122→125, 124→125, 125→125.
One honest correction to the README: it calls this "nearest," but it's ceil, not round. 120 doesn't go down to the equally-close 117 - it goes up to 121. That's usually what you want in video land (you're padding, not cropping), but if you were expecting true nearest-neighbor behavior, you'll be surprised exactly once. I was.
The one input and the one output
The whole graph is two pins:
- frame_number (INT) - forced input, meaning it's meant to be wired, not typed. Feed it the length of an image sequence, a video loader's frame count, or output from another math node.
- aligned_frame (INT) - the corrected count. Wire it into the
length/frame_countinput on your Wan-family sampler (orEmptyLatentVideo), and let the node fix the number for you.
Installing it
Plain and boring, in the good way. In ComfyUI Manager, search ComfyUI-PainterFrameCount and install; or:
cd ComfyUI/custom_nodes
git clone https://github.com/princepainter/ComfyUI-PainterFrameCount
Then restart ComfyUI. There's no requirements.txt, no models to download, no Python deps at all - it's a pure function using only the stdlib. This is the rare custom node that cannot break your environment, which given ComfyUI's notorious dependency hell is a feature worth naming. It shows up under the Prince category in the node menu.
Gotchas
None on the runtime side - there's nothing to fail. The two real traps are conceptual: remember it only rounds up (use it to pad, not shrink), and don't reach for it with LTX Video, which demands 8n+1 - a 4n+1 answer won't satisfy that constraint. For Wan and the 4x-temporal-VAE family, though, this is a small honest utility that quietly removes a whole class of "why is my video two frames short" bugs. You'll forget it's in your graph, and that's the point.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| frame_number | INT | 11–999999 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| aligned_frame | INT | — |