Nodes/ComfyUI_MatAnyone_Kytra/MatAnyone Video Kytra
ComfyUI Node

MatAnyone Video Kytra

Clean video cutouts from one mask, not one per frame

By KytraScript·Created about a year ago·Updated about a year ago· 153
MatAnyone Video Kytra
  • video_frames
  • mask
  • foreground_frames
  • alpha_frames
warmup_frames10
erode_kernel10
dilate_kernel10
bg_red120
bg_green255
bg_blue155

Background removal on a single image is basically solved. Background removal on video is a different animal, because you can't just run a matting model frame by frame and call it done - the mask will flicker, hair will pop in and out, and edges will crawl around from one frame to the next even if each individual frame looks fine in isolation. MatAnyoneVideoMatting is Kytra's ComfyUI wrapper around MatAnyone, a video matting model built specifically to fix that: you give it one mask for the first frame, and it propagates a temporally consistent alpha matte across the whole clip.

Why this exists, and what it's actually doing

Every image-based cutout tool - rembg, BiRefNet, InSPyReNet - solves foreground-vs-background per image, with no memory of what came before. Run one of those on every frame of a video and you get independent guesses stitched together, and independent guesses disagree with each other on exactly the pixels that matter: flyaway hair, motion blur, semi-transparent edges. MatAnyone's pitch, per its paper title, is "consistent memory propagation" - it builds up a memory of the subject as it goes and uses that to keep the matte stable frame to frame instead of re-deciding from scratch every time. That's also why it outputs a real alpha matte rather than a hard foreground/background label, same distinction as BiRefNet's dedicated matting weights, just stretched across time instead of one still image.

The catch, and it's the one thing every early adopter of this node hit: the model is only as good as the mask you feed it for frame one. A Reddit poster who tried the Kytra implementation put it bluntly - "it's just clearly masking on the first frame problem to solve." Propagation is the easy part now; getting a clean seed mask is still on you.

The inputs and outputs that matter

  • video_frames (IMAGE) - your video as a batch of frames. Kytra's own example workflow loads it with VHS's Video Loader node (ComfyUI-VideoHelperSuite).
  • mask (MASK) - the first-frame alpha mask only. Solid white where your subject is, solid black everywhere else. The README's suggested shortcut is to auto-generate this with the Rembg+ Session nodes from ComfyUI Essentials rather than paint it by hand - good enough for a clean subject on a simple background, less good on tricky hair, per the same community feedback above.
  • warmup_frames (default 10, range 1–30) - warmup passes before real propagation starts, so the model's memory bank stabilizes on the first frame before it's trusted to carry forward. Leave at default unless the matte drifts in the first couple seconds, then bump it up.
  • erode_kernel / dilate_kernel (both default 10, range 0–50) - clean-up on your seed mask before it hits the model. Ragged edges from an automatic mask source: tighten these up. Already hand-painted clean? Dial both down - the defaults assume a rough mask.
  • bg_red, bg_green, bg_blue (0–255 each, default 120/255/155 - a mint-green tint) - flat background color for the composited preview output. Swap to black or white to eyeball matte quality; the green-ish default is a nod to chroma-key work.

Two outputs: foreground_frames (IMAGE) is your subject composited over the flat bg_red/green/blue color - handy for a quick look, not something you'd usually ship. alpha_frames (MASK) is the actual payload: the per-frame alpha matte, which is what you feed into an image-composite node alongside your original video to place the subject over any new background, or into further masking/inpainting work downstream.

How to install it

Through ComfyUI Manager: search "ComfyUI_MatAnyone_Kytra" (or just "MatAnyone"), install, restart.

Manually:

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

One thing worth knowing before your first run: the model weights aren't bundled with the repo. They're pulled automatically on first use from Mothersuperior/ComfyUI_MatAnyone_Kytra on HuggingFace and land in the pack's own model/ folder. That first run will pause while it downloads - don't panic if the queue looks stuck, and don't kill it mid-download.

Common issues & troubleshooting

The matte looks messy or the subject's edges wander. Check your first-frame mask before assuming the model's broken - this is the single most-reported gap with this node. Propagation itself holds up well once seeded, but a noisy or imprecise first mask (especially from an automatic tool on hair or fine detail) propagates its own mistakes across every frame that follows. Tighten the mask by hand around the trouble areas, or lean harder on erode_kernel/dilate_kernel to clean it up before it hits the model.

First run hangs or errors out. Almost always the weight download from HuggingFace stalling - check your connection, or grab the weights manually from the HF repo above and drop them into ComfyUI_MatAnyone_Kytra/model/ yourself.

Long clips get slow or heavy. Memory-propagation models like this one keep building on what they've already seen, so cost scales with clip length, not just resolution - plan around it if you're feeding it a full scene instead of a short clip.

Want the exact demo setup. The README's example workflow (in the repo's workflow directory) pairs this node with VHS's Video Loader and the Rembg+ Session nodes from ComfyUI Essentials for the first-frame mask - grab both packs to reproduce it exactly.

CategoryKytra-MatAnyone

Inputs (8)

NameTypeDefaultDescription
video_framesIMAGE
maskMASK
warmup_framesINT101–30
erode_kernelINT100–50
dilate_kernelINT100–50
bg_redINT1200–255
bg_greenINT2550–255
bg_blueINT1550–255

Outputs (2)

NameTypeDescription
foreground_framesIMAGE
alpha_framesMASK