diff --git a/internal/app/README.md b/internal/app/README.md new file mode 100644 index 00000000..e3d0571f --- /dev/null +++ b/internal/app/README.md @@ -0,0 +1,54 @@ +- By default go2rtc will search config file `go2rtc.yaml` in current work directory +- go2rtc support multiple config files +- go2rtc support inline config as `YAML`, `JSON` or `key=value` format from command line +- Every next config will overwrite previous (but only defined params) + +``` +go2rtc -config "{log: {format: text}}" -config /config/go2rtc.yaml -config "{rtsp: {listen: ''}}" -config /usr/local/go2rtc/go2rtc.yaml +``` + +or simple version + +``` +go2rtc -c log.format=text -c /config/go2rtc.yaml -c rtsp.listen='' -c /usr/local/go2rtc/go2rtc.yaml +``` + +## Environment variables + +Also go2rtc support templates for using environment variables in any part of config: + +```yaml +streams: + camera1: rtsp://rtsp:${CAMERA_PASSWORD}@192.168.1.123/av_stream/ch0 + + ${LOGS:} # empty default value + +rtsp: + username: ${RTSP_USER:admin} # "admin" if env "RTSP_USER" not set + password: ${RTSP_PASS:secret} # "secret" if env "RTSP_PASS" not set +``` + +## Defaults + +```yaml +api: + listen: ":1984" + +ffmpeg: + bin: "ffmpeg" + +log: + level: "info" + +rtsp: + listen: ":8554" + default_query: "video&audio" + +srtp: + listen: ":8443" + +webrtc: + listen: ":8555/tcp" + ice_servers: + - urls: [ "stun:stun.l.google.com:19302" ] +``` \ No newline at end of file diff --git a/internal/app/app.go b/internal/app/app.go index 6afaebb4..08594e2e 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -79,22 +79,26 @@ func Init() { } for _, conf := range confs { - if conf[0] != '{' { + if len(conf) == 0 { + continue + } + if conf[0] == '{' { + // config as raw YAML or JSON + configs = append(configs, []byte(conf)) + } else if data := parseConfString(conf); data != nil { + configs = append(configs, data) + } else { // config as file if ConfigPath == "" { ConfigPath = conf } - data, _ := os.ReadFile(conf) - if data == nil { + if data, _ = os.ReadFile(conf); data == nil { continue } data = []byte(shell.ReplaceEnvVars(string(data))) configs = append(configs, data) - } else { - // config as raw YAML - configs = append(configs, []byte(conf)) } } @@ -190,3 +194,25 @@ func readRevisionTime() (revision, vcsTime string) { } return } + +func parseConfString(s string) []byte { + i := strings.IndexByte(s, '=') + if i < 0 { + return nil + } + + items := strings.Split(s[:i], ".") + if len(items) < 2 { + return nil + } + + // `log.level=trace` => `{log: {level: trace}}` + var pre string + var suf = s[i+1:] + for _, item := range items { + pre += "{" + item + ": " + suf += "}" + } + + return []byte(pre + suf) +}