-
Notifications
You must be signed in to change notification settings - Fork 20
/
probe.go
40 lines (34 loc) · 964 Bytes
/
probe.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package fluentffmpeg
import (
"encoding/json"
"log"
"os/exec"
"github.com/pkg/errors"
)
var ffprobePath = "ffprobe"
// Probe runs ffprobe with the filePath as input and returns the response as JSON
func Probe(filePath string) (map[string]interface{}, error) {
cmd := exec.Command(ffprobePath, "-of", "json", "-show_streams", "-show_format", filePath)
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
if err := cmd.Start(); err != nil {
return nil, errors.Wrap(err, "Running ffprobe failed")
}
response := make(map[string]interface{})
err = json.NewDecoder(stdout).Decode(&response)
if err != nil {
errors.Wrap(err, "Failed to decode ffprobe data")
return nil, err
}
if err := cmd.Wait(); err != nil {
log.Fatal(err)
return nil, errors.Wrap(err, "Running ffprobe failed")
}
return response, nil
}
// SetFfProbePath sets the path for the ffprobe executable
func SetFfProbePath(path string) {
ffprobePath = path
}