fix(render_audio): drop source video audio in mix_audio #1249

Merged
xiaoxia merged 2 commits from fix/skip-source-audio-in-mix into develop 2026-08-06 18:58:41 +08:00
Owner

背景

用户上传的视频素材经常带有环境杂音,如果直接提取主图层音频作为成片音轨,杂音会被混入最终输出,影响 TTS 配音 / BGM 的听感。

成片应只保留:TTS/配音(audio role 图层)+ BGM。

改动

apps/worker/video_processing/render_audio.pymix_audio()

  1. 在收集完 main_clips(main/broll/overlay/corner_voice)和 audio_clips(audio role)后,强制清空 main_clips = [],从而跳过源视频原始音频的提取与 concat。
  2. 删除原来对 main_clipsclip_has_audio 过滤(已无意义)。
  3. 重新组织后续分支:当 main_clips 为空时,将 audio_clips 作为有效主音频走 concat_main_audio 拼接;当二者均有则走 mix_with_independent_audio amix 混音。
  4. BGM 混入、多轨道混音、降噪后处理保持不变。

注意:auto_clip_service._score_candidate 是 per-clip 模板匹配评分(quality 0.5 + duration 0.3 + classification 0.2),用途与全局选素材不同,未纳入本次统一

测试

更新 tests/unit/test_unified_render_service.py 中依赖旧行为(从 main 图层提取音频)的 13 个用例,改为验证「main 音频被丢弃、仅 audio role 生效」的新行为;并新增 1 个直接覆盖 mix_with_independent_audio amix 路径的用例。

全量单测:13588 passed, 12 skipped

