Nodes/Trent Nodes/MatAnyone Video Matte
ComfyUI Node

MatAnyone Video Matte

How MatAnyone2 Matte Cuts Your Clip

By TrentHunter82·Created 9 months ago·Updated 3 days ago· 39
MatAnyone Video Matte
  • images
  • mask
  • background_images
  • composite
  • alpha_matte
model_versionv2 (CVPR 2026)
mask_frame_index-1
n_warmup10
bg_colorgreen
edge_modeguided
edge_refine4
mask_expand0

This is the node the whole pack is named after. Every other node in MatAnyone2 Video Matting exists to feed this one a good first-frame mask; MatAnyoneMatte is what turns that single mask into a clean alpha channel for your entire clip. It's video matting with temporal propagation - the thing that makes it different from slapping a per-frame background remover on your footage.

The pitch for MatAnyone was always "stable" matting: SAM2 gives you a hard matte that can't refine hair edges and flickers between frames, while MatAnyone propagates memory across the clip so a person's flyaway strands and semi-transparent regions stay cut across the whole shot. The MatAnyone2 checkpoint ("self-evaluating, trained on millions of real-world frames", per the March 2026 release roundups) is what this pack defaults to. If you've ever done a rotoscoping pass by hand, you know why this is a big deal.

How it works

You feed it the MATANYONE_MODEL from the Model Loader, your frame batch, and a first_frame_mask. Internally it:

  1. Binarizes your mask against mask_threshold (0.5), optionally inverts it, then erodes and dilates it with an ellipse kernel - erode_kernel and dilate_kernel both default to 10, which scrubs the fuzzy edges off your SAM mask so the propagation starts clean.
  2. Steps the InferenceCore once on the first frame with your mask, then runs warmup_iterations extra passes (default 10) over that same frame to stabilize the memory before it moves on.
  3. Propagates frame by frame, outputting a float alpha per frame.

That last part is why a long clip costs you: every frame goes through the model. Which is exactly why you should slice your clip down first with MatAnyoneSliceFrames instead of feeding it your whole video and hoping.

The settings that matter

  • invert_mask - flip this if your mask is on the background and you want the subject cut instead.
  • erode_kernel / dilate_kernel - your first-frame mask is rarely perfect. A little erode kills the edge halo; 0 disables it.
  • max_internal_size (default -1) - caps the internal resolution MatAnyone works at. Leave at -1 for best quality; if you're on 8 GB, dropping this is the single biggest VRAM lever here, and the README says so.
  • warmup_iterations - more warmup = stabler first frames, slower start. 10 is a fine default.

Outputs

  • foreground - the subject as IMAGE (frames multiplied by alpha, so the background is black).
  • alpha - the float matte (MASK). Wire this to a Save Video (via VideoHelperSuite) for a transparency layer, or use it downstream for compositing.
  • preview - the foreground composited over a solid color (preview_red/green/blue, defaulting to a green-ish 120/255/155). Handy for eyeballing the cut without a checkerboard.

Installing and running it

Install the pack via ComfyUI Manager (search "MatAnyone2") or:

cd ComfyUI/custom_nodes
git clone https://github.com/dreamrec/MatAnyone2_ComfyUI.git
cd MatAnyone2_ComfyUI
python -m pip install -r requirements.txt
python install.py

Restart ComfyUI. The MatAnyone2 checkpoint auto-downloads to ComfyUI/models/matanyone/ on first use (it's ~a few GB, so first run takes a minute). Requirements are modest - hydra, huggingface_hub, opencv-headless - but the real cost is VRAM: 8 GB minimum, 12+ recommended.

Where people get burned

The classic failure is a half-good cut on the first frame producing a half-good whole video. Fix the first frame, not the output - that's the entire game. And if the cut goes fuzzy halfway through a long clip, it's usually memory pressure: lower max_internal_size, or slice the clip into shorter passes. Don't expect per-frame perfection on extreme cases like fast occlusion - MatAnyone is genuinely good at this, but "stable" doesn't mean "miracle."

CategoryTrent/Video

Inputs (10)

NameTypeDefaultDescription
imagesIMAGEInput video frames (image batch); MatAnyone propagates the mask across all frames with temporal consistency
model_versionCOMBOv2 (CVPR 2026)MatAnyone 2 (CVPR 2026) adds a learned quality evaluator for better fine detail and robustness; v1 is the original stable model
maskoptMASKInitial foreground mask for the reference frame; if not provided, BiRefNet auto-segments the best frame with person-aware filtering
mask_frame_indexoptINT-1-1–9999Reference frame for the mask; -1 = auto-select sharpest frame (recommended); 0+ = manual
n_warmupoptINT101–30Warmup iterations on the reference frame; builds initial memory. 10 is the paper default; more = slightly better but slower
bg_coloroptCOMBOgreenBackground color for composite; 'transparent' outputs RGBA with alpha channel embedded; 'none' skips compositing and returns original images
background_imagesoptIMAGEOptional custom background images; overrides bg_color when connected. Auto-resized to match input dims. A single image is broadcast to all frames
edge_modeoptCOMBOguided'guided' uses the RGB image to preserve hair and fine edges; 'feather' applies Gaussian blur (softer but loses detail)
edge_refineoptINT40–20Edge refinement radius; for guided mode preserves detail at edges; for feather mode blurs edges. 0 = no refinement
mask_expandoptINT0-20–20Grow or shrink the matte boundary; positive expands foreground, negative shrinks it

Outputs (2)

NameTypeDescription
compositeIMAGEForeground composited over the selected background color or custom background; RGBA (4-channel) when bg_color=transparent
alpha_matteMASKTemporally-consistent alpha matte from MatAnyone (white = foreground)