Optical Flow Re-Vector (MEC)
Re-vector one frame of a shot to another, mask-locked and fast
- frame_a
- frame_b
- mask
- re_vectored
- flow_rgb
- consistency
VFX people know this move by a different name. You've got a locked-off plate, someone walks through it, and you need to replace part of that person with clean background - but the background pixels behind them don't exist in that frame. The classic trick is to steal them from an earlier or later frame and warp them into place using motion. That's re-vectoring, and Optical Flow Re-Vector (MEC) is the ComfyUI version: give it two frames, it computes dense optical flow between them, and warps frame A into alignment with frame B.
Dense flow, mask-locked
The key word is "dense." This isn't tracking a few feature points; it computes a per-pixel flow field. The engine is RAFT (via the pack's bundled ProPainter bridge) when it's available, with a pure-torch Lucas-Kanade pyramid as the fallback when it isn't. Both ship inside the pack - no separate RAFT install needed for this node. Flow is then used to grid_sample frame A into a warped version that lines up with frame B.
Here's the design choice that makes it production-useful: re-vectoring is restricted to the mask. Pass an optional mask (white = where to apply) and only the masked region gets the warped pixels; everything outside stays pixel-identical to frame A. That's the difference between "I replaced the background behind the walker" and "I warped my entire frame like a bad Instagram filter." Without a mask, it warps the whole frame - which is genuinely useful for motion preview or as a building block, just know you asked for it.
The knobs that matter
The knobs that matter: iters (default 20) is RAFT's iteration count - more passes mean tighter flow, diminishing returns past ~20. consistency_thr (default 1.5, in pixels) sets the forward/backward flow consistency cutoff; pixels where forward flow disagrees with backward flow beyond that threshold get flagged in the consistency output as unreliable. scale (default 1.0) multiplies the flow vectors - for re-vectoring you usually want 1.0, but you can push it when warping farther than the flow naturally covers.
The outputs
Three outputs: re_vectored (the warped frame, masked), flow_rgb (a visualization packing u/v/magnitude into R/G/B - handy to eyeball what the flow actually found), and consistency (a MASK of reliable vs. unreliable regions, which is gold for debugging). Feed re_vectored into a compositing node or a KSampler's image input; wire consistency into a matte to protect areas where flow lies.
Where to use it, and install
Real-world use: plate cleanup, object removal where you can borrow background from an adjacent frame, and inpainting prep - a re-vectored frame is often a better starting point than a flat inpaint, because the pixels are already motion-correct. It pairs naturally with the pack's Plate Stabilizer and ProPainter suite (the flow-refine mode uses the same RAFT kernels).
Install is the pack: clone Code2Collapse/ComfyUI-CustomNodePacks into custom_nodes or ComfyUI Manager → "CustomNodePacks", restart, find it under MaskEditControl/VFX. Requires opencv-python and scipy. The honest gotcha: re-vectoring is only as good as your flow, and flow lies at occlusions, specular highlights, and fast motion - that's what consistency is for. And the author's rule, straight from the source: never blur to fake motion. If your result looks soft, you over-warped or your frames are too far apart, not under-blurred.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| frame_a | IMAGE | — | |
| frame_b | IMAGE | — | |
| iters | INT | 201–100 | — |
| consistency_thr | FLOAT | 1.500–20 | — |
| maskopt | MASK | — | |
| scaleopt | FLOAT | 1.00-4–4 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| re_vectored | IMAGE | — |
| flow_rgb | IMAGE | — |
| consistency | MASK | — |