Wan VAE Encode
Getting images into Wan's 5D latent without shape gymnastics
- vae
- images
- latent
WASWANVAEEncode exists to solve one fiddly, boring problem that will otherwise eat an hour of your life: getting pixels into the exact [B,C,F,H,W] latent layout Wan expects. ComfyUI's stock VAE Encode hands you a 4D tensor, but Wan video models want the frame dimension spelled out explicitly - and whether your batch of images should become a batch of separate images or a sequence of video frames is a decision the stock node just dumps on you. This node makes the choice explicit and returns latents that actually match what the rest of the WAS Affine pack and Wan samplers expect.
It's the encode half of the pair that includes WASWANVAEDecode, and it's what you'd use to img2vid, to re-encode an existing clip for a second latent-space pass, or to feed the Ultimate Affine KSampler [Latent] path with something other than a raw generated latent. The README's Wan workflow - WAN example video linked right at the top - starts with getting frames into latent space correctly, and this is the node that does it.
How it works
Three inputs, and only one of them is interesting:
vae- the Wan VAE. Must match the model that will consume the latent.images- a[N,H,W,C]IMAGE tensor, where N is either a batch of images or a sequence of frames.batch_mode- the whole point of the node.imagestreats each of the N entries as a separate image and encodes to[B=N, C, F=1, H, W](each its own single-frame latent, stacked on the batch axis).framestreats the N entries as video frames and produces[B=1, C, F=N, H, W]- one latent whose frame axis is the whole clip.
The distinction matters more than it looks. Get it wrong and your "batch of 8 images" becomes "one 8-frame video latent" or vice versa, and the sampler either ignores half your batch or animates across images that were never meant to be frames. The node even handles the internal shape bookkeeping: it encodes per-image when needed and unsqueezes/permutes the result until it's the correct 5D [B,C,F,H,W] tensor, with a helpful console log of the final shape so you can verify what you got.
The output
A LATENT dict with samples shaped [B,C,F,H,W] - feed it straight into Wan samplers, or into WASUltimateCustomAdvancedAffineNoUpscaleLatent if your goal is an affine-tuned latent-space pass before decode. It's the natural front end for the pack's tiled-upscale-on-video path: frames in, Wan-compatible latent out, upscale and affine in latent space, then decode with WASWANVAEDecode.
Installing it
Part of WAS Affine (WASasquatch/was_affine). Manager: search "WAS Affine", install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/was_affine.git
No model downloads; deps are torch/numpy (plus matplotlib in requirements.txt). No UltimateSDUpscale requirement.
Where people get burned
- Wrong
batch_mode. If your video looks like it's sampling across unrelated stills, you built a batch of images instead of a frame sequence. Setframes. - Frame count / compression mismatch. Wan's VAE compresses 4x in time, so clip lengths that don't play nice with that can trip up downstream nodes - this encode node won't fix a clip length the model can't digest.
- VAE mismatch. Encode with Wan 2.2's VAE and decode with a 2.1 one and you'll chase color artifacts that are actually a VAE identity problem, not a node problem.
It's a small node, but it's the one that keeps the whole Wan side of this pack honest - shape correctness is 90% of getting video latents to behave.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| vae | VAE | VAE used to encode the images. | |
| images | IMAGE | Input images in ComfyUI format [N, H, W, C]. N can be a batch of images or frames. | |
| batch_mode | COMBO | images | images: treat N as separate image batches [B=N, F=1]. frames: treat N as video frames [B=1, F=N]. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| latent | LATENT | — |