Core: Stream works only 2 (or 6) seconds

Created on 5 Aug 2020  ·  30Comments  ·  Source: home-assistant/core

The problem


Stream works only for 2 seconds (sometimes for 6), then it freezes for 60 seconds, instantly loads 1 minute video and freezes again for next minute. I have this problem for 6-12 months. It works when Home Assistant is running in Python virtual environment, but not in Docker container. There is also a problem with fetch snapshot image.

Environment

  • Home Assistant Core release with the issue: 0.114
  • Last working Home Assistant Core release (if known): N/A
  • Operating environment (OS/Container/Supervised/Core): Container
  • Integration causing this issue: stream or ffmpeg
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/stream/

Problem-relevant configuration.yaml

amcrest:
  - host: cam.lan
    name: Cam
    binary_sensors:
      - motion_detected
    resolution: low
    username: !secret cam_user
    password: !secretcam_password

Traceback/Error logs when HA is running in Python virtual environment and stream works:

2020-08-05 23:49:57 ERROR (SyncWorker_2) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)                                                                                                                       
2020-08-05 23:50:02 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-05 23:50:07 ERROR (SyncWorker_0) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)                                                                                                                       
2020-08-05 23:50:09 ERROR (stream_worker) [libav.rtsp] RTP: PT=60: bad cseq 408f expected=2e5c
2020-08-05 23:50:11 ERROR (SyncWorker_6) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)                                                                                                                       
2020-08-05 23:50:11 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-05 23:50:12 ERROR (SyncWorker_7) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)                                                                                                                       
2020-08-05 23:50:12 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-05 23:50:22 ERROR (SyncWorker_5) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)                                                                                                                       
2020-08-05 23:50:22 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-05 23:50:32 ERROR (SyncWorker_4) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)                                                                                                                       
2020-08-05 23:50:42 ERROR (SyncWorker_1) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)                                                                                                                       
2020-08-05 23:50:57 ERROR (stream_worker) [libav.NULL] missing picture in access unit with size 216
2020-08-05 23:50:57 ERROR (stream_worker) [libav.NULL] missing picture in access unit with size 11019
2020-08-05 23:50:57 ERROR (stream_worker) [homeassistant.components.stream.worker] Stream packet without dts detected, skipping...                                                                                                              
2020-08-05 23:51:03 ERROR (SyncWorker_3) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)                                                                                                                       
2020-08-05 23:51:13 ERROR (SyncWorker_2) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)                                                                                                                       
2020-08-05 23:51:15 ERROR (stream_worker) [libav.NULL] missing picture in access unit with size 216
2020-08-05 23:51:15 ERROR (stream_worker) [libav.NULL] missing picture in access unit with size 23213
2020-08-05 23:51:15 ERROR (stream_worker) [homeassistant.components.stream.worker] Stream packet without dts detected, skipping...                                                                                                              
2020-08-05 23:51:18 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-05 23:51:23 ERROR (SyncWorker_6) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)                                                                                                                       
2020-08-05 23:51:28 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-05 23:51:33 ERROR (SyncWorker_4) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)                                                                                                                       
2020-08-05 23:51:38 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-05 23:51:44 ERROR (SyncWorker_4) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)                                                                                                                       
2020-08-05 23:51:48 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-05 23:51:54 ERROR (SyncWorker_5) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)                                                                                                                       
2020-08-05 23:51:59 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-05 23:52:04 ERROR (SyncWorker_7) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)                                                                                                                       
2020-08-05 23:52:14 ERROR (SyncWorker_4) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)                                                                                                                       
2020-08-05 23:52:27 ERROR (SyncWorker_7) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out.                
2020-08-05 23:52:34 ERROR (SyncWorker_6) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)                                                                                                                       
2020-08-05 23:52:39 ERROR (stream_worker) [homeassistant.components.stream.worker] Stream packet without dts detected, skipping...                                                                                                              
2020-08-05 23:52:42 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-05 23:52:44 ERROR (stream_worker) [homeassistant.components.stream.worker] Stream packet without dts detected, skipping...                                                                                                              
2020-08-05 23:52:44 ERROR (stream_worker) [homeassistant.components.stream.worker] Error demuxing stream: No dts in consecutive packets                                                                                                         
2020-08-05 23:52:45 ERROR (SyncWorker_7) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)                                                                                                                       
2020-08-05 23:52:49 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-05 23:52:55 ERROR (SyncWorker_2) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)                                                                                                                       
2020-08-05 23:53:00 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-05 23:53:05 ERROR (SyncWorker_5) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)                                                                                                                       
2020-08-05 23:53:10 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-05 23:53:20 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-05 23:53:41 ERROR (SyncWorker_2) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)
2020-08-05 23:53:55 ERROR (stream_worker) [libav.NULL] missing picture in access unit with size 216
2020-08-05 23:53:55 ERROR (stream_worker) [libav.NULL] missing picture in access unit with size 145461
2020-08-05 23:53:55 ERROR (stream_worker) [homeassistant.components.stream.worker] Stream packet without dts detected, skipping...

