视频剪辑和处理
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package video
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
dto "media/model/dto/video"
|
||||
service "media/service/video"
|
||||
|
||||
commonController "media/controller/common"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
type transcode struct{}
|
||||
|
||||
var Transcode = new(transcode)
|
||||
|
||||
// Transcode 上传视频并转码为 H.264+AAC+MP4(faststart) POST /video/transcode
|
||||
func (c *transcode) Transcode(ctx context.Context, req *struct {
|
||||
g.Meta `path:"/video/transcode" method:"post" tags:"视频转码" summary:"上传视频转码为H.264+AAC+MP4(faststart)" dc:"上传视频文件,转码为标准MP4格式"`
|
||||
OutputDir string `json:"outputDir" dc:"输出目录(可选),不传则输出到resource/temp下"`
|
||||
}) (res *dto.TranscodeRes, err error) {
|
||||
ctx = withUser(ctx)
|
||||
|
||||
// 保存上传文件
|
||||
filePaths, saveErr := commonController.SaveUploadedFilesFromCtx(ctx)
|
||||
if saveErr != nil || len(filePaths) == 0 {
|
||||
return nil, fmt.Errorf("上传文件失败: %v", saveErr)
|
||||
}
|
||||
inputPath := filePaths[0]
|
||||
g.Log().Infof(ctx, "[转码] 上传文件保存到: %s", inputPath)
|
||||
|
||||
// 调用转码服务,outputDir 为空则 service 用默认值
|
||||
res, err = service.Transcode.TranscodeToMP4(ctx, inputPath, req.OutputDir)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("转码失败: %v", err)
|
||||
}
|
||||
|
||||
g.Log().Infof(ctx, "[转码] 完成: %s", res.OutputPath)
|
||||
return res, nil
|
||||
}
|
||||
Reference in New Issue
Block a user