mirror of
https://github.com/linyqh/NarratoAI.git
synced 2025-12-12 19:52:48 +00:00
feat(v2): 添加开始视频剪辑任务的 API 接口- 新增 StartSubclipRequest 和 StartSubclipResponse 模型- 实现 /scripts/start-subclip 接口,用于启动视频剪辑任务
- 支持异步处理,返回任务 ID 和初始状态
This commit is contained in:
parent
bd1ce5c7b9
commit
1d5585e752
@ -8,14 +8,18 @@ from app.models.schema_v2 import (
|
||||
CropVideoRequest,
|
||||
CropVideoResponse,
|
||||
DownloadVideoRequest,
|
||||
DownloadVideoResponse
|
||||
DownloadVideoResponse,
|
||||
StartSubclipRequest,
|
||||
StartSubclipResponse
|
||||
)
|
||||
from app.models.schema import VideoClipParams
|
||||
from app.services.script_service import ScriptGenerator
|
||||
from app.services.video_service import VideoService
|
||||
from app.utils import utils
|
||||
from app.controllers.v2.base import v2_router
|
||||
from app.models.schema import VideoClipParams
|
||||
from app.services.youtube_service import YoutubeService
|
||||
from app.services import task as task_service
|
||||
|
||||
router = v2_router()
|
||||
|
||||
@ -119,3 +123,46 @@ async def download_youtube_video(
|
||||
except Exception as e:
|
||||
logger.exception(f"Download YouTube video failed: {str(e)}")
|
||||
raise
|
||||
|
||||
|
||||
@router.post(
|
||||
"/scripts/start-subclip",
|
||||
response_model=StartSubclipResponse,
|
||||
summary="异步请求;开始视频剪辑任务 (V2)"
|
||||
)
|
||||
async def start_subclip(
|
||||
request: VideoClipParams,
|
||||
background_tasks: BackgroundTasks
|
||||
):
|
||||
"""
|
||||
开始视频剪辑任务的V2版本API
|
||||
"""
|
||||
try:
|
||||
# 构建参数对象
|
||||
params = VideoClipParams(
|
||||
video_origin_path=request.video_origin_path,
|
||||
video_clip_json_path=request.video_clip_json_path,
|
||||
voice_name=request.voice_name,
|
||||
voice_rate=request.voice_rate,
|
||||
voice_pitch=request.voice_pitch,
|
||||
subtitle_enabled=request.subtitle_enabled,
|
||||
video_aspect=request.video_aspect,
|
||||
n_threads=request.n_threads
|
||||
)
|
||||
|
||||
# 在后台任务中执行视频剪辑
|
||||
background_tasks.add_task(
|
||||
task_service.start_subclip,
|
||||
task_id=request.task_id,
|
||||
params=params,
|
||||
subclip_path_videos=request.subclip_videos
|
||||
)
|
||||
|
||||
return {
|
||||
"task_id": request.task_id,
|
||||
"state": "PROCESSING" # 初始状态
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
logger.exception(f"Start subclip task failed: {str(e)}")
|
||||
raise
|
||||
|
||||
@ -40,3 +40,23 @@ class DownloadVideoResponse(BaseModel):
|
||||
resolution: str
|
||||
format: str
|
||||
filename: str
|
||||
|
||||
|
||||
class StartSubclipRequest(BaseModel):
|
||||
task_id: str
|
||||
video_origin_path: str
|
||||
video_clip_json_path: str
|
||||
voice_name: Optional[str] = None
|
||||
voice_rate: Optional[int] = 0
|
||||
voice_pitch: Optional[int] = 0
|
||||
subtitle_enabled: Optional[bool] = True
|
||||
video_aspect: Optional[str] = "16:9"
|
||||
n_threads: Optional[int] = 4
|
||||
subclip_videos: list # 从裁剪视频接口获取的视频片段字典
|
||||
|
||||
|
||||
class StartSubclipResponse(BaseModel):
|
||||
task_id: str
|
||||
state: str
|
||||
videos: Optional[List[str]] = None
|
||||
combined_videos: Optional[List[str]] = None
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user