Files
core/ffmpeg/skills/v4l2.go
Jan Stabenow eb1cc37456 Add GoSRT & improvements (repo-merge)
Commits (Ingo Oppermann):
- Add experimental SRT connection stats and logs
- Hide /config/reload endpoint in reade-only mode
- Add SRT server
- Create v16 in go.mod
- Fix data races, tests, lint, and update dependencies
- Add trailing slash for routed directories (datarhei/restreamer#340)
- Allow relative URLs in content in static routes

Co-Authored-By: Ingo Oppermann <57445+ioppermann@users.noreply.github.com>
2022-06-23 22:13:58 +02:00

69 lines
1.1 KiB
Go

package skills
import (
"bufio"
"bytes"
"os/exec"
"regexp"
"strings"
)
// DevicesV4L returns a list of available V4L devices
func DevicesV4L() ([]HWDevice, error) {
buf := bytes.NewBuffer(nil)
cmd := exec.Command("v4l2-ctl", "--list-devices")
cmd.Env = []string{}
cmd.Stdout = buf
cmd.Run()
devices := parseV4LDevices(buf)
return devices, nil
}
func parseV4LDevices(data *bytes.Buffer) []HWDevice {
devices := []HWDevice{}
reName := regexp.MustCompile(`^(.*)\((.*?)\):$`)
reDevice := regexp.MustCompile(`/dev/video[0-9]+`)
name := ""
extra := ""
scanner := bufio.NewScanner(data)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
line := scanner.Text()
matches := reDevice.FindStringSubmatch(line)
if matches == nil {
matches = reName.FindStringSubmatch(line)
if matches == nil {
continue
}
name = strings.TrimSpace(matches[1])
extra = matches[2]
continue
}
if name == "" {
continue
}
device := HWDevice{
Id: matches[0],
Name: name,
Extra: extra,
Media: "video",
}
devices = append(devices, device)
}
return devices
}