WAN Context Windows (Manual Custom)
Context windows for WAN models, with a yaw-driven reference prefix
- model
- window_reference_images
- vae
- background_images
- model
WAN-class video models have a native context of about 81 frames - roughly 5 seconds at 16fps. Everything longer has to be chunked: split the generation into overlapping windows, denoise each, and stitch. That arithmetic (81-frame windows, overlap, 4n+1 frame counts) is exactly the manual tax the community spent 2026 trying to remove. This node is this pack's answer for WanAnimate: a model wrapper that does the windowing for you, with two extras the stock chunkers don't have.
It wraps your MODEL and hands back a patched MODEL for the KSampler. Inside, it slices the latent's time dimension into overlapping windows according to a schedule, denoises each, and fuses the results with a weighting method. All context_length and context_overlap values are in pixel frames - the node converts to latent frames internally (every 4 pixel frames ≈ 1 latent frame), which is the single most common source of confusion.
The inputs that matter
- context_length (default 81) and context_overlap (default 30) - window size and overlap, pixel frames.
- context_schedule - how windows are placed:
standard_uniform(evenly spaced, no repeats) is the default pick for most work;looped_uniformiterates;standard_staticis a fixed stride;batchedis no-overlap quick batch processing. - fuse_method - how overlapping regions blend:
pyramid(center-weighted, the default and usually the best),flat,overlap-linear, orrelative. - freenoise - FreeNoise-style noise shuffling across windows; helps texture continuity when windows overlap little. Costs a bit of time.
- prefix_latent_num - the number of reference frames to prepend to every window. Set it to the count of your reference images; each encodes to one latent.
- causal_window_fix (default on) - the interesting one. In serial mode it prepends each window with the previous window's denoised last frame, so interaction details like footprints on the ground survive across windows. The cost is parallelism: windows run serially inside each denoising step.
The dynamic prefix (the part nothing else does)
Besides the static prefix above, this node can swap reference images per window based on yaw. Connect window_reference_images (from Reference Image Selector's raw_reference_images), latent_yaw_angles (from WanAnimateToVideoCustom's latent_yaw_angles), vae, and reference_angle_map - then each window picks the reference angle that best matches that segment's facing direction, so a turn-around gets the back-view reference instead of the front one. allow_switch_main governs whether the main reference can be swapped; background_images feeds the 1+4n tiling.
Common pitfalls
Everything here is in pixel frames except prefix_latent_num, which is in latent frames - don't multiply by 4 there. causal_window_fix on means serial execution; if you're wondering why a long generation is slow, this is why, and it's usually worth it. And the dynamic prefix silently doesn't activate unless you've connected all four inputs - the console prints a note when it's off, so check the log if your reference images aren't rotating.
Install
Part of ComfyUI-CustomNodeKit. ComfyUI Manager → search "ComfyUI-CustomNodeKit", or:
cd ComfyUI/custom_nodes
git clone https://github.com/user2318/ComfyUI-CustomNodeKit.git
cd ComfyUI-CustomNodeKit
pip install -r requirements.txt
Restart ComfyUI. No model files bundled.
Inputs (17)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | 要应用上下文窗口的模型。The model to apply context windows to during sampling. | |
| context_length | INT | 811–16384 | 上下文窗口的长度(不含像素帧)。The length of the context window (without prefix). |
| context_overlap | INT | 300–16384 | 上下文窗口的重叠长度。The overlap of the context window. |
| context_schedule | COMBO | 生成窗口的计划。The schedule for generating windows. | |
| context_stride | INT | 11–10 | 上下文窗口的步长;仅适用于 uniform 计划。The stride of the context window; only applicable to uniform schedules. |
| closed_loop | BOOLEAN | false | 是否闭合上下文窗口循环;仅适用于循环计划。Whether to close the context window loop; only applicable to looped schedules. |
| fuse_method | COMBO | pyramid | 融合上下文窗口的方法。The method to use to fuse the context windows. |
| freenoise | BOOLEAN | false | 是否应用 FreeNoise 噪声混洗,改善窗口融合。Whether to apply FreeNoise noise shuffling, improves window blending. |
| prefix_latent_num | INT | 00–16384 | 前缀参考帧的 latent 数量。接参考图选择器 raw_reference_images 的图片数量即可(每张图片编码为1个 latent)。这些帧会作为稳定参考拼接到每个窗口前。 |
| split_conds_to_windows | BOOLEAN | false | 是否根据区域索引将多个 conditioning 拆分到每个窗口。Whether to split multiple conditionings to each window based on region index. |
| causal_window_fix | BOOLEAN | true | 串行模式:在每个窗口前补上一窗口的denoised末帧,保留脚印等交互细节。会牺牲并行性(每次denoise step内窗口串行执行)。Serial mode: prepend the previous window's denoised last frame to each window, preserving interaction details like footprints. Sacrifices parallelism (windows execute serially within each denoise step). |
| window_reference_imagesopt | IMAGE | 原始参考图批次(来自 ReferenceImageSelector 的 raw_reference_images 输出),用于动态前缀。Raw reference image batch from ReferenceImageSelector's raw_reference_images output, used for dynamic prefix. | |
| latent_yaw_anglesopt | FLOAT | 下采样后的 latent 偏航角(来自 WanAnimateToVideoCustom 的 latent_yaw_angles 输出)。Downsampled latent yaw angles from WanAnimateToVideoCustom's latent_yaw_angles output. | |
| vaeopt | VAE | VAE 编码器,用于将参考图编码为 latent。VAE encoder for encoding reference images into latents. | |
| reference_angle_mapopt | STRING | 参考图角度映射 JSON(来自 ReferenceImageSelector 的 reference_angle_map 输出)。Reference image angle map JSON from ReferenceImageSelector's reference_angle_map output. | |
| allow_switch_mainopt | BOOLEAN | true | 动态前缀模式下是否允许更换主参考图。Whether to allow swapping the main reference image in dynamic prefix mode. |
| background_imagesopt | IMAGE | 可选的背景图,用于动态前缀的 1+4n 拼接。Optional background images for 1+4n concatenation in dynamic prefix. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| model | MODEL | — |