home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.7k stars 30.45k forks source link

Ring doorbell camera stream not working #92971

Closed soheiladeli closed 7 months ago

soheiladeli commented 1 year ago

The problem

Home Assistant 2023.5.2 Frontend 20230503.3 - latest

After upgrading HA Core to 2023 from 2022 the Ring camera stream is not working with following error: Logger: aiohttp.server Source: components/ring/camera.py:145 First occurred: 9:40:27 AM (3 occurrences) Last logged: 3:45:09 PM

Error handling request Traceback (most recent call last): File "/srv/homeassistant/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request resp = await request_handler(request) File "/srv/homeassistant/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle resp = await handler(request) File "/srv/homeassistant/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl return await handler(request) File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware return await handler(request) File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware return await handler(request) File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/request_context.py", line 28, in request_context_middleware return await handler(request) File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/ban.py", line 80, in ban_middleware return await handler(request) File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/auth.py", line 235, in auth_middleware return await handler(request) File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/view.py", line 146, in handle result = await result File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/camera/init.py", line 735, in get return await self.handle(request, camera) File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/camera/init.py", line 775, in handle stream = await camera.handle_async_mjpeg_stream(request) File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/ring/camera.py", line 145, in handle_async_mjpeg_stream await stream.close() File "/srv/homeassistant/lib/python3.10/site-packages/haffmpeg/core.py", line 159, in close await self._loop.run_in_executor(None, _close) File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/srv/homeassistant/lib/python3.10/site-packages/haffmpeg/core.py", line 154, in _close self._proc.stdin.write(b"q") BrokenPipeError: [Errno 32] Broken pipe

What version of Home Assistant Core has the issue?

core-2023.5.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Core

Integration causing the issue

Ring

Link to integration documentation on our website

https://www.home-assistant.io/integrations/ring/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: aiohttp.server
Source: components/ring/camera.py:145
First occurred: 9:40:27 AM (3 occurrences)
Last logged: 3:45:09 PM

Error handling request
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
  File "/srv/homeassistant/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/srv/homeassistant/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/auth.py", line 235, in auth_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/view.py", line 146, in handle
    result = await result
  File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/camera/__init__.py", line 735, in get
    return await self.handle(request, camera)
  File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/camera/__init__.py", line 775, in handle
    stream = await camera.handle_async_mjpeg_stream(request)
  File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/ring/camera.py", line 145, in handle_async_mjpeg_stream
    await stream.close()
  File "/srv/homeassistant/lib/python3.10/site-packages/haffmpeg/core.py", line 159, in close
    await self._loop.run_in_executor(None, _close)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.10/site-packages/haffmpeg/core.py", line 154, in _close
    self._proc.stdin.write(b"q")
BrokenPipeError: [Errno 32] Broken pipe

Additional information

No response

home-assistant[bot] commented 1 year ago

ring documentation ring source

thomasshawn commented 1 year ago

Same issue for me today.

thomasshawn commented 1 year ago

Neither doorbell camera works but stickup camera still showing preview

thomasshawn commented 1 year ago

Removed all instances, rediscovered all devices, now working

soheiladeli commented 1 year ago

Already did that, still not working with the same error log

Coder84619 commented 1 year ago

I'm getting the same error.

TechHummel commented 1 year ago

