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

Extend onvif server to support Unifi Protect #1520

Merged
merged 4 commits into from
Dec 30, 2024

Conversation

acortelyou
Copy link
Contributor

Resolves #613.

Marking draft pending feedback.

Note: Unifi uses appears to use MAC as unique identifier, requiring bridge network to achieve multiple instances

@AlexxIT
Copy link
Owner

AlexxIT commented Dec 24, 2024

FrameRateLimit should be integer. Where you get this values?

@AlexxIT AlexxIT self-assigned this Dec 24, 2024
@acortelyou
Copy link
Contributor Author

acortelyou commented Dec 24, 2024

I used tcpdump to compare go2rtc and a working implementation, 29.97 just happens to be the framerate from the NTSC cameras I have.

Bitrate and FPS are displayed in the Unifi Protect web GUI but unclear if exact values are critical to functionality.

The RateControl block is required but I didn't test if FPS comes from there or GetVideoSources.

I figure those values and more should be configurable, but I didn't see an obvious way to extract the information from a stream/producer object.

Unifi Protect also seems unwilling to authenticate over RTSP even when you embed the credentials in the stream uri. I couldn't find where in the onvif spec you're supposed to configure that. The creds are included in each soap request.

@acortelyou
Copy link
Contributor Author

I did some additional testing.

VideoEncoderConfiguration.RateControl is required to be present but the contents are not.

VideoEncoderConfiguration.RateControl.{FrameRateLimit,BitrateLimit} are optional but they are used as the values shown in the webui, for display only.

VideoEncoderConfiguration.Resolution is what shows in the webui, for display only.

Removing VideoSourceConfiguration seems to break the snapshots for some reason.

VideoSources.FrameRate don't seem to be required, removed.

VideoEncoderConfiguration Quality, Interval, and SessionTimeout don't seem to be required, removed.

@BrunoTCouto
Copy link
Contributor

Looking foward this implementation 👀

Thanks @acortelyou

@acortelyou acortelyou marked this pull request as ready for review December 30, 2024 00:23
@AlexxIT AlexxIT self-requested a review December 30, 2024 10:05
@AlexxIT AlexxIT merged commit 2c3219f into AlexxIT:master Dec 30, 2024
@AlexxIT
Copy link
Owner

AlexxIT commented Dec 30, 2024

Thanks!

@acortelyou
Copy link
Contributor Author

Thanks to you @AlexxIT !

Note, I minimized the changes for the purposes of this PR just to get things working.

Eventually when multiple onvif servers are implemented it would be great if we could configure Resolution, Quality, FrameRateLimit, BitrateLimit and SnapshotType: (none|jpeg|mp4) to allow for LQ/HQ switching and correct metadata for each video source in each onvif server.

Things could get complicated when you have multiple qualities and resolutions per stream eg:

streams:
  dahua_camera:
    - rtsp://admin:[email protected]/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif
    - rtsp://admin:[email protected]/cam/realmonitor?channel=1&subtype=1

@AlexxIT
Copy link
Owner

AlexxIT commented Dec 31, 2024

Things already complicated, because go2rtc don't know resolution for every stream right now.

@AlexxIT
Copy link
Owner

AlexxIT commented Jan 3, 2025

@AlexxIT AlexxIT added this to the v1.9.8 milestone Jan 3, 2025
@blockiindahood
Copy link

I reviewed #613 and some other issues, but I can't get clear information on how to implement go2rtc via onvif to record cameras from go2rtc in Unifi Protect, since it needs credentials to connect to an onvif server. Setting a pair of creds for the api does not do anything to UP, in Home Assistant though, it works without any, like Alex mentiones many times.

Sorry, If it's the wrong place to ask, but this issue seems to have the most accurate intention of getting go2rtc to work with Unifi.

@BrunoTCouto
Copy link
Contributor

@blockiindahood I used admin/admin and it worked fine, only thing that I was not able to do is use multiple cameras, so I'm running one instance of go2rtc for each camera.

Maybe @acortelyou and @AlexxIT can add a guide how to use multiple cameras at once, but as far I understood it's not possible at the moment

@blockiindahood
Copy link

@BrunoTCouto I also read that currently multi ONVIF Servers aren't supported, and that it's on the todo board.

I understand that only one camera is possible, but how do I make it clear to unifi?
Must I only implement one camera, and not more?

Also what IP did you fill in?
These settings do not work for me: (sadly also not admin/admin, did you set that in the api section of the config?)
Bildschirmfoto 2025-01-03 um 15 58 40

@BrunoTCouto
Copy link
Contributor

BrunoTCouto commented Jan 3, 2025

@blockiindahood I used the go2rtc IP address.

Nothing really fancy on my config.

Something like this 👇

streams:
  entrada_social: "rtsp://CameraUsername:[email protected]:554/Streaming/channels/101"
  
log:
  api: trace
  onvif: trace  

@BrunoTCouto
Copy link
Contributor

BrunoTCouto commented Jan 3, 2025

One thing you should check is, I download the binary directly from the build pipeline, so maybe check if you are in the release of this code, and if it is really deployed already.

@blockiindahood
Copy link

blockiindahood commented Jan 3, 2025

Looking in the logs of go2rtc, I see that Unifi is connecting and trying the credentials, but seems that they are wrong.
Do I have to set them anywhere?

I am using go2rtc with HASS on an Raspi 4.

@BrunoTCouto
Copy link
Contributor

Not sure, logs from where ? go2rtsp or something else?

@blockiindahood
Copy link

