Nodes/Image Processing Suite for ComfyUI/SAM2 Video Add Points (AnotherUtils)
ComfyUI Node

SAM2 Video Add Points (AnotherUtils)

Teach SAM2 What to Track on One Frame

By marcoc2·Created 2 years ago·Updated 5 months ago· 1
SAM2 Video Add Points (AnotherUtils)
  • model
  • image
  • prev_state
  • model
  • state
coordinates_positive
frame_index0
object_index0
coordinates_negative

Tracking a subject through a video without a tracker is a nightmare - you'd have to segment every frame by hand. SAM2's superpower is that you don't: tell it what the object is once, on one frame, and it follows it through the rest of the clip. AnotherSAM2VideoAddPoints is where that "once" happens. You give it a point (or a handful), say which frame and which object, and it builds the segmentation state that the pack's Propagate node then rides through the whole video.

It's part of AnotherUtils (marcoc2/ComfyUI-AnotherUtils), and the implementation is a faithful port of the well-known comfyui-segment-anything-2 video nodes - the author says as much in the code, which is the right way to borrow. The difference is it's bundled inside this pack with its own model loading, so you don't need a separate SAM2 node pack to get video tracking going.

How it works

You pass the model (loaded in video mode from the pack's SAM2 loader - AnotherLoadSAM2 with mode='video'), a JSON string of positive points, and a frame index. On its first call there's no state yet, so you also feed it the video's frames as image; it resizes them to the model's input resolution, initializes the inference state, and records the real frame count. Then it registers your points as "this is the object" (plus optional negative points as "not this"). It hands back the model and the state object - both must be threaded forward, which is why you'll see those two wires dangling in every workflow using it.

Points come from anywhere in the pack's ecosystem: ManualPointToSAM2 for hand-picked spots, AnotherBBoxToPoints to convert YOLO boxes into SAM2 points, or AnotherPoseToPoints to point at body parts from a pose detection.

The inputs

  • model - the ANOTHER_MODEL from the SAM2 loader, video mode required (it raises a clear error otherwise).
  • coordinates_positive - the JSON point list, e.g. [{"x": 512, "y": 300}]. String input, so it wires from the generator nodes.
  • frame_index - which frame the points refer to (0-based).
  • object_index - which object you're defining, if you're tracking several at once.
  • image (optional, but needed on the first call) - the video frames, used to initialize state.
  • coordinates_negative (optional) - points that say "definitely not the object," useful when the subject has confusing surroundings.
  • prev_state (optional) - the state from a previous AddPoints call, if you're adding more points to an already-initialized track.

What comes out

  • model - the same model object, passed through so you can keep chaining.
  • state - the ANOTHER_SAM2_STATE carrying the initialized inference state. This is the thing AnotherSAM2VideoPropagate consumes.

Installing it

Standard AnotherUtils install:

cd ComfyUI/custom_nodes
git clone https://github.com/marcoc2/ComfyUI-AnotherUtils.git

Restart ComfyUI, or search "AnotherUtils" in ComfyUI Manager. The SAM2 pipeline needs the sam2 pip package and its weights (auto-downloaded into models/sam2 on first use). See the pack's SAM2 loader for details.

Where people get burned

The two classic failures: feeding a single image instead of the full frame batch on the first call (state initialization needs to know the video length), and forgetting that positive points include everything around them - a sloppy point cloud pulls the background into the mask. That's what coordinates_negative is for. And if your points land on a frame where the object is partially occluded, tracking will inherit the confusion; pick a clean frame to define the object, then let propagation handle the rest.

CategoryAnotherUtils/inference

Inputs (7)

NameTypeDefaultDescription
modelANOTHER_MODEL
coordinates_positiveSTRING
frame_indexINT0
object_indexINT0
imageoptIMAGE
coordinates_negativeoptSTRING
prev_stateoptANOTHER_SAM2_STATE

Outputs (2)

NameTypeDescription
modelANOTHER_MODEL
stateANOTHER_SAM2_STATE