Who it is forA video editor or analyst who needs a mask on a moving object.
The problemRotoscoping frame by frame takes hours.
The outcomeMasklets for the object across every frame.
What you need first
- Python 3.10 or newer with torch 2.5.1 and torchvision 0.20.1 or newer
- An NVIDIA GPU with CUDA is recommended; Windows users should use WSL with Ubuntu
- A model checkpoint from the download script or Hugging Face
Steps
- Install SAM 2 and download checkpoints as in the README
- Create a predictor with build_sam2_video_predictor and call predictor.init_state on your video
- Add a point or box with predictor.add_new_points_or_box on one frame
- Loop over predictor.propagate_in_video(state) to get masks for every frame
Prompt for your agent
With facebookresearch/sam2, write a script that uses build_sam2_video_predictor, adds a box prompt on frame 0 of <my video frames folder>, propagates with propagate_in_video, and writes an overlay video.
Caveat. Setting vos_optimized=True enables full model compilation for a major speedup, per the latest updates.
Use this in your AI agent
Ask your agent
Using the Deduped MCP, get the setup steps for facebookresearch/sam2 and "Track an object through a video"
Add Deduped to Claude Code once
claude mcp add --transport http deduped https://dedupedai.com/mcp
Every Monday: the 5 hottest repos and exactly how to use them. Free, one email a week, unsubscribe anytime.
Get them freeShare: X LinkedIn Hacker News Email Copy link
Third-party repos we don't own. AI-written use cases can be wrong. Disclaimer