feat(#1970): 素材原子化切片 P1 - 数据层/切片逻辑/原子片段级选片 #1974

Merged
auto-approve-bot merged 4 commits from feat/1970-atom-clips into develop 2026-09-18 03:57:07 +08:00
Owner

#1970 智能剪辑流程重构 — PR1:素材原子化切片(P1 数据层 + 切片 + 原子片段级选片)

需求文档:docs/smart-edit-flow-redesign-20260916.md
本 PR 为 3 个 PR 中的第 1 个,只含原子切片数据层/切片逻辑/选片单元改造,不含降重微变换(PR2)和新 API 字段/叙事模式(PR3)。

改动内容

数据层

  • 新表 asset_atom_clips:id / asset_id(FK→assets, ondelete CASCADE) / start_time / end_time / duration / clip_index / tags(JSONB) / scene_change_at / is_fallback / created_at,(asset_id, clip_index) 唯一约束 + asset_id 索引(migration 079)
  • edit_plan_clips 新增 atom_clip_id String(32) nullable 默认空串 + 索引(migration 080)
  • 领域实体 AssetAtomClip + Repository 端口 + SQLAlchemy 实现(CRUD + find_candidates_for_selection)

切片逻辑(packages/domain/atom_clip_service.py,纯函数)

  • 3~6 秒随机时长;<6s 素材整条一段不切;末段 <3s 合并到前段、≥3s 独立
  • 切点 ±0.5s 内对齐 scdet 切换点(直接复用 asset_analyzer 已有的 scene_changes metadata,不重算)
  • 逻辑索引,不物理切割
  • 兜底:atom_clips 未就绪时内存 4.5s 均匀切片(is_fallback=True,不入库)

异步触发

  • 新 Celery 任务 worker.generate_atom_clips,ingest 入库 commit 后按 asset_id 触发;幂等(已有片段则跳过),失败只告警不阻断入库

选片改造

  • atom_clip_selector.py:选片单元从整条素材变为原子片段;评分维度保持(质量 0.35 / 时长适配 0.30 / 新鲜度 0.15 / 未使用加分 0.10 / 素材均衡 0.10 + 噪声),历史 recently_used 软降权
  • plan_generator_service._distribute_atom_clips:非预览场景优先原子选片,失败/预览自动回退旧 distribute_assets;片段数按配音总时长/4.5s 估算
  • reselect_plan_for_variant:变体重选优先原子路径,不足/异常回退旧函数
  • 每个 VirtualClip 落库 atom_clip_id + asset_id + start/end;同素材不同片段可多次选用,同一原子片段单视频硬排除
  • 跨变体避让:批量生成循环用 collect_plan_atom_clip_ids 累积前序变体已用 atom_clip_id,后续变体硬排除(批次内一个原子片段只用一次);跨任务/历史成片软降权
  • concat_engine trim 能力已确认可用(trim=start/end + atrim),渲染链路无需改动

测试

  • 新增 88 个单测:切片算法 55(边界/连续无重叠/末段合并/scdet 对齐/可复现)、selector 18、resolver 9、SQLite 端到端 4(落库唯一性/兜底/预览旧路径/无 repo 旧路径)、generation_common 新增 3(另有既有 1 个)
  • 全量 tests/unit:15655 passed, 28 skipped(含本分支改动)
  • ruff All checks passed

兼容性

  • 旧 clips atom_clip_id 为空串,所有新路径失败均 try/except 回退旧逻辑;预览路径完全不变
  • migration chain:078 → 079 → 080,单一 head

不做(留给 PR2/PR3)

  • dedup_enabled + 6 个微变换 filter(PR2)
  • assembly_mode/script_id/tts_voice_id/tts_voice_source/video_ratio 字段 + 叙事模式 TTS(PR3)
## #1970 智能剪辑流程重构 — PR1:素材原子化切片(P1 数据层 + 切片 + 原子片段级选片) 需求文档:`docs/smart-edit-flow-redesign-20260916.md` 本 PR 为 3 个 PR 中的第 1 个,只含原子切片数据层/切片逻辑/选片单元改造,不含降重微变换(PR2)和新 API 字段/叙事模式(PR3)。 ### 改动内容 **数据层** - 新表 `asset_atom_clips`:id / asset_id(FK→assets, ondelete CASCADE) / start_time / end_time / duration / clip_index / tags(JSONB) / scene_change_at / is_fallback / created_at,(asset_id, clip_index) 唯一约束 + asset_id 索引(migration 079) - `edit_plan_clips` 新增 `atom_clip_id` String(32) nullable 默认空串 + 索引(migration 080) - 领域实体 `AssetAtomClip` + Repository 端口 + SQLAlchemy 实现(CRUD + find_candidates_for_selection) **切片逻辑**(`packages/domain/atom_clip_service.py`,纯函数) - 3~6 秒随机时长;<6s 素材整条一段不切;末段 <3s 合并到前段、≥3s 独立 - 切点 ±0.5s 内对齐 scdet 切换点(直接复用 asset_analyzer 已有的 scene_changes metadata,不重算) - 逻辑索引,不物理切割 - 兜底:atom_clips 未就绪时内存 4.5s 均匀切片(is_fallback=True,不入库) **异步触发** - 新 Celery 任务 `worker.generate_atom_clips`,ingest 入库 commit 后按 asset_id 触发;幂等(已有片段则跳过),失败只告警不阻断入库 **选片改造** - `atom_clip_selector.py`:选片单元从整条素材变为原子片段;评分维度保持(质量 0.35 / 时长适配 0.30 / 新鲜度 0.15 / 未使用加分 0.10 / 素材均衡 0.10 + 噪声),历史 recently_used 软降权 - `plan_generator_service._distribute_atom_clips`:非预览场景优先原子选片,失败/预览自动回退旧 distribute_assets;片段数按配音总时长/4.5s 估算 - `reselect_plan_for_variant`:变体重选优先原子路径,不足/异常回退旧函数 - 每个 VirtualClip 落库 atom_clip_id + asset_id + start/end;同素材不同片段可多次选用,同一原子片段单视频硬排除 - **跨变体避让**:批量生成循环用 collect_plan_atom_clip_ids 累积前序变体已用 atom_clip_id,后续变体硬排除(批次内一个原子片段只用一次);跨任务/历史成片软降权 - concat_engine trim 能力已确认可用(trim=start/end + atrim),渲染链路无需改动 ### 测试 - 新增 88 个单测:切片算法 55(边界/连续无重叠/末段合并/scdet 对齐/可复现)、selector 18、resolver 9、SQLite 端到端 4(落库唯一性/兜底/预览旧路径/无 repo 旧路径)、generation_common 新增 3(另有既有 1 个) - 全量 tests/unit:**15655 passed, 28 skipped**(含本分支改动) - ruff All checks passed ### 兼容性 - 旧 clips atom_clip_id 为空串,所有新路径失败均 try/except 回退旧逻辑;预览路径完全不变 - migration chain:078 → 079 → 080,单一 head ### 不做(留给 PR2/PR3) - dedup_enabled + 6 个微变换 filter(PR2) - assembly_mode/script_id/tts_voice_id/tts_voice_source/video_ratio 字段 + 叙事模式 TTS(PR3)
xiaoxia added 2 commits 2026-09-18 02:15:17 +08:00
- 新增 asset_atom_clips 表(FK→assets 级联删除)+ Alembic 079
- edit_plan_clips 新增 atom_clip_id 列 + Alembic 080
- AssetAtomClip 领域实体 + Repository 接口/SQLAlchemy 实现
- 切片逻辑:3~6s 随机、scdet 切点对齐、<6s 不切、末段<3s 合并
- Celery worker.generate_atom_clips:素材 READY 后异步切片,失败不阻断入库
- 选片改造:PlanGeneratorService/变体 reselect 从原子片段选取,
  同片段单视频不重复、同素材多片段可用、跨视频/跨变体原子片段级避让
- atom_clips 未就绪时内存 3-6s 均匀兜底切片,再回退整条素材旧路径
- 85 个单元测试(切片算法/选片器/resolver/service 端到端)
feat(#1970): 批量变体跨变体原子片段级硬避让
CI/CD Pipeline / Check push changed paths (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 / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 2s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped 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 / PR Build API Image (pull_request) Successful in 36s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 1m39s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 2m53s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 2m55s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 5m17s
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
CI/CD Pipeline / Validate - Style (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Security (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
AI Code Review / AI Code Review (pull_request) Has been cancelled
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been cancelled
2339385d2c
- reselect_plan_for_variant 新增 batch_used_atom_ids 参数
- generation_common 新增 collect_plan_atom_clip_ids
- 批量生成循环累积各变体已用 atom_clip_id 传入下一变体

🚀 预览环境已部署

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

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

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

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

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1974 | | 预览链接 | [https://pr-1974.preview.xiaoxiajianji.com](https://pr-1974.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
auto-approve-bot added 1 commit 2026-09-18 02:21:06 +08:00
style: auto-format with black + isort + ruff + prettier [skip ci-format-check]
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
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 / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 3s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 3s
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 / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped 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 / PR Build Worker Image (pull_request) Successful in 47s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 49s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m38s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 2m58s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 4m31s
CI/CD Pipeline / Validate - Style (pull_request) Failing after 5m7s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 5m34s
AI Code Review / AI Code Review (pull_request) Successful in 6m37s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 11m16s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 11m28s
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 / Canary Release to Production (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 / CI Gate (pull_request) Failing after 2s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 8m39s
7ba0d122bd
xiaoxia added 1 commit 2026-09-18 03:41:27 +08:00
fix: 修复 develop 遗留 ruff B904/B005(scripts_ai raise from None、douyin rstrip noqa)
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 1s
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
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 / 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 / PR Build Worker Image (pull_request) Successful in 42s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 46s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m19s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 4m15s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 4m53s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 5m19s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 5m28s
AI Code Review / AI Code Review (pull_request) Successful in 6m45s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 10m51s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 14m59s
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 / CI Gate (pull_request) Successful in 1s
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
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 10m20s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 22s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 23s
fbb229bd83
auto-approve-bot merged commit f1621ace9f into develop 2026-09-18 03:57:07 +08:00
auto-approve-bot deleted branch feat/1970-atom-clips 2026-09-18 03:57:10 +08:00

🗑️ 预览环境已清理

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

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

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