This commit is contained in:
2025-09-24 10:50:34 +08:00
parent c055a68592
commit ec1705769c
18 changed files with 348 additions and 330 deletions

View File

@@ -2,12 +2,13 @@ import subprocess
import os
import logging
from abc import ABC, abstractmethod
from typing import Optional, Union
from typing import Union
from opentelemetry.trace import Status, StatusCode
from entity.render_task import RenderTask
from entity.ffmpeg_command_builder import FFmpegCommandBuilder
from entity.ffmpeg import FfmpegTask
from util.exceptions import RenderError, FFmpegError
from util.ffmpeg import (
probe_video_info,
@@ -26,7 +27,7 @@ class RenderService(ABC):
"""渲染服务抽象接口"""
@abstractmethod
def render(self, task: Union[RenderTask, "FfmpegTask"]) -> bool:
def render(self, task: Union[RenderTask, FfmpegTask]) -> bool:
"""
执行渲染任务
@@ -72,7 +73,7 @@ class RenderService(ABC):
class DefaultRenderService(RenderService):
"""默认渲染服务实现"""
def render(self, task: Union[RenderTask, "FfmpegTask"]) -> bool:
def render(self, task: Union[RenderTask, FfmpegTask]) -> bool:
"""执行渲染任务"""
# 兼容旧的FfmpegTask
if hasattr(task, "get_ffmpeg_args"): # 这是FfmpegTask
@@ -146,7 +147,7 @@ class DefaultRenderService(RenderService):
error_msg,
)
raise FFmpegError(
f"FFmpeg execution failed",
"FFmpeg execution failed",
command=args,
return_code=process.returncode,
stderr=error_msg,

View File

@@ -3,9 +3,14 @@
"""
import threading
from typing import Dict, Type, TypeVar, Optional
from typing import Dict, Type, TypeVar, Optional, TYPE_CHECKING
import logging
if TYPE_CHECKING:
from .render_service import RenderService
from .template_service import TemplateService
from .task_service import TaskService
logger = logging.getLogger(__name__)
T = TypeVar("T")

View File

@@ -2,7 +2,7 @@ import logging
import os
from abc import ABC, abstractmethod
from concurrent.futures import ThreadPoolExecutor
from typing import Dict, Any, List, Optional
from typing import Dict, Any, Optional
from opentelemetry.trace import Status, StatusCode
@@ -125,7 +125,11 @@ class DefaultTaskService(TaskService):
# 报告任务成功
api.report_task_success(
task_info,
videoInfo={"width": width, "height": height, "duration": duration},
videoInfo={
"width": width,
"height": height,
"duration": duration,
},
)
span.set_status(Status(StatusCode.OK))
@@ -249,7 +253,10 @@ class DefaultTaskService(TaskService):
)
def _parse_video_source(
self, source: str, task_params: Dict[str, Any], template_info: Dict[str, Any]
self,
source: str,
task_params: Dict[str, Any],
template_info: Dict[str, Any],
) -> tuple[Optional[str], Dict[str, Any]]:
"""解析视频源"""
if source.startswith("PLACEHOLDER_"):
@@ -274,7 +281,10 @@ class DefaultTaskService(TaskService):
return os.path.join(template_info.get("local_path", ""), source), {}
def _check_placeholder_exist_with_count(
self, placeholder_id: str, task_params: Dict[str, Any], required_count: int = 1
self,
placeholder_id: str,
task_params: Dict[str, Any],
required_count: int = 1,
) -> bool:
"""检查占位符是否存在足够数量的片段"""
if placeholder_id in task_params: