Repository: blakeblackshear/frigate

Issue:
[Support]: ERROR : Option user_agent not found.
### Describe the problem you are having

After updating to the latest Dev version Frigate fails to start with an error: ERROR : Option user_agent not found.

Reverting back to dev-5ad3919 makes it work again.

### Version

dev-007fa75

### Frigate config file

```yaml
mqtt:
  host: 192.168.1.76
  user: frigate
  password: *

detectors:
  coral:
    type: edgetpu
    device: usb

detect:
  width: 640
  height: 480
  fps: 10
  max_disappeared: 100
  stationary:
    interval: 100

record:
  enabled: True
  retain:
    days: 6
    mode: all
  events:
    pre_capture: 45
    post_capture: 45
    objects:
      - person
    retain:
      default: 14
      mode: active_objects

objects:
  track:
    - person

snapshots:
  enabled: True
  bounding_box: True
  retain:
    default: 14

rtmp:
  enabled: False

ffmpeg:
  output_args:
    record: -f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:v copy -c:a aac

cameras:
  front:
    ffmpeg:
      inputs:
        - path: rtsp://*@192.168.20.25:554//h265Preview_01_main
          roles:
            - record
            - restream
        - path: rtsp://*@192.168.20.25:554//h264Preview_01_sub
          roles:
            - detect
    detect:
      width: 640
      height: 360
    motion:
      mask:
        - 0,360,0,0,640,0,640,293,527,145,535,83,365,38,256,41
    zones:
      drive:
        coordinates: 0,360,149,151,276,42,346,38,396,52,467,36,640,0,640,360
    record:
      events:
        required_zones:
          - drive
    snapshots:
      required_zones:
        - drive

  garage:
    ffmpeg:
      hwaccel_args: preset-rpi-64-h264
      input_args: preset-rtmp-generic
      inputs:
        - path: rtmp://192.168.20.13/bcs/channel0_main.bcs?channel=0&stream=0&user=*&password=*
          roles:
            - record
            - restream
        - path: rtmp://192.168.20.13/bcs/channel0_sub.bcs?channel=0&stream=0&user=*&password=*
          roles:
            - detect
    motion:
      mask:
        - 640,0,303,0,184,0,0,0,0,90,105,89,113,169,276,183,347,81,539,106,640,204
    zones:
      drive:
        coordinates: 640,480,0,480,0,206,269,228,349,82,520,104,640,268
      front_lawn:
        coordinates: 164,72,0,90,0,200,145,220,260,212,338,72
    record:
      events:
        required_zones:
          - drive
          - front_lawn
    snapshots:
      required_zones:
        - drive
        - front_lawn

  rear:
    ffmpeg:
      hwaccel_args: preset-rpi-64-h264
      input_args: preset-rtmp-generic
      inputs:
        - path: rtmp://192.168.20.14/bcs/channel0_main.bcs?channel=0&stream=0&user=*&password=*
          roles:
            - record
            - restream
        - path: rtmp://192.168.20.14/bcs/channel0_sub.bcs?channel=0&stream=0&user=*&password=*
          roles:
            - detect
    motion:
      mask:
        - 225,171,155,237,67,155,55,0,255,0

  garden:
    ffmpeg:
      hwaccel_args: preset-rpi-64-h264
      input_args: preset-rtmp-generic
      inputs:
        - path: rtmp://192.168.20.16/bcs/channel0_main.bcs?channel=0&stream=0&user=*&password=*
          roles:
            - record
            - restream
        - path: rtmp://192.168.20.16/bcs/channel0_sub.bcs?channel=0&stream=0&user=*&password=*
          roles:
            - detect
    motion:
      mask:
        - 0,0,0,34,484,83,435,356,640,480,640,55,640,0
    zones:
      grass:
        coordinates: 25,139,154,108,504,192,416,450,0,266,115,201,30,178
```


### Relevant log output

