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

选项

选项 默认值 说明
--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.1.tar.gz (10.9 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.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rmbg_video-1.0.1.tar.gz
  • Upload date:
  • Size: 10.9 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.1.tar.gz
Algorithm Hash digest
SHA256 026914e3b5843c20c18263d5c4c88a0089ebacbbd667d72b720a69a2603e8615
MD5 59d19560ad50a95ba2042971e8791af1
BLAKE2b-256 e57ce80eb274d76de9a5cdd771169ae35d335bf32a96cddc4d323e9a2cfb4fc5

See more details on using hashes here.

Provenance

The following attestation bundles were made for rmbg_video-1.0.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: rmbg_video-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.0 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 79786899cfa1a5ff9915a9a0d96fe41ee37fbc19b633b637a6386fd99d79effe
MD5 070ed45113dd11254ea11063a6c283ac
BLAKE2b-256 ae54067d0d8a0a6e62e8e53ee00fdd188a10e001da60b88786fac8528b28eb41

See more details on using hashes here.

Provenance

The following attestation bundles were made for rmbg_video-1.0.1-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