Repository: blakeblackshear/frigate

Issue:
[Config Support]: Docker fails to start with KeyError: 'go2rtc'
### Describe the problem you are having

Starting an instance of frigate with a minimal config gives error `KeyError: 'go2rtc'`

Config file was based on the startup walk though from DOCs https://deploy-preview-4055--frigate-docs.netlify.app/guides/getting_started

Not sure if its a doc or build issue. Also tried putting in basic restream config and getting same error

### Version

v0.12.0-beta4

### Frigate config file

```yaml
mqtt:
  enabled: false

cameras:
  camera_1:
    ffmpeg:
      inputs:
        - path: rtsp://10.0.20.102:554/s0
          roles:
            - detect
      hwaccel_args: -c:v h264_cuvid
    detect:
      width: 1920
      height: 1080
```


### Relevant log output

```shell
docker-compose up
Pulling frigate (ghcr.io/blakeblackshear/frigate:0.12.0-beta4-tensorrt)...
0.12.0-beta4-tensorrt: Pulling from blakeblackshear/frigate
8740c948ffd4: Pull complete
b84a1ada9828: Pull complete
832b257640b7: Pull complete
60beb73d7e76: Pull complete
8e29f3174a08: Pull complete
4b46f368fd71: Pull complete
b651bc39c0a3: Pull complete
43b988f71200: Pull complete
Digest: sha256:7010839f6794a5d21a98bc9088400fdc3c382e089539f0409e0cec1ca64473fa
Status: Downloaded newer image for ghcr.io/blakeblackshear/frigate:0.12.0-beta4-tensorrt
Creating frigate ... done
Attaching to frigate
frigate    | s6-rc: info: service s6rc-oneshot-runner: starting
frigate    | s6-rc: info: service s6rc-oneshot-runner successfully started
frigate    | s6-rc: info: service fix-attrs: starting
frigate    | s6-rc: info: service fix-attrs successfully started
frigate    | s6-rc: info: service legacy-cont-init: starting
frigate    | cont-init: info: running /etc/cont-init.d/prepare-logs.sh
frigate    | cont-init: info: /etc/cont-init.d/prepare-logs.sh exited 0
frigate    | s6-rc: info: service legacy-cont-init successfully started
frigate    | s6-rc: info: service legacy-services: starting
frigate    | services-up: info: copying legacy longrun frigate (no readiness notification)
frigate    | services-up: info: copying legacy longrun go2rtc (no readiness notification)
frigate    | services-up: info: copying legacy longrun nginx (no readiness notification)
frigate    | s6-rc: info: service legacy-services successfully started
frigate    | Traceback (most recent call last):
frigate    |   File "/usr/local/go2rtc/create_config.py", line 23, in <module>
frigate    |     go2rtc_config: dict[str, any] = config["go2rtc"]
frigate    | KeyError: 'go2rtc'
frigate    | s6-rc: info: service legacy-services: stopping
frigate    | s6-svwait: fatal: supervisor died
frigate    | s6-rc: info: service legacy-services successfully stopped
frigate    | s6-rc: info: service legacy-cont-init: stopping
frigate    | s6-rc: info: service legacy-cont-init successfully stopped
frigate    | s6-rc: info: service fix-attrs: stopping
frigate    | s6-rc: info: service fix-attrs successfully stopped
frigate    | s6-rc: info: service s6rc-oneshot-runner: stopping
frigate    | s6-rc: info: service s6rc-oneshot-runner successfully stopped
```


### Frigate stats

```json
N/A Frigate doesn't start
```


### Operating system

Other Linux

### Install method

Docker Compose

### Coral version

CPU (no coral)

### Any other information that may be helpful

Using a basic restream config:
``` yaml
mqtt:
  enabled: false

  #detectors:
  #tensorrt:
  #  type: tensorrt
  #  device: 0 #This is the default, select the first GPU

go2rtc:
  streams:
    test_cam: ffmpeg:rtsp://10.0.20.102:554/s0

cameras:
  camera_1:
    ffmpeg:
      inputs:
        - path: rtsp://127.0.0.1:8554/test_cam?video=copy
          input_args: preset-rtsp-restream
          roles:
            - detect
      hwaccel_args: -c:v h264_cuvid
    detect:
      width: 1920
      height: 1080
```
results in the same error


Discussion:

Resolving patch:
diff --git a/docker/rootfs/usr/local/go2rtc/create_config.py b/docker/rootfs/usr/local/go2rtc/create_config.py
--- a/docker/rootfs/usr/local/go2rtc/create_config.py
+++ b/docker/rootfs/usr/local/go2rtc/create_config.py
@@ -5,6 +5,7 @@
 import yaml
 
 
+BTBN_PATH = "/usr/lib/btbn-ffmpeg"
 config_file = os.environ.get("CONFIG_FILE", "/config/config.yml")
 
 # Check if we can use .yaml instead of .yml
@@ -20,12 +21,27 @@
 elif config_file.endswith(".json"):
     config = json.loads(raw_config)
 
-go2rtc_config: dict[str, any] = config["go2rtc"]
+go2rtc_config: dict[str, any] = config.get("go2rtc", {})
 
-if not go2rtc_config.get("log", {}).get("format"):
+# we want to ensure that logs are easy to read
+if go2rtc_config.get("log") is None:
     go2rtc_config["log"] = {"format": "text"}
+elif go2rtc_config["log"].get("format") is None:
+    go2rtc_config["log"]["format"] = "text"
 
+# should set default stun server so webrtc can work
 if not go2rtc_config.get("webrtc", {}).get("candidates", []):
     go2rtc_config["webrtc"] = {"candidates": ["stun:8555"]}
 
-print(json.dumps(go2rtc_config))
\ No newline at end of file
+# need to replace ffmpeg command when using ffmpeg4
+if not os.path.exists(BTBN_PATH):
+    if go2rtc_config.get("ffmpeg") is None:
+        go2rtc_config["ffmpeg"] = {
+            "rtsp": "-fflags nobuffer -flags low_delay -stimeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i {input}"
+        }
+    elif go2rtc_config["ffmpeg"].get("rtsp") is None:
+        go2rtc_config["ffmpeg"][
+            "rtsp"
+        ] = "-fflags nobuffer -flags low_delay -stimeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i {input}"
+
+print(json.dumps(go2rtc_config))


Test patch: