Mask Tracker — Motion/Propagate/Anchor/Consistency
Four video-mask engines behind one mode switch
- mask
- video
- sam_model
- masks
- preview
- score
- info_json
- metric
This pack ships a lot of video-mask machinery, and Mask Tracker (MEC) is the node that pulls four of those engines under one roof. Pick a mode, and the corresponding engine runs: per-frame motion detection, seed-mask propagation, keyframe interpolation, or a flicker consistency check. Same (mask, video) input pair for all of them, same five-port output schema. It's the "unified video-mask tracker" and it's worth reaching for before you go hunting through the individual nodes.
The four modes
motion(default) - per-frame motion mask from four independent detectors:pixel_diff,optical_flow(Farneback or phase correlation),background_sub, andhistogram_diff.camera_compensation(default on) subtracts global camera motion viastabilization_method(homography/affine/translation) so a panning shot doesn't trigger motion everywhere.combine_method(union/intersection) merges the active detectors, thengrow_pixelsandmin_region_sizeclean up the result. The outputscoreis motion intensity. This is the mode for "what actually moved in this clip."propagate- seed mask on onesource_frame, push it to all frames. Methods:static(same mask everywhere),optical_flow,sam2_video(needs a wiredsam_model+ optionalpoints_json),fade,scale_linear.bidirectionalpropagates both forward and backward from the seed. This is the rotoscope-helper.anchor- SDF-based interpolation between keyframe masks. Giveanchor_framesas a CSV ("0,10,30") and one mask per anchor in themaskinput; it morphs smoothly between them acrosstotal_frameswith your choice ofeasingandsdf_iterations. Optionalflow_refinementwarps the SDF to follow actual motion (needsvideo). The outputscoreis mean confidence.consistency_check- flicker scoring between consecutive frames, viametric(mask_iou / pixel_diff / flow_warp). This is the QA mode: run it on a propagated batch to find the frames that break.
Outputs
All modes share: masks (per-frame batch), preview, score (mode-specific scalar), info_json (the mode's diagnostic payload), and metric (a label string saying what produced the result). The mask input is required by propagate/anchor/consistency but optional for motion.
Where it fits
For a video cutout, propagate + SAM2 is the quality path (SAM2's video memory is genuinely good at holding identity). For change detection, motion with camera compensation is the fast, model-free path. For a clean keyframe morph without any tracking, anchor is overkill-free interpolation. And after any of them, consistency_check tells you if it actually held together - pair that with MaskTemporal for the stabilization + warning report.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/Code2Collapse/ComfyUI-CustomNodePacks.git
pip install opencv-python>=4.7.0 scipy>=1.10.0
or ComfyUI Manager → search "CustomNodePacks", restart, confirm [MEC] Loaded .... The only heavy dependency is sam2_video propagate mode, which needs a SAM 2.1 checkpoint in ComfyUI/models/sam2/. Everything else is OpenCV/torch and works on CPU. When a mode silently does less than you expected, read info_json - the node reports what actually ran.
Inputs (36)
| Name | Type | Default | Description |
|---|---|---|---|
| mode | COMBO | motion | motion: per-frame motion mask (pixel/flow/bg/hist). propagate: seed mask on one frame, push to all frames. anchor: SDF interpolation between anchor masks. consistency_check: score flicker between consecutive frames. |
| camera_compensation | BOOLEAN | true | [motion] subtract global camera motion |
| stabilization_method | COMBO | homography | [motion] camera-motion model |
| detection_mode | COMBO | combined | [motion] active method(s) |
| pixel_diff_enabled | BOOLEAN | true | [motion] enable pixel-diff method |
| pixel_diff_threshold | FLOAT | 0.0500.001–1 | [motion] pixel-diff threshold |
| flow_enabled | BOOLEAN | true | [motion] enable optical flow |
| flow_threshold | FLOAT | 1.00.1–50 | [motion] flow magnitude threshold |
| flow_algorithm | COMBO | farneback | [motion] flow algorithm |
| bg_sub_enabled | BOOLEAN | false | [motion] background subtraction |
| bg_model_frames | INT | 51–30 | [motion] frames for bg model |
| bg_sub_threshold | FLOAT | 0.1000.001–1 | [motion] bg-diff threshold |
| hist_enabled | BOOLEAN | false | [motion] histogram diff |
| hist_grid_size | INT | 164–64 | [motion] histogram grid NxN |
| hist_threshold | FLOAT | 0.150.01–1 | [motion] histogram L2 threshold |
| combine_method | COMBO | union | [motion] method combination |
| grow_pixels | FLOAT | 40–64 | [motion] dilate result |
| min_region_size | INT | 1000–10000 | [motion] noise filter |
| temporal_smooth | BOOLEAN | true | [motion] gaussian time smoothing |
| source_frame | INT | 00–99999 | [propagate] frame where mask is drawn |
| propagate_mode | COMBO | static | [propagate] propagation method |
| prop_flow_threshold | FLOAT | 2.00–50 | [propagate] optical-flow threshold |
| fade_start | FLOAT | 1.000–1 | [propagate] opacity at source frame |
| fade_end | FLOAT | 0.000–1 | [propagate] opacity at last frame |
| bidirectional | BOOLEAN | true | [propagate] forward+backward from source |
| anchor_frames | STRING | 0 | [anchor] CSV frame indices for each anchor mask |
| total_frames | INT | 301–99999 | [anchor] total output frames |
| easing | COMBO | smooth_step | [anchor] easing curve |
| sdf_iterations | INT | 644–512 | [anchor] SDF diffusion iterations |
| flow_refinement | BOOLEAN | false | [anchor] optical-flow refine (needs video) |
| metric | COMBO | pixel_diff | [consistency_check] metric |
| binarize_threshold | FLOAT | 0.500.01–0.99 | [consistency_check] mask binarize threshold |
| maskopt | MASK | Required by propagate (seed), anchor (anchor stack), consistency_check (mask_iou). Optional for motion. | |
| videoopt | IMAGE | Video frame batch (B,H,W,C). Required by motion, propagate, anchor flow_refinement, and pixel/flow consistency. | |
| sam_modelopt | SAM_MODEL | [propagate sam2_video mode] SAM2 model | |
| points_jsonopt | STRING | [propagate sam2_video mode] point prompts |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| masks | MASK | Per-frame mask batch (B,H,W). |
| preview | IMAGE | Preview overlay (propagate) or video passthrough. |
| score | FLOAT | Mode-specific scalar: motion intensity / mean confidence / flicker score. |
| info_json | STRING | Mode-specific JSON diagnostic payload. |
| metric | STRING | Mode/metric label string. |