feat: 绿幕抠像 + 音频降噪引擎(Chroma Key + Noise Reduction) #303

Merged
xiaoxia merged 3 commits from feat/chroma-key-and-noise-reduction into develop 2026-07-14 10:52:01 +08:00
Owner

功能概述

新增两个渲染能力:绿幕抠像(Chroma Key)+ 音频降噪(Noise Reduction),纯FFmpeg实现,不引入新服务。

核心设计

绿幕抠像 ChromaKeyEngine

  • 基于 FFmpeg colorkey 滤镜,支持绿幕/蓝幕/红幕及自定义颜色
  • 可配置参数:抠除颜色(key_color)、相似度(similarity)、边缘平滑(blend)、溢色抑制(spill_suppress)
  • 5种预设:green_screen / blue_screen / red_screen / precise_green / soft_green
  • 溢色抑制:通过 colorchannelmixer 降低绿通道增益,减少绿幕反光
  • 降级策略:参数越界自动钳制,解析失败不阻断渲染
  • 配置读取:从 clip.config.chroma_key 读取,零侵入数据模型

音频降噪 NoiseReductionEngine

  • 基于 FFmpeg afftdn 滤镜(短时傅里叶变换频域降噪)
  • 3档预设 + 自定义:low(-35dB) / medium(-25dB) / high(-15dB) / custom
  • 人声增强模式:highpass + compressor + loudnorm 三级优化
  • 降级策略:参数越界自动钳制,降噪失败回退到原始音频
  • 配置读取:从 plan.config.audio_noise_reduction 读取,全局生效

系统集成

  • 绿幕抠像:UnifiedRenderService Step 1 接入(scale之后,fps之前)
    • filter_complex 路径 + 直通模式 双路径同时支持
    • try/catch 保护,失败自动跳过不阻断
  • 音频降噪:后处理模式,在 mix_audio 最终输出前应用
    • filter_complex 路径通过 RenderContext 传递配置
    • 直通模式通过 -af 参数独立应用

单测数量

  • 69个新增单测 + 1435个现有测试 = 1504个全绿,零回归

改动范围

  • 新增 apps/worker/video_processing/chroma_key_engine.py - 绿幕抠像引擎
  • 新增 apps/worker/video_processing/noise_reduction_engine.py - 音频降噪引擎
  • 修改 apps/worker/video_processing/unified_render_service.py - 双路径接入
  • 修改 apps/worker/video_processing/render_audio.py - 降噪后处理
  • 新增 tests/unit/test_chroma_key_and_noise_reduction.py - 单元测试

5 files changed, 1153 insertions(+), 3 deletions(-)

## 功能概述 新增两个渲染能力:绿幕抠像(Chroma Key)+ 音频降噪(Noise Reduction),纯FFmpeg实现,不引入新服务。 ## 核心设计 ### 绿幕抠像 ChromaKeyEngine - **基于 FFmpeg colorkey 滤镜**,支持绿幕/蓝幕/红幕及自定义颜色 - **可配置参数**:抠除颜色(key_color)、相似度(similarity)、边缘平滑(blend)、溢色抑制(spill_suppress) - **5种预设**:green_screen / blue_screen / red_screen / precise_green / soft_green - **溢色抑制**:通过 colorchannelmixer 降低绿通道增益,减少绿幕反光 - **降级策略**:参数越界自动钳制,解析失败不阻断渲染 - **配置读取**:从 `clip.config.chroma_key` 读取,零侵入数据模型 ### 音频降噪 NoiseReductionEngine - **基于 FFmpeg afftdn 滤镜**(短时傅里叶变换频域降噪) - **3档预设 + 自定义**:low(-35dB) / medium(-25dB) / high(-15dB) / custom - **人声增强模式**:highpass + compressor + loudnorm 三级优化 - **降级策略**:参数越界自动钳制,降噪失败回退到原始音频 - **配置读取**:从 `plan.config.audio_noise_reduction` 读取,全局生效 ## 系统集成 - **绿幕抠像**:UnifiedRenderService Step 1 接入(scale之后,fps之前) - filter_complex 路径 + 直通模式 双路径同时支持 - try/catch 保护,失败自动跳过不阻断 - **音频降噪**:后处理模式,在 mix_audio 最终输出前应用 - filter_complex 路径通过 RenderContext 传递配置 - 直通模式通过 -af 参数独立应用 ## 单测数量 - 69个新增单测 + 1435个现有测试 = **1504个全绿,零回归** ## 改动范围 - 新增 `apps/worker/video_processing/chroma_key_engine.py` - 绿幕抠像引擎 - 新增 `apps/worker/video_processing/noise_reduction_engine.py` - 音频降噪引擎 - 修改 `apps/worker/video_processing/unified_render_service.py` - 双路径接入 - 修改 `apps/worker/video_processing/render_audio.py` - 降噪后处理 - 新增 `tests/unit/test_chroma_key_and_noise_reduction.py` - 单元测试 5 files changed, 1153 insertions(+), 3 deletions(-)
Author
Owner

【代码审计】PR #303 绿幕抠像+音频降噪引擎 审查结论:通过

