ComfyUI Node Runs on cloud

Mask Optical Flow (DragNUWA)

Restrict a motion field to a region for DragNUWA

By Fannovel16·Created 3 years ago·Updated 4 months ago· 4,134
Mask Optical Flow (DragNUWA)
  • optical_flow
  • mask
  • OPTICAL_FLOW
  • PREVIEW_IMAGE

This is a video-motion node, and a narrow one. Optical flow is a per-pixel map of how things move between frames - direction and speed of motion across the image. The pack's Unimatch preprocessor estimates that flow, mostly for DragNUWA-style motion-driven video generation. Mask Optical Flow does one thing to it: it masks the flow to a region. Where your mask is white, the motion is kept; everywhere else it's zeroed out. So you can say "only this part of the scene should move," which is exactly what you want when you're driving controllable motion and don't want the whole frame drifting.

How it works

The node takes an existing optical flow field and a mask, and multiplies them: the flow survives inside the masked region and gets suppressed outside it. The output is a new OPTICAL_FLOW - the region-limited motion field - that feeds into a DragNUWA / motion-conditioning pipeline, plus a PREVIEW_IMAGE so you can eyeball what the masked flow actually looks like before committing it. In practice this is how you isolate motion: estimate flow over the whole clip with Unimatch, paint a mask over the thing you want to animate, and let this node strip out all the incidental background motion so only your target moves.

The inputs and outputs

Two inputs, two outputs, no settings:

  • optical_flow (OPTICAL_FLOW) - the motion field, wired from the Unimatch optical flow preprocessor.
  • mask (MASK) - the region to keep. White = motion retained, black = motion zeroed. Standard ComfyUI mask, from a mask editor, a load-image alpha, or a segmentation step.

Outputs are OPTICAL_FLOW (the masked field, into your motion pipeline) and PREVIEW_IMAGE (an IMAGE visualization for sanity-checking).

Installing it

ComfyUI Manager: search ComfyUI's ControlNet Auxiliary Preprocessors, install, restart. Or manually:

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

Restart ComfyUI. No model download for this node - it's a masking operation. The upstream Unimatch flow estimator does need its own weights (the hr16/Unimatch gmflow checkpoints), which download on first use.

Where people get burned

Fair warning up front: this whole corner of the pack is legacy-ish and specialized. DragNUWA-style optical-flow motion control was an early approach to controllable video, and the modern video-control story has largely moved to VACE (Wan) and IC-LoRA adapters (LTX-2) - if you're just trying to make a video move, that's probably where you should be looking, not here. Within an optical-flow workflow, though, this node is straightforward: the only real gotcha is the mask. Get the masked region right, use the PREVIEW_IMAGE to confirm the flow is where you expect, and remember that zeroing flow means "hold still," so anything outside the mask stays put in the driven motion.

CategoryControlNet Preprocessors/Optical Flow

Inputs (2)

NameTypeDefaultDescription
optical_flowOPTICAL_FLOW
maskMASK

Outputs (2)

NameTypeDescription
OPTICAL_FLOWOPTICAL_FLOW
PREVIEW_IMAGEIMAGE