SeC + MatAnyone2 Pipeline
SeC finds it, MatAnyone2 keeps it steady
- image
- bbox
- rgb
- alpha_mask
- coarse_mask
- preview
- info
The hard version of matting is video. Per-frame, a static matting model gives you gorgeous hair edges that flicker from one frame to the next because nothing remembers the previous frame. The production fix is a temporal matting model that carries a memory, and that's what this pipeline assembles: SeC - a segmentation model with a vision-language backbone that understands "the cat" or "person in red" as a semantic target - produces the coarse masks, and MatAnyone2's temporal alpha matting refines them into a stable, compositing-grade alpha across the whole clip. It's the pack's answer to "mask this thing for the entire shot," and it's the one with text prompts and occlusion handling built in.
The flow
The flow: you feed image (single frame, or a batch B>1 for video) and describe the target in text_prompt ("cat", "person in red"). SeC uses that language understanding to track the object semantically - which is the whole advantage over point-clicking when the subject occludes and reappears, or changes shape. Leave text_prompt empty and it drops to point/bbox prompting (points_json / bbox_json, plus optional positive_coords/negative_coords from a Points Mask Editor and a bbox from upstream). Then matting_backend does the edges: auto picks MatAnyone2 for video and ViTMatte for single images; matanyone2 is the temporal engine, with n_warmup (default 5) frames of warmup - more warmup, better temporal initialization.
Why it beats plain SAM+ViTMatte on video
The mechanism detail that matters: SeC tracks semantically, MatAnyone2 refines temporally, and the alpha carries that memory through occlusions and re-appearances - the exact failure mode the README calls out for plain SAM+ViTMatte, which has no temporal component. After matting you get optional edge_refine_method (vitmatte / guided_filter / multi_scale_guided) for a last edge pass, then cleanup: fill_holes_enabled and min_region_size (64).
Outputs
Outputs: rgb (the original frames, passed through for downstream), alpha_mask (the compositing-grade alpha), coarse_mask (the pre-matting segmentation - keep it for before/afters), preview (input + alpha overlay), and info (JSON of stages, models, per-stage timings). precision (default fp16) applies to the segmentation model, and keep_model_loaded (default on) holds the models in VRAM between runs - turn it off if you're juggling a big diffusion model on the same card.
Install
Install is the pack's most involved setup: clone Code2Collapse/ComfyUI-CustomNodePacks into custom_nodes (or Manager → "CustomNodePacks"), then the model downloads. SeC weights plus MatAnyone2 (and ViTMatte, if you want that backend) - the README's licensing table is worth a skim: everything here is Apache-2.0 or MIT, so it's commercial-safe, unlike the pack's RMBG-2.0 background-remover option. Expect a multi-GB first-run download and real VRAM during video inference; this is a "make sure your card can breathe" pipeline, not a quick preview node. But for a clean, temporally-stable cutout of one named thing across a shot, it's the right tool.
Inputs (16)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Single image or video frames (B>1 for video). | |
| segmentation_model | COMBO | sam2.1_hiera_base_plus | Segmentation model for coarse masks. SeC: best for video with text prompts. SAM2/3: best for point/bbox prompts. |
| text_prompt | STRING | Text description of target object (e.g. 'cat', 'person in red'). Used by SeC for semantic tracking. Leave empty for point/bbox prompts. | |
| points_json | STRING | [] | Point prompts: [{"x":100,"y":200,"label":1}, ...] |
| bbox_json | STRING | Bounding box: [x1,y1,x2,y2] | |
| matting_backend | COMBO | auto | Alpha matting backend. auto: MatAnyone2 for video (B>1), ViTMatte for single images. matanyone2: Video matting with temporal consistency. vitmatte_small/base: Neural matting (best edge quality per frame). |
| edge_radius | INT | 151–200 | Edge refinement radius in pixels. |
| n_warmup | INT | 51–30 | MatAnyone2 warmup frames (more = better temporal init). |
| precision | COMBO | fp16 | Segmentation model precision. |
| fill_holes_enabled | BOOLEAN | true | Fill interior holes in the final alpha. |
| min_region_size | INT | 640–10000 | Remove isolated regions smaller than N pixels. |
| positive_coordsopt | STRING | Positive points from Points Mask Editor. | |
| negative_coordsopt | STRING | Negative points from Points Mask Editor. | |
| bboxopt | BBOX | Positive bbox from upstream node. | |
| edge_refine_methodopt | COMBO | none | Optional post-matting edge refinement. none: use raw MatAnyone2 output. vitmatte/guided_filter: refine edges after matting. |
| keep_model_loadedopt | BOOLEAN | true | Keep models in VRAM between runs. |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| rgb | IMAGE | Original RGB frames passed through for downstream nodes. |
| alpha_mask | MASK | Compositing-grade alpha mask after MatAnyone2 + optional refinement. |
| coarse_mask | MASK | Coarse segmentation mask before alpha matting. |
| preview | IMAGE | Side-by-side preview of input frames and final alpha overlay. |
| info | STRING | JSON summary of stages, models, and per-stage timings. |