```shell
[2022-12-04 13:58:55] watchdog.rear                  ERROR   : The following ffmpeg logs include the last 100 lines prior to exit.
[2022-12-04 13:58:55] ffmpeg.rear.detect             ERROR   : Option user_agent not found.
[2022-12-04 13:58:55] ffmpeg.rear.record_restream    ERROR   : Option user_agent not found.
[2022-12-04 13:58:55] watchdog.rear                  INFO    : Terminating the existing ffmpeg process...
[2022-12-04 13:58:55] watchdog.rear                  INFO    : Waiting for ffmpeg to exit gracefully...
[2022-12-04 13:58:55] watchdog.garden                ERROR   : Ffmpeg process crashed unexpectedly for garden.
[2022-12-04 13:58:55] watchdog.garden                ERROR   : The following ffmpeg logs include the last 100 lines prior to exit.
[2022-12-04 13:58:55] ffmpeg.garden.detect           ERROR   : Option user_agent not found.
[2022-12-04 13:58:55] ffmpeg.garden.record_restream  ERROR   : Option user_agent not found.
[2022-12-04 13:58:55] watchdog.garden                INFO    : Terminating the existing ffmpeg process...
[2022-12-04 13:58:55] watchdog.garden                INFO    : Waiting for ffmpeg to exit gracefully...
```


### FFprobe output from your camera

```shell
pi@raspberrypi:~ $ docker exec frigate ffprobe "rtmp://192.168.20.13/bcs/channel0_main.bcs?channel=0&stream=0&user=*&password=*"
ffprobe version n5.1-2-g915ef932a3-20220731 Copyright (c) 2007-2022 the FFmpeg developers
  built with gcc 12.1.0 (crosstool-NG 1.25.0.55_3defb7b)
  configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=aarch64-ffbuild-linux-gnu- --arch=aarch64 --target-os=linux --enable-gpl --enable-version3 --disable-debug --enable-iconv --enable-libxml2 --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvorbis --enable-opencl --enable-libpulse --enable-libvmaf --enable-libxcb --enable-xlib --enable-amf --enable-libaom --enable-libaribb24 --enable-avisynth --enable-libdav1d --disable-libdavs2 --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libgme --enable-libass --enable-libbluray --enable-libjxl --enable-libmp3lame --enable-libopus --enable-mbedtls --enable-librist --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --disable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-librav1e --enable-librubberband --disable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --enable-libdrm --disable-vaapi --enable-libvidstab --enable-vulkan --enable-libshaderc --enable-libplacebo --enable-libx264 --enable-libx265 --disable-libxavs2 --enable-libxvid --enable-libzimg --enable-libzvbi --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-ldexeflags=-pie --extra-libs='-ldl -lgomp' --extra-version=20220731
  libavutil      57. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  libavdevice    59.  7.100 / 59.  7.100
  libavfilter     8. 44.100 /  8. 44.100
  libswscale      6.  7.100 /  6.  7.100
  libswresample   4.  7.100 /  4.  7.100
  libpostproc    56.  6.100 / 56.  6.100
Input #0, flv, from 'rtmp://192.168.20.13/bcs/channel0_main.bcs?channel=0&stream=0&user=*&password=*':
  Metadata:
    |RtmpSampleAccess: true
    displayWidth    : 2560
    displayHeight   : 1920
  Duration: 00:00:00.00, start: 44293.392000, bitrate: N/A
  Stream #0:0: Video: h264 (High), yuv420p(progressive), 2560x1920, 29 fps, 30 tbr, 1k tbn
  Stream #0:1: Audio: aac (LC), 16000 Hz, mono, fltp
```


### Frigate stats

