Object Separation
Separate a person, product or hand from the background in a video, on the user's own...
Install
npx skills add Barty-Bart/motion-graphics --skill object-separation -g -a claude-code -y- Repository
- Barty-Bart/motion-graphics997
- Category
- Media
- Updated
- 22d ago
- License
- See repository
- Context cost
- Mediumabout 2,254 tokens
- Runs scripts
- No, instructions only
What it does
Separate a person, product or hand from the background in a video, on the user's own computer with SAM 2. Scans the machine first to pick the right model size, then outputs the same video with the separated subject highlighted in green, plus frame-by-frame masks. Use when someone wants to separate, isolate, cut out or rotoscope something in a video.
Object separation
Separate one subject from the background in a video. Everything runs on the user's computer and nothing is uploaded. The result is the same video with the subject highlighted in green, so the user can see exactly what was separated, plus a mask for every frame saved to disk.
You write and run the Python as you go. The code blocks below are tested; adapt them rather than starting from scratch.
1. Set up in a folder that can be deleted
Needs python 3.10+ and ffmpeg. Install everything into a virtual environment in the project folder, so removing that one folder removes it all:
python3 -m venv .object-separation
.object-separation/bin/pip install torch transformers opencv-python-headless pillow numpy
On Windows use .object-separation\Scripts\pip. With an NVIDIA card on Windows, install the CUDA build of torch from pytorch.org first, because plain pip gives the slower CPU build. Run all the Python below with the venv's python.
2. Scan the computer and pick the model
Run the scan first and tell the user what it found: the device, the model it picked, the download size, and what speed to expect.
| Machine | Model | Download |
|---|---|---|
| NVIDIA GPU with 12 GB+ | facebook/sam2.1-hiera-large | 898 MB |
| NVIDIA GPU under 12 GB, or Apple Silicon | facebook/sam2.1-hiera-base-plus | 323 MB |
| No GPU (CPU only) | facebook/sam2.1-hiera-tiny | 156 MB |
On a CPU it works but it is slow: about 5 seconds per frame, so a 10 second clip at 30 fps takes around half an hour. It uses under 2 GB of RAM. A GPU is much faster. If the clip is long and there is no GPU, suggest separating only the part the user needs.


