Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native WebRTC and URL Template #797

Open
coserotondo opened this issue Dec 2, 2024 · 8 comments
Open

Native WebRTC and URL Template #797

coserotondo opened this issue Dec 2, 2024 · 8 comments

Comments

@coserotondo
Copy link

Home Assistant:
Core 2024.11.3
Supervisor 2024.11.4
Operating System 13.2
Frontend 20241106.2

Frigate (standalone):
0.14.1

frigate-hass-integration:
5.5.1

To leverage WebRTC, I created new streams with go2rtc in frigate configuration with H264 transcoding. The streams are not used by Frigate itself but I put this RTSP URL template in the integration configuration to point to the new "live" streams:
rtsp://frigate.home.arpa:8554/{{name}}_live

  1. The streams work in RTC (I used Chrome WebRTC debug) both in the camera entities and in the integration.
  2. There is no delay in the streaming (I can see the streamlined clock timestamp overlay and there is no buffering) but the streams start initially at a lower ratio/resolution, for 3 or 4 seconds and then go to full resolution.
  3. If I use the Native Frigate WebRTC in the integration, the template URL is ignored and it point to a non existant stream:
    aiohttp.client_exceptions.ContentTypeError: 500, message='Attempt to decode JSON with unexpected mimetype: text/plain; charset=utf-8', url='http://frigate.home.arpa:5000/api/go2rtc/webrtc?src=<camera_name>'
  4. If then I want to delete the Template URL, blanking it, it is not eliminated: I have to put a space in the input field.

Effectively the stream does not exist neither if I manually add the "_live" stream that exist in go2rtc inside frigate.

Go2rtc configuration in Frigate:

go2rtc:
  streams:
    ingresso_ovest:
      - rtsp://{FRIGATE_RTSP_USER}:{FRIGATE_RTSP_PASSWORD}@192.168.210.3:554/chID=1&streamType=main&linkType=tcp#media=video
    ingresso_ovest_live:
      - ffmpeg:rtsp://127.0.0.1:8554/ingresso_ovest#video=h264#hardware=vaapi
    ingresso_ovest_sub:
      - rtsp://{FRIGATE_RTSP_USER}:{FRIGATE_RTSP_PASSWORD}@192.168.210.3:554/chID=1&streamType=sub&linkType=tcp#media=video
    giardino:
      - rtsp://{FRIGATE_RTSP_USER}:{FRIGATE_RTSP_PASSWORD}@192.168.210.3:554/chID=2&streamType=main&linkType=tcp#media=video
    giardino_live:
      - ffmpeg:rtsp://127.0.0.1:8554/giardino#video=h264#hardware=vaapi
    giardino_sub:
      - rtsp://{FRIGATE_RTSP_USER}:{FRIGATE_RTSP_PASSWORD}@192.168.210.3:554/chID=2&streamType=sub&linkType=tcp#media=video
    vialetto_sud:
      - rtsp://{FRIGATE_RTSP_USER}:{FRIGATE_RTSP_PASSWORD}@192.168.210.3:554/chID=3&streamType=main&linkType=tcp#media=video
    vialetto_sud_live:
      - ffmpeg:rtsp://127.0.0.1:8554/vialetto_sud#video=h264#hardware=vaapi
    vialetto_sud_sub:
      - rtsp://{FRIGATE_RTSP_USER}:{FRIGATE_RTSP_PASSWORD}@192.168.210.3:554/chID=3&streamType=sub&linkType=tcp#media=video
    vialetto_nord:
      - rtsp://{FRIGATE_RTSP_USER}:{FRIGATE_RTSP_PASSWORD}@192.168.210.3:554/chID=4&streamType=main&linkType=tcp#media=video
    vialetto_nord_live:
      - ffmpeg:rtsp://127.0.0.1:8554/vialetto_nord#video=h264#hardware=vaapi
    vialetto_nord_sub:
      - rtsp://{FRIGATE_RTSP_USER}:{FRIGATE_RTSP_PASSWORD}@192.168.210.3:554/chID=4&streamType=sub&linkType=tcp#media=video
    ingresso_est:
      - rtsp://{FRIGATE_RTSP_USER}:{FRIGATE_RTSP_PASSWORD}@192.168.210.3:554/chID=5&streamType=main&linkType=tcp#media=video
    ingresso_est_live:
      - ffmpeg:rtsp://127.0.0.1:8554/ingresso_est#video=h264#hardware=vaapi
    ingresso_est_sub:
      - rtsp://{FRIGATE_RTSP_USER}:{FRIGATE_RTSP_PASSWORD}@192.168.210.3:554/chID=5&streamType=sub&linkType=tcp#media=video
    patio:
      - rtsp://{FRIGATE_RTSP_USER}:{FRIGATE_RTSP_PASSWORD}@192.168.210.3:554/chID=6&streamType=main&linkType=tcp#media=video
    patio_live:
      - ffmpeg:rtsp://127.0.0.1:8554/patio#video=h264#hardware=vaapi
    patio_sub:
      - rtsp://{FRIGATE_RTSP_USER}:{FRIGATE_RTSP_PASSWORD}@192.168.210.3:554/chID=6&streamType=sub&linkType=tcp#media=video
  webrtc:
    candidates:
      - 192.168.210.10:8555
      - stun:8555