Oh, sorry, logs from go2rtc!

@BrunoTCouto
Copy link
Contributor

Im without my personal computer to test the release from today. But saw that other changes were made to onvif. Can't help much more as my config was really simple

@blockiindahood
Copy link

Okay, thank you @BrunoTCouto, I'll then must look further into it.

@BrunoTCouto
Copy link
Contributor

Maybe try with the binaries from this action. It's the ones I'm using

https://github.com/AlexxIT/go2rtc/actions/runs/12549881204/job/34991696663

@AlexxIT
Copy link
Owner

AlexxIT commented Jan 3, 2025

I managed to run UniFi Protect using https://github.com/dciancu/unifi-protect-unvr-docker-arm64
Haven't had a chance to test compatibility with the latest version of go2rtc yet.

@acortelyou
Copy link
Contributor Author

Must I only implement one camera, and not more?

Unifi Protect assumes that each ONVIF server you are adopting is a single camera which can have multiple streams (ie LQ/HQ).

You must implement one go2rtc server per "camera" you wish to adopt with just one or two streams.

Unifi Protect also assumes each ONVIF server will have it's own IP (and maybe MAC).

You must also implement an IP per "camera" you wish to adopt.

There are many ways to do that but it is highly dependent on your scenario so I won't be able to provide a one size fits all guide.

Docker can create virtual interfaces with unique IP/MAC for each container.
see here: https://docs.docker.com/engine/network/tutorials/macvlan/

You might be able to add extra static IPs to your network interface and have each API/ONVIF server only listen on the correct IP/port but I didn't test that.
see here: https://www.computernetworkingnotes.com/linux-tutorials/how-to-configure-multiple-ip-addresses-on-linux.html

@AlexxIT
Copy link
Owner

AlexxIT commented Jan 4, 2025

@acortelyou were you able to connect at least one camera from go2rtc to UniFi?
It looks like UniFi is using auto discovery mode. Which is not yet implemented in go2rtc.
I haven't found a way to enter onvif host/post manually into UniFi Protect.

@blockiindahood
Copy link

@AlexxIT there is a way to manually add a onvif cam: image

@acortelyou
Copy link
Contributor Author

acortelyou commented Jan 5, 2025

@AlexxIT Yes, I have had five separate go2rtc docker containers using macvlan networking adopted in Unifi Protect on a UDM for several weeks now.

I manually adopted them using host:port, admin, 1234 but did not configure auth in go2rtc as Unifi Protect does seem to send auth for the RTSP stream.

streams:
  hq: 'rtsp://admin:[email protected]/cam/realmonitor?channel=2&subtype=0&unicast=true&proto=Onvif'

log:
  api: trace
  onvif: trace  

Bildschirmfoto 2025-01-03 um 15 58 40

Screenshot_2025-01-05-02-01-57-88_c722f61f790e99e8e2542f6c7087a0aa

@michael-blue2
Copy link

@AlexxIT Yes, I have had five separate go2rtc docker containers using macvlan networking adopted in Unifi Protect on a UDM for several weeks now.

I manually adopted them using host:port, admin, 1234 but did not configure auth in go2rtc as Unifi Protect does seem to send auth for the RTSP stream.

streams:
  hq: 'rtsp://admin:[email protected]/cam/realmonitor?channel=2&subtype=0&unicast=true&proto=Onvif'

log:
  api: trace
  onvif: trace  

Bildschirmfoto 2025-01-03 um 15 58 40

Screenshot_2025-01-05-02-01-57-88_c722f61f790e99e8e2542f6c7087a0aa

It might sound dump, but which port did you use? and how did you choose that one? on the host:port in the udm

@AlexxIT
Copy link
Owner

AlexxIT commented Jan 5, 2025

@blockiindahood thanks!

@acortelyou look like I have broke your PR with removing empty RateControl tag. It's important for UniFi. I'll bring it back in an update.

Successfully connected one camera from go2rtc to UniFi Protect.

@acortelyou
Copy link
Contributor Author

acortelyou commented Jan 5, 2025

@AlexxIT Yes, the RateControl block is required. Framerate and bitrate would be configured there but are optional.

I thought I mentioned that but the conversation is split up over multiple issues and the PR... Might be wise to lock this conversation and all ONVIF/Unifi issues except for one.

@ALL The version in this PR worked. The current officially released version doesn't work. I suspect that's why there's so many questions/frustration about how to use it.

Unifi Protect needs the port of the ONVIF server which is part of the go2rtc API server which listens on 1984 by default.

@AlexxIT
Copy link
Owner

AlexxIT commented Jan 5, 2025

Two news:

  1. I have created issue for discussion UniFi Protect UniFi Protect discussion #1538
  2. I "hacked" this thing :)

You can add as many cameras as you want from go2rtc to UniFi Protect without any problems:

  • WebUI > Settings > System > Migration > Download File
  • Unpack zip file, edit cameras.json, add new cameras
  • Important to use different (random) mac and id
  • Important to fill correct thirdPartyCameraInfo
    "thirdPartyCameraInfo": {
       "port": "1984",
       "username": "admin",
       "password": "admin",
       "rtspUrl": "rtsp://192.168.1.123:8554/reolink2",
       "rtspUrlLQ": null,
       "snapshotUrl": "http://192.168.1.123:1984/api/frame.jpeg?src=reolink2"
     }
  • Pack zip with changes
  • WebUI > Settings > System > Migration > Import File

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

Successfully merging this pull request may close these issues.

Implement Unifi Protect-complaint output
5 participants