From 6faaecf3a9d00cae9eb76c3decb9eb485698acb9 Mon Sep 17 00:00:00 2001 From: Connor <963408438@qq.com> Date: Thu, 15 Jan 2026 09:44:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwindows=E4=B8=8A=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E5=90=88=E5=B9=B6BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- infrastructure/external/ffmpeg/ffmpeg.go | 42 +++++++++++++++--------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/infrastructure/external/ffmpeg/ffmpeg.go b/infrastructure/external/ffmpeg/ffmpeg.go index b5c450a..624964e 100644 --- a/infrastructure/external/ffmpeg/ffmpeg.go +++ b/infrastructure/external/ffmpeg/ffmpeg.go @@ -138,33 +138,37 @@ func (f *FFmpeg) trimVideo(inputPath, outputPath string, startTime, endTime floa "start", startTime, "end", endTime) - // 如果startTime和endTime都为0,或者endTime <= startTime,直接复制整个视频 + // 如果startTime和endTime都为0,或者endTime <= startTime,复制整个视频 + // 使用重新编码而非-c copy以确保输出文件完整性 if (startTime == 0 && endTime == 0) || endTime <= startTime { - f.log.Infow("No valid trim range, copying entire video") + f.log.Infow("No valid trim range, re-encoding entire video") cmd := exec.Command("ffmpeg", "-i", inputPath, - "-c", "copy", + "-c:v", "libx264", + "-preset", "fast", + "-crf", "23", + "-c:a", "aac", + "-b:a", "128k", + "-movflags", "+faststart", "-y", outputPath, ) output, err := cmd.CombinedOutput() if err != nil { - f.log.Errorw("FFmpeg copy failed", "error", err, "output", string(output)) - return fmt.Errorf("ffmpeg copy failed: %w, output: %s", err, string(output)) + f.log.Errorw("FFmpeg re-encode failed", "error", err, "output", string(output)) + return fmt.Errorf("ffmpeg re-encode failed: %w, output: %s", err, string(output)) } - f.log.Infow("Video copied successfully", "output", outputPath) + f.log.Infow("Video re-encoded successfully", "output", outputPath) return nil } // 使用FFmpeg裁剪视频 - // -i: 输入文件 // -ss: 开始时间(秒) - // -to: 结束时间(秒)或使用-t指定持续时间 - // -c copy: 直接复制流,不重新编码(速度快) - // -avoid_negative_ts 1: 避免负时间戳问题 + // -to/-t: 结束时间或持续时间 + // 使用重新编码而非-c copy以确保输出文件完整性,避免Windows环境下流信息丢失 var cmd *exec.Cmd if endTime > 0 { // 有明确的结束时间 @@ -172,9 +176,13 @@ func (f *FFmpeg) trimVideo(inputPath, outputPath string, startTime, endTime floa "-i", inputPath, "-ss", fmt.Sprintf("%.2f", startTime), "-to", fmt.Sprintf("%.2f", endTime), - "-c", "copy", - "-avoid_negative_ts", "1", - "-y", // 覆盖输出文件 + "-c:v", "libx264", + "-preset", "fast", + "-crf", "23", + "-c:a", "aac", + "-b:a", "128k", + "-movflags", "+faststart", + "-y", outputPath, ) } else { @@ -182,8 +190,12 @@ func (f *FFmpeg) trimVideo(inputPath, outputPath string, startTime, endTime floa cmd = exec.Command("ffmpeg", "-i", inputPath, "-ss", fmt.Sprintf("%.2f", startTime), - "-c", "copy", - "-avoid_negative_ts", "1", + "-c:v", "libx264", + "-preset", "fast", + "-crf", "23", + "-c:a", "aac", + "-b:a", "128k", + "-movflags", "+faststart", "-y", outputPath, ) From 18b11f3836c64091248dab8bb72bdcaf50b79b7c Mon Sep 17 00:00:00 2001 From: Connor <963408438@qq.com> Date: Thu, 15 Jan 2026 12:03:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9openai=E7=9A=84=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E8=8E=B7=E5=8F=96=E6=98=AF=E5=A4=9A=E7=9A=84/v1?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/video/openai_sora_client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/video/openai_sora_client.go b/pkg/video/openai_sora_client.go index 772bb84..027b603 100644 --- a/pkg/video/openai_sora_client.go +++ b/pkg/video/openai_sora_client.go @@ -133,7 +133,7 @@ func (c *OpenAISoraClient) GenerateVideo(imageURL, prompt string, opts ...VideoO } func (c *OpenAISoraClient) GetTaskStatus(taskID string) (*VideoResult, error) { - endpoint := c.BaseURL + "/v1/videos/" + taskID + endpoint := c.BaseURL + "/videos/" + taskID req, err := http.NewRequest("GET", endpoint, nil) if err != nil { return nil, fmt.Errorf("create request: %w", err)