home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.65k stars 30.79k forks source link

Synology Camera Snapshot Resolution #57684

Closed Salvora closed 2 years ago

Salvora commented 3 years ago

The problem

I have 5 cams set up in Synology Surveillance Station. They all show up in HA and streams are working fine. The problem is when HA takes snapshots, the snapshot resolution is always downscaled. For example, when I use "take snapshot" service for a camera streaming in 1920x1080, the snapshot resolution is 528x432. This in itself is not a big issue, however, when I try to use image processors for object and face detection, the downscaled resolution negatively affects the detection. Is this an intended behavior? Is there a way to use the Synology integration to use high res snapshots?

Not related, but I would really appreciate an addition of a "motion" attribute for Synology cameras.

What is version of Home Assistant Core has the issue?

core-2021.10.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Synology DSM, Camera

Link to integration documentation on our website

https://www.home-assistant.io/integrations/camera/

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

probot-home-assistant[bot] commented 3 years ago

synology_dsm documentation synology_dsm source (message by IssueLinks)

probot-home-assistant[bot] commented 3 years ago

Hey there @hacf-fr, @quentame, @mib1185, mind taking a look at this issue as it has been labeled with an integration (synology_dsm) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

mib1185 commented 3 years ago

Hi @Salvora the take snapshot service is part of the camera integration, but not the Synology DSM. Please change the initial post accordingly.

Salvora commented 3 years ago

Sorry about that, since non-synology camera snapshots were fine, I assumed it was due to synology integration. I will change it accordingly.

mib1185 commented 3 years ago

I've done a short static code analysis, there is no point where the resolution is set - the image data are directly gathered via API from the Surveillance Station - maybe there is an configuration option in Surveillance Station itself 🤔

Salvora commented 3 years ago

Not sure, I just checked the api docs and saw this. It might be related.

image

Default is set to 1 which is balanced.

mib1185 commented 3 years ago

since nothing besides the cameraId is used for the API call in the libraray, I guess the default is used. But do not know, what exactly balanced mean. Honestly "528x432" sounds not really balanced - if so, I don't want to know, what "low bandwith" will result in 🙈

Salvora commented 3 years ago

Synology, by default, exposes 1 main stream and 2 sub-streams named High Quality, Balanced, and Low Bandwidth depending on your setup. They have different resolutions. I just checked and the snapshot resolution taken from HA matches exactly the "Balanced" stream resolution of the Surveillance Station. So, the profileType option somehow had to be set to 0 when taking a snapshot.

mib1185 commented 3 years ago

Many thanks for poiting this out 👍 Changing/setting the profileType need changes on underlying python lib, as well as here in the integration. Will think about it and provide respective PRs in the next few days...

mib1185 commented 3 years ago

Hi @Salvora I have updated the py-synologydsm-api lib and created an PR here to add a new integration option to select the quality level for camera snapshots. Could you please test this PR in your environment?

Salvora commented 3 years ago

I am not too sure about how to apply those changes. Could you point the way?

mib1185 commented 3 years ago

First create a backup!

The easiest way is to ...

Salvora commented 3 years ago

I cant seem to get it to work as a custom component.

Getting "Config flow cannot be loaded error"

2021-10-26 20:46:39 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 709, in async_create_flow
    integration.get_platform("config_flow")
  File "/usr/src/homeassistant/homeassistant/loader.py", line 532, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 537, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/config/custom_components/synology_dsm/__init__.py", line 58, in <module>
    from .const import (
  File "/config/custom_components/synology_dsm/const.py", line 24, in <module>
    from homeassistant.const import (
ImportError: cannot import name 'ENTITY_CATEGORY_CONFIG' from 'homeassistant.const' (/usr/src/homeassistant/homeassistant/const.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 151, in async_init
    flow, result = await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 169, in _async_init
    flow = await self.async_create_flow(handler, context=context, data=data)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 716, in async_create_flow
    raise data_entry_flow.UnknownHandler
homeassistant.data_entry_flow.UnknownHandler
2021-10-26 20:46:50 ERROR (MainThread) [homeassistant.setup] Setup failed for synology_dsm: Unable to import component: cannot import name 'ENTITY_CATEGORY_CONFIG' from 'homeassistant.const' (/usr/src/homeassistant/homeassistant/const.py)
mib1185 commented 3 years ago

ah I see ... there is already the "entity category" feature included, but this is only available with 2021.11 (which is currently in beta phase), those this can only be tested, after you have updated

Salvora commented 3 years ago

oh, will this fix be included in the 2021.11?

mib1185 commented 3 years ago

Since this is not a fix, but a new feature it will not be included in 2021.11 (we are already in beta phase). But you can test it like described in https://github.com/home-assistant/core/issues/57684#issuecomment-950863398 with 2021.11. Aft er your confirmation, that this feature works as expected, it would be integrated with 2021.12

Salvora commented 3 years ago

Updated HA and tested this one. It works with no issue. The snapshot resolution is correct after setting it high. Thanks for the update.