Skip to content

Use first onvif profile with ptz config #10012

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

Merged
merged 7 commits into from
Feb 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions frigate/ptz/onvif.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ def _init_onvif(self, camera_name: str) -> bool:
if (
onvif_profile.VideoEncoderConfiguration
and onvif_profile.VideoEncoderConfiguration.Encoding == "H264"
and onvif_profile.PTZConfiguration
and onvif_profile.PTZConfiguration.DefaultContinuousPanTiltVelocitySpace
is not None
):
profile = onvif_profile
logger.debug(f"Selected Onvif profile for {camera_name}: {profile}")
Expand Down Expand Up @@ -151,7 +154,10 @@ def _init_onvif(self, camera_name: str) -> bool:

# autoracking relative panning/tilting needs a relative zoom value set to 0
# if camera supports relative movement
if self.config.cameras[camera_name].onvif.autotracking.zooming:
if (
self.config.cameras[camera_name].onvif.autotracking.zooming
!= ZoomingModeEnum.disabled
):
zoom_space_id = next(
(
i
Expand Down Expand Up @@ -182,23 +188,21 @@ def _init_onvif(self, camera_name: str) -> bool:
try:
if (
self.config.cameras[camera_name].onvif.autotracking.zooming
== ZoomingModeEnum.relative
!= ZoomingModeEnum.disabled
):
if zoom_space_id is not None:
move_request.Translation.Zoom.space = ptz_config["Spaces"][
"RelativeZoomTranslationSpace"
][0]["URI"]
][zoom_space_id]["URI"]
else:
move_request.Translation.Zoom = []
except Exception:
if (
self.config.cameras[camera_name].onvif.autotracking.zooming
== ZoomingModeEnum.relative
):
self.config.cameras[
camera_name
].onvif.autotracking.zooming = ZoomingModeEnum.disabled
logger.warning(
f"Disabling autotracking zooming for {camera_name}: Relative zoom not supported"
)
self.config.cameras[
camera_name
].onvif.autotracking.zooming = ZoomingModeEnum.disabled
logger.warning(
f"Disabling autotracking zooming for {camera_name}: Relative zoom not supported"
)

if move_request.Speed is None:
move_request.Speed = configs.DefaultPTZSpeed if configs else None
Expand Down Expand Up @@ -387,7 +391,11 @@ def _move_relative(self, camera_name: str, pan, tilt, zoom, speed) -> None:
move_request.Translation.PanTilt.x = pan
move_request.Translation.PanTilt.y = tilt

if "zoom-r" in self.cams[camera_name]["features"]:
if (
"zoom-r" in self.cams[camera_name]["features"]
and self.config.cameras[camera_name].onvif.autotracking.zooming
== ZoomingModeEnum.relative
):
move_request.Speed = {
"PanTilt": {
"x": speed,
Expand All @@ -403,7 +411,11 @@ def _move_relative(self, camera_name: str, pan, tilt, zoom, speed) -> None:
move_request.Translation.PanTilt.x = 0
move_request.Translation.PanTilt.y = 0

if "zoom-r" in self.cams[camera_name]["features"]:
if (
"zoom-r" in self.cams[camera_name]["features"]
and self.config.cameras[camera_name].onvif.autotracking.zooming
== ZoomingModeEnum.relative
):
move_request.Translation.Zoom.x = 0

self.cams[camera_name]["active"] = False
Expand Down