Auto Remove the Background from a Video with ComfyUI
In this guide you’ll learn how to automatically remove the background from a video using SAM 3 and ComfyUI. Type what you want to keep, SAM 3 detects and tracks it across every frame, and the workflow turns everything else transparent. The result is saved as a video with an alpha channel that you can drop into your editor over any background you like. No green screen and no generation model is involved, so it runs quickly.
New to ComfyUI?
If you don’t have ComfyUI installed yet, don’t worry. Watch this video to get it up and running in just a few minutes, then you can jump straight into this workflow.
Instructions
- Make sure you are using a recent version of ComfyUI which has built in SAM 3 nodes.
- Install VideoHelperSuite custom node (dropping workflow should prompt you to install it).
- Download the model file linked below and copy it to the location shown.
- Download the workflow and drag it into ComfyUI.
- Paste the absolute path to your video into the
Load Video (Uploads)node. - Set the
SAM3 Promptnode to what you want to keep, for exampleperson. - Click the Run button, your video with a transparent background will be saved to the
outputfolder. - If you have any problems then leave a comment on the YouTube video and I can help you out.
Models
Download this file:
Place it in this folder:
📂 ComfyUI/
├── 📂 models/
│ ├── 📂 checkpoints/
│ │ └── sam3.1_multiplex_fp16.safetensors
Workflow
Sample Input (optional)
If you want to test with the same source video I used on YouTube then download this video.
Settings
- What to keep: the
SAM3 Promptnode is set toperson. Change it to whatever you want to keep, for exampleface, and everything else becomes transparent. - Keep only some of the matches: enter a comma separated list of indices in the
object_indicesfield of theTrack To Masknode, for example0,3,5. - Output format: the
Video Combinenode is set to ProRes 4444, which preserves the alpha channel. If your editor prefers a different format then change it here, but make sure it supports alpha. - Speed: increasing
detect_intervalon theSAM3 Video Tracknode can speed up processing. - Out of memory errors: lower the
frames_per_batchvalue on theBatch Managernode (36 by default).
How It Works
The video is loaded and split into batches of frames. For each batch, the SAM3 Video Track node detects everything matching your prompt and tracks it from frame to frame. The Track To Mask node turns that tracking data into a mask, the Invert Mask node flips it so it covers the background, and the Join Image with Alpha node uses it as the alpha channel of the original frames. The result is encoded to a ProRes 4444 mov with a transparent background.