Skip to content
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

FFmpeg camera component - timeout reading image with Xiaomi Dafang cameras #15403

Closed
tsvi opened this issue Jul 10, 2018 · 22 comments
Closed

FFmpeg camera component - timeout reading image with Xiaomi Dafang cameras #15403

tsvi opened this issue Jul 10, 2018 · 22 comments

Comments

@tsvi
Copy link
Contributor

tsvi commented Jul 10, 2018

Home Assistant release with the issue:

0.73.1

Last working Home Assistant release (if known):
N/A

Operating environment (Hass.io/Docker/Windows/etc.):

Ubuntu Bionic. Using virtualenv
Running on old x86 Intel Celeron 900Mhz with 1Gb of RAM and 8Gb of HD

Also when using HASSIO on Rpi 3B+

Component/platform:

ffmpeg

Description of problem:
Keep getting timeout on reading image. Network related has been ruled out.

Due to the old hardware I'm using HASS on, the timeout value of 15 sec for ffmpeg getting still images is not enough.
Changing the timeout locally to 20 sec stabilizes the system. Better would be to have it as a configuration setting for the ffmpeg component.

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

camera:
  - platform: ffmpeg
    name: Entrance
    input: -rtsp_transport tcp -i rtsp://10.0.0.98:8554/unicast

Traceback (if applicable):

2018-06-24 21:41:58 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2018-06-24 21:42:00 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting

Additional information:

@isabellaalstrom
Copy link
Contributor

I'm also having problems with ffmpeg. Can you discribe where you changed timeout locally, then I can try that too and see if it's the same problem.

@marciogranzotto
Copy link
Contributor

This is also a problem for me

@isabellaalstrom
Copy link
Contributor

isabellaalstrom commented Sep 11, 2018

More error messages:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/haffmpeg/core.py", line 114, in open
    stderr=stderr
  File "/usr/local/lib/python3.6/asyncio/subprocess.py", line 225, in create_subprocess_exec
    stderr=stderr, **kwds)
  File "uvloop/loop.pyx", line 2603, in subprocess_exec
  File "uvloop/loop.pyx", line 2563, in __subprocess_run
  File "uvloop/handles/process.pyx", line 595, in uvloop.loop.UVProcessTransport.new
  File "uvloop/handles/process.pyx", line 130, in uvloop.loop.UVProcess._init
OSError: [Errno 9] Bad file descriptor
2018-09-09 15:18:39 WARNING (MainThread) [haffmpeg.tools] Error starting FFmpeg.
2018-09-09 15:18:39 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 496, in send_camera_still
    image = await async_get_image(hass, msg['entity_id'])
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 160, in async_get_image
    image = await camera.async_camera_image()
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/camera/local_file.py", line 72, in camera_image
    with open(self._file_path, 'rb') as file:
OSError: [Errno 9] Bad file descriptor
2018-09-09 15:18:44 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2018-09-09 15:19:14 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2018-09-09 15:19:24 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2018-09-09 15:19:34 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2018-09-09 15:19:44 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2018-09-09 15:19:54 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2018-09-09 15:20:24 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2018-09-09 15:21:34 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2018-09-09 15:23:04 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2018-09-09 15:23:14 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2018-09-09 15:23:24 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2018-09-09 15:23:34 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2018-09-09 15:23:44 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2018-09-09 15:23:54 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.```

@tsvi
Copy link
Contributor Author

tsvi commented Sep 11, 2018 via email

@isabellaalstrom
Copy link
Contributor

I'm hesitant to think my problems are related to performance since I'm running on an Intel nuc.

@marciogranzotto
Copy link
Contributor

I'm also hesitant. My instance is running on a RPi 3.

@MarsWarrior
Copy link

After upgrading from an old version (0.73.2) to the latest version (0.79.1), all my camera's give the error:
[haffmpeg.tools] Timeout reading image.

So, something has changed, and I hope it will be fixed soon!

@jixd
Copy link

jixd commented Oct 8, 2018

I'm experiencing the same issue(0.79.3). For me it seems to be working and then crashes after a couple of min with error "Timeout reading image."

@MarsWarrior
Copy link

Using 0.80.1 I get this error in the log while the camera component is setup:

/usr/src/app/homeassistant/components/camera/ffmpeg.py:35: RuntimeWarning: coroutine 'FFmpegManager.async_run_test' was never awaited

if not hass.data[DATA_FFMPEG].async_run_test(config.get(CONF_INPUT)):

@alexandre-leites
Copy link

How to change the timeout? I've the same errors.

@raoulteeuwen
Copy link
Contributor

raoulteeuwen commented Dec 26, 2018

i have a Xiaomi Aqara "hub&cam"/"cam&hub", and also get this "timeout reading image" in my log many times (sometimes 6 per minute, than a pauze for 1 or >30 minutes etc).

Not sure whether it is related to the camera going into sleep mode; just did a short test by getting the cam out of sleep, rebooting the Rpi, and 25min in, not a single error about reading the image...

@raoulteeuwen
Copy link
Contributor

raoulteeuwen commented Dec 26, 2018

Just found https://www.programcreek.com/python/example/104604/async_timeout.timeout, see example 39 ... i'm not a programmer, but i think when some checks fail, it leads to the error written to the logs. Maybe there are too many situations not handled, leading to that error being written, and we can ignore it in many cases? @pvizeli might know more.

@ivanovd
Copy link

ivanovd commented Dec 30, 2018

Same issues on 0.84.6
I had zero problems with RPI3b+ and Xiaomi Dafang camera and suddenly I started getting:
Timeout reading image.

I restarted the HASS and the camera with no luck. When streaming the RTSP via VLC I have very minimal lag (miliseconds) so I am not sure what happened.

@ReindDooyeweerd
Copy link

Same issue over here, camera worked for about a week or 2 without any problems and today it started to give me these errors, https://community.home-assistant.io/t/out-of-the-blue-issues-with-camera-snapshot-service/90526

@tsvi
Copy link
Contributor Author

tsvi commented Jan 10, 2019

@vout this does bot seem related. The error here is specifically with Xiaomi Dafang cameras.
According to your write up your issue seems to be specifci to hikvision component. I suggest you open another issue.

@tsvi tsvi changed the title FFmpeg camera component should allow longer timeouts FFmpeg camera component - timeout reading image with Xiaomi Dafang cameras Jan 10, 2019
@ReindDooyeweerd
Copy link

ReindDooyeweerd commented Jan 10, 2019

@tsvi No it seems like exactly the same error, an timeout issue. So probably it isn't an Xiaomy Dafang issue only but an general rtsp stream issue.

The "setup" you have in your opening post is the same i have,

- platform: ffmpeg
  name: IP camera oprit
  input: !secret ip_camera_oprit_stream
  extra_arguments: '-q:v 1 -r 25 -vf "scale=640:360"'

Where !secret ip_camera_oprit_stream is just an regular rtsp stream

@tsvi
Copy link
Contributor Author

tsvi commented Jan 16, 2019

I did some extensive debugging.
First of all try running ffmpeg on the command line as follows:
time ffmpeg [input arguments] -an -frames:v 1 -y -c:v mjpeg -loglevel verbose test.jpg

I discovered that this was taking 5+ seconds, because it was trying to detect the sound stream which was badly configured.
By disabling the sound from the camera I brought it down to 1 sec.
Also the MQTT server is a bit sluggish on the camera. Once I stopped using MQTT for sending commands I got a reasonable performance.

@superdj4life
Copy link

superdj4life commented Jan 22, 2019

Seeing the same error using a Yi home cam. I'm migrating HA to new hardware and this config is working on the old installation (RPI Zero)

  - platform: yi
    name: 'Front Yard'
    host: '10.0.0.13'
    password: !secret FrontCamPass
    path: /tmp/sd/record
    ffmpeg_arguments: '-vf scale=640:480'

@GuitarSkater
Copy link

Is this still an issue you are experiencing? Can you please try upgrading to the latest version of Home Assistant (0.90) and report back if this is still a problem? Thanks!

@superdj4life
Copy link

superdj4life commented Mar 22, 2019 via email

@sashao
Copy link
Contributor

sashao commented Dec 31, 2021

This is still an issue for me on quite powerful hass running as virtual machine
core-2021.12.7

2021-12-31 10:56:58 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2021-12-31 10:56:58 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2021-12-31 10:56:58 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2021-12-31 10:56:58 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.

It worked several times, but now even after reboot I constantly getting timeouts.

@sashao
Copy link
Contributor

sashao commented Dec 31, 2021

timeout fixed by adding -rtsp_transport tcp -i from recommendation https://www.home-assistant.io/integrations/ffmpeg/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests