fwestenberg / reolink_dev

Home Assistant Reolink addon
MIT License
553 stars 101 forks source link

Camera stream errors in HomeKit #413

Open muxa opened 2 years ago

muxa commented 2 years ago

Describe the bug Camera streaming works in HA but does not work via HomeKit (waiting for the stream times out). I have tried different permutations of the integration configuration parameters for protocol, stream and codec without any luck.

To Reproduce Every time I open the camera from the Apple Home app it does not work. HA logs shows:

Logger: homeassistant.components.homekit.type_cameras
Source: components/homekit/type_cameras.py:461
Integration: HomeKit (documentation, issues)
First occurred: 08:36:01 (7 occurrences)
Last logged: 18:56:54

[b69eded9-d7c2-4c8a-83ac-772ce2fd5ba5] Failed to close stream
[b4aba904-b9bc-40f5-b66a-26ab83999a42] Failed to close stream
[8ec0fbb2-ec95-4c9c-94d6-32bce1577c39] Failed to close stream
[95d7a5e1-a921-4faf-ae5f-14429f7dccf7] Failed to close stream
[00bafa0e-7586-49cc-bfbb-ad9c3d1b0e0a] Failed to close stream
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/homekit/type_cameras.py", line 461, in stop_stream
    await getattr(stream, shutdown_method)()
  File "/usr/local/lib/python3.9/site-packages/haffmpeg/core.py", line 158, in close
    await self._loop.run_in_executor(None, _close)
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.9/site-packages/haffmpeg/core.py", line 153, in _close
    self._proc.stdin.write(b"q")
BrokenPipeError: [Errno 32] Broken pipe

Expected behavior I'm expecting the camera stream to work via HomeKit, as it works for generic cameras.

Screenshots n/a

Environment: Please provide useful information about your environment, like:

Additional context The above mentioned problem happens with 2 cameras setup via Reolink integration, however it does not happen with another camera configured using generic camera:

  - platform: generic
    name: Carport
    stream_source: "-re -rtsp_transport tcp -i rtsp://admin:password@192.168.1.166:554/h264Preview_01_sub"
xannor commented 2 years ago

I have been trying to figure this out as well. The best I can figure out so far is that I think HomeKit wants MJPEG video (though apple was the biggest proponent of H264.) and currently the integration passes the video through as-is, in whatever format the camera provides. The "Generic" camera forces MJPEG via FFMPEG which is why it works. I think if there is a way to know what video format the camera provides, and what format HomeKit is requesting HA can automatically convert via FFMPEG when necessary.

skynet01 commented 2 years ago

I had the same issue, I was able to fix it by setting the stream type as RTSP and 264 in the config options for the integration. See if that helps

flame4ever commented 1 year ago

I have also adjusted it as follows, with me unfortunately no camera comes even after restart HassIO. image

skynet01 commented 1 year ago

I actually ended up installing Scrypted it handles all of the HomeKit for me and all videos show up instantly (I also use it to rebroadcast streams to HA and they work more stable). There is a Home Assistant addon of Scrypted as well if you want to run it on the same platform as HA.