From ae706ad195b0db276ad7b89f2476ef2bda8be56d Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Tue, 6 Feb 2024 08:45:20 -0600 Subject: [PATCH 1/4] use first h264 onvif profile --- frigate/ptz/onvif.py | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/frigate/ptz/onvif.py b/frigate/ptz/onvif.py index 8aae216f1a..8abbb3d48f 100644 --- a/frigate/ptz/onvif.py +++ b/frigate/ptz/onvif.py @@ -67,21 +67,51 @@ def _init_onvif(self, camera_name: str) -> bool: # create init services media = onvif.create_media_service() + logger.debug(f"Onvif media xaddr for {camera_name}: {media.xaddr}") try: # this will fire an exception if camera is not a ptz capabilities = onvif.get_definition("ptz") logger.debug(f"Onvif capabilities for {camera_name}: {capabilities}") - profile = media.GetProfiles()[0] except (ONVIFError, Fault, TransportError) as e: - logger.error(f"Unable to connect to camera: {camera_name}: {e}") + logger.error( + f"Unable to get Onvif capabilities for camera: {camera_name}: {e}" + ) + return False + + try: + profiles = media.GetProfiles() + except (ONVIFError, Fault, TransportError) as e: + logger.error( + f"Unable to get Onvif media profiles for camera: {camera_name}: {e}" + ) return False + for key, onvif_profile in enumerate(profiles): + # skip non-H264 profiles + if ( + not onvif_profile.VideoEncoderConfiguration + or onvif_profile.VideoEncoderConfiguration.Encoding != "H264" + ): + continue + else: + # use the first H264 profile + profile = onvif_profile + break + ptz = onvif.create_ptz_service() # get the PTZ config for the first onvif profile - configs = profile.PTZConfiguration - logger.debug(f"Onvif ptz config for media profile in {camera_name}: {configs}") + try: + configs = profile.PTZConfiguration + logger.debug( + f"Onvif ptz config for media profile in {camera_name}: {configs}" + ) + except Exception as e: + logger.error( + f"Invalid Onvif PTZ configuration for camera: {camera_name}: {e}" + ) + return False request = ptz.create_type("GetConfigurationOptions") request.ConfigurationToken = profile.PTZConfiguration.token From bd2dda825f8eb0a703c79a818f06b296849c065d Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Tue, 6 Feb 2024 08:56:57 -0600 Subject: [PATCH 2/4] error if profile remains unset --- frigate/ptz/onvif.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/frigate/ptz/onvif.py b/frigate/ptz/onvif.py index 8abbb3d48f..1c97314c5a 100644 --- a/frigate/ptz/onvif.py +++ b/frigate/ptz/onvif.py @@ -87,21 +87,24 @@ def _init_onvif(self, camera_name: str) -> bool: ) return False + ptz = onvif.create_ptz_service() + + profile = None for key, onvif_profile in enumerate(profiles): - # skip non-H264 profiles if ( - not onvif_profile.VideoEncoderConfiguration - or onvif_profile.VideoEncoderConfiguration.Encoding != "H264" + onvif_profile.VideoEncoderConfiguration + and onvif_profile.VideoEncoderConfiguration.Encoding == "H264" ): - continue - else: - # use the first H264 profile profile = onvif_profile break - ptz = onvif.create_ptz_service() + if profile is None: + logger.error( + f"No appropriate Onvif profiles found for camera: {camera_name}." + ) + return False - # get the PTZ config for the first onvif profile + # get the PTZ config for the profile try: configs = profile.PTZConfiguration logger.debug( From 99a2dde364a00f7f501e4e3275052a04520c5596 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Tue, 6 Feb 2024 09:00:25 -0600 Subject: [PATCH 3/4] move create_ptz_service call --- frigate/ptz/onvif.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frigate/ptz/onvif.py b/frigate/ptz/onvif.py index 1c97314c5a..ec461ec46c 100644 --- a/frigate/ptz/onvif.py +++ b/frigate/ptz/onvif.py @@ -87,8 +87,6 @@ def _init_onvif(self, camera_name: str) -> bool: ) return False - ptz = onvif.create_ptz_service() - profile = None for key, onvif_profile in enumerate(profiles): if ( @@ -116,6 +114,8 @@ def _init_onvif(self, camera_name: str) -> bool: ) return False + ptz = onvif.create_ptz_service() + request = ptz.create_type("GetConfigurationOptions") request.ConfigurationToken = profile.PTZConfiguration.token ptz_config = ptz.GetConfigurationOptions(request) From 22bbb9c58f04d0f17e3889ac57c865b4776ff1e8 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Tue, 6 Feb 2024 09:29:01 -0600 Subject: [PATCH 4/4] add profile logger debug --- frigate/ptz/onvif.py | 1 + 1 file changed, 1 insertion(+) diff --git a/frigate/ptz/onvif.py b/frigate/ptz/onvif.py index ec461ec46c..a7a2cd68b5 100644 --- a/frigate/ptz/onvif.py +++ b/frigate/ptz/onvif.py @@ -94,6 +94,7 @@ def _init_onvif(self, camera_name: str) -> bool: and onvif_profile.VideoEncoderConfiguration.Encoding == "H264" ): profile = onvif_profile + logger.debug(f"Selected Onvif profile for {camera_name}: {profile}") break if profile is None: