You've already forked VptPassiveAdapter
如果结束时间读取错误,不报错,由后续逻辑处理
This commit is contained in:
@ -300,3 +300,30 @@ func handleFfmpegProcess(ffmpegCmd []string) (bool, error) {
|
||||
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)
|
||||
if err != nil {
|
||||
return time.Time{}, time.Time{}, err
|
||||
return startTime, startTime, nil
|
||||
}
|
||||
return startTime, stopTime, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user