Skip to main content

绿幕视频背景扣除 CLI 工具 — 使用 rembg AI 模型逐帧去除视频背景,输出带透明通道的 VP8 WebM 视频

Project description

rmbg-video

使用 rembg AI 模型逐帧去除视频背景,输出带透明通道的 VP8 WebM 视频,保留原音频。

系统要求

  • Python >= 3.9
  • ffmpeg 和 ffprobe 已安装并在 PATH 中

安装

pip install rmbg-video

使用方式

命令行

# 基本用法
rmbg-video input.mp4
rmbg-video input.mp4 output.webm

# 选择模型
rmbg-video input.mp4 --model u2net

# 调节质量 (0-63,越小越好)
rmbg-video input.mp4 --crf 5

# 输出不含透明通道的普通 WebM
rmbg-video input.mp4 --no-alpha

# 跳过音频处理
rmbg-video input.mp4 --no-audio

# 强制使用 CPU
rmbg-video input.mp4 --no-gpu

# 保留临时文件用于调试
rmbg-video input.mp4 --keep-temp

# 测试模式:只处理前5帧(快速预览效果)
rmbg-video input.mp4 --test

Web 界面

启动 Web 服务后,团队成员可通过浏览器上传视频、配置参数并预览处理结果。处理任务自动排队,单 GPU 串行执行。

# 启动 Web 服务
rmbg-video-web

# 或通过 Python 模块启动
python -m rmbg_video.web

启动后访问 http://localhost:7860,界面功能:

  • 上传视频 — 支持 .mp4 / .webm / .mov / .avi / .mkv 格式
  • 参数配置 — 所有 CLI 参数均可通过界面调整,测试模式(仅处理前 5 帧)快捷开关位于最前
  • 排队处理 — 多人同时提交时自动排队,显示队列状态,单任务串行处理
  • 透明预览 — 结果视频以灰色棋盘格为背景预览,直观查看透明通道效果
  • 下载结果 — 处理完成后可直接下载 WebM 视频

选项

选项 默认值 说明
--model birefnet-general rembg 模型名
--no-alpha-matting 禁用 alpha matting(更快但边缘较硬)
--fg-threshold 240 前景阈值
--bg-threshold 10 背景阈值
--erode-size 10 腐蚀尺寸
--post-process-mask 对遮罩做后处理平滑
--crf 10 VP8 质量 0-63(越小越好)
--speed good 编码速度预设 (good/best/realtime)
--no-alpha 输出不含透明通道的普通 WebM
--no-audio 跳过音频处理
--keep-temp 保留临时文件用于调试
--ffmpeg-path 自动检测 ffmpeg 可执行文件路径
--no-gpu 强制使用 CPU
--test 测试模式:只处理前5帧

工作原理

  1. 使用 ffmpeg 管道流式解码视频为原始 RGBA 帧
  2. 通过 rembg AI 模型逐帧去除背景,应用 alpha matting 平滑边缘
  3. 通过 ffmpeg 管道编码为 VP8 + yuva420p 像素格式(支持透明通道)
  4. 提取原音频为 Opus 编码,与视频流合并输出最终 WebM

许可证

MIT

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

rmbg_video-1.0.2.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rmbg_video-1.0.2-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file rmbg_video-1.0.2.tar.gz.

File metadata

  • Download URL: rmbg_video-1.0.2.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rmbg_video-1.0.2.tar.gz
Algorithm Hash digest
SHA256 de8052be4aa1364bee781b58f765a506a5346ecfd32596624a166606f03bb4bb
MD5 5ac34642792addab7b1ac6e0e8e9a3a5
BLAKE2b-256 d5807b848c7015fb93f38f758b0151f94ec01b118eb22f4568eb9be6076b7a9d

See more details on using hashes here.

Provenance

The following attestation bundles were made for rmbg_video-1.0.2.tar.gz:

Publisher: python-publish.yml on jijinggang/rmbg-video

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rmbg_video-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: rmbg_video-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rmbg_video-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 74608f81c6413164ebea3d46d034706fc8996e1eb5525842f25aac6718065982
MD5 2e04673933d7932c56d7086a1c324dfe
BLAKE2b-256 aa2000162bd28200092c3fbfac9557994a83ca96666e24dd58eb6195085b5837

See more details on using hashes here.

Provenance

The following attestation bundles were made for rmbg_video-1.0.2-py3-none-any.whl:

Publisher: python-publish.yml on jijinggang/rmbg-video

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page