How to Fix AnimateDiff Flicker With Context Overlap
You cut flicker in AnimateDiff by raising the motion module’s context window and giving consecutive windows a healthy overlap, typically context_length=16 with context_overlap=4 for a 48-frame clip. Flicker is almost never a prompt problem, even though it looks like one.
AnimateDiff generates motion in chunks. The motion module was trained on 16-frame windows, so anything longer gets stitched. Stitching is where stability is won or lost.
Why does AnimateDiff flicker on clips longer than 16 frames?
Because each window is denoised with knowledge of only its own frames. Frame 15 and frame 16 see each other, but frame 16 and frame 17 do not share denoising context unless you force an overlap.
The visible symptom is a periodic pulse — a brightness or texture jump every N frames, where N equals your window length minus overlap. If the pulse comes every 16 frames, the overlap is zero.
Two other causes get blamed unfairly:
- Low CFG with high motion scale. Motion buckets amplify motion, and the model fills the gap with noise between windows.
- Batch size above 16 on a 16-frame window. Some ComfyUI nodes silently pad the batch, producing a duplicate window boundary.
Check the pulse interval first. It tells you more than any parameter sweep.
What do context_length, overlap and stride actually do?
The three settings form one equation:
context_length— how many frames the motion module sees at once. 16 is the trained value; 32 works on newer motion modules trained for it, at a real VRAM cost.context_overlap— how many frames are shared between adjacent windows. With 16/4, window two starts at frame 12.- stride — the advance between window starts, computed as
context_length - context_overlap. You rarely set it directly.
More overlap means smoother transitions and slower generation, because shared frames get denoised repeatedly. Going from 4 to 8 overlap on a 48-frame clip roughly doubles the second half of generation time and buys a visible smoothness gain. Going to 12 gives diminishing returns and risks the model over-committing to the overlap frames.
With 48 frames, context_length=16, overlap=4 gives 4 windows per pass. That is the reliable default.
Step 1: Set up a controlled test
Before changing settings, freeze everything else. Fix the seed, the prompt, the sampler (DPM++ 2M Karras at 20-25 steps is a solid baseline), and the resolution.
Then render the same 48-frame clip three times:
context_length=16, overlap=0(control)context_length=16, overlap=4context_length=32, overlap=8
Watch frames 14-18 and 30-34, the window boundaries. Do not watch the whole clip in motion — flicker hides in motion and shows plainly in single frames.
If setup 2 removes the pulse, stop. Most users do not need 32-frame contexts.
Step 2: Handle the tail frames
A 48-frame clip with 16/4 leaves a final window that starts at frame 36 and ends at 51, five frames past your clip. Most implementations pad with the last frame, which causes a subtle hold at the end.
Either set your frame count to fit the window maths (48 works; 47 does not) or trim the padded tail in your output node. A one-frame hold on loop playback is far more noticeable than a one-frame trim on a one-shot clip.
Frame counts that divide cleanly for 16/4: 28, 40, 52, 64. For 16/8: 24, 32, 40, 48, 56.
Step 3: Reduce motion scale before touching anything else
If the clip is still wobbly after overlap is fixed, drop motion scale (the motion_scale or motion_bucket_id depending on your node pack) by 20-30 points. High motion settings demand more from the model than the training data can supply, and you get texture instability rather than actual movement.
A practical ceiling: motion around 127 with CFG 7-8 on SD1.5-based checkpoints. Above 150 the output usually looks like sand.
What hardware do you need for stable clips?
Context length is a VRAM multiplier. At 512×512 with a 16-frame window, a 12GB card runs comfortably. A 32-frame window at 768×768 needs 16GB and above; on 8GB you are limited to 512×512 with 8-frame windows and an unavoidable fade.
Expect 2-4 minutes for a 48-frame clip at 512×512 on an RTX 3060 12GB, and roughly double that with overlap 8 and a 32-frame context. CPU-only rendering is not realistic — a single clip takes over an hour.
Who this applies to, and who should look elsewhere
This is for people running AnimateDiff locally through ComfyUI or the WebUI extension, with a working SD1.5 pipeline. If you have never rendered a clip, fix that first — overlap tuning is a second-order problem.
If your goal is character-consistent narrative video longer than a few seconds, AnimateDiff is the wrong tool. Newer video models handle 5-10 seconds with far better temporal coherence, and fighting window overlap on a 200-frame render is a losing battle.
A real drawback: documentation is thin and split across countless community nodes with different parameter names. context_overlap in one node is overlap in another, and one popular node silently clamps it to 25% of context length. Trust the render, not the label.
Quick Summary
- AnimateDiff flicker usually comes from zero overlap between 16-frame windows.
- Use
context_length=16withcontext_overlap=4for clips up to 64 frames. - The pulse interval equals context length minus overlap — a fast diagnostic.
- Choose frame counts that divide cleanly: 24, 32, 40, 48, 52, 56.
- Drop motion scale by 20-30 points before raising context length.
- 12GB VRAM handles 512×512 with 16-frame windows; 8GB is the practical floor.
