Nodes/ComfyUI-Video-Matting/Robust Video Matting
ComfyUI Node Runs on cloud

Robust Video Matting

Clean cutouts frame after frame

By Fannovel16·Created 3 years ago·Updated 2 years ago· 227
Robust Video Matting
  • video_frames
  • IMAGE
  • MASK
backboneresnet50
fp16true
bg_colorgreen
batch_size4

The hard part of cutting a person out of video was never getting a mask. Run any per-frame background remover across your footage and each individual frame looks great. Then you play it back and the subject shimmers like a cheap green-screen composite from 2005, because every frame's hairline is a slightly different guess. Robust Video Matting exists to kill that flicker, and this node drops it into ComfyUI with two small model downloads and no training required.

RVM is PeterL1n's real-time video matting model - the one that quietly powers background replacement in a bunch of consumer video tools. This node is a minimal wrapper around it from Fannovel16, who you may already trust from ComfyUI-VideoHelperSuite and comfyui_controlnet_aux. It takes your frames, hands them to RVM, and gives you back a composited cutout plus a mask.

How it works

The interesting bit is the recurrence. RVM isn't a per-frame network; it carries a hidden state forward through the footage, so the matte at frame 40 "remembers" frames 1–39. That temporal consistency is the whole trick, and it's why the result doesn't wobble the way an image-model-per-frame approach does.

Inside the node (grep the source and you'll see it):

  • On first run it downloads a pre-frozen TorchScript checkpoint from the RVM GitHub releases into ComfyUI/custom_nodes/ComfyUI-Video-Matting/ckpts/. mobilenetv3_fp16 is about 8MB; resnet50_fp16 is ~54MB. The fp16 toggle literally changes which file downloads, so flip it and it re-downloads.
  • Frames are padded to a multiple of batch_size (repeating the last frame), auto-downsampled so the longest side is 512px, and processed in batches while the recurrent state is passed across every batch. One shared state, all your frames.
  • It produces a fractional alpha matte, then binarizes it - the source does pha.gt(0) with a comment that reads "Remove blur". That matters, see below.
  • The subject gets composited onto your bg_color, which is why the IMAGE output is a flat-colored cutout rather than a transparent one.

The inputs that matter

  • video_frames (IMAGE) - feed the frame batch from your video loader. It's frames, not a video file.
  • backbone - mobilenetv3 (fast, light) or resnet50 (default, better on hard edges). If your footage is clean and you want speed, mobile is fine; for hair, resnet50.
  • fp16 (BOOLEAN, default true) - half precision. Keep it on; there's no real accuracy cost and it halves the download.
  • bg_color (STRING, default "green") - any CSS color name or hex, the flat color composited behind the subject. Green is the classic chroma-key convention for a reason.
  • batch_size (INT, default 4) - frames per forward pass. RAM is your only constraint.

Wiring the outputs

Two outputs, both worth knowing:

  • IMAGE - the subject on your flat bg_color. If you specifically wanted a green-screen asset for a video editor, you're done; this is exactly what one Blender workflow in the wild used it for.
  • MASK - a binary (hard 0/1) matte you can wire into any mask input, a composite node, or SetLatentNoiseMask.

Here's the gotcha: because the node hard-thresholds RVM's soft alpha, fine hair and flyaway strands get clipped. For compositing onto a new background you'll often get a better result by reaching for a matting model that outputs fractional alpha rather than this hard mask - the background-removal knowledge base makes exactly this segmentation-versus-matting distinction. If you want transparency, take the MASK and composite yourself.

Installing it

The easy path is ComfyUI Manager - search "ComfyUI-Video-Matting". Or:

cd ComfyUI/custom_nodes
git clone https://github.com/Fannovel16/ComfyUI-Video-Matting

Then restart ComfyUI. Dependencies are basically free: einops and Pillow, both of which you almost certainly already have; torch and torchvision come from ComfyUI itself. The real install is the model download on first run, which needs GitHub reachable. If it stalls, that's the thing to check.

Where people get burned

  • Expecting transparent output. The IMAGE output is subject-on-a-color, not RGBA. Wire the MASK to a composite for real alpha.
  • Hard mask edges. pha.gt(0) is a blunt instrument on hair. RVM's real alpha is softer; this wrapper intentionally clips it.
  • Internal 512px. The network runs at max-side-512 and upscales the matte back to full res - that's RVM's Deep Guided Filter doing its job, but don't expect 4K-edge-level precision on a 1080p frame.

Niche, single-purpose, but for temporally stable video matting in ComfyUI this is the one you'd actually reach for.

CategoryVideo Matting

Inputs (5)

NameTypeDefaultDescription
video_framesIMAGE
backboneCOMBOresnet502 options: mobilenetv3, resnet50
fp16BOOLEANtrue
bg_colorSTRINGgreen
batch_sizeINT41–64

Outputs (2)

NameTypeDescription
IMAGEIMAGE
MASKMASK