Compare commits

...

2 Commits

Author SHA1 Message Date
f9256895b7 去除错误 2025-04-13 18:32:20 +08:00
104930c413 优化stopTime为空时逻辑爆炸的问题 2025-04-13 16:07:29 +08:00
3 changed files with 9 additions and 4 deletions

View File

@ -51,7 +51,10 @@ func (l *LocalAdapter) GetFileList(ctx context.Context, dirPath string, relDt ti
if err != nil {
continue
}
if startTime.Equal(stopTime) || stopTime.IsZero() {
if stopTime.IsZero() {
stopTime = startTime
}
if startTime.Equal(stopTime) {
// 如果文件名没有时间戳,则认为该文件是未录制完成的
// 尝试读取一下视频信息
duration, err := util.GetVideoDuration(subCtx, path.Join(l.StorageConfig.Path, dirPath, file.Name()))

View File

@ -91,7 +91,10 @@ func (s *S3Adapter) GetFileList(ctx context.Context, dirPath string, relDt time.
if err != nil {
continue
}
if startTime.Equal(stopTime) || stopTime.IsZero() {
if stopTime.IsZero() {
stopTime = startTime
}
if startTime.Equal(stopTime) {
stopTime = stopTime.Add(time.Second * time.Duration(config.Config.Record.Duration))
}
presignClient := s3.NewPresignClient(client)

View File

@ -461,12 +461,11 @@ func GetVideoDuration(ctx context.Context, filePath string) (float64, error) {
span.SetStatus(codes.Error, "failed to get video duration")
return 0, fmt.Errorf("failed to get video duration: %w", err)
}
span.SetAttributes(attribute.String("ffmpeg.stdout", out.String()))
span.SetAttributes(attribute.String("ffprobe.stdout", out.String()))
durationStr := strings.TrimSpace(out.String())
duration, err := strconv.ParseFloat(durationStr, 64)
if err != nil {
span.SetAttributes(attribute.String("error", err.Error()))
span.SetStatus(codes.Error, "failed to parse video duration")
return 0, fmt.Errorf("failed to parse video duration: %w", err)
}
span.SetAttributes(attribute.Float64("video.duration", duration))