ComfyUI Node

AP Temporal Blend Latents

Kill the flicker without leaving latent space

By adampolczynski·Created 6 months ago·Updated 6 months ago· 1
AP Temporal Blend Latents
  • latent_1
  • latent_2
  • latent_3
  • latent_4
  • latent_5
  • mask
  • blended_latent
  • blend_mask
favor_previous_frame_when_fewfalse
blend_modesimilarity_weighted
recency_decay0.35
trim_ratio0.20
similarity_sigma0.1000
robust_delta0.0800
detail_preservation0.15

If you've generated video or done frame-by-frame inpainting in ComfyUI, you know the tell: every frame is great on its own, and the moment you play them back, the whole thing shimmers. That's temporal flicker, and it's the single most obvious sign a clip was generated per-frame. AP Temporal Blend Latents is one of the cleanest ways to knock it down, because it blends up to five latents together before the VAE decode - so you smooth history into the current frame without ever leaving latent space.

This is a node from Adam Polczynski's AP_OpticalFlow pack (he announced it on r/comfyui as a reaction to optical-flow nodes that were "outdated, incompatible with newer ComfyUI versions, or too limited"). Its natural home is inside the pack's recursive latent loop: AP Loop Open (Latent) gives you previous_processed_latent_1..N, you wire those into this node as the history, and the blended result feeds the next iteration. Because everything stays latent, you skip the VAE encode/decode round-trip on every loop pass - the pack's README calls that out explicitly, and it's the reason this node exists at all.

How the blend actually works

latent_1 is your current frame, and latent_2 through latent_5 are progressively older history. The node stacks them and reduces the stack with one of five modes:

  • similarity_weighted (default) - weights each history pixel by how similar it is to the current frame. This is the best default for flicker, because it only pulls in history where the content actually agrees.
  • weighted_mean - the stable, fast baseline.
  • median - strong outlier killer, great for sporadic artifacts.
  • trimmed_mean - robust to outliers but smoother than median.
  • robust_huber - adaptive weighting, useful in unstable inpaint regions.

Two knobs do most of the work. recency_decay (default 0.35) controls how fast older frames lose weight - higher means only the most recent history matters. detail_preservation (default 0.15) blends back in a percentage of the current frame so you don't wash out fresh detail; if the result looks soft, raise it.

The mask is the power move. Wire a mask in and blending only happens inside the masked region - outside it, the output stays the current frame. That's how you stabilize a face or a moving object without letting the background drift into mush. favor_previous_frame_when_few boosts the nearest history when you only have 2–3 latents, which keeps continuity when your window is small.

Outputs

blended_latent (LATENT) goes straight back into a KSampler or into AP Loop Close (Latent). blend_mask (MASK) shows where blending actually happened - handy for debugging why a region stayed untouched.

Install

In ComfyUI Manager, search "AP Optical Flow" (the pack title is ComfyUI_AP_OpticalFlow) and install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/adampolczynski/ComfyUI_AP_OpticalFlow
cd ComfyUI_AP_OpticalFlow
pip install -r requirements.txt

Then restart ComfyUI. There are no model files to fetch - the only dependency is torchvision>=0.15, and the RAFT weights download automatically on first use. The one real gotcha: this pack's blend nodes are pure torch math, so no RAFT needed here, but the pack as a whole requires a torch/torchvision pair where RAFT imports cleanly; a mismatch throws at node load.

Start with similarity_weighted, recency_decay around 0.35, and only crank detail_preservation up if output turns soft. Blend latents that differ wildly in content and you'll get ghosts - temporal blending assumes the frames are roughly aligned, which is exactly what the flow-warp nodes in this pack are for.

CategoryAP_OpticalFlow

Inputs (13)

NameTypeDefaultDescription
latent_1LATENT
favor_previous_frame_when_fewBOOLEANfalse
blend_modeCOMBOsimilarity_weighted5 options: weighted_mean, similarity_weighted, median, trimmed_mean, robust_huber
recency_decayFLOAT0.350–4
trim_ratioFLOAT0.200–0.49
similarity_sigmaFLOAT0.10000.0001–2
robust_deltaFLOAT0.08000.0001–2
detail_preservationFLOAT0.150–1
latent_2optLATENT
latent_3optLATENT
latent_4optLATENT
latent_5optLATENT
maskoptMASK

Outputs (2)

NameTypeDescription
blended_latentLATENT
blend_maskMASK