From 07ce23b36f9a16d5e9c589178108b7be9c90dd8f Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Tue, 25 Aug 2026 09:04:55 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E9=A2=84=E8=A7=88=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=E6=A0=B9=E6=8D=AEvideo=5Fratio=E8=AE=A1=E7=AE=97=E5=88=86?= =?UTF-8?q?=E8=BE=A8=E7=8E=87=EF=BC=8C=E4=B8=8D=E5=86=8D=E9=BB=98=E8=AE=A4?= =?UTF-8?q?1280x720?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根据video_ratio计算output_width/output_height,传入CreateGenerationTaskCommand。 9:16→1080x1920, 16:9→1920x1080, 1:1→1920x1920。 更新1个已有测试的断言。 --- apps/api/app/api/routes/generation_preview.py | 32 ++++++++++++++++++- tests/unit/test_generation_preview.py | 5 ++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/apps/api/app/api/routes/generation_preview.py b/apps/api/app/api/routes/generation_preview.py index 4209df1a3..03be31208 100755 --- a/apps/api/app/api/routes/generation_preview.py +++ b/apps/api/app/api/routes/generation_preview.py @@ -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: diff --git a/tests/unit/test_generation_preview.py b/tests/unit/test_generation_preview.py index 4c48b049b..bb97b7f2e 100644 --- a/tests/unit/test_generation_preview.py +++ b/tests/unit/test_generation_preview.py @@ -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}" # ═══════════════════════════════════════════════════════════════════════════════ -- 2.54.0 From 3462deaaf34c6d247e11013b196cc2691a835e50 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Tue, 25 Aug 2026 09:27:53 +0800 Subject: [PATCH 2/2] chore: trigger CI -- 2.54.0