Fix Wan 2.2 (4n+1) and LTX-2 (8n+1) Frame Mismatches
RuntimeError: The size of tensor a (34) must match the size of tensor b (33) | Latent temporal stride mismatch / clipped final frames Local ComfyUI video generation crashes inside KSampler or VAEDecode with a PyTorch tensor shape mismatch error, or exports weirdly shortened/stuttering trailing frames right after changing duration or switching to 1920×1080.
3D spatiotemporal video VAEs compress frames and pixels in rigid mathematical strides: Alibaba Wan 2.2 requires frame counts satisfying 4n+1 (e.g., 49, 81, 121) and spatial dimensions divisible by 16/32, while Lightricks LTX-2 strictly requires 8n+1 frames (97, 121, 169) and spatial dimensions divisible by 32—and 1080 does NOT divide evenly by 32.
Copy-Paste Verified Fix
=== ALIBABA WAN 2.2 (Formula: 4n + 1 frames | Spatial: /16 & /32 safe) ===
- 3.0s @ 16 fps -> 49 frames (4*12 + 1)
- 5.0s @ 16 fps -> 81 frames (4*20 + 1) [RECOMMENDED STUDIO DEFAULT]
- 5.0s @ 24 fps -> 121 frames (4*30 + 1)
- Safe 16:9 Canvas: 1280x704 or 1344x768 (NEVER 1920x1080 raw into 720p latent)
- Safe 9:16 Canvas: 704x1280 or 768x1344
=== LIGHTRICKS LTX-2 (Formula: 8n + 1 frames | Spatial: strictly /32) ===
- 4.0s @ 24 fps -> 97 frames (8*12 + 1)
- 5.0s @ 24 fps -> 121 frames (8*15 + 1) [RECOMMENDED AUDIO+VIDEO DEFAULT]
- 7.0s @ 24 fps -> 169 frames (8*21 + 1)
- Safe 16:9 Canvas: 1280x704 or 1344x768 (1080 is NOT divisible by 32!)
=== POST-GENERATION 1080p SCALE (AFTER CLEAN BASE RENDER) ===
ffmpeg -y -i wan_1280x704.mp4 -vf "scale=1920:1080:flags=lanczos,noise=alls=4:allf=t+u" -c:v libx264 -crf 18 -pix_fmt yuv420p final_1080p.mp4 Before vs. After (Broken Pattern vs. Verified Fix)
"width": 1920, "height": 1080, "length": 80 // 1080/32=33.75 (CRASH!) | (80-1)/4=19.75 (INVALID!) "width": 1280, "height": 704, "length": 81 // Wan 2.2: 1280/32=40, 704/32=22, 4*20+1=81 (5.06s @ 16fps)
"width": 1280, "height": 704, "length": 121 // LTX-2 & Wan 2.2: 8*15+1=121 (5.04s @ 24fps) Why this works: Snapping both width and height to multiples of 32 and locking length to 81 (Wan) or 121 (both Wan and LTX-2) eliminates every spatiotemporal tensor shape crash permanently.
Why This Failure Happens in Real Pipelines
Image models only compress 2D height and width (usually ÷8 or ÷16), so creators naturally assume a 1920×1080 image and "80 frames for 5 seconds at 16 fps" will work in video diffusion. In reality, 3D video VAEs treat frame 0 as a standalone keyframe anchor and compress every subsequent group of 4 frames (Wan 2.2) or 8 frames (LTX-2) into one temporal latent slice—forcing total frame counts to obey 4n + 1 or 8n + 1.
Spatial height 1080 is the second silent trap: 1080 ÷ 32 = 33.75 (non-integer!). Feeding a raw 1920×1080 opening PNG into a /32 video latent either crashes immediately with a mismatched tensor size (34 vs 33) or silently crops the bottom edge, introducing edge shimmer. Always generate opening keyframes at /32-clean dimensions (1280×704 or 1344×768 for 16:9; 704×1280 for 9:16), lock frame length to 81 or 121, and perform final 1080p scaling during FFmpeg conform.
Step-by-Step Resolution & Verification
- 01
Replace 1920×1080 inputs with divisible-by-32 opening keyframes
Resize or generate opening PNG plates at 1280×704 (16:9) or 704×1280 (9:16) so width and height divide evenly by 32 with zero cropping distortion.
- 02
Lock exact 4n+1 (Wan 2.2) or 8n+1 (LTX-2) frame lengths
Use 81 frames for Wan 2.2 5s (16fps) and 121 frames for LTX-2 5s (24fps). Notice 121 satisfies both 4n+1 and 8n+1 simultaneously.
- 03
Upscale base 704p video to 1920×1080 cleanly in post-production
Use Lanczos scaling plus light temporal grain in FFmpeg (Workflow 14) after diffusion finishes—saving ~55% VRAM and avoiding latent artifacts.
python3 -c 'w,h,f=1280,704,121; print("div32:", w%32==0 and h%32==0, "| wan 4n+1:", (f-1)%4==0, "| ltx 8n+1:", (f-1)%8==0)' div32: True | wan 4n+1: True | ltx 8n+1: True How to Prevent This Error From Recurring
Generate opening FLUX/Qwen stills directly at 1280×704 or 704×1280
Matching your opening still aspect ratio exactly to your video latent prevents aspect-ratio warping on frame 1.
Bookmark 121 frames as your universal 5-second 24fps preset
Because 120 divides cleanly by both 4 and 8, 121 frames never crashes either Wan 2.2 or LTX-2 graphs.
Validate custom aspect ratios with our DPI & ComfyUI Calculator
Check any non-standard canvas in /tools/print-dpi-calculator before queuing long overnight ComfyUI batches.
Troubleshooting FAQs
- Why does 121 frames work cleanly on both Wan 2.2 and LTX-2?
- Because 120 is divisible by both 4 (30x4) and 8 (15x8), adding 1 gives 121 frames—satisfying both 4n+1 and 8n+1 temporal VAE strides simultaneously.
- Should I upscale 1280x704 Wan 2.2 output to 1920x1080 inside ComfyUI or FFmpeg?
- Render the clean base motion at 1280x704 first so diffusion stays stable and VRAM stays low, then upscale to 1920x1080 via Lanczos + subtle 35mm grain during final conform (Workflow 14).
- Does 1280×704 look noticeably stretched when scaled to 1920×1080?
- 704p is 1.818:1 vs 16:9 (1.778:1)—a tiny 2% variance. Center-cropping 14 pixels on each side before Lanczos scaling (or rendering at 1344×768) preserves exact 1.778 geometry with zero visible distortion.
- What happens if I set Wan 2.2 frame length to 80 instead of 81?
- ComfyUI either throws a tensor shape mismatch inside KSampler/VAEDecode or silently truncates/pads the temporal slice down to 77 frames, shortening your expected clip timing.