1
This commit is contained in:
@@ -7,6 +7,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
import os
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from app.config import settings
|
from app.config import settings
|
||||||
@@ -82,7 +83,7 @@ def api_upscale_execute_local_simple(self, upscale_task_id: str) -> dict[str, An
|
|||||||
"""简化版本地超分执行(API v3 专用)。"""
|
"""简化版本地超分执行(API v3 专用)。"""
|
||||||
from app.models.base import async_session
|
from app.models.base import async_session
|
||||||
from app.models.video_upscale_task import VideoUpscaleTask
|
from app.models.video_upscale_task import VideoUpscaleTask
|
||||||
from app.services.video_upscale.local_ffmpeg_service import run_local_ffmpeg_upscale
|
from app.services.video_upscale.local_ffmpeg_service import execute_local_ffmpeg_crop
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
|
||||||
async def _execute():
|
async def _execute():
|
||||||
@@ -105,18 +106,25 @@ def api_upscale_execute_local_simple(self, upscale_task_id: str) -> dict[str, An
|
|||||||
await db.commit()
|
await db.commit()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# 构建输出路径
|
||||||
|
date_dir = _now_str()
|
||||||
|
final_local_path = f"./storage/generate/api/videos/{date_dir}/{upscale.api_generation_task_id or 'unknown'}.mp4"
|
||||||
|
|
||||||
# 执行本地 FFmpeg 超分
|
# 执行本地 FFmpeg 超分
|
||||||
output_path = await run_local_ffmpeg_upscale(upscale)
|
output_path = await execute_local_ffmpeg_crop(
|
||||||
|
source_path=upscale.source_local_path,
|
||||||
|
final_path=final_local_path,
|
||||||
|
target_width=int(upscale.target_width or 0),
|
||||||
|
target_height=int(upscale.target_height or 0),
|
||||||
|
)
|
||||||
|
|
||||||
# 计算相对 URL 路径
|
# 计算相对 URL 路径
|
||||||
# output_path 是绝对路径,需要转换为 /generate/api/videos/... 格式
|
|
||||||
date_dir = _now_str()
|
|
||||||
url_path = f"/generate/api/videos/{date_dir}/{upscale.api_generation_task_id}.mp4"
|
url_path = f"/generate/api/videos/{date_dir}/{upscale.api_generation_task_id}.mp4"
|
||||||
|
|
||||||
# 更新成功状态
|
# 更新成功状态
|
||||||
upscale.status = "completed"
|
upscale.status = "completed"
|
||||||
upscale.stage = "upscale_completed"
|
upscale.stage = "upscale_completed"
|
||||||
upscale.final_local_path = f"./storage/generate/api/videos/{_now_str()}/{upscale.api_generation_task_id or "unknown"}.mp4"
|
upscale.final_local_path = final_local_path
|
||||||
upscale.final_resource_url = url_path # 相对 URL
|
upscale.final_resource_url = url_path # 相对 URL
|
||||||
upscale.completed_at = _now()
|
upscale.completed_at = _now()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user