fix(render): 修复生成视频时长短于模板要求时长 #1614
Reference in New Issue
Block a user
Delete Branch "fix/video-duration-mismatch"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
问题
模板要求14s视频,渲染输出只有12s,少了2s。
根因
_resolve_clips中min(duration, actual_duration)在素材实际时长不足时截短 clipxfade_builder.py的offset = cumulative - td * i未考虑前序转场的累积时长缩减修复
1. 素材不足时自动减速补偿(unified_render_service.py)
_resolve_clips: 当final_duration > actual_duration时,自动降低playback_speed = actual_duration / final_duration_clip_effective_duration: 减速场景(speed < 1)返回配置的duration而非min(duration, actual)2. xfade offset 修正(xfade_builder.py)
offset = cumulative - td * i(错误,offset 分布不均)offset = first_input_dur - td(正确,每个转场等间距)3. from-assets 转场补偿(clips.py)
raw_duration += (n-1) * td / n4. Debug 日志
测试
test_duration_compensation.py(4 个测试用例)🚀 预览环境已部署
【阻塞级判定】
📊 审查概览
🔴 阻塞级问题(必须修复)
无
💡 改进建议(不阻塞合并)
logger.info日志(如第203-218行、1449-1456行、1514-1523行、1544-1552行、1762-1769行)。在生产环境中,如果视频片段较多或并发渲染量大,这些详细日志会产生巨大的 I/O 开销和磁盘占用,影响性能。建议将所有标记为[debug]的日志级别调整为logger.debug,以便仅在需要排查问题时开启。✅ 良好实践
clips.py中预先增加transition_compensation请求更长的素材,而在unified_render_service.py中通过playback_speed减速来兜底处理素材不足的情况,形成了良好的容错机制。actual_duration > 0,避免了除以零的风险;对计算出的速度进行了max(0.25, ...)下限钳制,防止速度过低导致渲染异常。test_duration_compensation.py并更新了相关断言,确保了新逻辑的测试覆盖率。✅ 格式检查通过 | ✅ 逻辑审查通过 | ⚠️ 建议关注性能
🤖 由 AI 代码审查机器人自动生成 | 2026-09-01 11:56:32 | 模型:
🗑️ 预览环境已清理
PR #1614 已关闭或合并,对应的预览环境已被清理。