Sam2VideoSegmentationAddPoints
Tell SAM2 what to track in a video
- sam2_model
- image
- prev_inference_state
- sam2_model
- inference_state
This is the prompt step for SAM2's video mode. The headline feature of Segment Anything 2 over the original SAM is that it tracks objects across frames - click a fish in frame 1 and it follows that fish through the whole clip, occlusions and all. But SAM2 needs to be told what to follow first. That's this node: you drop points on the object you care about, on the frame where it's clearly visible, and SAM2 builds an internal plan for tracking it. It doesn't produce a mask itself - it produces the state that Sam2VideoSegmentation then propagates.
Think of it as two-stage on purpose. AddPoints is where you say "this, this object, starting here." Sam2VideoSegmentation is where SAM2 runs that instruction across every frame. Splitting them is what lets you prompt multiple objects in one video - you chain several AddPoints nodes, each tagging a different object, before you propagate.
How it works
SAM2 keeps an "inference state" for a video - a memory of what it's tracking. Each AddPoints node injects a set of prompt points into that state, tied to a specific object id and a specific frame. Positive points mark the object; negative points carve out what to exclude. You can seed the object on frame 0, or on a later frame where it's less occluded, and SAM2 propagates both forward and backward from there.
To track several things, you daisy-chain: the node takes an optional prev_inference_state in and passes an updated one out, so AddPoints(object 0) → AddPoints(object 1) → AddPoints(object 2) stacks all three into one state before segmentation runs.
The inputs and outputs that matter
Required:
sam2_model(SAM2MODEL) - from the loader, and it must be loaded invideomode. This is the single most common mistake with the video nodes.coordinates_positive(STRING) - the points marking the object to track. The core input; this is what SAM2 latches onto.frame_index(INT, default 0) - which frame your points refer to. Seed on a frame where the object is clean and unobstructed, not necessarily frame 0.object_index(INT, default 0) - the id for this object. Use a different value per object when you're chaining to track more than one.
Optional but useful:
coordinates_negative(STRING) - exclusion points, for when the positive points also grab something you don't want.image(IMAGE) - the video frames, as a batch.prev_inference_state(SAM2INFERENCESTATE) - the chaining input. Wire the previous AddPoints node'sinference_statehere to add another object to the same run.
Outputs:
sam2_model(SAM2MODEL) - pass-through to the next node.inference_state(SAM2INFERENCESTATE) - the payload. Feed this into the next AddPoints (to add another object) or into Sam2VideoSegmentation (to actually generate the masks).
How to install it
Part of the SAM2 pack. ComfyUI Manager → search ComfyUI-segment-anything-2 → install → restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/kijai/ComfyUI-segment-anything-2
Restart after. The loader downloads the weights; on ComfyICU the pack is already in the image.
Common issues
- Loader not in
videomode. Thesam2_modelhas to come from a DownloadAndLoadSAM2Model set tovideo. Single-image mode won't build the tracking machinery and you'll get an error. Check this first, always. - Tracking drifts off the object. SAM2 loses the thread on fast motion, heavy occlusion, or when several similar objects cross paths. Seed on a cleaner frame via
frame_index, add more positive points, or add a negative point on the distractor. - Two objects merging into one mask. Give each its own
object_indexand chain throughprev_inference_state- don't try to prompt both in a single node. - VRAM climbing on long clips. Video state grows with clip length. Shorten the clip or drop to a smaller Hiera model in the loader if you're running out of memory.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| sam2_model | SAM2MODEL | — | |
| coordinates_positive | STRING | — | |
| frame_index | INT | 0 | — |
| object_index | INT | 0 | — |
| imageopt | IMAGE | — | |
| coordinates_negativeopt | STRING | — | |
| prev_inference_stateopt | SAM2INFERENCESTATE | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| sam2_model | SAM2MODEL | — |
| inference_state | SAM2INFERENCESTATE | — |