如果结束时间读取错误,不报错,由后续逻辑处理

This commit is contained in:
2025-02-19 10:28:28 +08:00
parent 253de366db
commit 9b8f61e8e1
3 changed files with 37 additions and 2 deletions

View File

@ -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
}