Wan Video Frames Padding
Why 121 frames silently becomes 121 and 122 doesn't
- image
- mask
- image
- mask
- width
- height
- length
- input_length
Wan is a diffusion transformer with a very specific appetite: it wants its frame counts in 4*n + 1 shape. 81, 121, 161 - fine. 83 or 122 - it doesn't care how close you think you are, that's a broken run or a mysterious error. This node is the fixer: give it a batch of frames, and it pads to the next valid count by repeating the last frame.
That's the entire job, and it's a real one. Any Wan workflow that sources frames from outside - an input video with an odd length, a frame sequence you built yourself, a face-swap or interpolation pipeline that spits out arbitrary counts - will eventually hit this wall. The standard solution in the wild is a hand-rolled pad node or a "round to multiple" hack; this one is purpose-built and comes with the rest of the Turing Utils pack.
How it works
The mechanism is the least glamorous thing in this pack: copy the final frame N times and append. The node's own _ceil_wan_frame_count rounds frame_count up to the next 4*n+1. If you give it an explicit target_frame_count instead, it pads exactly to that - but only if that count is itself 4*n+1, and only if it isn't shorter than the input. This node pads; it never trims. Trim upstream if your video is too long.
The inputs that matter
- image - the
IMAGEbatch[frames, height, width, channels]. - target_frame_count -
0(default) means "round me up to the next valid count." Set a specific number if you need an exact length. - mask (optional) - padded with the same repeated last frame, so a mask tracks the video frame-for-frame.
Outputs: image, mask, plus width, height, length (the padded output length), and input_length (what went in) - the last two are handy for wiring into a text or logging node to see how much padding actually happened.
How to install
It ships with ComfyUI Turing Utils ("comfyui-svdint4" in Manager):
cd ComfyUI/custom_nodes
git clone https://github.com/wjie98/comfyui-svdint4
cd comfyui-svdint4
python -m pip install -v --no-build-isolation -e ./kernel
The kernel build step is manual for the pack as a whole, though this particular node is pure tensor logic - it works even if you've only installed the Python side. Restart ComfyUI either way.
The honest take
The repeat-last-frame trick is the community-standard way to pad video for Wan, and it's the right call for short gaps: one or two repeated frames are invisible to the model. It stops being invisible if you're padding dozens of frames, so don't use this node to stretch a 30-frame clip to 81 and expect magic - at that point the repeated frames become a frozen tail the model has to reconcile. For the "my input is 79 frames, Wan wants 81" problem, it's the one you reach for, and it's over in seconds.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| target_frame_count | INT | 00–16385 | Target real-frame count. Use 0 to round the input length up to the next 4*n+1 frame count. |
| maskopt | MASK | — |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| width | INT | — |
| height | INT | — |
| length | INT | — |
| input_length | INT | — |