Nodes/ComfyUI_CineStyle/CS MatAnyone2
ComfyUI Node

CS MatAnyone2

From Janky Hard Mask to Hair-Detail Alpha

By chflame163·Created 21 days ago·Updated about 17 hours ago· 64
CS MatAnyone2
  • image
  • mask
  • MASK
  • info
max_megapixels2.1
anchor_frames0
anchor_min_spacing48
anchor_hysteresis3
anchor_limit12
overlap12
analysis_stride1
anchor_sensitivity0.35
mask_threshold0.50
seed_morphology0
warmup10
memory_interval5
memory_frames5
use_long_termfalse
deviceauto
model_filematanyone2.pth
auto_unload_modeltrue
wait_for_input_cachefalse

Run any SAM3.1 or SeC-4B segmenter over a person and you get a hard binary mask: sharp, mostly right, and useless at the edges. Hair strands get sheared off, flyaways vanish, and the moment you composite onto a new background you get that construction-paper halo. CS MatAnyone2 exists to fix exactly that. You feed it your video frames plus the coarse per-frame mask from a segmenter, and it returns a soft floating-point alpha matte - fractional, hair-level transparency - using MatAnyone2, the video matting model from pq-yang that made the rounds in early 2026 for being the first thing that beat SAM2's hard masks at real edges.

The mental model that matters: segmentation tells you where the person is; matting tells you, pixel by pixel, how much of that pixel is actually them. The whole background-removal crowd has been leaning on this distinction for years (BiRefNet-matting weights exist for the still-image version of the same idea). This node is the temporal, video-wide version - one subject or one union foreground, propagated across a whole clip.

How it actually works

Under the hood it's a layer of engineering on top of MatAnyone2's official checkpoint, and the engineering is the interesting part. A single matting pass drifts - the subject turns, the camera moves, occlusion happens - so the node lets you pin anchor frames: frames where your coarse mask is trustworthy. It cuts the clip into windows around each anchor and propagates both directions from every one (backward by running the video flipped), then blends overlapping windows with distance-weighted cosine seams so you never see a stitch line. The anchor mask itself gets thresholded and, if you like, eroded or dilated into a clean seed before propagation.

That's why so many of the inputs exist. anchor_frames defaults to 0 - one anchor, the lazy path that works for short, stable clips. Add more for anything long or cutty. Honestly, the only knobs a beginner should touch are these:

  • anchor_frames - JSON or comma-separated local frame numbers ([0,48,96]). Out-of-range values get clamped instead of erroring, which is friendly.
  • Max inference size (MPixels) - defaults to 2.1, i.e. about 1080p. Above it, the clip is downscaled for inference and restored afterward. This is your main VRAM/time dial.
  • wait for input cache - explained below, and it matters more than it looks.

anchor_min_spacing, anchor_hysteresis, and anchor_limit only steer the automatic anchor candidate analysis in the preview window - they don't reject frames you type in yourself. The Memory interval/Memory frames and Use long-term memory toggles are MatAnyone2's working-memory settings; enable long-term memory for long or fast-changing shots and pay for it in VRAM. Outputs are mask (the full alpha matte, same frame count and size as your input) and an info dict with frame count, inference size, anchors, and timing - handy for a log.

Getting it installed

Same drill as the rest of the pack. ComfyUI Manager, search ComfyUI_CineStyle, install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/chflame163/ComfyUI_CineStyle.git

Restart ComfyUI and find it under Add Node → 😺dzNodes/CineStyle/Video. First run downloads matanyone2.pth into ComfyUI/models/matanyone/ from the official MatAnyone2 release and checks its MD5 - it needs GitHub access, so if you're fully offline, grab the checkpoint manually and drop it there. Note the license: MatAnyone2 ships under the NTU S-Lab License 1.0, which is not the pack's MIT. Read it before anything commercial.

The trap people hit: the preview dance

Here's where beginners get stuck. If your frames come straight from a CS Load Video or a segmenter node, fine. But if the mask and video only exist after an upstream node runs (say, a segmenter downstream of generated frames), the Matte Preview editor has nothing to show you yet. Set wait for input cache to true and run once - the node caches its inputs, then halts execution. Open Matte Preview, scrub the timeline, add or remove anchors on real frames, hit Apply, switch wait for input cache back off, and run again. Two other gotchas worth knowing: if an anchor frame's mask comes up empty after thresholding, the node refuses to run (pick another anchor or nudge mask_threshold/seed_morphology), and if your mask batch doesn't match the frame count or size it'll warn and silently resize rather than abort. For a single-frame mask from a one-shot segmenter, skip the preview entirely - just put that frame's number in anchor_frames and let it propagate from there.

Category😺dzNodes/CineStyle/Video

Inputs (20)

NameTypeDefaultDescription
imageIMAGEVideo frames as a ComfyUI IMAGE batch.
maskMASKMatched per-frame coarse masks from SAM3 or another segmenter.
max_megapixelsFLOAT2.10.1–64
anchor_framesSTRING0JSON list or comma-separated local frame numbers.
anchor_min_spacingINT481–100000
anchor_hysteresisINT31–1000
anchor_limitINT121–128
overlapINT120–10000
analysis_strideINT11–120
anchor_sensitivityFLOAT0.350–1
mask_thresholdFLOAT0.500–1
seed_morphologyINT0-64–64Negative erodes; positive dilates anchor masks.
warmupINT101–50
memory_intervalINT51–100
memory_framesINT52–50
use_long_termBOOLEANfalse
deviceCOMBOauto2 options: auto, cpu
model_fileCOMBOmatanyone2.pth1 options: matanyone2.pth
auto_unload_modelBOOLEANtrue
wait_for_input_cacheBOOLEANfalse

Outputs (2)

NameTypeDescription
MASKMASK
infoDICT