From c03adc8d2c70ecbc51eb447c1077b6200ffb5e9c Mon Sep 17 00:00:00 2001 From: lmk <1095689763@qq.com> Date: Mon, 22 Jun 2026 17:29:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E5=BF=97bug?= =?UTF-8?q?=EF=BC=8C=E5=92=8C=E7=A1=AC=E7=BC=96=E7=A0=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/video/concat_service.go | 23 +++++++++++++++++++---- service/video/cut_service.go | 3 +-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/service/video/concat_service.go b/service/video/concat_service.go index d6b91d4..c0badb7 100644 --- a/service/video/concat_service.go +++ b/service/video/concat_service.go @@ -12,6 +12,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "strings" "time" @@ -248,9 +249,8 @@ func (s *concatService) concatByFilter(ctx context.Context, ffmpegPath string, i "-filter_complex", filterStr, "-map", "[outv]", "-map", "[outa]", - "-c:v", "h264_videotoolbox", + "-c:v", videoEncoder(), "-b:v", "5M", - "-allow_sw", "true", "-c:a", "aac", "-y", output, @@ -342,6 +342,15 @@ func (s *concatService) hasVideoAudio(ctx context.Context, ffmpegPath, videoPath return true } +// videoEncoder 根据平台选择视频编码器 +func videoEncoder() string { + if runtime.GOOS == "darwin" { + return "h264_videotoolbox" + } + // Linux/Docker 使用 libx264(软件编码) + return "libx264" +} + func (s *concatService) getFFmpegPath() (string, error) { ctx := context.Background() ffmpegPath := g.Cfg().MustGet(ctx, "ffmpeg.path", "").String() @@ -565,7 +574,10 @@ func (s *concatService) processAsyncTaskWithFiles(user *beans.User, taskID strin concatErr := s.executeConcat(bgCtx, taskID, filePaths, method, upload) if concatErr != nil { - dao.ConcatTask.UpdateError(bgCtx, taskID, concatErr.Error()) + g.Log().Errorf(bgCtx, "[异步拼接 %s] 失败: %v", taskID, concatErr) + if err := dao.ConcatTask.UpdateError(bgCtx, taskID, concatErr.Error()); err != nil { + g.Log().Errorf(bgCtx, "[异步拼接 %s] 更新失败状态到数据库出错: %v", taskID, err) + } s.concatCallback(bgCtx, taskID, callbackURL) return } @@ -620,7 +632,10 @@ func (s *concatService) processAsyncTask(user *beans.User, taskID string, videoU CleanupConcat(savePaths) if concatErr != nil { - dao.ConcatTask.UpdateError(bgCtx, taskID, concatErr.Error()) + g.Log().Errorf(bgCtx, "[异步拼接 %s] 失败: %v", taskID, concatErr) + if err := dao.ConcatTask.UpdateError(bgCtx, taskID, concatErr.Error()); err != nil { + g.Log().Errorf(bgCtx, "[异步拼接 %s] 更新失败状态到数据库出错: %v", taskID, err) + } s.concatCallback(bgCtx, taskID, callbackURL) return } diff --git a/service/video/cut_service.go b/service/video/cut_service.go index 941e6fd..1cf3c58 100644 --- a/service/video/cut_service.go +++ b/service/video/cut_service.go @@ -271,9 +271,8 @@ func (s *cutService) cutByFilterComplex(ctx context.Context, ffmpegPath, inputPa "-filter_complex", filterStr, "-map", "[outv]", "-map", "[outa]", - "-c:v", "h264_videotoolbox", + "-c:v", videoEncoder(), "-b:v", "5M", - "-allow_sw", "true", "-c:a", "aac", "-y", outputPath,