Nodes/Comfyui-WanVideo-Context/WanVideo Context Selector
ComfyUI Node

WanVideo Context Selector

Stop your long Wan videos from forgetting everything five seconds ago

By Long-form-AI-video-generation·Created 7 months ago·Updated 7 months ago· 3
WanVideo Context Selector
  • images
  • clip_vision
  • text_encoder
  • context_images
selection_modecontiguous
context_size16
current_prompt
contiguous_size4
text_weight0.00
diversity_radius16
similarity_threshold0.00

Wan's native context is short - 81 frames, roughly five seconds at 16fps. Everything longer is chunking: sample a window, decode it, feed the tail back in as the next window's start. That's the sliding-window trick behind nearly every long-form Wan workflow, and it has a dirty secret: it drifts. Keep only the last N frames and the model forgets everything before them, so faces subtly reshape, the room redecorates itself, and five minutes of history might as well never have happened.

WanVideoContextSelector is a smarter replacement for the GetImageRangeFromBatch sitting inside that loop. It's the one node in the jajos12/Comfyui-WanVideo-Context pack, and it ships in two flavors. (Not to be confused with Kijai's "WanVideo Context Options" in WanVideoWrapper - that sets the wrapper's sliding-window parameters; this is a standalone selector.)

Two modes, one drop-in replacement

selection_mode: contiguous is exactly the sliding window: return the last context_size frames of whatever you feed into images. No models, no cost, nothing clever. Swap it in where GetImageRangeFromBatch used to be and you should get the same behavior with less fiddling - a genuinely safe first move.

selection_mode: moc is the "Mixture of Contexts" pitch, and it's the interesting half. It splits your context_size budget into a motion buffer and a semantic memory. The motion buffer (contiguous_size, default 4) always keeps the newest frames so motion doesn't jump-cut. The remaining slots get filled by retrieving the most relevant frames from your whole generation history - relevance being cosine similarity between your CLIP Vision embeddings of each past frame and the latest one. A soft-NMS pass (diversity_radius, default 16) penalizes neighbors inside that window so you pull frame 100, 350, and 800 instead of 100, 101, 102.

The inputs that actually matter

Required: images (your accumulated history buffer) and context_size (total frames out, default 16). Then:

  • clip_vision - the dealbreaker. In moc mode this is effectively required; wire the Wan CLIP vision you already load for I2V. Leave it empty and the node silently falls back to plain history[-context_size:]. Moc without a vision model is contiguous with extra steps.
  • text_encoder + current_prompt - "Director Mode" steering. Push text_weight above 0 and a prompt like "a dark cave" biases retrieval toward matching frames. Catch: the text encoder's pooled embedding has to line up with the vision embedding's dimension, or the node prints a dimension-mismatch warning and disables text steering. Graceful, but the fiddliest input here.
  • similarity_threshold - a quality gate that skips frames scoring below it. Default 0 means "accept anything," so it only bites if you raise it.

One output: context_images, an IMAGE with distant frames first and the recent block last - so the newest frames are always at the tail, which is exactly what your I2V anchor wants.

Install

Via ComfyUI Manager (search "Comfyui-WanVideo-Context"), or:

cd ComfyUI/custom_nodes
git clone https://github.com/jajos12/Comfyui-WanVideo-Context

Restart ComfyUI. That's it - requirements.txt is a single line (torch>=2.0.0), no model downloads, no SageAttention drama. You still need a Wan CLIP vision (and optionally the Wan text encoder) loaded, but you already have those if you run Wan at all.

Where people get burned

The README's own clone command has a placeholder URL (your-repo) - copy it and you clone nothing, so use the one above. Bigger caveat: this is a young pack, essentially a single-commit project with zero community footprint at the time of writing, so treat moc as experimental. Get your loop stable in contiguous mode first, then flip the switch and A/B a couple of clips. And if [WanVideo Context] lines start showing up in the console, that's the node telling you it fell back to something simpler - read them before you blame your sampler.

CategoryWanVideo/Context

Inputs (10)

NameTypeDefaultDescription
imagesIMAGE
selection_modeCOMBOcontiguous2 options: contiguous, moc
context_sizeINT161–128
clip_visionoptCLIP_VISION
text_encoderoptWANTEXTENCODER
current_promptoptSTRING
contiguous_sizeoptINT40–32Recent frames to always preserve
text_weightoptFLOAT0.000–10=Visual Only, 1=prompt Only
diversity_radiusoptINT160–128Suppression window to prevent clumping (Soft-NMS)
similarity_thresholdoptFLOAT0.00-1–1Minimum score to include a frame

Outputs (1)

NameTypeDescription
context_imagesIMAGE