```json
{"cpu_usages":{"%Cpu(s):":{"cpu":"id,","mem":"2.0"},"1":{"cpu":"0.0","mem":"0.0"},"101":{"cpu":"2.0","mem":"1.1"},"105":{"cpu":"0.0","mem":"1.1"},"107":{"cpu":"0.0","mem":"0.1"},"108":{"cpu":"0.0","mem":"1.1"},"109":{"cpu":"0.0","mem":"0.1"},"110":{"cpu":"0.0","mem":"1.1"},"111":{"cpu":"2.7","mem":"1.0"},"112":{"cpu":"0.0","mem":"0.1"},"113":{"cpu":"0.0","mem":"1.1"},"116":{"cpu":"0.0","mem":"0.1"},"117":{"cpu":"0.0","mem":"1.1"},"118":{"cpu":"5.3","mem":"0.4"},"120":{"cpu":"0.0","mem":"1.1"},"126":{"cpu":"0.0","mem":"0.1"},"128":{"cpu":"12.6","mem":"0.3"},"14":{"cpu":"0.0","mem":"0.0"},"15":{"cpu":"0.0","mem":"0.0"},"17":{"cpu":"0.0","mem":"0.0"},"24":{"cpu":"0.0","mem":"0.0"},"25":{"cpu":"0.0","mem":"0.0"},"31":{"cpu":"0.0","mem":"0.0"},"528":{"cpu":"0.0","mem":"0.0"},"532":{"cpu":"0.0","mem":"0.0"},"534":{"cpu":"0.0","mem":"0.0"},"541":{"cpu":"0.0","mem":"0.0"},"62":{"cpu":"0.0","mem":"0.0"},"63":{"cpu":"0.0","mem":"0.0"},"65":{"cpu":"0.0","mem":"0.2"},"66":{"cpu":"0.0","mem":"0.2"},"73":{"cpu":"1.7","mem":"2.2"},"75":{"cpu":"0.0","mem":"0.1"},"89":{"cpu":"0.0","mem":"1.0"},"95":{"cpu":"0.3","mem":"0.1"},"96":{"cpu":"0.0","mem":"1.3"},"98":{"cpu":"1.0","mem":"1.1"},"MiB":{"cpu":"5717.8","mem":"avail"},"PID":{"cpu":"%CPU","mem":"%MEM"},"Tasks:":{"cpu":"stopped,","mem":"3"},"top":{"cpu":"load","mem":"average:"}},"detection_fps":0.0,"detectors":{"coral":{"detection_start":0.0,"inference_speed":14.7,"pid":96}},"front":{"camera_fps":10.0,"capture_pid":111,"detection_fps":0.0,"ffmpeg_pid":118,"pid":101,"process_fps":10.0,"skipped_fps":0.0},"garage":{"camera_fps":0.0,"capture_pid":113,"detection_fps":0.0,"ffmpeg_pid":526,"pid":105,"process_fps":0.0,"skipped_fps":0.0},"garden":{"camera_fps":0.0,"capture_pid":120,"detection_fps":0.0,"ffmpeg_pid":531,"pid":110,"process_fps":0.0,"skipped_fps":0.0},"gpu_usages":{"rpi-v4l2m2m":{"gpu":-1,"mem":-1}},"rear":{"camera_fps":0.0,"capture_pid":117,"detection_fps":0.0,"ffmpeg_pid":529,"pid":108,"process_fps":0.0,"skipped_fps":0.0},"service":{"latest_version":"0.11.1","storage":{"/dev/shm":{"free":267.1,"mount_type":"tmpfs","total":268.4,"used":1.3},"/media/frigate/clips":{"free":1966794.1,"mount_type":"ext4","total":1967846.1,"used":1035.2},"/media/frigate/recordings":{"free":1966794.1,"mount_type":"ext4","total":1967846.1,"used":1035.2},"/tmp/cache":{"free":1989.8,"mount_type":"tmpfs","total":2000.0,"used":10.2}},"temperatures":{},"uptime":331,"version":"0.12.0-007fa75"}}
```


### Operating system

Debian

### Install method

Docker Compose

### Coral version

USB

### Network connection

Wired

### Camera make and model

Reolink

### Any other information that may be helpful

_No response_


Discussion:
Hmm, might need to only add this option for rtsp streams and not make it a constant option. 

For now you can simply overwrite the global args for that camera

cc @felipecrs 
Hm, I think I have a better idea. Which is to include it in the rtsp input presets only. What do you think?
> Hm, I think I have a better idea. Which is to include it in the rtsp input presets only. What do you think?

Ah yeah that makes sense

Resolving patch:
diff --git a/frigate/config.py b/frigate/config.py
--- a/frigate/config.py
+++ b/frigate/config.py
@@ -359,13 +359,7 @@ class BirdseyeCameraConfig(BaseModel):
     )
 
 