总览

  • 结论:通过
  • 问题统计:P0 x0项,P1 x0项,P2 x0项,P3 x0项
  • 核心改动:新增ChromaKeyEngine绿幕抠像引擎(colorkey滤镜)+ NoiseReductionEngine音频降噪引擎(afftdn滤镜),纯FFmpeg实现

亮点

  • 边界钳制完善(similarity 0.01-1.0, blend 0-1.0, noise_floor -60~-5dB)
  • 参数类型安全(_safe_float容错处理,无效参数回退默认值)
  • 降级模式正确(便捷函数apply_chroma_key_if_needed / apply_noise_reduction_if_needed 都有try/except,失败返回None)
  • 预设配置丰富(5种抠像预设:green_screen/blue_screen/red_screen/precise_green/soft_green;3种降噪等级:low/medium/high)
  • 溢色抑制(colorchannelmixer降低绿通道增益)设计合理
  • 人声增强(highpass + acompressor + loudnorm)组合实用
  • 代码结构清晰,每个引擎职责单一

注意事项

  • chromakey滤镜(更高级版本)作为备选方案保留,注意兼容性说明
  • arnndn需要额外模型文件,已标注默认不使用
  • 建议后续在渲染管道中集成时,确认降噪的应用时机(在混音前还是后)

代码质量优秀,可直接合并。

【代码审计】PR #303 绿幕抠像+音频降噪引擎 审查结论:通过 ## 总览 - 结论:通过 - 问题统计:P0 x0项,P1 x0项,P2 x0项,P3 x0项 - 核心改动:新增ChromaKeyEngine绿幕抠像引擎(colorkey滤镜)+ NoiseReductionEngine音频降噪引擎(afftdn滤镜),纯FFmpeg实现 ## 亮点 - 边界钳制完善(similarity 0.01-1.0, blend 0-1.0, noise_floor -60~-5dB) - 参数类型安全(_safe_float容错处理,无效参数回退默认值) - 降级模式正确(便捷函数apply_chroma_key_if_needed / apply_noise_reduction_if_needed 都有try/except,失败返回None) - 预设配置丰富(5种抠像预设:green_screen/blue_screen/red_screen/precise_green/soft_green;3种降噪等级:low/medium/high) - 溢色抑制(colorchannelmixer降低绿通道增益)设计合理 - 人声增强(highpass + acompressor + loudnorm)组合实用 - 代码结构清晰,每个引擎职责单一 ## 注意事项 - chromakey滤镜(更高级版本)作为备选方案保留,注意兼容性说明 - arnndn需要额外模型文件,已标注默认不使用 - 建议后续在渲染管道中集成时,确认降噪的应用时机(在混音前还是后) 代码质量优秀,可直接合并。
xiaoxia force-pushed feat/chroma-key-and-noise-reduction from 04af89e54c to 76d82322fe 2026-07-14 10:35:47 +08:00 Compare
xiaoxia added 2 commits 2026-07-14 10:42:11 +08:00
新增两个渲染能力:

【绿幕抠像 ChromaKeyEngine】
- 基于 FFmpeg colorkey 滤镜,支持绿幕/蓝幕/红幕
- 可配置:抠除颜色、相似度、边缘平滑、溢色抑制
- 5种预设:green_screen/blue_screen/red_screen/precise_green/soft_green
- 从 clip.config.chroma_key 读取配置,零侵入数据模型
- 降级策略:参数越界自动钳制,解析失败不阻断渲染

【音频降噪 NoiseReductionEngine】
- 基于 FFmpeg afftdn 滤镜(短时傅里叶变换降噪)
- 3档预设:低/中/高 + 自定义阈值(-60~-5 dB)
- 人声增强模式:highpass + compressor + loudnorm
- 从 plan.config.audio_noise_reduction 读取配置
- 降级策略:参数越界自动钳制,降噪失败用原始音频

【系统集成】
- 绿幕抠像:UnifiedRenderService Step 1 接入(scale之后,fps之前)
  - 支持 filter_complex 路径 + 直通模式 双路径
- 音频降噪:后处理模式,在 mix_audio 最终输出前应用
  - filter_complex 路径通过 RenderContext 传递配置
  - 直通模式通过 -af 参数应用

69个新增单测 + 1435个现有测试 = 1504个全绿,零回归
chore: black + isort 格式化
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Successful in 36s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 1m5s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m9s
CI/CD Pipeline / Build & Push Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Build Production Runtime Images (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Failing after 1m4s
4d137a5836
xiaoxia force-pushed feat/chroma-key-and-noise-reduction from 76d82322fe to 4d137a5836 2026-07-14 10:42:11 +08:00 Compare
xiaoxia added 1 commit 2026-07-14 10:47:38 +08:00
fix: 合并重复的mix_audio调用(BGM+降噪合并为一次)
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Successful in 38s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 1m35s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m38s
CI/CD Pipeline / Build & Push Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Build Production Runtime Images (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Failing after 1m44s
91509d7b6b
xiaoxia merged commit e9a6d19e00 into develop 2026-07-14 10:52:01 +08:00
Sign in to join this conversation.