Traceback/Error logs when HA is running in Docker container and stream works for 2/6 seconds:

2020-08-06 00:04:53 ERROR (SyncWorker_1) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)
2020-08-06 00:04:58 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-06 00:05:03 ERROR (SyncWorker_0) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)
2020-08-06 00:05:13 ERROR (SyncWorker_9) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)
2020-08-06 00:05:23 ERROR (SyncWorker_1) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)
2020-08-06 00:05:33 ERROR (SyncWorker_8) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)
2020-08-06 00:05:53 ERROR (SyncWorker_0) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)
2020-08-06 00:06:03 ERROR (SyncWorker_8) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)
2020-08-06 00:06:08 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-06 00:06:13 ERROR (SyncWorker_9) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)
2020-08-06 00:06:18 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-06 00:06:18 ERROR (stream_worker) [homeassistant.components.stream.worker] Stream packet without dts detected, skipping...
2020-08-06 00:06:23 ERROR (SyncWorker_7) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)
2020-08-06 00:06:23 ERROR (stream_worker) [homeassistant.components.stream.worker] Stream packet without dts detected, skipping...
2020-08-06 00:06:23 ERROR (stream_worker) [homeassistant.components.stream.worker] Error demuxing stream: No dts in consecutive packets
2020-08-06 00:06:28 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-06 00:06:34 ERROR (SyncWorker_0) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)
2020-08-06 00:06:38 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-06 00:06:44 ERROR (SyncWorker_10) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)
2020-08-06 00:06:49 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-06 00:06:54 ERROR (SyncWorker_0) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)
2020-08-06 00:06:59 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-06 00:07:04 ERROR (SyncWorker_0) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)
2020-08-06 00:07:15 ERROR (SyncWorker_5) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)
2020-08-06 00:07:25 ERROR (SyncWorker_6) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)
2020-08-06 00:07:46 ERROR (SyncWorker_7) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)
2020-08-06 00:07:56 ERROR (SyncWorker_4) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)
2020-08-06 00:08:01 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2020-08-06 00:08:07 ERROR (SyncWorker_11) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)
2020-08-06 00:08:17 ERROR (SyncWorker_3) [homeassistant.components.onvif] Fetch snapshot image failed from Cam, falling back to FFmpeg; HTTPConnectionPool(host='cam.lan', port=80): Read timed out. (read timeout=5)

Additional information

Tried Amcrest, Generic IP Camera and ONVIF integrations.

stream

Most helpful comment

I‘m having problems with 6 second videos since 0.115.
It’s always showing a cached 6 second video, which is the same after reboots, too. Also if I comment out the generic camera in yaml it’s still the Same 6 second Video.
The only error I see in the log, that may have to do with it is:
Stream packet without dts detected, skipping

I‘m using a yi cam with you hack and can solve the error by disabling audio in the rtsp Video. If it’s activate it it creates the 6 second video again. Problem is, that the Audio it streams isn’t supported by home assistant, but if i need it I’m using vlc to stream the rtsp directly.

All 30 comments

Hey there @hunterjm, mind taking a look at this issue as its been labeled with an integration (stream) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

