hjdhjd / homebridge-unifi-protect

:video_camera: Complete HomeKit integration for all UniFi Protect device types with full support for most features including HomeKit Secure Video, and more. https://homebridge.io
Other
1.48k stars 93 forks source link

The image snapshot handler for the given accessory is slow to respond #1048

Closed ryanburnett closed 7 months ago

ryanburnett commented 7 months ago

Homebridge UniFi Protect Version

v6.19.0

Homebridge Platform and OS

macOS Sonoma 14.4

Homebridge Version

v1.7.0

Node Version

v18.19.0

UniFi OS Version

v3.2.12

UniFi Protect Controller Version

v3.0.22

Describe the problem

Thanks for all the hard work on homebridge-unifi-protect. It's amazing to see my UniFi Protect cameras in the Apple Home app.

I have a G4 Pro and G4 Doorbell Pro (both running firmware 4.70.32).

I'm not running a firewalled environment or have the above items on a separate network.

I'm getting these Homebridge Log entries:

Is this a problem? If so, is there anything I can do to fix it? Thank you!

Homebridge HBUP JSON configuration

{
    "bridge": {
        "name": "Homebridge A142",
        "username": "0E:D3:D4:2C:A1:42",
        "port": 51651,
        "pin": "751-56-223",
        "advertiser": "avahi"
    },
    "accessories": [],
    "platforms": [
        {
            "name": "Config",
            "port": 8581,
            "platform": "config"
        },
        {
            "controllers": [
                {
                    "address": "10.1.1.1",
                    "password": "(removed)",
                    "username": "Homebridge"
                }
            ],
            "platform": "UniFi Protect",
            "_bridge": {
                "username": "0E:9E:76:2B:16:BC",
                "port": 37193
            }
        }
    ]
}

Relevant log output

[G4 Pro] The image snapshot handler for the given accessory is slow to respond! See https://homebridge.io/w/JtMGR for more info.
[G4 Doorbell Pro] The image snapshot handler for the given accessory is slow to respond! See https://homebridge.io/w/JtMGR for more info.

Acknowledgment that you are only running UniFi OS and UniFi Protect releases from the Ubiquiti Official release channel

hjdhjd commented 7 months ago

Thanks! So I've written this previously on the Discord. As stated in the changelog starting in 6.19.0 - snapshots are now generated differently.

Ubiquiti, for apparently performance and "design" reasons, has chosen to significantly reduce the quality of the snapshot images produced natively by the Protect API. Additionally, this API endpoint has been increasingly slower, less responsive, and prone to problems than the rest of the Protect API in recent months.

To address this, and bring back the snapiness we used to have in Protect snapshots when viewed in HomeKit, how snapshots are generated in HBUP has been redesigned. Snapshots are now generated using the following sources, in order:

When one fails, we go to the next one until we have exhausted all the options. I've made these design choices to focus on quality and speed. Trying each of these takes time, and there's a finite limit of time that HomeKit gives you to provide a snapshot before it gives up. On the plus side, once we've generated an image, HBUP caches it for a minute or so in case we have other failures, so we always have a fallback option.

TL;DR: the errors are warnings and will happen on occasion. It's by design and may continue to evolve as I continue to adapt to the shifting Protect API landscape over time.

PS: You're somehow running on Sonoma, using avahi for mDNS, and you don't have hardware acceleration enabled. Are you running in a virtualized environment? If so, I would encourage you to reconsider and run natively on macOS. Hardware acceleration makes a huge difference on macOS. Those tiny delays when running virtualized, compounded, can (and do) contribute to slower snapshot generation times.

Best of luck and hope this helps.

ryanburnett commented 7 months ago

You're somehow running on Sonoma, using avahi for mDNS, and you don't have hardware acceleration enabled. Are you running in a virtualized environment? If so, I would encourage you to reconsider and run natively on macOS. Hardware acceleration makes a huge difference on macOS. Those tiny delays when running virtualized, compounded, can (and do) contribute to slower snapshot generation times.

Yes, that definitely helps - thank you!

Sorry, I meant to write Raspberry Pi 4 (I was entering the issue on my Mac). I set gpu_mem=128 in my Pi's config.txt file and enabled hardware acceleration in the Homebridge webUI for my G4 Pro and G4 Doorbell Pro cameras:

{
    "controllers": [
        {
            "address": "10.1.1.1",
            "password": "(removed)",
            "username": "Homebridge"
        }
    ],
    "platform": "UniFi Protect",
    "_bridge": {
        "username": "0E:9E:76:2B:16:BC",
        "port": 37193
    },
    "options": [
        "Enable.Video.Transcode.Hardware.D021F9CC4A97",
        "Enable.Video.Transcode.Hardware.68D79ACF8A3E",
        "Enable.Video.Transcode.Hardware.F4E2C60F25C6"
    ]
}

Nice catch - thanks again.

github-actions[bot] commented 7 months ago

This issue is locked to prevent necroposting on closed issues. Please create a new issue for related support requests, bug reports, or feature suggestions.