AlexxIT / WebRTC

Home Assistant custom component for real-time viewing of almost any camera stream using WebRTC and other technologies.
https://github.com/AlexxIT/Blog
MIT License
1.55k stars 183 forks source link

error="streams: codecs not matched ... #739

Closed musapinar closed 3 months ago

musapinar commented 3 months ago

Hello,

Stream works fine in go2rtc through the browser (default port 1984) : 2024-08-10_04h43_34 info link returns json such as

{
  "producers": [
    {
      "url": "rtsp://ccab4aaf-frigate:8554/Garage"
    }
  ],
  "consumers": []
}

This url does not work any better in VLC (it's stuck in a loading loop and does not pop any error)

It fails in HA integration : 2024-08-10_04h39_49

go2rtc logs : 2024-08-10_04h40_09

04:38:54.484 WRN github.com/AlexxIT/go2rtc/internal/webrtc/webrtc.go:240 > error="streams: codecs not matched: H265 => VP8, VP9, H264, OPUS, G722, PCMU, PCMA, S16B, S16L"

Here is my frigate yml:

mqtt:
  enabled: false
  host: 192.168.X.X
  user: username
  password: password
  port: 1883

# Only enable this if you are using GPU pass-through with Intel GPUs
#ffmpeg:
#  hwaccel_args: preset-vaapi

# Only enable the detector if you are using coral PCIe passthrough
#detectors:
#  coral:
#    type: edgetpu
#    device: pci

go2rtc:
  streams:
    Garage:
      - rtsp://usr:pwd@192.168.1.28:554/Streaming/channels/401
      - "ffmpeg:Garage#audio=opus"
    Garage_sub:
      - rtsp://usr:pwd@192.168.1.28:554/Streaming/channels/402
      - "ffmpeg:Garage_sub#audio=opus"
    Porche:
      - rtsp://usr:pwd@192.168.1.28:554/Streaming/channels/301
      - "ffmpeg:Porche#audio=opus"
    Porche_sub:
      - rtsp://usr:pwd@192.168.1.28:554/Streaming/channels/302
      - "ffmpeg:Porche_sub#audio=opus"
    Terrasse:
      - rtsp://usr:pwd@192.168.1.28:554/Streaming/channels/101
      - "ffmpeg:Porche#audio=opus"
    Terrasse_sub:
      - rtsp://usr:pwd@192.168.1.28:554/Streaming/channels/102
      - "ffmpeg:Porche_sub#audio=opus"
#    Allee:
#      - rtsp://usr:pwd@192.168.1.28:554/Streaming/channels/201
#      - "ffmpeg:Porche#audio=opus"
#    Allee_sub:
#      - rtsp://usr:pwd@192.168.1.28:554/Streaming/channels/202
#      - "ffmpeg:Porche_sub#audio=opus"

cameras:
  Garage:
    ffmpeg:
      output_args:
        record: preset-record-generic-audio-copy
      inputs:
        - path: rtsp://127.0.0.1:8554/Garage
          input_args: preset-rtsp-restream
          roles:
            - record
        - path: rtsp://127.0.0.1:8554/Garage_sub
          input_args: preset-rtsp-restream
          roles:
            - detect
    detect:
      enabled: true
      width: 640
      height: 480
  Porche:
    ffmpeg:
      output_args:
        record: preset-record-generic-audio-copy
      inputs:
        - path: rtsp://127.0.0.1:8554/Porche
          input_args: preset-rtsp-restream
          roles:
            - record
        - path: rtsp://127.0.0.1:8554/Porche_sub
          input_args: preset-rtsp-restream
          roles:
            - detect
    detect:
      enabled: true
      width: 640
      height: 480
    objects:
      track:
        - person
        #- car
        - cat
        - dog
#      filters:
#        person:
#          min_score: 0.4
#          threshold: 0.5
#          min_area: 700
    snapshots:
      enabled: true
      timestamp: true
      bounding_box: true
      crop: true
      height: 500
      retain:
        default: 30
    record:
      enabled: false
      retain:
        days: 1
        mode: motion
      events:
        retain:
          default: 14
          mode: motion
        pre_capture: 10
        post_capture: 30
  Terrasse:
    ffmpeg:
      output_args:
        record: preset-record-generic-audio-copy
      inputs:
        - path: rtsp://127.0.0.1:8554/Terrasse
          input_args: preset-rtsp-restream
          roles:
            - record
        - path: rtsp://127.0.0.1:8554/Terrasse_sub
          input_args: preset-rtsp-restream
          roles:
            - detect
    detect:
      enabled: true
      width: 640
      height: 480
#  Allee:
#    ffmpeg:
#      output_args:
#        record: preset-record-generic-audio-copy
#      inputs:
#        - path: rtsp://127.0.0.1:8554/Allee
#          input_args: preset-rtsp-restream
#          roles:
#            - record
#        - path: rtsp://127.0.0.1:8554/Allee_sub
#          input_args: preset-rtsp-restream
#          roles:
#            - detect
#    detect:
#      enabled: true
#      width: 640
#      height: 480

version: 0.14

(only usr:pwd has been redacted)

All rtps links in VLC works fine like this : rtsp://usr:pwd@192.168.1.28:554/Streaming/channels/401 Frigate streams all work fine as well

here is a restart log of Frigate :

...
2024-08-10 02:54:50.736610802  [2024-08-10 04:54:50] frigate.record.cleanup         INFO    : Exiting recording cleanup...
2024-08-10 02:54:50.738661730  [2024-08-10 04:54:50] watchdog.Garage                INFO    : Terminating the existing ffmpeg process...
2024-08-10 02:54:50.739631598  [2024-08-10 04:54:50] watchdog.Garage                INFO    : Waiting for ffmpeg to exit gracefully...
2024-08-10 02:54:50.784457220  [2024-08-10 04:54:50] frigate.object_processing      INFO    : Exiting object processor...
2024-08-10 02:54:50.896055384  [2024-08-10 04:54:50] frigate.app                    INFO    : Waiting for capture process for Porche to stop
2024-08-10 02:54:50.898534821  [2024-08-10 04:54:50] watchdog.Porche                INFO    : Terminating the existing ffmpeg process...
2024-08-10 02:54:50.898543440  [2024-08-10 04:54:50] watchdog.Porche                INFO    : Waiting for ffmpeg to exit gracefully...
2024-08-10 02:54:50.959769009  [2024-08-10 04:54:50] frigate.app                    INFO    : Waiting for capture process for Terrasse to stop
2024-08-10 02:54:50.960831960  [2024-08-10 04:54:50] watchdog.Terrasse              INFO    : Terminating the existing ffmpeg process...
2024-08-10 02:54:50.963861160  [2024-08-10 04:54:50] watchdog.Terrasse              INFO    : Waiting for ffmpeg to exit gracefully...
2024-08-10 02:54:51.035952142  [2024-08-10 04:54:51] frigate.app                    INFO    : Waiting for process for Garage to stop
2024-08-10 02:54:51.254938677  [2024-08-10 04:54:51] frigate.video                  INFO    : Garage: emptying frame queue
2024-08-10 02:54:51.261485613  [2024-08-10 04:54:51] frigate.video                  INFO    : Garage: exiting subprocess
2024-08-10 02:54:51.299593109  [2024-08-10 04:54:51] frigate.app                    INFO    : Closing frame queue for Garage
2024-08-10 02:54:51.676856660  [2024-08-10 04:54:51] frigate.events.maintainer      INFO    : Exiting event processor...
2024-08-10 02:54:51.798482353  [2024-08-10 04:54:51] frigate.app                    INFO    : Waiting for process for Porche to stop
2024-08-10 02:54:52.089134358  [2024-08-10 04:54:52] frigate.video                  INFO    : Porche: emptying frame queue
2024-08-10 02:54:52.090792034  [2024-08-10 04:54:52] frigate.video                  INFO    : Porche: exiting subprocess
2024-08-10 02:54:52.106707805  [2024-08-10 04:54:52] frigate.app                    INFO    : Closing frame queue for Porche
2024-08-10 02:54:52.608884200  [2024-08-10 04:54:52] frigate.app                    INFO    : Waiting for process for Terrasse to stop
2024-08-10 02:54:52.859699279  [2024-08-10 04:54:52] frigate.video                  INFO    : Terrasse: emptying frame queue
2024-08-10 02:54:52.859707799  [2024-08-10 04:54:52] frigate.video                  INFO    : Terrasse: exiting subprocess
2024-08-10 02:54:52.876454301  [2024-08-10 04:54:52] frigate.app                    INFO    : Closing frame queue for Terrasse
2024-08-10 02:54:53.377291382  [2024-08-10 04:54:53] root                           INFO    : Waiting for detection process to exit gracefully...
2024-08-10 02:54:53.378121769  [2024-08-10 04:54:53] detector.cpu                   INFO    : Signal to exit detection process...
2024-08-10 02:54:54.088535123  [2024-08-10 04:54:54] detector.cpu                   INFO    : Exited detection process...
2024-08-10 02:54:54.102794237  [2024-08-10 04:54:54] root                           INFO    : Detection process has exited...
2024-08-10 02:54:54.605601223  [2024-08-10 04:54:54] frigate.app                    INFO    : Detection queue closed
2024-08-10 02:54:55.107178133  [2024-08-10 04:54:55] frigate.app                    INFO    : Detected frames queue closed
2024-08-10 02:54:55.607844924  [2024-08-10 04:54:55] frigate.app                    INFO    : Timeline queue closed
2024-08-10 02:54:57.055421752  [2024-08-10 04:54:57] frigate.output.output          INFO    : exiting output process...
s6-rc: info: service s6rc-fdholder: starting
s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service s6rc-fdholder successfully started
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service log-prepare: starting
s6-rc: info: service log-prepare successfully started
s6-rc: info: service nginx-log: starting
s6-rc: info: service go2rtc-log: starting
s6-rc: info: service frigate-log: starting
s6-rc: info: service certsync-log: starting
s6-rc: info: service go2rtc-log successfully started
s6-rc: info: service go2rtc: starting
s6-rc: info: service nginx-log successfully started
s6-rc: info: service frigate-log successfully started
s6-rc: info: service certsync-log successfully started
s6-rc: info: service go2rtc successfully started
s6-rc: info: service go2rtc-healthcheck: starting
s6-rc: info: service frigate: starting
s6-rc: info: service go2rtc-healthcheck successfully started
s6-rc: info: service frigate successfully started
s6-rc: info: service nginx: starting
2024-08-10 02:55:02.114571773  [INFO] Preparing Frigate...
2024-08-10 02:55:02.128197026  [INFO] Starting NGINX...
2024-08-10 02:55:02.134981822  [INFO] Preparing new go2rtc config...
2024-08-10 02:55:02.166072261  [INFO] Starting Frigate...
2024-08-10 02:55:02.175256796  [INFO] No TLS certificate found. Generating a self signed certificate...
2024-08-10 02:55:02.421233198  [INFO] Got IP address from supervisor: 192.168.1.52
2024-08-10 02:55:02.775620018  [INFO] Got WebRTC port from supervisor: 8585
2024-08-10 02:55:04.130845926  [INFO] Starting go2rtc...
s6-rc: info: service nginx successfully started
s6-rc: info: service certsync: starting
s6-rc: info: service certsync successfully started
s6-rc: info: service legacy-services: starting
2024-08-10 02:55:04.605250488  [INFO] Starting certsync...
s6-rc: info: service legacy-services successfully started
2024-08-10 02:55:04.733240558  04:55:04.728 INF go2rtc platform=linux/amd64 revision=b2399f3 version=1.9.2
2024-08-10 02:55:04.733249493  04:55:04.730 INF config path=/dev/shm/go2rtc.yaml
2024-08-10 02:55:04.733256118  04:55:04.732 INF [api] listen addr=:1984
2024-08-10 02:55:04.737251975  04:55:04.737 INF [rtsp] listen addr=:8554
2024-08-10 02:55:04.741486034  04:55:04.741 INF [webrtc] listen addr=:8555/tcp
2024-08-10 02:55:04.996380877  127.0.0.1 - - [10/Aug/2024:04:55:04 +0200] "" 400 0 "-" "-" "-"
2024-08-10 02:55:06.996479834  2024/08/10 04:55:06 [error] 168#168: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: , request: "GET /api/version HTTP/1.1", subrequest: "/auth", upstream: "http://127.0.0.1:5001/auth", host: "127.0.0.1:5000"
2024-08-10 02:55:06.996485757  2024/08/10 04:55:06 [error] 168#168: *2 auth request unexpected status: 502 while sending to client, client: 127.0.0.1, server: , request: "GET /api/version HTTP/1.1", host: "127.0.0.1:5000"
2024-08-10 02:55:07.985893688  [2024-08-10 04:55:07] frigate.app                    INFO    : Starting Frigate (0.14.0-da913d8)
2024-08-10 02:55:07.986871123  [2024-08-10 04:55:07] frigate.app                    INFO    : Creating directory: /tmp/cache
2024-08-10 02:55:07.987700244  [2024-08-10 04:55:07] frigate.util.config            INFO    : Checking if frigate config needs migration...
2024-08-10 02:55:08.086592562  [2024-08-10 04:55:08] frigate.util.config            INFO    : frigate config does not need migration...
2024-08-10 02:55:08.098572610  2024/08/10 04:55:08 [error] 169#169: *4 connect() failed (111: Connection refused) while connecting to upstream, client: 172.30.32.2, server: , request: "GET /ws HTTP/1.1", subrequest: "/auth", upstream: "http://127.0.0.1:5001/auth", host: "hass.redacted_by_musa.com"
2024-08-10 02:55:08.098584470  2024/08/10 04:55:08 [error] 169#169: *4 auth request unexpected status: 502 while sending to client, client: 172.30.32.2, server: , request: "GET /ws HTTP/1.1", host: "hass.redacted_by_musa.com"
2024-08-10 02:55:08.098595610  172.30.32.2 - - [10/Aug/2024:04:55:08 +0200] "GET /ws HTTP/1.1" 500 579 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" "127.0.0.1, 172.30.32.1"
2024-08-10 02:55:08.221552551  [2024-08-10 04:55:08] frigate.util.services          WARNING : Did not detect hwaccel, using a GPU for accelerated video decoding is highly recommended
2024-08-10 02:55:08.294536528  [2024-08-10 04:55:08] peewee_migrate.logs            INFO    : Starting migrations
2024-08-10 02:55:08.297729730  [2024-08-10 04:55:08] peewee_migrate.logs            INFO    : There is nothing to migrate
2024-08-10 02:55:08.312532416  [2024-08-10 04:55:08] frigate.app                    INFO    : Recording process started: 287
2024-08-10 02:55:08.327552231  [2024-08-10 04:55:08] frigate.app                    INFO    : Recording process started: 289
2024-08-10 02:55:08.349704047  [2024-08-10 04:55:08] frigate.app                    INFO    : go2rtc process pid: 98
2024-08-10 02:55:08.483238818  [2024-08-10 04:55:08] detector.cpu                   INFO    : Starting detection process: 315
2024-08-10 02:55:08.489412094  [2024-08-10 04:55:08] frigate.app                    INFO    : Output process started: 317
2024-08-10 02:55:08.498713682  [2024-08-10 04:55:08] frigate.detectors              WARNING : CPU detectors are not recommended and should only be used for testing or for trial purposes.
2024-08-10 02:55:08.622642510  [2024-08-10 04:55:08] frigate.app                    INFO    : Camera processor started for Garage: 332
2024-08-10 02:55:08.660554129  [2024-08-10 04:55:08] frigate.app                    INFO    : Camera processor started for Porche: 333
2024-08-10 02:55:08.730557290  [2024-08-10 04:55:08] frigate.app                    INFO    : Camera processor started for Terrasse: 341
2024-08-10 02:55:08.733653743  [2024-08-10 04:55:08] frigate.app                    INFO    : Capture process started for Garage: 349
2024-08-10 02:55:08.755694408  [2024-08-10 04:55:08] frigate.app                    INFO    : Capture process started for Porche: 359
2024-08-10 02:55:08.776041987  [2024-08-10 04:55:08] frigate.app                    INFO    : Capture process started for Terrasse: 362
2024-08-10 02:55:12.116262987  [INFO] Starting go2rtc healthcheck service...
2024-08-10 02:55:50.503336697  172.30.32.2 - - [10/Aug/2024:04:55:50 +0200] "GET / HTTP/1.1" 200 2651 "-" "HomeAssistantSupervisor/2024.08.0 aiohttp/3.9.5 Python/3.12" "-"
2024-08-10 02:56:05.195225457  127.0.0.1 - - [10/Aug/2024:04:56:05 +0200] "" 400 0 "-" "-" "-"
2024-08-10 02:56:34.149266684  172.30.32.2 - - [10/Aug/2024:04:56:34 +0200] "GET /ws HTTP/1.1" 101 9212 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" "127.0.0.1, 172.30.32.1"
2024-08-10 02:57:05.330251181  127.0.0.1 - - [10/Aug/2024:04:57:05 +0200] "" 400 0 "-" "-" "-"

I would like to use the "restream" output in HA instead of the rtsp direct links. Thank you for your help.

musapinar commented 3 months ago

also, ports config in Frigate : 2024-08-10_05h02_32

(Had to change the Frigate defaults because go2rtc already use 8555 and 8554 thus Frigate would refuse to start)

AlexxIT commented 3 months ago

https://github.com/AlexxIT/go2rtc#codecs-madness

musapinar commented 3 months ago

Switching the codec on the NVR from H265 to H264 solved the issue indeed. Thank you.