Repository: blakeblackshear/frigate

Issue:
[Support]: Frigate 0.13 - IPC-S21 - PTZ
### Describe the problem you are having

Hi,

I can't configure PTZ with my iMou Cruiser SE+ (IPC-S21) with the last version of Frigate 0.13-dev-7c629c1

Can you help me ? :)

Thank !

### Version

0.13-dev-7c629c1

### Frigate config file

```yaml
autotracking: false
```


### Relevant log output

```shell
2023-08-21 17:03:14.539781496  [2023-08-21 17:03:14] frigate.http                   ERROR   : Exception on /CruiserPTZ/ptz/info [GET]
2023-08-21 17:03:14.539786084  Traceback (most recent call last):
2023-08-21 17:03:14.539787667    File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 2190, in wsgi_app
2023-08-21 17:03:14.539788910      response = self.full_dispatch_request()
2023-08-21 17:03:14.539790212    File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 1486, in full_dispatch_request
2023-08-21 17:03:14.539791264      rv = self.handle_user_exception(e)
2023-08-21 17:03:14.539792416    File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 1484, in full_dispatch_request
2023-08-21 17:03:14.539793338      rv = self.dispatch_request()
2023-08-21 17:03:14.539794480    File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 1469, in dispatch_request
2023-08-21 17:03:14.539795552      return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
2023-08-21 17:03:14.539796724    File "/opt/frigate/frigate/http.py", line 1155, in camera_ptz_info
2023-08-21 17:03:14.539797746      return jsonify(current_app.onvif.get_camera_info(camera_name))
2023-08-21 17:03:14.539798848    File "/opt/frigate/frigate/ptz/onvif.py", line 333, in get_camera_info
2023-08-21 17:03:14.539799800      self._init_onvif(camera_name)
2023-08-21 17:03:14.539800822    File "/opt/frigate/frigate/ptz/onvif.py", line 107, in _init_onvif
2023-08-21 17:03:14.539801834      move_request.Translation.Zoom.space = ptz_config["Spaces"][
2023-08-21 17:03:14.539802936  IndexError: list index out of range
```


### FFprobe output from your camera

```shell
[{"return_code":0,"stderr":"","stdout":{"programs":[],"streams":[{"avg_frame_rate":"20/1","codec_long_name":"H.264/AVC/MPEG-4AVC/MPEG-4part10","height":1080,"width":1920},{"avg_frame_rate":"0/0","codec_long_name":"AAC(AdvancedAudioCoding)"},{"avg_frame_rate":"0/0"}]}}]
```


### Frigate stats

_No response_

### Operating system

HassOS

### Install method

HassOS Addon

### Coral version

USB

### Network connection

Wired

### Camera make and model

iMou IPC-S21

### Any other information that may be helpful

_No response_


Discussion:
@hawkeye217 is there a reason why `fov_space_id` is used for `PanTiltTranslationSpace` but `0` is always used for `ZoomTranslationSpace` ?

https://github.com/blakeblackshear/frigate/blob/7c629c1874ecb16a3e946cbf9156751a699c33fa/frigate/ptz/onvif.py#L100-L109
Either way I don't think we should fail if these don't come through since currently they are only required for auto tracking
> @hawkeye217 is there a reason why `fov_space_id` is used for `PanTiltTranslationSpace` but `0` is always used for `ZoomTranslationSpace` ?
> 
> https://github.com/blakeblackshear/frigate/blob/7c629c1874ecb16a3e946cbf9156751a699c33fa/frigate/ptz/onvif.py#L100-L109

@NickM-27  I don't use the zoom space for anything at the moment, so that line could probably be deleted until I work on zooming with autotracking. Interesting that the pan/tilt space index was found, but the index of the zoom space was not zero. Perhaps the user's camera only supports pan/tilt and not zoom? 

In any case, I definitely agree, we shouldn't fail there.

We probably should do something similar with the zoom space as I did with the pan/tilt space (https://github.com/blakeblackshear/frigate/blob/7c629c1874ecb16a3e946cbf9156751a699c33fa/frigate/ptz/onvif.py#L81).

I can do some testing and make a PR later this week as I'm traveling and don't have easy access to my development environment for a few more days.
@hawkeye217 I'll put up a PR to remove this for now, if we aren't using it for anything then I don't see a reason to parse it. 

Resolving patch:
diff --git a/frigate/ptz/onvif.py b/frigate/ptz/onvif.py
--- a/frigate/ptz/onvif.py
+++ b/frigate/ptz/onvif.py
@@ -104,9 +104,15 @@ def _init_onvif(self, camera_name: str) -> bool:
             move_request.Translation.PanTilt.space = ptz_config["Spaces"][
                 "RelativePanTiltTranslationSpace"
             ][fov_space_id]["URI"]
+
+        try:
             move_request.Translation.Zoom.space = ptz_config["Spaces"][
                 "RelativeZoomTranslationSpace"
             ][0]["URI"]
+        except Exception:
+            # camera does not support relative zoom
+            pass
+
         if move_request.Speed is None:
             move_request.Speed = ptz.GetStatus({"ProfileToken": profile.token}).Position
         self.cams[camera_name]["relative_move_request"] = move_request


Test patch: