ComfyUI Node

MatAnyone2

One mask in, a whole video's alpha out

By FuouM·Created about a year ago·Updated 6 months ago· 102
MatAnyone2
  • src_video
  • foreground_mask
  • foreground_MASK
  • solid_color
  • matte
  • green_screen
mask_frame0
n_warmup10
r_erode0
r_dilate0
max_internal_size-1
max_mem_frames5
use_long_termfalse

If you want to cut a person out of a video and keep the edges moving with the footage, this is the node you were looking for. MatAnyone2 is the newer, improved model in FuouM's pack, and it does something the per-image background removers can't: it takes a single mask you drew on one frame and propagates it through the whole clip, producing per-frame alpha that stays temporally consistent instead of shimmering like a frame-by-frame cutout. That distinction - matting with memory vs. re-segmenting every frame - is the whole point.

The model underneath is pq-yang's MatAnyone 2, "Scaling Video Matting via a Learned Quality Evaluator" (CVPR 2026), the sequel to the original MatAnyone (arXiv 2501.14677) whose weights made the rounds in early 2025. The first one earned genuinely good community reviews: people who tested it against SAM2 pointed out that SAM2's output is a hard matte that can't refine hair edges, while MatAnyone actually handles them. This node wraps the better version of that.

How it works

Consistent memory propagation. You feed it a video (an IMAGE batch) plus one annotated frame. There's a warmup phase - n_warmup iterations, default 10 - where the model turns your rough mask into its own first-frame alpha prediction. The README is upfront that "your input mask won't actually be in the final matte"; it's a seed, not the result. From there the alpha propagates through the clip while a rolling working memory of recent frames keeps it from drifting.

The inputs that matter

  • src_video - your clip as an IMAGE batch, typically from a Video Helper Suite Load Video node.
  • foreground_mask (IMAGE) or foreground_MASK (MASK) - the annotated frame. The IMAGE version auto-converts a black/white image to a mask; the MASK version is more direct. Feed at least one.
  • mask_frame - which frame that mask belongs to: 0 for first frame, or the last/middle index for backward or two-pass propagation.
  • n_warmup - warmup iterations before propagation.
  • r_erode / r_dilate - V2-only additions: morphological cleanup applied to your mask before it seeds the model. Bump them from 0 if your hand-drawn mask is noisy.
  • The memory trio: max_internal_size (-1 = full res; try 480 or 360 to save VRAM), max_mem_frames (how many frames stay in high-res working memory, default 5), use_long_term (compresses older frames into long-term prototype memory - flip it on for long videos).

Outputs are matte (the alpha, as a grayscale-looking RGB batch - the channel is repeated three times) and green_screen (foreground composited over a solid color). Feed either into a VHS Video Combine to save it.

Install

Install is genuinely light. Grab it through ComfyUI Manager by searching "ComfyUI-MatAnyone", or:

cd ComfyUI/custom_nodes
git clone https://github.com/FuouM/ComfyUI-MatAnyone

then restart. The pack depends on only torch and omegaconf - the model code is vendored in the repo - so no dependency hell here.

The one thing you must do by hand is the model file:

# matanyone2.pth from https://github.com/pq-yang/MatAnyone2
# → ComfyUI/custom_nodes/ComfyUI-MatAnyone/checkpoint/matanyone2.pth

Miss this and the node raises FileNotFoundError the moment it loads.

Where people get burned

The quality of the mask you draw on that one frame is everything - the model propagates it, so garbage in means garbage over the whole clip. Don't hand-rotoscope if you can avoid it; generate the first-frame mask with BiRefNet or SAM and feed that in. If it OOMs on a long or high-res clip, drop max_internal_size to 480 (or 360) before blaming the node, and turn on use_long_term for anything past a few hundred frames. Also worth knowing: the green_screen output stays empty unless you actually wire solid_color in - the pack's example workflow uses the bundled SolidColorBatched node (default green) for exactly that. And both this node and the original reload the checkpoint from disk on every run, so expect a pause before the progress bar fills - that's normal, not a hang.

If you're torn between this and the older MatAnyone node in the same pack, don't be. Same inputs, same outputs, and this is the model the README now leads with.

CategoryMatAnyone

Inputs (11)

NameTypeDefaultDescription
src_videoIMAGE
mask_frameINT0
n_warmupINT10
foreground_maskoptIMAGE
foreground_MASKoptMASK
solid_coloroptIMAGE
r_erodeoptINT0
r_dilateoptINT0
max_internal_sizeoptINT-1
max_mem_framesoptINT5
use_long_termoptBOOLEANfalse

Outputs (2)

NameTypeDescription
matteIMAGE
green_screenIMAGE