fix: 预览渲染根据video_ratio计算分辨率,不再默认1280x720 #1489

Merged
auto-approve-bot merged 2 commits from fix/preview-resolution-ratio into develop 2026-08-25 09:36:01 +08:00
2 changed files with 35 additions and 2 deletions
+31 -1
View File
@@ -264,6 +264,34 @@ def create_preview_generation_task(
if not video_ratio and request.template_id:
video_ratio = _infer_video_ratio_from_template(request.template_id, db, user_id)
# 根据 video_ratio 计算输出分辨率(默认竖屏 1080x1920)
output_width, output_height = 1080, 1920
if video_ratio:
parts = video_ratio.split(":")
if len(parts) == 2:
try:
w, h = int(parts[0]), int(parts[1])
base = 1920
if w < h:
# 竖屏
output_width = round(base * w / h)
output_height = base
else:
# 横屏
output_width = base
output_height = round(base * h / w)
# 对齐到偶数
output_width = output_width - output_width % 2
output_height = output_height - output_height % 2
except (ValueError, ZeroDivisionError):
output_width, output_height = 1080, 1920
resolution = f"{output_width}x{output_height}"
logger.info(
"[预览生成] 分辨率: video_ratio=%s%s (%dx%d)",
video_ratio, resolution, output_width, output_height,
)
# 从模板读取 editing_mode / mode 作为 strategy_id(渲染 pipeline 的 mode 参数)
strategy_id = _resolve_strategy_id_from_template(request.template_id, db, user_id)
@@ -287,12 +315,14 @@ def create_preview_generation_task(
asset_select_mode="",
batch_id="",
video_title=request.video_title,
resolution="",
resolution=resolution,
bgm_config=request.bgm_config or {},
auto_retry_enabled=False,
auto_retry_max=0,
is_preview=True,
title_config=title_config,
output_width=output_width,
output_height=output_height,
)
)
except ValueError as e:
+4 -1
View File
@@ -1206,7 +1206,10 @@ class TestPreviewRouteAutoInfersVideoRatio:
# Verify the resolution passed to CreateGenerationTaskCommand
call_args = MockUC.return_value.execute.call_args
cmd = call_args[0][0]
assert cmd.resolution == "", f"Expected empty resolution, got {cmd.resolution}"
# video_ratio inferred from pip → 9:16 → resolution=1080x1920
assert cmd.resolution == "1080x1920", f"Expected 1080x1920, got {cmd.resolution}"
assert cmd.output_width == 1080, f"Expected output_width=1080, got {cmd.output_width}"
assert cmd.output_height == 1920, f"Expected output_height=1920, got {cmd.output_height}"
# ═══════════════════════════════════════════════════════════════════════════════