61 lines
2.0 KiB
Go
61 lines
2.0 KiB
Go
package video
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
dto "media/model/dto/video"
|
|
service "media/service/video"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
)
|
|
|
|
type template struct{}
|
|
|
|
var Template = new(template)
|
|
|
|
// CreateTemplate 创建模板视频任务 POST /video/template
|
|
func (c *template) CreateTemplate(ctx context.Context, req *dto.CreateTemplateTaskReq) (res *dto.CreateTemplateTaskRes, err error) {
|
|
ctx = withUser(ctx)
|
|
g.Log().Infof(ctx, "[模板视频] 收到请求 入参: video_count=%d, template_count=%d, callback=%s",
|
|
len(req.VideoURLs), len(req.Templates), req.CallbackURL)
|
|
if reqJSON, err := json.MarshalIndent(req, "", " "); err == nil {
|
|
g.Log().Infof(ctx, "[lmk模板视频] 完整入参(JSON):\n%s", string(reqJSON))
|
|
} else {
|
|
g.Log().Infof(ctx, "[lmk模板视频] 完整入参序列化失败: %v, 原始: %+v", err, *req)
|
|
}
|
|
|
|
if len(req.VideoURLs) < 1 {
|
|
return nil, fmt.Errorf("至少需要1个视频")
|
|
}
|
|
|
|
taskID, taskErr := service.Template.CreateAsyncTask(ctx, req.VideoURLs, req.AudioURL, req.Templates, req.Subtitles, req.SubtitleStyle, req.CallbackURL)
|
|
if taskErr != nil {
|
|
return nil, taskErr
|
|
}
|
|
g.Log().Infof(ctx, "[模板视频] 模板任务创建成功 taskId=%s(模板解析完成,转交异步渲染)", taskID)
|
|
|
|
return &dto.CreateTemplateTaskRes{TaskID: taskID}, nil
|
|
}
|
|
|
|
// GetTemplateTask 查询模板任务结果 GET /video/template/{taskId}
|
|
// 实际委托给字幕叠加服务的查询(任务由 Caption 服务创建)
|
|
func (c *template) GetTemplateTask(ctx context.Context, req *dto.GetTemplateTaskReq) (res *dto.GetTemplateTaskRes, err error) {
|
|
ctx = withUser(ctx)
|
|
captionRes, err := service.Caption.GetTaskResult(ctx, req.TaskID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
// 映射响应
|
|
return &dto.GetTemplateTaskRes{
|
|
TaskID: captionRes.TaskID,
|
|
Status: captionRes.Status,
|
|
FileURL: captionRes.FileURL,
|
|
FileSize: captionRes.FileSize,
|
|
FileName: captionRes.FileName,
|
|
DurationStr: captionRes.DurationStr,
|
|
ErrorMessage: captionRes.ErrorMessage,
|
|
}, nil
|
|
}
|