Remove background from video with BEN3
Run BEN3 on your computer. Keep the foreground in a transparent WebM for compositing, or export an MP4 with the new background already in the picture.
One clip, two exports
The original two-second animation shows a striped ball moving across a blue grid. Play each clip to compare how BEN3 handles the background.
The checkerboard shows through transparent pixels.
The sand background is part of the image. Its target color is #F4E1C3.
View the still comparison
If your player does not show WebM transparency, compare these decoded frames at one second.
Set up BEN3 locally
For the CUDA path, use a CUDA-capable NVIDIA GPU and a driver compatible with your CUDA-enabled PyTorch build. Run nvidia-smi to see your GPU and driver version.
Create a Python virtual environment. These commands use a POSIX shell.
python3 -m venv .venv
source .venv/bin/activate
Use the PyTorch installation selector in Sources. On the CUDA path, choose a CUDA build for your platform and driver. On the CPU path, choose CPU and continue to the BEN3 install.
On the CUDA path, check that PyTorch can run a GPU operation.
python - <<'PYTHON'
import torch
print("PyTorch CUDA build", torch.version.cuda)
assert torch.cuda.is_available(), "CUDA unavailable"
print(torch.cuda.get_device_name(0))
print("CUDA test result", torch.ones(1, device="cuda").item())
PYTHON
Expect a CUDA version, the GPU name, and a test result of 1.0. If it reports CUDA unavailable, check the NVIDIA driver and the PyTorch build. A version of None indicates a CPU build.
Install BEN3 with the Transformers version that matches the public checkpoint.
python -m pip install transformers==4.57.6 \
git+https://github.com/PramaLLC/BEN3.git@852e1a702beec9ab1d2fed2f09c9e36899f14c4e
Put ffmpeg and ffprobe on your PATH for WebM export and audio muxing. Check that the libvpx-vp9 encoder lists yuva420p under supported pixel formats. The final check is for the libx264 encoder used in the browser-compatible MP4 step.
command -v ffmpeg ffprobe
ffmpeg -hide_banner -h encoder=libvpx-vp9
ffmpeg -hide_banner -h encoder=libx264
Export the same clip twice
Save input.mp4 and remove-background.py in the same folder. The first model load downloads the public weights from Hugging Face. BEN3 decodes and processes the video locally.
python remove-background.py input.mp4 --device cuda
To reproduce the CPU exports shown here, use --device cpu.
python remove-background.py input.mp4 --device cpu
Transparent WebM for compositing
The first segment_video call sets webm=True and saves foreground.webm as VP9 with alpha. In an editor that supports VP9 alpha, place it above the layer you want to show through.
Solid-background MP4 for playback
The second call sets rgb_value=(244, 225, 195) to composite each frame over sand. BEN3 writes solid-ben3.mp4. Encode that file as H.264 for browser playback.
ffmpeg -i solid-ben3.mp4 -c:v libx264 -crf 17 \
-pix_fmt yuv420p -movflags +faststart solid.mp4
The clip is silent, so both calls use add_audio=False. For a clip with sound, set add_audio=True to let BEN3 probe and mux the audio.
Inspect the exported frames
Decode the WebM with libvpx-vp9 to keep its alpha channel. Extract a frame from each export at the same time.
ffmpeg -c:v libvpx-vp9 -i foreground.webm -ss 1 \
-frames:v 1 -pix_fmt rgba foreground.png
ffmpeg -i solid.mp4 -ss 1 -frames:v 1 -pix_fmt rgb24 solid.png
Open both PNGs. The WebM frame should have transparent pixels around the ball. The MP4 frame should be opaque, with background pixels close to RGB (244, 225, 195) after compression.
What the public model includes
The public release includes the BEN3 generator weights and inference code for images and video. The generator predicts several candidate foreground masks and uses a learned score to select one. The commercial release adds a proprietary fusion stage that refines the mask using multiple candidates. Prama LLC keeps the training dataset private.