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

  1. Make sure you are using a recent version of ComfyUI which has built in SAM 3 nodes.
  2. Install VideoHelperSuite custom node (dropping workflow should prompt you to install it).
  3. Download the model file linked below and copy it to the location shown.
  4. Download the workflow and drag it into ComfyUI.
  5. Paste the absolute path to your video into the Load Video (Uploads) node.
  6. Set the SAM3 Prompt node to what you want to keep, for example person.
  7. Click the Run button, your video with a transparent background will be saved to the output folder.
  8. 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 Prompt node is set to person. Change it to whatever you want to keep, for example face, and everything else becomes transparent.
  • Keep only some of the matches: enter a comma separated list of indices in the object_indices field of the Track To Mask node, for example 0,3,5.
  • Output format: the Video Combine node 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_interval on the SAM3 Video Track node can speed up processing.
  • Out of memory errors: lower the frames_per_batch value on the Batch Manager node (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.