rroller / dahua

Dahua Camera and Doorbell Home Assistant Integration
MIT License
404 stars 82 forks source link

Error from stream worker: Error opening stream (INVALIDDATA, Invalid data found when processing input...) #415

Open ScratMan opened 2 weeks ago

ScratMan commented 2 weeks ago

Hello, I'm facing an issue with a VTO2311R-WP since I updated HA to 2024.11.0. I'm using a picture entity card in my dashboard to display image of the camera instance created by this integration, card code below:

show_state: false
show_name: true
camera_view: auto
type: picture-entity
camera_image: camera.visiophone_portail_main
entity: camera.visiophone_portail_main

Screenshot_20241107-225322

This card works, I see the picture that refreshes around every 10 seconds. But if I click on the picture to open the live stream, the stream doesn't work, it looks broken: Screenshot_20241107-225343

And I get an error after few seconds :

Failed to start WebRTC stream: webrtc: streams: parse "rtsp://admin:password": invalid port ":password" after host, exec/rtsp [in#0 @ 0x7fa0612b00] Error opening input: Invalid data found when processing input Error opening input file rtsp://127.0.0.1:18554/camera.visiophone_portail_sub?audio. Error opening input files: Invalid data found when processing input

In HA logs I have some warnings:

Enregistreur: homeassistant.components.go2rtc.server
Source: components/go2rtc/server.py:148
intégration: go2rtc (documentation, problèmes)
S'est produit pour la première fois: 23:44:36 (130 occurrences)
Dernier enregistrement: 23:56:09

23:55:48.020 WRN [rtsp] error="streams: parse \"rtsp://admin:password\": invalid port \":password\" after host, exec/rtsp\n[in#0 @ 0x7fb3c12b00] Error opening input: Invalid data found when processing input\nError opening input file rtsp://127.0.0.1:18554/camera.visiophone_portail_main?audio.\nError opening input files: Invalid data found when processing input\n" stream=camera.visiophone_portail_main

I tried to revert my HA docker container to 2024.10.4, the Dahua camera is now working again, but HA says go2rtc is missing and I lost the streaming on my Eufy cameras. Had to remove the "WebRTC Camera" custom integration and reinstall it to get my Eufy cams back, but I still have the missing go2rtc message.

ScratMan commented 2 weeks ago

I found a more verbose error in the logs, myu password contains a "#":

Enregistreur: root
Source: components/stream/__init__.py:100
S'est produit pour la première fois: 00:09:09 (3 occurrences)
Dernier enregistrement: 00:13:36

Uncaught thread exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/stream/worker.py", line 526, in stream_worker
    container = av.open(source, options=pyav_options, timeout=SOURCE_TIMEOUT)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "av/container/core.pyx", line 398, in av.container.core.open
  File "av/container/core.pyx", line 270, in av.container.core.Container.__cinit__
  File "av/container/core.pyx", line 290, in av.container.core.Container.err_check
  File "av/error.pyx", line 336, in av.error.err_check
av.error.ValueError: [Errno 22] Invalid argument: 'rtsp://admin:pass#word@192.168.1.108:554/cam/realmonitor?channel=1&subtype=0'; last error log: [tcp] Port missing in uri

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/yarl/_url.py", line 1105, in _split_netloc
    port = int(port_str)
           ^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'pass'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/src/homeassistant/homeassistant/components/stream/__init__.py", line 438, in _run_worker
    stream_worker(
  File "/usr/src/homeassistant/homeassistant/components/stream/worker.py", line 529, in stream_worker
    f"Error opening stream ({redact_av_error_string(err)})"
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/stream/worker.py", line 54, in redact_av_error_string
    parts.append(redact_credentials(err.filename))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/stream/__init__.py", line 100, in redact_credentials
    yurl = URL(url)
           ^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/yarl/_url.py", line 280, in __new__
    username, password, host, port = cls._split_netloc(val[1])
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/yarl/_url.py", line 1107, in _split_netloc
    raise ValueError("Invalid URL: port can't be converted to integer")
ValueError: Invalid URL: port can't be converted to integer
ScratMan commented 1 week ago

I made many trials to get the stream working, unfortunately it still fails to stream in HA. I changed the password, to remove the "#" in it ; I also tried disabling the HA WebRTC cloud service, uninstalling and reinstalling integration, reverting HA to 2024.10.4, reverting Dahua integration to 0.9.62 now, but it always fails. So I returned to HA 2024.11.1 and the integration to 0.9.68, and I can see the error message is different now, there are two messages in log:

Enregistreur: homeassistant.components.go2rtc.server
Source: components/go2rtc/server.py:151
intégration: go2rtc (documentation, problèmes)
S'est produit pour la première fois: 23:05:58 (3 occurrences)
Dernier enregistrement: 23:05:59

23:05:58.529 WRN [rtsp] error="streams: read tcp 192.168.1.29:58738->192.168.1.108:554: read: connection reset by peer" stream=camera.visiophone_portail_main_orginal
23:05:58.551 WRN [rtsp] error="streams: read tcp 192.168.1.29:58758->192.168.1.108:554: read: connection reset by peer" stream=camera.visiophone_portail_main_orginal
23:05:59.030 WRN [rtsp] error="streams: read tcp 192.168.1.29:58774->192.168.1.108:554: read: connection reset by peer" stream=camera.visiophone_portail_main_orginal

and

Enregistreur: homeassistant.components.stream.stream.camera.visiophone_portail_main
Source: components/stream/__init__.py:448
intégration: Stream (documentation, problèmes)
S'est produit pour la première fois: 23:05:58 (9 occurrences)
Dernier enregistrement: 23:11:58

Error from stream worker: Error opening stream (INVALIDDATA, Invalid data found when processing input, rtsp://****:****@192.168.1.108:554/cam/realmonitor?channel=1&subtype=0)

Don't know if it's related, but in the docker container's log, there is also another message in between the two above :

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 377, in data_received
    messages, upgraded, tail = self._request_parser.feed_data(data)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "aiohttp/_http_parser.pyx", line 563, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message:
  Invalid method encountered:
    b'MGLNDD_***my_ip_address***_8123\n'

       ^
2024-11-14 23:14:40.736 ERROR (MainThread) [aiohttp.server] Error handling request
gituser28910 commented 1 week ago

I don't have your camera, but a Dahua NVR. Facing the same issue with video streaming, which made me give up on trying to get the video feed in through this integration. One easy test would be to check if you have "RTSP over TLS" enabled in your camera configuration - if yes, and streaming works if you disable it, then see below.

My working setup is to leverage the Generic Camera integration for video (including almost real-time view in the card - as opposed to snapshots) and the Dahua integration for camera events (e.g. Motion Detection). It required a bit of tweaking on the NVR side, I assume you can do the same on your camera/doorbell itself. More details here: https://github.com/rroller/dahua/issues/348#issuecomment-2463231460