@felipecrs
Copy link
Contributor

Is this option enabled or disabled?

image

@coserotondo
Copy link
Author

When I enable it, the template URL is ignored.

@felipecrs
Copy link
Contributor

It is not completely ignored. It is still used for legacy HLS playing, like when you cast your camera to a Chromecast. But this is a different topic.


Your issue is that you are creating streams in go2rtc with different names. This is unsupported. Just make sure the H264 stream name in go2rtc is the same as your Frigate camera name.

go2rtc:
  streams:
    camera_name_here: rtsp://something

cameras:
  camera_name_here:
    [...]

These names must match.

@felipecrs
Copy link
Contributor

The exact same expectation is used by the Frigate UI as well, when streaming the camera.

@coserotondo
Copy link
Author

Yes, I assumed so. The fact is that I wanted to retain the native H265 stream for recording and use the transcoded H264 one just for WebRTC. What I don't understand is the stream name matching: it has to match the stream that has record role?
Because, like in the example from documentation, the only "match" between the go2rtc/frigate steams name is for the record role.
In addiction, could I use the H264 go2rtc stream for live?

go2rtc:
  streams:
    test_cam:
      - rtsp://192.168.1.5:554/live0 # <- stream which supports video & aac audio.
      - "ffmpeg:test_cam#audio=opus" # <- copy of the stream which transcodes audio to opus for webrtc
    test_cam_sub:
      - rtsp://192.168.1.5:554/substream # <- stream which supports video & aac audio.
      - "ffmpeg:test_cam_sub#audio=opus" # <- copy of the stream which transcodes audio to opus for webrtc

cameras:
  test_cam:
    ffmpeg:
      output_args:
        record: preset-record-generic-audio-copy
      inputs:
        - path: rtsp://127.0.0.1:8554/test_cam # <--- the name here must match the name of the camera in restream
          input_args: preset-rtsp-restream
          roles:
            - record
        - path: rtsp://127.0.0.1:8554/test_cam_sub # <--- the name here must match the name of the camera_sub in restream
          input_args: preset-rtsp-restream
          roles:
            - detect
    live:
      stream_name: test_cam_sub

@felipecrs
Copy link
Contributor

felipecrs commented Dec 5, 2024

You are free to write whatever URL in the camera ffmpeg inputs, the URL there doesn't need to match anything at all.

What matters is the camera name under Frigate cameras, and under go2rtc streams. They must match.

@coserotondo
Copy link
Author

I mean, in the example, in go2rtc there are 2 streams test_cam and test_cam_sub.

In go2rtc there s only 1 camera with name test_cam.

So the match has to be on the on the go2rtc stream used for WebRTC? Otherwise, I could choose in Frigate as camera_name either test_cam or test_cam_sub.

@felipecrs
Copy link
Contributor

So the match has to be on the on the go2rtc stream used for WebRTC?

Yes, the go2rtc stream whose name is the same as the camera name in Frigate is the stream where Frigate and Home Assistant will use for live streaming, including WebRTC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants