feat: 统一预览与确认生成渲染路径 — 预览=正式品质+确认复用
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 30s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m29s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m30s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m30s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m43s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m23s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 2m22s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m36s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 4m36s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 5m29s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m35s
CI/CD Pipeline / CI Gate (pull_request) Failing after 6s
AI Code Review / AI Code Review (pull_request) Successful in 6m45s
CI/CD Pipeline / Production Browser E2E (pull_request) Failing after 880h48m4s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 880h48m4s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 880h48m5s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 880h48m5s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 880h53m34s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 880h53m34s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 880h53m34s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 880h54m0s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 880h54m0s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 880h54m4s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 880h54m6s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 880h54m6s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 881h21m32s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 881h21m33s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 881h27m28s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 881h27m34s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 30s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m29s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m30s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m30s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m43s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m23s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 2m22s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m36s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 4m36s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 5m29s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m35s
CI/CD Pipeline / CI Gate (pull_request) Failing after 6s
AI Code Review / AI Code Review (pull_request) Successful in 6m45s
CI/CD Pipeline / Production Browser E2E (pull_request) Failing after 880h48m4s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 880h48m4s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 880h48m5s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 880h48m5s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 880h53m34s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 880h53m34s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 880h53m34s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 880h54m0s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 880h54m0s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 880h54m4s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 880h54m6s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 880h54m6s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 881h21m32s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 881h21m33s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 881h27m28s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 881h27m34s
## 渲染管线统一 - UnifiedRenderService: 移除 is_preview 参数,统一 CRF 23 + medium preset - RenderAdapter: 移除 is_preview 参数,统一执行校验和缩略图生成 - Worker generation.py: 移除 480p+1M 码率覆盖逻辑 - generation_preview.py: 删除 PREVIEW_RESOLUTION 常量和 _calc_preview_resolution() ## 确认生成复用预览产物 - Domain: 新增 GenerationTask.mark_confirmed() 方法 - confirm_generation: 预览已完成时直接复用产物(秒出),无需重新渲染 - Editor generate: 检查 plan 关联的预览任务,plan未修改时复用产物 - Schema: CreatePreviewGenerationTaskRequest 新增 source_edit_plan_id 字段 ## 测试更新 - test_1280_preview_speedup: 重写为验证统一品质参数 - test_confirm_generation: 重写为验证复用逻辑 ## 交付标准 - 预览渲染质量与确认生成一致(1080p, CRF 23, medium) - 预览后确认生成直接复用产物(秒出) - Worker 端无任何 is_preview 低质量渲染代码残留
This commit is contained in:
@@ -45,7 +45,6 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
PREVIEW_RESOLUTION = "854x480"
|
||||
|
||||
# 模板 mode → 视频比例映射
|
||||
_TEMPLATE_MODE_TO_RATIO = {
|
||||
@@ -55,24 +54,7 @@ _TEMPLATE_MODE_TO_RATIO = {
|
||||
}
|
||||
|
||||
|
||||
def _calc_preview_resolution(video_ratio: str = "") -> str:
|
||||
"""根据视频比例计算预览分辨率(短边 480,长边按比例)。
|
||||
|
||||
支持的比例:16:9, 9:16, 1:1, 4:3, 3:4, 其他默认 16:9。
|
||||
"""
|
||||
ratio_map = {
|
||||
"16:9": "854x480",
|
||||
"9:16": "480x854",
|
||||
"1:1": "480x480",
|
||||
"4:3": "640x480",
|
||||
"3:4": "480x640",
|
||||
}
|
||||
return ratio_map.get(video_ratio.strip(), PREVIEW_RESOLUTION)
|
||||
|
||||
|
||||
def _infer_video_ratio_from_template(
|
||||
template_id: str, db: Session, user_id: str = ""
|
||||
) -> str:
|
||||
def _infer_video_ratio_from_template(template_id: str, db: Session, user_id: str = "") -> str:
|
||||
"""从模板 mode 推断视频比例,前端未传 video_ratio 时使用。
|
||||
|
||||
Returns:
|
||||
@@ -102,9 +84,7 @@ def _infer_video_ratio_from_template(
|
||||
return ""
|
||||
|
||||
|
||||
def _resolve_strategy_id_from_template(
|
||||
template_id: str, db: Session, user_id: str = ""
|
||||
) -> str:
|
||||
def _resolve_strategy_id_from_template(template_id: str, db: Session, user_id: str = "") -> str:
|
||||
"""从模板读取 editing_mode / mode 作为 strategy_id。
|
||||
|
||||
优先查新模板系统(EditTemplate.editing_mode),fallback 旧模板(Template.mode)。
|
||||
@@ -236,7 +216,7 @@ def _to_preview_response(task, generated_videos: list | None = None) -> PreviewG
|
||||
status=task.status.value if hasattr(task.status, "value") else str(task.status),
|
||||
progress=float(task.progress or 0.0),
|
||||
is_preview=bool(getattr(task, "is_preview", True)),
|
||||
resolution=getattr(task, "resolution", PREVIEW_RESOLUTION) or PREVIEW_RESOLUTION,
|
||||
resolution=getattr(task, "resolution", "") or "",
|
||||
video_url=video_url,
|
||||
duration=duration,
|
||||
file_size=file_size,
|
||||
@@ -260,7 +240,7 @@ def create_preview_generation_task(
|
||||
) -> PreviewGenerationTaskResponse:
|
||||
"""创建预览生成任务。
|
||||
|
||||
预览为完整时长的低清版(480p + 低码率),效果与正式生成一致,仅清晰度降低。
|
||||
预览渲染品质与正式生成一致(1080p, CRF 23, medium preset),确认生成时可直接复用预览产物。
|
||||
|
||||
Args:
|
||||
request: 预览任务创建请求(template_id + asset_ids 等)
|
||||
@@ -318,11 +298,11 @@ def create_preview_generation_task(
|
||||
title_ids=list(request.title_ids),
|
||||
voice_ids=list(request.voice_ids),
|
||||
created_by_user_id=user_id,
|
||||
source_edit_plan_id="",
|
||||
source_edit_plan_id=request.source_edit_plan_id,
|
||||
asset_select_mode="",
|
||||
batch_id="",
|
||||
video_title=request.video_title,
|
||||
resolution=_calc_preview_resolution(video_ratio),
|
||||
resolution="",
|
||||
bgm_config=request.bgm_config or {},
|
||||
auto_retry_enabled=False,
|
||||
auto_retry_max=0,
|
||||
|
||||
@@ -352,10 +352,11 @@ def confirm_generation(
|
||||
generation_task_repository: Any = Depends(get_generation_task_repository),
|
||||
project_repository: Any = Depends(get_project_repository),
|
||||
) -> BatchGenerationTaskResponse:
|
||||
"""确认生成 — 基于预览任务创建正式生成任务。
|
||||
"""确认生成 -- 复用预览渲染产物(预览与正式品质一致)。
|
||||
|
||||
查找预览任务,复制其配置,创建新的正式生成任务(is_preview=False),
|
||||
使用高分辨率,复用 worker.generate_video 渲染路径。
|
||||
预览已使用 1080p / CRF 23 / medium 渲染,品质与正式生成一致。
|
||||
确认时直接将预览任务标记为正式产出,无需重新渲染,实现秒出。
|
||||
仅当预览任务未完成时,才创建新的正式任务走渲染流程。
|
||||
"""
|
||||
# 1. 查找源预览任务
|
||||
source_task = generation_task_repository.get(task_id)
|
||||
@@ -368,7 +369,26 @@ def confirm_generation(
|
||||
if source_task.project_id:
|
||||
check_project_access(source_task.project_id, authenticated_user.user.id, project_repository)
|
||||
|
||||
# 3. 创建正式生成任务,复制预览任务的配置
|
||||
# 3. 如果预览任务已完成,直接复用产物(秒出)
|
||||
if source_task.is_completed and getattr(source_task, "is_preview", False):
|
||||
source_task.mark_confirmed(
|
||||
cover_url=request.cover_url,
|
||||
custom_title=request.custom_title,
|
||||
output_width=request.output_width,
|
||||
output_height=request.output_height,
|
||||
)
|
||||
generation_task_repository.update(source_task)
|
||||
logger.info(
|
||||
"[确认生成] 复用预览产物: task_id=%s, user_id=%s",
|
||||
task_id,
|
||||
authenticated_user.user.id,
|
||||
)
|
||||
return BatchGenerationTaskResponse(
|
||||
items=[_to_generation_task_response(source_task)],
|
||||
total=1,
|
||||
)
|
||||
|
||||
# 4. 预览任务未完成,创建新的正式任务走渲染流程
|
||||
use_case = CreateGenerationTaskUseCase(generation_task_repository)
|
||||
new_task = use_case.execute(
|
||||
CreateGenerationTaskCommand(
|
||||
@@ -394,7 +414,7 @@ def confirm_generation(
|
||||
)
|
||||
)
|
||||
|
||||
# 4. 调度 worker.generate_video(同一条渲染路径)
|
||||
# 5. 调度 worker
|
||||
try:
|
||||
if not safe_enqueue_generation_task(
|
||||
new_task,
|
||||
|
||||
@@ -80,6 +80,40 @@ def generate_editor_draft(
|
||||
user_id=str(current_user.user.id),
|
||||
)
|
||||
|
||||
# 检查是否可复用已完成的预览产物(预览品质已与正式一致)
|
||||
gen_task_repo = SQLAlchemyGenerationTaskRepository(db)
|
||||
reusable_task = _find_reusable_preview_task(gen_task_repo, plan_id, plan_check)
|
||||
if reusable_task:
|
||||
# 复用预览产物:标记为正式产出,跳过渲染
|
||||
reusable_task.mark_confirmed()
|
||||
gen_task_repo.update(reusable_task)
|
||||
|
||||
# 将产物 URL 写入 plan config
|
||||
rendered_url = _get_task_output_url(reusable_task, gen_task_repo)
|
||||
plan_svc.update_plan_config(
|
||||
plan_id,
|
||||
{
|
||||
"generation_task_id": reusable_task.id,
|
||||
"rendered_url": rendered_url,
|
||||
},
|
||||
)
|
||||
plan_svc.transition_status(plan_id, EditPlanStatus.COMPLETED)
|
||||
|
||||
updated_plan = plan_svc.get_plan_or_raise(plan_id)
|
||||
logger.info(
|
||||
"模板编辑器复用预览产物: template_id=%s plan_id=%s task_id=%s by user=%s",
|
||||
template_id,
|
||||
plan_id,
|
||||
reusable_task.id,
|
||||
current_user.user.id,
|
||||
)
|
||||
return EditPlanGenerateResponse(
|
||||
plan_id=plan_id,
|
||||
plan_status=updated_plan.status.value if hasattr(updated_plan.status, "value") else updated_plan.status,
|
||||
generation_task_id=reusable_task.id,
|
||||
clip_count=len((plan_check.config or {}).get("clips", [])),
|
||||
)
|
||||
|
||||
# 检查是否可生成(含最后防线自动修复 + 诊断日志)
|
||||
try:
|
||||
can_gen, reason = plan_svc.can_generate(plan_id)
|
||||
@@ -91,7 +125,6 @@ def generate_editor_draft(
|
||||
try:
|
||||
clip_count = plan_svc.mark_clips_ready(plan_id)
|
||||
|
||||
gen_task_repo = SQLAlchemyGenerationTaskRepository(db)
|
||||
user_id = current_user.user.id
|
||||
_check_queue_limits(gen_task_repo, user_id)
|
||||
|
||||
@@ -147,6 +180,50 @@ def generate_editor_draft(
|
||||
) from _e
|
||||
|
||||
|
||||
def _find_reusable_preview_task(gen_task_repo, plan_id: str, plan) -> "object | None":
|
||||
"""查找该 plan 关联的已完成预览任务,判断是否可复用。
|
||||
|
||||
复用条件:
|
||||
1. 存在 source_edit_plan_id == plan_id 的已完成预览任务
|
||||
2. plan 在预览完成后未被修改(updated_at <= 预览完成时间)
|
||||
|
||||
Returns:
|
||||
可复用的 GenerationTask,或 None
|
||||
"""
|
||||
try:
|
||||
tasks = gen_task_repo.list_by_source_edit_plan(plan_id)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
for task in tasks:
|
||||
if not getattr(task, "is_preview", False):
|
||||
continue
|
||||
if not task.is_completed:
|
||||
continue
|
||||
# 检查 plan 是否在预览完成后被修改
|
||||
completed_at = getattr(task, "completed_at", None)
|
||||
if completed_at and hasattr(plan, "updated_at"):
|
||||
plan_updated = plan.updated_at
|
||||
# 如果 plan 在预览完成后又被修改了,不能复用
|
||||
if plan_updated > completed_at:
|
||||
continue
|
||||
return task
|
||||
return None
|
||||
|
||||
|
||||
def _get_task_output_url(task, gen_task_repo) -> str:
|
||||
"""获取任务的输出视频 URL。"""
|
||||
try:
|
||||
from app.core.task_repository_helpers import get_generated_videos_for_task
|
||||
|
||||
videos = get_generated_videos_for_task(task.id, gen_task_repo)
|
||||
if videos:
|
||||
return getattr(videos[0], "file_url", "") or ""
|
||||
except Exception:
|
||||
pass
|
||||
return ""
|
||||
|
||||
|
||||
@router.get("/generation-status", response_model=EditPlanGenerationStatusResponse)
|
||||
def get_editor_generation_status(
|
||||
template_id: str,
|
||||
|
||||
Reference in New Issue
Block a user