forked from dwoja22/ffmpeg-webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigurator.go
66 lines (53 loc) · 1.08 KB
/
configurator.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"encoding/json"
"errors"
"io/ioutil"
"os/exec"
"strings"
)
type Config struct {
Camera Camera
Server Server
}
func generateConfig() error {
supportedDevices, err := checkDevices()
if err != nil {
return err
}
if len(supportedDevices) < 1 {
return errors.New("no supported devices")
}
var camera Camera
for _, device := range supportedDevices {
out, err := exec.Command("v4l2-ctl", "--device="+device, "-D").Output()
if err != nil {
return err
}
data := processV4l2(string(out))
rawName := strings.Split(data, "\n")[2]
name := strings.Split(rawName, ":")[1]
camera.Name = name
camera.Width = 640
camera.Height = 480
camera.DevicePath = device
//this example supports a stream from a single device
//exit loop on finding one supported device
break
}
server := Server{
Port: ":5000",
}
config := Config{
Camera: camera,
Server: server,
}
j, err := json.MarshalIndent(config, "", " ")
if err != nil {
return err
}
if err := ioutil.WriteFile("config.json", j, 0755); err != nil {
return err
}
return nil
}