I want to get duration of hls. But when I run it gives me error: exit status 1
Here's my Go code
func (i *ImageGenerationService) GenerateImages(movieID int) (models.FileResponse, error) {
if _, err := exec.LookPath("ffprobe"); err != nil {
return models.FileResponse{}, errors.New("video.Init: ffprobe was not found in your PATH ")
}
files, err := i.GetVideoFiles(movieID)
if err != nil {
i.logger.Warn("failed to get files", zap.Error(err))
return models.FileResponse{}, err
}
var ii int
var file *models.ProcessedFiles
for ii, file = range files {
if file.Quality == "1080p" {
break
}
}
_, err = os.Getwd()
if err != nil {
i.logger.Warn("failed to get current directory", zap.Error(err))
return models.FileResponse{}, err
}
args := utils.GetDurationScript(files[ii].Filename)
cmd := exec.Command("ffprobe", args...)
cmd.Stderr, cmd.Stdout = os.Stderr, os.Stdout
err = cmd.Run()
if err != nil {
return models.FileResponse{}, err
}
return models.FileResponse{}, nil
}
func GetDurationScript(hls string) []string {
return []string{
"-v",
"quiet",
"-show_entries",
"format=duration",
"-print_format",
"json",
"-headers",
`"Authorization: YOUR_TOKEN"`,
hls,
}
}
I'm using OS X, go1.22.
My HLS file looks like this: https://example.com/999/1080/41509578-e299-4594-a506-cf1ff9864a1b.m3u8
Correct my code if I'm wrong or give me some suggestions of how to fix this!!!
I found my error it was while I'm writing header:
func GetDurationScript(hls string) []string {
return []string{
"-v",
"quiet",
"-show_entries",
"format=duration",
"-print_format",
"json",
"-headers",
`Authorization: YOUR_TOKEN`,
"-i",
hls,
}
}
headers must be without quotes(', '')