I have the same issue with a different camera (ONVIF integration - more information also in #84551). Running homeassistant in a container on a Raspberry Pi 4.

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 738, in get
    return await self.handle(request, camera)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 778, in handle
    stream = await camera.handle_async_mjpeg_stream(request)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/onvif/camera.py", line 195, in handle_async_mjpeg_stream
    await stream.close()
  File "/usr/local/lib/python3.11/site-packages/haffmpeg/core.py", line 159, in close
    await self._loop.run_in_executor(None, _close)
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/haffmpeg/core.py", line 154, in _close
    self._proc.stdin.write(b"q")
BrokenPipeError: [Errno 32] Broken pipe

Seems like the same error messages were also reported in different issues: #86025 (different problem description) and #89139.

issue-triage-workflows[bot] commented 1 year ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment šŸ‘ This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

martinw72 commented 12 months ago

the issue still exists!

Error with Version 2023.10.5:

File "/usr/local/lib/python3.11/site-packages/haffmpeg/core.py", line 154, in _close self._proc.stdin.write(b"q") BrokenPipeError: [Errno 32] Broken pipe

ecammit commented 11 months ago

I was getting the same error, but in my case it was because my ffmpeg (on openwrt) lacks of compiled in support for h.264.

Once you unwrap all the python, you get down to a command like this being executed:

ffmpeg -i 'https://filestore-048723199962-us-east-2-prod-data.s3.us-east-2.amazonaws.com/66c3d568-3c36-4702-a306-2456379f5182.mp4?X-Amz-Security-Token=XXXXXXXXXXXXXXXX...&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20231115T195938Z&X-Amz-SignedHeaders=host&X-Amz-Expires=900&X-Amz-Credential=XXXXXXX...&X-Amz-Signature=XXX...' -an -frames:v 1 -c:v mjpeg -s 1340x754 -f image2pipe -

When running on my openwrt router, it outputs:

ffmpeg version 5.1.3 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 12.3.0 (OpenWrt GCC 12.3.0 r23617-3d006f95f2)
  configuration: --enable-cross-compile --cross-prefix=arm-openwrt-linux-muslgnueabi- --arch=arm --cpu=cortex-a9 --target-os=linux --prefix=/usr --pkg-config=pkg-config --enable-shared --enable-static --enable-pthreads --enable-zlib --disable-doc --disable-debug --disable-lzma --disable-vaapi --disable-vdpau --disable-outdevs --disable-runtime-cpudetect --enable-lto --enable-vfp --disable-neon --disable-x86asm --enable-gnutls --disable-decoder=atrac3 --disable-decoder=h264 --disable-decoder=hevc --disable-decoder=vc1 --disable-muxer=h264 --disable-muxer=hevc --disable-muxer=vc1 --disable-demuxer=h264 --disable-demuxer=hevc --disable-demuxer=vc1 --disable-parser=h264 --disable-parser=hevc --disable-parser=vc1 --enable-libopus --enable-small --enable-libmp3lame --enable-libfdk-aac
  libavutil      57. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  libavdevice    59.  7.100 / 59.  7.100
  libavfilter     8. 44.100 /  8. 44.100
  libswscale      6.  7.100 /  6.  7.100
  libswresample   4.  7.100 /  4.  7.100
[h264_v4l2m2m @ 0xb55d9400] Could not find a valid device
[h264_v4l2m2m @ 0xb55d9400] can't configure decoder
[mov,mp4,m4a,3gp,3g2,mj2 @ 0xb59d7c40] Failed to open codec in avformat_find_stream_info
[h264_v4l2m2m @ 0xb55d9400] Could not find a valid device
[h264_v4l2m2m @ 0xb55d9400] can't configure decoder

In the case of OpenWRT, this is because libx264 is patented, so OpenWRT no longer distributes it by default and so the ffmpeg package that is distributed has x.264 disabled. You have to compile your own to install it.

I'm not sure what other distributions, like on Rasberry Pi are doing, but I suspect something similar is happening there too. But in any case, I don't think this is a problem with Home Assistant. Rather, this is a problem with lack of h.264 support in individual's ffmpeg.

Perhaps Home Assistant's ring module can pre-detect h.264 support in ffmpeg and disable and/or display an error message so users know the real issue. Otherwise, this is not a Home Assistant bug.

Stono commented 10 months ago

I have ffpmeg compiled with enable-libx264 so with 264 support and i also get these errors, albeit sporadically, so i think its just a masking error over the top of several other issues - so i agree that logging more underlying context would be useful!

sdb9696 commented 7 months ago

Hi, this appears to be an issue with underlying codecs rather than HA or library so I'm closing this issue as the original post with logs etc is quite old. Ideally anyone experiencing current issues could raise a new issue with fresh diagnostics etc and I'll look into it.

sdb9696 commented 7 months ago

@home-assistant close