Reputation: 35
I am trying to get the duration of a video using ffprobe and exec.Command but I keep getting an error. However, stdout and stderr are both empty so I don't know what the problem is.
func getVideoLength(filename string) float64 {
cmd := exec.Command("ffprobe", "-i", filename, "-show_entries", "format=duration", "-v", "quiet", "-of", "csv=\"p=0\"")
fmt.Println("ffprobe", "-i", filename, "-show_entries", "format=duration", "-v", "quiet", "-of", "csv=\"p=0\"")
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
fmt.Println("out: " + out.String())
fmt.Println("stderr: " + stderr.String())
log.Fatal(err)
}
length, err := strconv.ParseFloat(out.String(), 64)
if err != nil {
log.Fatal(err)
}
return length
}
Here is the output I get:
ffprobe -i amelie.mp4 -show_entries format=duration -v quiet -of csv="p=0"
out:
stderr:
2019/02/18 21:04:39 exit status 1
not very helpful.
Any ideas?. Thanks.
Upvotes: 1
Views: 1690
Reputation: 34367
The reason you aren't getting any clues is that you have set the command to not say anything. From the ffprobe docs
-loglevel [flags+]loglevel | -v [flags+]loglevel Set logging level and flags used by the library. ....
loglevel is a string or a number containing one of the following values:
‘quiet, -8’ Show nothing at all; be silent.
Upvotes: 2