如果结束时间读取错误,不报错,由后续逻辑处理
This commit is contained in:
parent
253de366db
commit
9b8f61e8e1
@ -42,7 +42,15 @@ func (l *LocalAdapter) GetFileList(dirPath string, relDt time.Time) ([]dto.File,
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if startTime.Equal(stopTime) {
|
if startTime.Equal(stopTime) {
|
||||||
stopTime = stopTime.Add(time.Second * time.Duration(config.Config.Record.Duration))
|
// 如果文件名没有时间戳,则认为该文件是未录制完成的
|
||||||
|
// 尝试读取一下视频信息
|
||||||
|
duration, err := util.GetVideoDuration(path.Join(l.StorageConfig.Path, dirPath, file.Name()))
|
||||||
|
if err != nil {
|
||||||
|
// 如果还是没有,就按照配置文件里的加起来
|
||||||
|
stopTime = stopTime.Add(time.Second * time.Duration(config.Config.Record.Duration))
|
||||||
|
} else {
|
||||||
|
stopTime = stopTime.Add(time.Second * time.Duration(duration))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fileList = append(fileList, dto.File{
|
fileList = append(fileList, dto.File{
|
||||||
BasePath: l.StorageConfig.Path,
|
BasePath: l.StorageConfig.Path,
|
||||||
|
@ -300,3 +300,30 @@ func handleFfmpegProcess(ffmpegCmd []string) (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetVideoDuration(filePath string) (float64, error) {
|
||||||
|
ffprobeCmd := []string{
|
||||||
|
"ffprobe",
|
||||||
|
"-v", "error",
|
||||||
|
"-show_entries", "format=duration",
|
||||||
|
"-of", "default=noprint_wrappers=1:nokey=1",
|
||||||
|
filePath,
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command(ffprobeCmd[0], ffprobeCmd[1:]...)
|
||||||
|
var out bytes.Buffer
|
||||||
|
cmd.Stdout = &out
|
||||||
|
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("failed to get video duration: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
durationStr := strings.TrimSpace(out.String())
|
||||||
|
duration, err := strconv.ParseFloat(durationStr, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("failed to parse video duration: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return duration, nil
|
||||||
|
}
|
||||||
|
@ -19,7 +19,7 @@ func ParseStartStopTime(filePath string, relativeDate time.Time) (time.Time, tim
|
|||||||
}
|
}
|
||||||
stopTime, err := ParseTime(split[1], relativeDate)
|
stopTime, err := ParseTime(split[1], relativeDate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return time.Time{}, time.Time{}, err
|
return startTime, startTime, nil
|
||||||
}
|
}
|
||||||
return startTime, stopTime, nil
|
return startTime, stopTime, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user