MatAnyone2 Slice Frames
MatAnyone2 Slice Frames
- images
- images
- start_frame_used
- end_frame_used
Here's a sentence that sounds obvious but saves you real GPU time: don't matte the whole video if you only need part of it. MatAnyoneSliceFrames slices an IMAGE batch - which in ComfyUI land is exactly what a loaded video is - down to the frame range you care about, and everything downstream only ever sees that range.
Video matting is per-frame work. The Matte node propagates through every single frame you hand it, and the README's own VRAM advice ("12+ GB recommended for longer or higher-resolution clips") is a direct consequence of that. If your clip is three minutes but the subject only matters for forty seconds, slicing first turns a possible OOM into a comfortable run. It also makes the interactive editor snappier, because Select Frame and Interactive SAM get a smaller batch to chew on.
How it works
Dead simple, and honest about it. Inputs: images (the IMAGE batch), start_frame (default 0), and end_frame_exclusive (default -1). That last one is the gotcha - it's exclusive, so start 10, end 20 gives you frames 10–19. Default -1 means "to the end of the clip," which is how the bundled demo workflow rides along: slice from wherever you want, let it run out the end.
The node clamps your indices to the actual batch, so asking for frame 999999 on a 100-frame clip doesn't error - it gives you the last frame. Outputs: images (the sliced batch), plus start_frame_used and end_frame_used (INTs reporting what you actually got, in case you were off the end). The frames are contiguous and stay in order; no resampling, no interpolation.
Where it sits in the flow
The demo pipeline is Load Video (VHS) → Slice Frames → Select Frame → Interactive SAM → Matte → Save Video. You slice once, then everything downstream - the editor's first frame and the propagation range - agrees about what the clip is. Keep your slicing before Select Frame, not after, and the whole pack stays consistent.
Install
Nothing special - it ships in the MatAnyone2 Video Matting pack. ComfyUI Manager search "MatAnyone2", or:
cd ComfyUI/custom_nodes
git clone https://github.com/dreamrec/MatAnyone2_ComfyUI.git
cd MatAnyone2_ComfyUI
python -m pip install -r requirements.txt
python install.py
Restart.
The trap
Forgetting that end_frame_exclusive is exclusive. People set 0 to 100 expecting 101 frames, get 100, and think they've lost a frame. You haven't - that's just how slice semantics work. The other one: slicing happens in memory on the already-decoded batch, so it saves you compute, not the RAM cost of loading the video in the first place. If the load itself is the problem, trim the video file before it reaches ComfyUI, not after.
A thin node, but it's the difference between a matte that finishes and one that crawls. Use it.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| start_frame | INT | 00–999999 | — |
| end_frame_exclusive | INT | -1-1–999999 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| images | IMAGE | — |
| start_frame_used | INT | — |
| end_frame_used | INT | — |