Me too!
Error demuxing stream: No dts in consecutive packets
12:33:58 – Stream (ERROR) - il messaggio si è verificato per la prima volta alle 11 agosto 2020, 20:37:39 e compare 8 volte
Stream packet without dts detected, skipping...
12:33:58 – Stream (ERROR) - il messaggio si è verificato per la prima volta alle 11 agosto 2020, 20:37:34 e compare 16 volte
RTP: PT=60: bad cseq 0d42 expected=fe62
12:33:35 – components/stream/worker.py (ERROR) - il messaggio si è verificato per la prima volta alle 9:08:34 e compare 2 volte

Same here:
Fetch snapshot image failed from HIKDVR, falling back to FFmpeg; HTTPConnectionPool(host='10.10.10.100', port=80): Read timed out.
4:28:41 PM – ONVIF (ERROR) - message first occurred at 4:26:43 PM and shows up 29 times

It seems I'm having a similar error, is a yi hack camera, each time I try to get snapshot:

2020-08-14 08:03:36 ERROR (SyncWorker_4) [homeassistant.components.onvif] Fetch snapshot image failed from Cámara pasillo, falling back to FFmpeg; HTTPConnectionPool(host='192.168.100.20', port=8080): Max retries exceeded with url: /cgi-bin/snapshot.sh?res=high&watermark=yes (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f8d401850>: Failed to establish a new connection: [Errno 111] Connection refused'))
2020-08-14 08:03:37 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.

Sometimes after some of this errors, a bigger one appears that does not let access to the video neither, but is fixed itself some time later:

2020-08-14 08:03:40 ERROR (stream_worker) [libav.tcp] Connection to tcp://192.168.100.20:554?timeout=5000000 failed: Connection refused
2020-08-14 08:03:40 ERROR (stream_worker) [root] Uncaught thread exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/src/homeassistant/homeassistant/components/stream/worker.py", line 49, in stream_worker
    container = av.open(stream.source, options=stream.options)
  File "av/container/core.pyx", line 354, in av.container.core.open
  File "av/container/core.pyx", line 225, in av.container.core.Container.__cinit__
  File "av/container/core.pyx", line 257, in av.container.core.Container.err_check
  File "av/error.pyx", line 336, in av.error.err_check
av.error.ConnectionRefusedError: [Errno 111] Connection refused: 'rtsp://XXXXX:[email protected]/ch0_0.h264'; last error log: [tcp] Connection to tcp://192.168.100.20:554?timeout=5000000 failed: Connection refused
2020-08-14 08:03:40 ERROR (stream_worker) [libav.tcp] Connection to tcp://192.168.100.20:554?timeout=5000000 failed: Connection refused
2020-08-14 08:03:40 ERROR (stream_worker) [root] Uncaught thread exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/src/homeassistant/homeassistant/components/stream/worker.py", line 49, in stream_worker
    container = av.open(stream.source, options=stream.options)
  File "av/container/core.pyx", line 354, in av.container.core.open
  File "av/container/core.pyx", line 225, in av.container.core.Container.__cinit__
  File "av/container/core.pyx", line 257, in av.container.core.Container.err_check
  File "av/error.pyx", line 336, in av.error.err_check
av.error.ConnectionRefusedError: [Errno 111] Connection refused: 'rtsp://XXXXXX:[email protected]/ch0_0.h264'; last error log: [tcp] Connection to tcp://192.168.100.20:554?timeout=5000000 failed: Connection refused

The user and password appear in the log, maybe this must be fixed too, I have replaced it by XXXXX.

At first I thought it was the camera, but the snapshot is never working and if I go manually to the URL it works perfectly and I can get the snapshot. I can differentiate them because the correct one has a watermark and the ffmpeg one that it gets from the video hasn't.

Is a connection refused, maybe some kind of problem of authentication?

Looking deeply at the logs I can find this:

2020-08-13 09:32:29 ERROR (MainThread) [homeassistant.core] Error executing service: <ServiceCall camera.snapshot (c:1b51e5aedd3711eaa7d69d325599db33): filename=Template("/config/www/XXXXXXXXXXX/casa_snapshot_20200813_073213.jpg"), entity_id=['camera.pasillo']>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1324, in catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1343, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 208, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 454, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 583, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 485, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 667, in async_handle_snapshot_service
    await hass.async_add_executor_job(_write_image, snapshot_file, image)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 664, in _write_image
    img_file.write(image_data)
TypeError: a bytes-like object is required, not 'NoneType'

If finally it is some kind of authentication problem, maybe this fixes it: https://github.com/home-assistant/core/pull/38729

@McGiverGim it's easy to verify - just use curl with the snapshot url. If it fails with digest auth but succeeds with basic auth, it should be fixed by https://github.com/home-assistant/core/pull/38729.

@OnFreund great idea! I have tried and I get a 401 Unauthorized when I use --digest but it seems to work without, so it seems clear that is not supported and the PR maybe fixes it for me. Waiting for a release that contains it...

@McGiverGim Sounds like it should be fixed with that PR, but if you want to be certain, you can checkout that branch locally and test.

@OnFreund is there a way to install your changes over the actual stable version? It seems your PR is taking long to be merged.

I'm a developer, but I don't know how Home Assistant works, so I'm not sure if I can add your modified files "somewhere" to see if they work.

I added your files in config/custom_components/onvif but it seems is not compatible with my version or your code has some bug, I think is more the first. I can find my camera with the integration flow, but it does not add any sensor (camera). I see this error:

2020-09-02 13:19:14 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Unknown - 7c:a7:b0:XX:XX:XX for onvif
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 222, in async_setup
    result = await component.async_setup_entry(  # type: ignore
  File "/config/custom_components/onvif/__init__.py", line 86, in async_setup_entry
    await async_populate_snapshot_auth(hass, device, entry)
  File "/config/custom_components/onvif/__init__.py", line 153, in async_populate_snapshot_auth
    auth = await _get_snapshot_auth(hass, device, entry)
  File "/config/custom_components/onvif/__init__.py", line 139, in _get_snapshot_auth
    if response.status_code == 401:
AttributeError: 'NoneType' object has no attribute 'status_code'

Hmm, that's really strange. I don't know how None can be returned from requests.get.
Can you try adding a log with the snapshot_uri before this?

Sure, if you tell me how to add a log line 👍
I'm a developer, but not of python, not of Home Assistant ;)

I found the code in another integration, this is the snapshot (I replaced the IP with XX):

[custom_components.onvif] snapshot_uri http://192.168.XXX.XX:8080/cgi-bin/snapshot.sh?res=high&watermark=yes

It seems correct and it shows the snapshot in the browser after authenticated.

@OnFreund more info, I changed the if by a:

if response is None or response.status_code == 401:

And now the snapshot works, with basic authentication of course.

I don't know why it returns None and not the response in my case. Is a Yi cam with the allwinner firmware.

Can you try to use digest auth on this url with curl and see what happens?

Of course, I tested it before, but this is the complete response, if it helps:

curl --digest -uUSER:PASSWORD http://192.168.XXX.XX:8080/cgi-bin/snapshot.sh\?res\=high\&watermark\=yes                                            
<HTML><HEAD><TITLE>401 Unauthorized</TITLE></HEAD>
<BODY><H1>401 Unauthorized</H1>

</BODY></HTML>
curl: (18) transfer closed with 874 bytes remaining to read

Removing the --digest works.

If you want that I execute with more params please tell me.

Ok, I made a stupid mistake, sorry. Can you add return before requests.get(snapshot_uri, timeout=1, auth=auth) in line 134?

In my defense, I'm used to Ruby, rather than Python, where the return isn't necessary :)

Change done...

    def _get():
        # so we can handle keyword arguments
        return requests.get(snapshot_uri, timeout=1, auth=auth)

and working!!! I now have a high resolution snapshot and not the low resolution ffmpeg one...

Thanks for your work!! Only thing left is to merge it :P

@OnFreund in what version I can expect this merge?

Is at 105.0 0.115.0 and working for me!

@McGiverGim for sure? ;) maybe you mean 0.115?

Of course!! 😄

Yes, it's included in 0.115

I‘m having problems with 6 second videos since 0.115.
It’s always showing a cached 6 second video, which is the same after reboots, too. Also if I comment out the generic camera in yaml it’s still the Same 6 second Video.
The only error I see in the log, that may have to do with it is:
Stream packet without dts detected, skipping

I‘m using a yi cam with you hack and can solve the error by disabling audio in the rtsp Video. If it’s activate it it creates the 6 second video again. Problem is, that the Audio it streams isn’t supported by home assistant, but if i need it I’m using vlc to stream the rtsp directly.

always showing a cached 6 second video, which is the same after reboots, too. Also if I comment out the generic camera in yaml it’s still the Same 6 second Video.
The only error I see in the log, that may have to do with it is:
Stream packet without dts detected, skipping

I‘m using a yi cam with you hack and can solve the error by disabling audio in the rtsp Video. If it’s activate it it creates the 6 second video again. Problem is, that the Audio it streams isn’t supported by home assistant, but if i need it I’m using vlc to stream the rts

@hagenuck1 , did you find any solution?

Nope. After deactivating the audio feature at the camera it was working for a short moment, but since then I have the same issue again.

I'm seeing a very similar issue with 0.115.6.

2020-10-04 12:56:00 ERROR (SyncWorker_29) [homeassistant.components.onvif] Fetch snapshot image failed from test cam, falling back to FFmpeg; HTTPConnectionPool(host='192.168.10.215', port=80): Max retries exceeded with url: /tmpfs/auto.jpg (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x45c5b650>, 'Connection to 192.168.10.215 timed out. (connect timeout=5)'))
2020-10-04 12:56:01 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.

