获取时直接传入相对时间,还是0点可能会出问题,使用path.join而不是直接拼接地址

This commit is contained in:
2025-02-16 14:43:52 +08:00
parent 1115bed7e2
commit 5b4d94e905
7 changed files with 46 additions and 24 deletions

View File

@ -8,6 +8,7 @@ import (
"math/rand"
"os"
"os/exec"
"path"
"strconv"
"strings"
"sync"
@ -45,7 +46,7 @@ func runFfmpegForMultipleFile1(task *dto.FfmpegTask) bool {
wg.Add(1)
go func(file *dto.File) {
defer wg.Done()
tmpFile := os.TempDir() + "/" + file.Name + ".ts"
tmpFile := path.Join(os.TempDir(), file.Name+".ts")
result, err := convertMp4ToTs(*file, tmpFile)
if err != nil {
log.Printf("转码出错: %v", err)
@ -101,6 +102,15 @@ func runFfmpegForSingleFile(task *dto.FfmpegTask) bool {
if err != nil {
return false
}
outfile, err := os.Stat(task.OutputFile)
if err != nil {
log.Printf("文件不存在:%s", task.OutputFile)
return false
}
if outfile.Size() < 4096 {
log.Printf("文件大小过小:%s", task.OutputFile)
return false
}
return result
}
@ -138,7 +148,7 @@ func CheckFileCoverageAndConstructTask(fileList []dto.File, beginDt, endDt time.
Files: fileList,
Length: int(endDt.Sub(beginDt).Seconds()),
Offset: int(beginDt.Sub(fileList[0].StartTime).Seconds()),
OutputFile: os.TempDir() + "/" + task.TaskID + ".mp4",
OutputFile: path.Join(os.TempDir(), task.TaskID+".mp4"),
}
return ffmpegTask, nil