mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-10-29 19:02:15 +08:00
64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
package device
|
|
|
|
import (
|
|
"bytes"
|
|
"github.com/AlexxIT/go2rtc/pkg/streamer"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
// https://trac.ffmpeg.org/wiki/Capture/Webcam
|
|
const deviceInputPrefix = "-f avfoundation"
|
|
|
|
func deviceInputSuffix(videoIdx, audioIdx int) string {
|
|
video := findMedia(streamer.KindVideo, videoIdx)
|
|
audio := findMedia(streamer.KindAudio, audioIdx)
|
|
switch {
|
|
case video != nil && audio != nil:
|
|
return `"` + video.Title + `:` + audio.Title + `"`
|
|
case video != nil:
|
|
return `"` + video.Title + `"`
|
|
case audio != nil:
|
|
return `"` + audio.Title + `"`
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func loadMedias() {
|
|
cmd := exec.Command(
|
|
Bin, "-hide_banner", "-list_devices", "true", "-f", "avfoundation", "-i", "dummy",
|
|
)
|
|
|
|
var buf bytes.Buffer
|
|
cmd.Stderr = &buf
|
|
_ = cmd.Run()
|
|
|
|
var kind string
|
|
|
|
lines := strings.Split(buf.String(), "\n")
|
|
process:
|
|
for _, line := range lines {
|
|
switch {
|
|
case strings.HasSuffix(line, "video devices:"):
|
|
kind = streamer.KindVideo
|
|
continue
|
|
case strings.HasSuffix(line, "audio devices:"):
|
|
kind = streamer.KindAudio
|
|
continue
|
|
case strings.HasPrefix(line, "dummy"):
|
|
break process
|
|
}
|
|
|
|
// [AVFoundation indev @ 0x7fad54604380] [0] FaceTime HD Camera
|
|
name := line[42:]
|
|
media := loadMedia(kind, name)
|
|
medias = append(medias, media)
|
|
}
|
|
}
|
|
|
|
func loadMedia(kind, name string) *streamer.Media {
|
|
return &streamer.Media{
|
|
Kind: kind, Title: name,
|
|
}
|
|
}
|