if I use

ffmpeg -rtsp_transport tcp -i rtsp://192.168.10.215/1 -f image2 -vf fps=fps=1 test%03d.png 

it works fine.

I think part of the problem for me, is the poll interval of 10 seconds, and the camera not coping.
How can I control the poll interval?

Config, ONVIF integration.
By default this added -pred 1 as a system option.

I also have tried

camera:
  - platform: ffmpeg
    name: Camera ffmpeg
    input: rtsp://192.168.10.215/1

and get the same issues with the poll time being too aggressive and causing timeouts.

Hello:

I am running HA 0.117.6 with Onvif, connected to an ANNKE DT81DP NVR. I get the following errors on my six analog cameras every 10 seconds. The images render fine on the dashboard, I just see the errors in the log every 10 seconds. My IP Cameras report no issues.

Any clues? Thanks!

2020-11-13 08:51:57 ERROR (MainThread) [homeassistant.components.onvif] Fetch snapshot image failed from DVR DT81DP, falling back to FFmpeg; Unknown error:
2020-11-13 08:51:57 ERROR (MainThread) [homeassistant.components.onvif] Fetch snapshot image failed from DVR DT81DP, falling back to FFmpeg; Unknown error:
2020-11-13 08:51:57 ERROR (MainThread) [homeassistant.components.onvif] Fetch snapshot image failed from DVR DT81DP, falling back to FFmpeg; Unknown error:
2020-11-13 08:51:57 ERROR (MainThread) [homeassistant.components.onvif] Fetch snapshot image failed from DVR DT81DP, falling back to FFmpeg; Unknown error:
2020-11-13 08:51:57 ERROR (MainThread) [homeassistant.components.onvif] Fetch snapshot image failed from DVR DT81DP, falling back to FFmpeg; Unknown error:
2020-11-13 08:51:57 ERROR (MainThread) [homeassistant.components.onvif] Fetch snapshot image failed from DVR DT81DP, falling back to FFmpeg; Unknown error:

Correction, this error occurs on all cameras. My apologies...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

balloob picture balloob  ·  371Comments

jeromelaban picture jeromelaban  ·  123Comments

gieljnssns picture gieljnssns  ·  277Comments

grantalewis picture grantalewis  ·  145Comments

Gio76 picture Gio76  ·  223Comments