libonvif icon indicating copy to clipboard operation
libonvif copied to clipboard

MacOS 15.5 - OnvivGUI 3.0.11 - Freeze due to: argument 1 has unexpected type 'memoryview'

Open Arsoth opened this issue 7 months ago • 4 comments

Discovery finds the camera well, but on hitting the start stream button the app locks up after a few seconds and the dock shows the Application as not responding: Image

The logs I get are as follows:

2025-06-13 19:02:19.925 | DEBUG    | onvif_gui.panels.camera.camerapanel:btnDiscoverClicked:284 - Using broadcast discovery
2025-06-13 19:02:20.430 | DEBUG    | onvif_gui.panels.camera.datastructures:info:61 -  ONVIF Discovery found 0 unique devices on network: 127.51.68.120
2025-06-13 19:02:21.431 | DEBUG    | onvif_gui.panels.camera.datastructures:info:61 -  ONVIF Discovery found 0 unique devices on network: 192.168.0.68
2025-06-13 19:02:22.441 | DEBUG    | onvif_gui.panels.camera.datastructures:info:61 -  ONVIF Discovery found 1 unique devices on network: 192.168.1.178
2025-06-13 19:02:22.568 | DEBUG    | onvif_gui.panels.camera.camerapanel:getData:469 - Discovery completed for Camera: D8X3NT, Stream URI: rtsp://192.168.1.102:554/ONVIFMedia, xaddrs: http://192.168.1.102:8000/onvif/device_service, D8X3NT
2025-06-13 19:02:49.957 | DEBUG    | onvif_gui.main:mediaPlayingStarted:571 - Camera stream opened D8X3NT (PROFILE_000), stream_uri : rtsp://192.168.1.102:554/ONVIFMedia, resolution : 720 x 576, fps: 30, Display Profile, Window: Main
2025-06-13 19:02:50.118 | ERROR    | onvif_gui.glwidget:renderCallback:123 - GLWidget render callback exception: arguments did not match any overloaded call:
  QImage(): too many arguments
  QImage(size: QSize, format: QImage.Format): argument 1 has unexpected type 'memoryview'
  QImage(width: int, height: int, format: QImage.Format): argument 1 has unexpected type 'memoryview'
  QImage(data: Optional[bytes], width: int, height: int, format: QImage.Format, cleanupFunction: Optional[Callable[..., None]] = None, cleanupInfo: Optional[Any] = None): argument 1 has unexpected type 'memoryview'
  QImage(data: Optional[bytes], width: int, height: int, bytesPerLine: int, format: QImage.Format, cleanupFunction: Optional[Callable[..., None]] = None, cleanupInfo: Optional[Any] = None): argument 1 has unexpected type 'memoryview'
  QImage(data: Optional[PyQt6.sip.voidptr], width: int, height: int, format: QImage.Format, cleanupFunction: Optional[Callable[..., None]] = None, cleanupInfo: Optional[Any] = None): argument 1 has unexpected type 'memoryview'
  QImage(data: Optional[PyQt6.sip.voidptr], width: int, height: int, bytesPerLine: int, format: QImage.Format, cleanupFunction: Optional[Callable[..., None]] = None, cleanupInfo: Optional[Any] = None): argument 1 has unexpected type 'memoryview'
  QImage(xpm: list[str]): argument 1 has unexpected type 'memoryview'
  QImage(fileName: Optional[str], format: Optional[str] = None): argument 1 has unexpected type 'memoryview'
  QImage(a0: QImage): argument 1 has unexpected type 'memoryview'
  QImage(variant: Any): too many arguments

That's the last thing that occurs before I have to force kill it.

It seems python downloads the stream for a bit but nothing shows, as I can see it pulling a ~1mbit connection from the camera with my network tools.

All other functions seem to work fine, I can change camera settings etc, but the stream itself does not.

Arsoth avatar Jun 13 '25 23:06 Arsoth

Thank you so much for reaching out, the feedback is greatly appreciated. I think the long story short is that Onvif GUI is not able to handle the stream from this camera. I did some research and it looks like the iSpy software might work here, but the data is sketchy. I wrote down some ideas for later reference, so if I can get my hands on one of these cameras, I could take a crack at troubleshooting.

I wasn't able to find a datasheet for this type of camera, but it seems like it is an infrared thermal imaging camera if I have to guess. The model number seems to be a dali-irtech product, but their web site was not responding. In any event, it looks like the image processing pipeline I have set up for Onvif GUI is choking on this camera output. There are a few possibilities for the ultimate cause of failure, so it's difficult to find without the actual camera.

The proximate cause of failure is in the glwidget renderCallback code where the stream frame data is converted into a numpy array then wrapped in a QImage. Note that F is the raw frame data from the camera.

    ary = np.array(F, copy = False) 

    if len(ary.shape) < 2:
        return
    h = ary.shape[0]
    w = ary.shape[1]
    d = 1
    if ary.ndim > 2:
        d = ary.shape[2]

...

    if d > 1:
        player.image = QImage(ary.data, w, h, d * w, QImage.Format.Format_RGB888)
    else:
        player.image = QImage(ary.data, w, h, w, QImage.Format.Format_Grayscale8)


Pretty much every camera I have ever worked with will take the first path, where d > 1. In fact, there is a filter placed on the stream to convert output to RGB888 format, so theoretically, every stream would take that path, but with ffmpeg, you never know for sure. The memoryview in the error message refers to the ary.data parameter in the first position. It's possible that the stream is taking the second path and there is an error in the assumptions for the call and just taking out the second w would fix the issue.

Another possibility is that the frame data is not aligned on a 32 bit boundary, which apparently can cause the QImage conversion to fail. A detailed post shows how to make arbitrarily aligned frame data compatible with the QImage structure.

Another possibility is that the Onvif GUI ffmpeg libraries are missing some piece needed by the camera for processing. The ffmpeg libraries are very bare bones. Most mainstream cameras work fine, but there are some cameras that don't stream for that reason. I intended to beef up those modules at first opportunity. An Onvif GUI instance compiled from source would test that theory, as the homebrew libraries are comprehensive.

sr99622 avatar Jun 14 '25 02:06 sr99622

Thanks for the quick response!

I'd found this software from a thread about the camera, where someone apparently had used it successfully. However, it looks like they would have been using v2.2.9 Birmingham at the latest, which a quick dif is showing 344 changed files with 31,272 additions and 20,423 deletions since then, so.... just a bit that could be different now!

Arsoth avatar Jun 14 '25 03:06 Arsoth

For the older versions of libonvif, the program was installed by compiling from source, so there's a good possibility that doing that might bring the camera online. It's a bit difficult though, which is why I have been putting so much effort into the installation process. The full featured ffmpeg libraries used when building from source may have something that is missing in the bare bones version I have in the installer. There have been many changes in the program since then, but the basic stream handling is the same, with the exception of the ffmpeg libraries.

sr99622 avatar Jun 14 '25 11:06 sr99622

I'll try building from source then, just to see!

Arsoth avatar Jun 14 '25 14:06 Arsoth