dtpf76658
dtpf76658
2019-02-18 21:09

exec.Command错误,没有输出到stdout或stderr

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.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • drsw9390405 drsw9390405 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.

    点赞 评论 复制链接分享

为你推荐