## 背景 用户上传的视频素材经常带有环境杂音,如果直接提取主图层音频作为成片音轨,杂音会被混入最终输出,影响 TTS 配音 / BGM 的听感。 成片应只保留:TTS/配音(audio role 图层)+ BGM。 ## 改动 `apps/worker/video_processing/render_audio.py` — `mix_audio()`: 1. 在收集完 `main_clips`(main/broll/overlay/corner_voice)和 `audio_clips`(audio role)后,**强制清空 `main_clips = []`**,从而跳过源视频原始音频的提取与 concat。 2. 删除原来对 `main_clips` 的 `clip_has_audio` 过滤(已无意义)。 3. 重新组织后续分支:当 `main_clips` 为空时,将 `audio_clips` 作为有效主音频走 `concat_main_audio` 拼接;当二者均有则走 `mix_with_independent_audio` amix 混音。 4. BGM 混入、多轨道混音、降噪后处理保持不变。 注意:`auto_clip_service._score_candidate` 是 per-clip 模板匹配评分(quality 0.5 + duration 0.3 + classification 0.2),用途与全局选素材不同,**未纳入本次统一**。 ## 测试 更新 `tests/unit/test_unified_render_service.py` 中依赖旧行为(从 main 图层提取音频)的 13 个用例,改为验证「main 音频被丢弃、仅 audio role 生效」的新行为;并新增 1 个直接覆盖 `mix_with_independent_audio` amix 路径的用例。 全量单测:**13588 passed, 12 skipped** ✅
xiaoxia added 1 commit 2026-08-06 18:49:11 +08:00
fix(render_audio): drop source video audio in mix_audio
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (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 / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 38s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 55s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 59s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m13s
CI/CD Pipeline / Validate - Code Quality (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / PR Build API Image (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
AI Code Review / AI Code Review (pull_request) Has been cancelled
PR Automation / Auto Approve on CI Green (pull_request) Has been cancelled
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been cancelled
23b6a6cafa
Upload videos may contain unwanted noise; the final video should only
keep TTS/dubbing + BGM.

mix_audio():
- Force main_clips = [] after layer collection so source video audio
  from main/broll/overlay/corner_voice layers is never extracted.
- audio_clips (role=audio, TTS/dubbing) become the effective main audio
  and are concat'd as the primary track.
- BGM and multi-track mixing still apply afterwards.
- Noise reduction post-processing is unchanged.

Tests: adapt unit tests to the new behavior (main layer audio ignored),
and add one direct mix_with_independent_audio amix coverage test.
Full unit suite: 13588 passed, 12 skipped.

🚀 预览环境已部署

项目 详情
PR号 #1249
预览链接 https://pr-1249.preview.xiaoxiajianji.com
API环境 staging

💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。

🔄 每次提交新代码后预览环境会自动更新。

🗑️ PR 关闭或合并后,预览环境会自动清理。

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1249 | | 预览链接 | [https://pr-1249.preview.xiaoxiajianji.com](https://pr-1249.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
auto-approve-bot added 1 commit 2026-08-06 18:50:49 +08:00
style: auto-format with black + isort + prettier [skip ci-format-check]
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (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 / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 34s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 45s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 58s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m19s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m49s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 1m59s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m44s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m24s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 2m52s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 3m38s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
AI Code Review / AI Code Review (pull_request) Successful in 4m9s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m28s
CI/CD Pipeline / CI Gate (pull_request) Successful in 7s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 37s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 49s
76ee39d7c5
Collaborator

【阻塞级判定】

  • 是否存在阻塞级问题:否
  • 阻塞级问题数量:0 个

📊 审查概览

  • 整体评价:通过
  • 建议级问题数量:1 个

🔴 阻塞级问题(必须修复)

💡 改进建议(不阻塞合并)

  1. [apps/worker/video_processing/render_audio.py: 144-159] 简化条件判断逻辑
    • 具体内容:由于代码在第 126 行显式将 main_clips 赋值为空列表 [],导致第 144 行的 if main_clips: 判断恒为 False,第 147-148 行的代码块(effective_main = main_clips 等)实际上为死代码。同时,第 155 行的 if effective_main and not effective_audio: 判断在当前逻辑下等价于 if audio_clips:,导致 else 分支(调用 mix_with_independent_audio)在 mix_audio 函数中不可达。建议直接简化逻辑为 effective_main = audio_clips,并移除不可达的 else 分支,以提高代码可读性并明确业务意图。

良好实践

  • 测试用例更新非常全面,准确覆盖了“丢弃源视频音频、仅保留独立音频轨”的各种场景(包括空音频、多音频拼接、混合场景等)。
  • 新增 test_mix_with_independent_audio_amix 单元测试,虽然主流程不再调用该函数,但验证了底层混音逻辑的健壮性,这是良好的防御性测试实践。
  • 代码注释清晰(如“丢弃源视频的原始音频...”),有助于理解业务逻辑变更。

格式检查通过 | 逻辑审查通过 | 性能良好


🤖 由 AI 代码审查机器人自动生成 | 2026-08-06 10:54:59 | 模型:

### 【阻塞级判定】 - 是否存在阻塞级问题:否 - 阻塞级问题数量:0 个 ### 📊 审查概览 - 整体评价:通过 - 建议级问题数量:1 个 ### 🔴 阻塞级问题(必须修复) 无 ### 💡 改进建议(不阻塞合并) 1. **[apps/worker/video_processing/render_audio.py: 144-159] 简化条件判断逻辑** - 具体内容:由于代码在第 126 行显式将 `main_clips` 赋值为空列表 `[]`,导致第 144 行的 `if main_clips:` 判断恒为 False,第 147-148 行的代码块(`effective_main = main_clips` 等)实际上为死代码。同时,第 155 行的 `if effective_main and not effective_audio:` 判断在当前逻辑下等价于 `if audio_clips:`,导致 `else` 分支(调用 `mix_with_independent_audio`)在 `mix_audio` 函数中不可达。建议直接简化逻辑为 `effective_main = audio_clips`,并移除不可达的 `else` 分支,以提高代码可读性并明确业务意图。 ### ✅ 良好实践 - 测试用例更新非常全面,准确覆盖了“丢弃源视频音频、仅保留独立音频轨”的各种场景(包括空音频、多音频拼接、混合场景等)。 - 新增 `test_mix_with_independent_audio_amix` 单元测试,虽然主流程不再调用该函数,但验证了底层混音逻辑的健壮性,这是良好的防御性测试实践。 - 代码注释清晰(如“丢弃源视频的原始音频...”),有助于理解业务逻辑变更。 --- ✅ 格式检查通过 | ✅ 逻辑审查通过 | ✅ 性能良好 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-08-06 10:54:59 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia merged commit 91ac40dbef into develop 2026-08-06 18:58:41 +08:00

🗑️ 预览环境已清理

PR #1249 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #1249 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Sign in to join this conversation.