CLI tool to remove video backgrounds with rembg and OpenCV
Project description
A Python CLI tool that removes backgrounds from videos using rembg and OpenCV. It supports full video export, transparent frame extraction, and animated WebP / GIF generation.
✨ Features
- Split a video into frames, remove the background, and rebuild it as a video
- Export transparent
webp/pngframes at fixed intervals - Generate transparent animated
webp/gif - Replace the removed background with a solid color or background image
- Switch between
isnet-general-use,u2net,u2netp,u2net_human_seg, andsilueta
📋 Requirements
- Python 3.10 or later
- FFmpeg is not required
- The model is downloaded on first run
🛠️ Install
From PyPI
pip install video-background-remover
Local development
pip install -e ".[dev]"
With uv
uv sync --extra dev
🚀 Quick Start
1. Export a video with a white background
video-background-remover assets/onizuka_idle_motion.mp4 output/output_white.mp4 --bg-color white
2. Export a transparent animated WebP
video-background-remover assets/onizuka_idle_motion.mp4 output/output_animated.webp --animated webp --webp-fps 10
3. Export transparent frames every second
video-background-remover assets/onizuka_idle_motion.mp4 output/frames --interval 1 --format webp
💡 Usage
video-background-remover INPUT OUTPUT [options]
If you are running directly from the repository, python main.py ... and python -m video_background_remover_cli ... still work.
Full video export
video-background-remover input.mp4 output.mp4 --bg-color white
video-background-remover input.mp4 output.mp4 --bg-image background.jpg
video-background-remover input.mp4 output.mp4 --fps 30
Regular video output does not preserve alpha transparency. If you want a visible background, pass --bg-color or --bg-image.
Transparent frame export
video-background-remover input.mp4 output/frames --interval 0.5 --format webp
video-background-remover input.mp4 output/frames --interval 1 --format png
When --interval is set, OUTPUT is treated as a directory name instead of a file path.
Animated WebP / GIF export
video-background-remover input.mp4 output/output_animated.webp --animated webp
video-background-remover input.mp4 output/output.gif --animated gif --webp-fps 8
video-background-remover input.mp4 output/output --animated both --webp-fps 8 --max-frames 120
With --animated both, the tool writes both .webp and .gif using the same base name.
⚙️ Options
| Option | Description |
|---|---|
--model |
Background removal model. Default: isnet-general-use |
--fps |
FPS for regular video output. Defaults to the input video's FPS |
--bg-color |
Background color. Supports white, black, green, blue, red, gray, transparent, or 255,128,0 |
--bg-image |
Path to a background image |
--keep-frames |
Keep intermediate frames instead of deleting them |
--work-dir |
Working directory for extracted frames |
--interval |
Export frames every N seconds |
--format |
Output format for --interval mode: webp or png |
--animated |
Animated output mode: webp, gif, or both |
--webp-fps |
FPS for animated output |
--max-frames |
Maximum number of frames for animated output |
🧠 Models
| Model | Description |
|---|---|
isnet-general-use |
General-purpose default model |
u2net |
Good for salient object extraction |
u2netp |
Lightweight variant of u2net |
u2net_human_seg |
Optimized for human segmentation |
silueta |
Higher quality but slower |
🔥 Fire Effect Comparison
Test clip: assets/onizuka_fire_motion.mp4
Test settings:
video-background-remover assets/onizuka_fire_motion.mp4 output/model.webp --animated webp --webp-fps 8 --model <model>
| Model | Preview | Notes |
|---|---|---|
isnet-general-use |
Keeps some effect detail, but halo noise remains around the subject | |
u2net |
Stable silhouette, but removes most of the fire aura | |
u2netp |
Fastest, but quality drops on complex fire frames | |
u2net_human_seg |
Not suitable for this effect-heavy clip | |
silueta |
Best overall balance for this sample |
Experiment Summary
siluetagave the best overall balance on this clip.u2netwas the cleanest fallback when you prefer a stable silhouette.u2net_human_segwas not suitable for this stylized, effect-heavy sample.
Visual Comparison
Re-run This Experiment
The tracked experiment definition lives in experiments/onizuka_fire_motion/.
- Script:
experiments/onizuka_fire_motion/run_experiment.py - Config:
experiments/onizuka_fire_motion/experiment_config.json - Notes:
experiments/onizuka_fire_motion/README.md - Generated files:
output/model_experiments/onizuka_fire_motion/
Run it again from the repository root:
python experiments/onizuka_fire_motion/run_experiment.py
To test an additional model later, add it to the models array in experiments/onizuka_fire_motion/experiment_config.json and run the same command again.
The script regenerates:
<model>_anim.webp<model>_anim_frames/results.csvalpha_stats.csvcomparison_sheet.pngcomparison_masks.png
🖼️ Output Examples
- Input video:
assets/onizuka_idle_motion.mp4 - Animated WebP:
example/output_animated.webp - GIF:
output/output.gif - Comparison GIF:
example/onizuka_walk_motion.gif - Comparison WebP:
example/onizuka_walk_motion.webp - Transparent frames:
output_frames_webp/
GIF / WebP Comparison
| GIF | WebP |
|---|---|
📝 Notes
- The initial model load can take some time
- Long videos exported as
--animated gifcan become large - If you need transparency, prefer
--animated webpor--intervaloutput instead of regular video export
🎨 Documentation Color Map
🧪 Docs Development
- The social card image is published at
docs/public/ogp.jpg. - Social card metadata is configured in
docs/.vitepress/config.ts. - To verify the current card after a docs change or deployment, open
https://www.opengraphs.com/tools/og-debuggerand testhttps://sunwood-ai-labs.github.io/video-background-remover-cli/.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file video_background_remover-0.1.4.tar.gz.
File metadata
- Download URL: video_background_remover-0.1.4.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d3b94695641ab274b69fd2dbc94ed41625f21830952ee87ff3ce418379eb011
|
|
| MD5 |
bb4cb1e291420b18d9a6a8a06e5d0b8b
|
|
| BLAKE2b-256 |
92e2cc0285c90a90b67c1d3970fe84c1be9edb7e166cc5cc54081e42ca48cf62
|
Provenance
The following attestation bundles were made for video_background_remover-0.1.4.tar.gz:
Publisher:
publish-pypi.yml on Sunwood-ai-labs/video-background-remover-cli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
video_background_remover-0.1.4.tar.gz -
Subject digest:
7d3b94695641ab274b69fd2dbc94ed41625f21830952ee87ff3ce418379eb011 - Sigstore transparency entry: 1055387295
- Sigstore integration time:
-
Permalink:
Sunwood-ai-labs/video-background-remover-cli@99126cd429ab63d753aa328b2cb2dd7557897af1 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/Sunwood-ai-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@99126cd429ab63d753aa328b2cb2dd7557897af1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file video_background_remover-0.1.4-py3-none-any.whl.
File metadata
- Download URL: video_background_remover-0.1.4-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d1c091da1a442b9a3f816ed5e8b5f45384aa87cdaf90fe95c25d1b3e8eb779f
|
|
| MD5 |
9f6c1ce0f9821b9ef9b1f5f012f45ccc
|
|
| BLAKE2b-256 |
fc2431975f9a8eca0a91b028bd6dd5bc32819986fff7f3177b2fd977031e4549
|
Provenance
The following attestation bundles were made for video_background_remover-0.1.4-py3-none-any.whl:
Publisher:
publish-pypi.yml on Sunwood-ai-labs/video-background-remover-cli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
video_background_remover-0.1.4-py3-none-any.whl -
Subject digest:
1d1c091da1a442b9a3f816ed5e8b5f45384aa87cdaf90fe95c25d1b3e8eb779f - Sigstore transparency entry: 1055387359
- Sigstore integration time:
-
Permalink:
Sunwood-ai-labs/video-background-remover-cli@99126cd429ab63d753aa328b2cb2dd7557897af1 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/Sunwood-ai-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@99126cd429ab63d753aa328b2cb2dd7557897af1 -
Trigger Event:
push
-
Statement type: