Nodes/Wan22FirstLastFrameToVideoLatent for ComfyUI/Wan22FirstLastFrameToVideoLatent
ComfyUI Node

Wan22FirstLastFrameToVideoLatent

Wan 2.2 first/last-frame video, without swapping back to the old VAE

By stduhpf·Created about a year ago·Updated about a year ago· 38
Wan22FirstLastFrameToVideoLatent
  • vae
  • start_image
  • end_image
  • latent
width832
height480
length81
batch_size1

You've got Wan 2.2 5B loaded and you want the first-frame/last-frame trick - give the model a start and an end image and let it animate between them. Stock ComfyUI makes you pick a side: WanFirstLastFrameToVideo is built for the old Wan 2.1 VAE, and Wan22ImageToVideoLatent only takes a start frame. This node is the missing combo: start-frame, end-frame, or both, encoded into the Wan 2.2 latent space. That's the whole job, and it does it by being a near-copy of ComfyUI's own code (the author says so in the README - it's GPL 3.0 for that reason).

Why care about first/last-frame at all? Because it's the standard trick for getting clips that are longer and more coherent than a single I2V pass. You generate clip one, grab its last frame, and feed it back as clip two's start. Or you plant a start and end keyframe and let the model interpolate the middle, so all your keyframes stay one step removed from the source image instead of degrading chain by chain. Wan 2.2 handles both cases on the 5B model without breaking a sweat - this node just exposes them.

How it works

The mechanism is straightforward once you see it. The node builds an empty latent tensor in Wan 2.2's format - 48 channels, spatial downsampled 16x, temporal downsampled 4x, so length 81 becomes ((81-1)//4)+1 = 21 latent frames. Then:

  • start_image gets VAE-encoded into the front latent frames.
  • end_image gets VAE-encoded into the back latent frames.
  • Everything else stays zeros, and a noise_mask is set so the sampled frames stay fixed - the sampler only denoises the middle.

The output is a single latent (with an embedded noise_mask) that wires straight into your KSampler, which is why the node lives under conditioning/video_models. Give it no images at all and you get a plain empty latent, i.e. text-to-video.

The inputs that matter

  • vae - must be the Wan 2.2 VAE, not the 2.1 one. The 5B model uses the new Wan 2.2 VAE; the A14B still uses the old 2.1. Get this wrong and you'll wonder why your output is static noise.
  • start_image / end_image - both optional. One frame, both, or neither. A single start frame makes it functionally identical to Wan22ImageToVideoLatent.
  • length - default 81 (about 5 seconds at 16fps). The step is 4, but keep it at 4n+1 (49, 81, 121…). Anything else and the latent frame count won't round-trip through the VAE, which is where the classic "VAE dimension mismatch" error comes from.
  • width / height - step 16, defaults 832x480. Your images get resized to this, so a mismatch here just means a re-crop, not an error.

Installing

ComfyUI Manager: search "Wan22FirstLastFrameToVideoLatent" and hit install. Or the manual way:

cd ComfyUI/custom_nodes
git clone https://github.com/stduhpf/ComfyUI--Wan22FirstLastFrameToVideoLatent

Restart ComfyUI and you're done. There's no requirements.txt and no extra model to download - it leans entirely on ComfyUI's own VAE encode, which is the nice thing about this pack: it's a thin, dependency-free wrapper.

Where people get burned

The end frame is a keyframe, not a suggestion. If your start and end images are totally different scenes, Wan will do something heroic and usually wrong - keep the composition in the same ballpark, and follow the standard Wan rule of describing only the motion in the i2v prompt, not re-describing the still. And know that the Wan 2.2 VAE itself is memory-hungry; if the encode step OOMs (yes, people have hit this even on a 5090), grab the Tiled VAE variant from the same pack instead - same inputs, far less VRAM.

Categoryconditioning/video_models

Inputs (7)

NameTypeDefaultDescription
vaeVAE
widthINT83216–16384
heightINT48016–16384
lengthINT811–16384
batch_sizeINT11–4096
start_imageoptIMAGE
end_imageoptIMAGE

Outputs (1)

NameTypeDescription
latentLATENT