-FFMPEG_GLOBAL_ARGS_DEFAULT = [
-    "-hide_banner",
-    "-loglevel",
-    "warning",
-    "-user_agent",
-    f"FFmpeg Frigate/{VERSION}",
-]
+FFMPEG_GLOBAL_ARGS_DEFAULT = ["-hide_banner", "-loglevel", "warning"]
 FFMPEG_INPUT_ARGS_DEFAULT = [
     "-avoid_negative_ts",
     "make_zero",
diff --git a/frigate/ffmpeg_presets.py b/frigate/ffmpeg_presets.py
--- a/frigate/ffmpeg_presets.py
+++ b/frigate/ffmpeg_presets.py
@@ -2,6 +2,12 @@
 
 from typing import Any
 
+from frigate.version import VERSION
+
+_user_agent_args = [
+    "-user_agent",
+    f"FFmpeg Frigate/{VERSION}",
+]
 
 PRESETS_HW_ACCEL = {
     "preset-rpi-32-h264": ["-c:v", "h264_v4l2m2m"],
@@ -39,7 +45,8 @@ def parse_preset_hardware_acceleration(arg: Any) -> list[str]:
 
 
 PRESETS_INPUT = {
-    "preset-http-jpeg-generic": [
+    "preset-http-jpeg-generic": _user_agent_args
+    + [
         "-r",
         "{}",
         "-stream_loop",
@@ -59,7 +66,8 @@ def parse_preset_hardware_acceleration(arg: Any) -> list[str]:
         "-use_wallclock_as_timestamps",
         "1",
     ],
-    "preset-http-mjpeg-generic": [
+    "preset-http-mjpeg-generic": _user_agent_args
+    + [
         "-avoid_negative_ts",
         "make_zero",
         "-fflags",
@@ -73,7 +81,8 @@ def parse_preset_hardware_acceleration(arg: Any) -> list[str]:
         "-use_wallclock_as_timestamps",
         "1",
     ],
-    "preset-http-reolink": [
+    "preset-http-reolink": _user_agent_args
+    + [
         "-avoid_negative_ts",
         "make_zero",
         "-fflags",
@@ -107,7 +116,8 @@ def parse_preset_hardware_acceleration(arg: Any) -> list[str]:
         "-f",
         "live_flv",
     ],
-    "preset-rtsp-generic": [
+    "preset-rtsp-generic": _user_agent_args
+    + [
         "-avoid_negative_ts",
         "make_zero",
         "-fflags",
@@ -119,7 +129,8 @@ def parse_preset_hardware_acceleration(arg: Any) -> list[str]:
         "-use_wallclock_as_timestamps",
         "1",
     ],
-    "preset-rtsp-udp": [
+    "preset-rtsp-udp": _user_agent_args
+    + [
         "-avoid_negative_ts",
         "make_zero",
         "-fflags",
@@ -131,7 +142,10 @@ def parse_preset_hardware_acceleration(arg: Any) -> list[str]:
         "-use_wallclock_as_timestamps",
         "1",
     ],
-    "preset-rtsp-blue-iris": [
+    "preset-rtsp-blue-iris": _user_agent_args
+    + [
+        "-user_agent",
+        f"FFmpeg Frigate/{VERSION}",
         "-avoid_negative_ts",
         "make_zero",
         "-flags",


Test patch:
diff --git a/frigate/test/test_ffmpeg_presets.py b/frigate/test/test_ffmpeg_presets.py
--- a/frigate/test/test_ffmpeg_presets.py
+++ b/frigate/test/test_ffmpeg_presets.py
@@ -76,8 +76,9 @@ def test_default_ffmpeg_input_arg_preset(self):
         frigate_config.cameras["back"].create_ffmpeg_cmds()
         frigate_preset_config.cameras["back"].create_ffmpeg_cmds()
         assert (
-            frigate_preset_config.cameras["back"].ffmpeg_cmds[0]["cmd"]
-            == frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"]
+            # Ignore global and user_agent args in comparison
+            frigate_preset_config.cameras["back"].ffmpeg_cmds[0]["cmd"][6::]
+            == frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"][4::]
         )
 
     def test_ffmpeg_input_preset(self):