1

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.

n3wton
  • 35
  • 6
  • 2
    If the command is failing with no output, that's an issue with the program you're executing, it has nothing to do with the code that's executing it. What happens when you run that same command from a terminal? – Adrian Feb 18 '19 at 21:20
  • @Adrian it works fine in the terminal, gives me the length of the video – n3wton Feb 18 '19 at 23:41
  • The quotes around `p=0` seem suspicious. A shell would parse and eliminate them before executing ffprobe, but Go doesn't. What happens if you remove them? – Peter Feb 18 '19 at 23:52
  • This may be helpful, https://stackoverflow.com/questions/52770746/executing-bash-echo-and-nc-together-in-golang – nilsocket Feb 19 '19 at 01:12
  • @Peter You were correct, the quotes were the issue. After removing them it worked fine. – n3wton Feb 19 '19 at 16:50

1 Answers1

2

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.

Vorsprung
  • 32,923
  • 5
  • 39
  • 63