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
69.88k stars 28.98k forks source link

Can not play reolink videos provided by integration's Media browser #110939

Open majkers opened 4 months ago

majkers commented 4 months ago

The problem

I have a Reolink Duo 2 WiFi camera set up using official reolink integration's Media browser. I see a list of videos but when I try to play any of them I have an error in log. My camera is set up with rtsp:

image

What version of Home Assistant Core has the issue?

core-2024.2.2

What was the last working version of Home Assistant Core?

None?

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Reolink

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.components.stream
Source: components/stream/__init__.py:431
Integration: Stream (documentation, issues)
First occurred: 12:14:24 (20 occurrences)
Last logged: 12:46:16

Error from stream worker: Error opening stream (ERRORTYPE_5, I/O error) rtmp://192.168.Y.X:1935/vod/Mp4Record%202024-02-19%20RecS02_20240219_000000_000202_8B28818_FD950B.mp4?channel=0&stream=1&user=****&password=****

Additional information

No response

home-assistant[bot] commented 4 months ago

Hey there @starkillerog, mind taking a look at this issue as it has been labeled with an integration (reolink) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `reolink` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign reolink` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


reolink documentation reolink source (message by IssueLinks)

starkillerOG commented 4 months ago

Do both the low resolution and high resolution fail?

Do you have special caracters in your password or username? WARNING: only answer with yes/no, DO NOT POST YOUR PASSWORD.

Do you have the RTMP port enabled in the reolink desktop client? Are you able to play the same URL using for instance VLC media player?

majkers commented 4 months ago

Do both the low resolution and high resolution fail?

I do not see any distinction in media browser list....

Do you have special caracters in your password or username?

Yes.

Do you have the RTMP port enabled in the reolink desktop client?

Yes, exactly on that port

Are you able to play the same URL using for instance VLC media player?

No but maybe becasue of those escaped chars like '%20' ?

starkillerOG commented 4 months ago

@majkers you could play around with the escaped chars and VLC media player, most likely there are also escaped chars in the username/password if you have special chars in there. If you can find a working URL I can then adjust the HomeAssistant code.

Could also be usefull to temporarly change the username/password to something with only letters and numbers and see if it works then.

majkers commented 4 months ago

Sorry I can't make it work. Username and password are not a problem for VLC since I can play rtsp streams. From reolink camera's pplayback page I see a link like this:

<video class="h5_video-fill bc-h5_player" muted="" src="/cgi-bin/api.cgi?token=757f7f9adec706d&amp;cmd=Playback&amp;source=Mp4Record/2024-02-19/RecS02_20240219_050031_050231_8B28818_F85252.mp4&amp;output=Mp4Record/2024-02-19/RecS02_20240219_050031_050231_8B28818_F85252.mp4&amp;encrypt=24WujG4UasdfC2k8u+CPj/rUsfubB5/9h6sdN2/4=" preload="metadata" flashstopped="true" id="dummyid12"></video>

So no vod part. But still can't prepare any working link for VLC....

majkers commented 4 months ago

OK I made a quic search and IMHO a link shoud look like this (at least it is working in VLC):

http://IP_NO_PORT/cgi-bin/api.cgi?cmd=Playback&source=filename.mp4&output=filenam.mp4&user=USER&password=PASS

majkers commented 4 months ago

I also found this https://reolink.com/wp-content/uploads/2017/01/Reolink-CGI-command-v1.61.pdf but it doesn't seem to work casue it is very old document....

mogli7 commented 4 months ago
``Logger: homeassistant.components.stream
Source: components/stream/__init__.py:431
Integration: Stream (documentation, issues)
First occurred: 18. Februar 2024 um 20:32:46 (294 occurrences)
Last logged: 20:22:59

Error from stream worker: Error opening stream (ERRORTYPE_5, I/O error) rtmp://192.168.1.150:1935/vod/Mp4Record%202024-02-18%20RecM04_20240218_203151_203220_6D28C0000_C440E7.mp4?channel=0&stream=0&user=****&password=****
Error from stream worker: Error opening stream (ERRORTYPE_5, I/O error) rtmp://192.168.1.150:1935/vod/Mp4Record%202024-02-18%20RecM04_20240218_200955_201035_6D28C0000_112923E.mp4?channel=0&stream=0&user=****&password=****
Error from stream worker: Error opening stream (ERRORTYPE_5, I/O error) rtmp://192.168.1.150:1935/vod/Mp4Record%202024-02-19%20RecM04_20240219_185931_185958_6D28C0000_A13A46.mp4?channel=0&stream=0&user=****&password=****

I have that too when I try it via the HA app The integration in the media of reolink freezes the app When trying to download in the file browser only a browser window comes up with 401 (no download) I upload via FTP from the camera to the media folder In your own network, viewing in HA only via “my media” via reolink does not work Neither works via the HA app Screenshot 2024-02-19 204244

xannor commented 4 months ago

Question, do you have RTMP enabled in the camera? RTSP is not supported for playback by them, only RTMP and "download". Also, try changing your password to very basic letters and numbers. For some of the urls, the cameras have very poor url encoding support and some special characters will get encoded by the browser and appear to be invalid paswords to the cameras.

mogli7 commented 4 months ago

I've tried everything now - no change With FLV there was even a deterioration - no more stream in the home network for the cam entities - that worked very well with RTSP I will now switch back to rtsp

I have the feeling that the cloud isn't involved When I tried FLV I had a picture on the app after 3 minutes but only happened once?! and the app becomes very viscous with "my media" and "reolink" in media sources "camera" in media sources also works with rtsp!!! but that's only live result: No access to the history data via the app

Everything works with the reolink app But of course without the Reolink cloud only in the home network

majkers commented 4 months ago

I've already said what IMHO is wrong. Reolink integration uses very old URL with 'vod' word in it. Latest API uses different one:

http://IP_NO_PORT/cgi-bin/api.cgi?cmd=Playback&source=filename.mp4&output=filenam.mp4&user=USER&password=PASS

It is also working in VLC

xannor commented 4 months ago

Does VLC report it as an hls stream or just as an mp4? I ask because I have been toying with the ability to download the HD video, but the output is the raw file, which cannot be passed through the stream integration. This means that only a direct connection to the camera would be supported, so it would break using via an off network connection (i.e. the nabu casa cloud, or a proxy) the vod playback method provides an hls mpeg-url format stream which is compatible with the stream integration.

xannor commented 4 months ago

@starkillerOG you might want to ask reolink themselves if they removed the rtmp vod playback from newer firmware.

They might have also just forgot, I have a first gen duo and its initial firmware had a bug where the snap function with a get call would return the same lens snap for both channels, but a post would return the correct snap. This was fixed in a following release.

majkers commented 4 months ago

Does VLC report it as an hls stream or just as an mp4?

Sorry but I don't know what do You mean? How can I check it?

sezlony commented 4 months ago

same here with the same error log (ERRORTYPE 5), but I don't understand that it says RTMP, dispite I'm using RSTP stream

important to mention, that it has worked before the 2.3 update, now it doesn't

starkillerOG commented 4 months ago

@sezlony The playback of recordings only supports RTMP not RTSP. So it will always be using RTMP for past recordings. Could you check if you have the RTMP port enabled in the settings of the reolink desktop client under Settings > Network > Advanced > Port Settings?

You mention the playback was working in a older version of HomeAssistant. I have changed the way the password and username are encoded for the RTMP playback stream in reolink-aio 0.8.7 This was first included in HomeAssistant 2024.1.4 So if that is really the issue it should work on HA 2024.1.3 and should fail on 2024.1.4 or higher.

Would someone be able to test if the issue does not exist on HA 2024.1.3 and apears on HA 2024.1.4?

sezlony commented 4 months ago

I manage 2 instances, one of them had 1.2 before the upgrade, I can confirm it was fine

edit: RTMP port is enabled (1935) and as a test I configured one stream in reolink integration to RTMP and gives nice live feedback, only playback does not work

Stephan-4711 commented 3 months ago

I have rtmp on port 1935 enabled too, I get the same error And playback in google home and alexa isn't possible

xannor commented 3 months ago

If I remember correctly if there are special characters in the password they cannot be encoded for some cameras. The first step to try would be to test with a simple text and number only password to see if it is an encoding issue.

As for google and Alexa playback, unless you are exposing your cameras to the internet, or using the uuid feature via the Reolink app, they would have no access except through HA.

sezlony commented 3 months ago

@xannor: do I have to completely reconfig the reolink integration (from scratch) after changing the password or will it ask for new credentials only?

xannor commented 3 months ago

It should, on receiving an auth error, allow you to fix the password via the devices list.

Stephan-4711 commented 3 months ago

I changed the password, inside of Homeassisant it self its working all time for me. But I'm not able to proxy the camera to amazon alexa and google home. I see the entities in google home and alexa, but there is no video

sezlony commented 3 months ago

@Stephan-4711: to be honest I don't really like the idea to change password to a less secure, but c'est la vie, let's see if it works

Stephan-4711 commented 3 months ago

I just did it with an extra user for testing this behavior and I can say, it's not because of a to strong password, have still the same problems.

sezlony commented 3 months ago

@Stephan-4711: I said 'less secure' password, because if you remove a special character from a password it surely becomes less secure and yes, I confirm that using a password without anything fancy does the trick

I would have never thought of it... now that it's solved I would gently suggest that this be included in the documentation

sezlony commented 3 months ago

ok, the one is solved, the other just starts 🤣🤣🤣🤣🤣🤣

Logger: homeassistant.components.stream.stream.camera.udvar_folyekony
Source: components/stream/__init__.py:431
Integration: Stream (documentation, issues)
First occurred: 11:01:14 (14 occurrences)
Last logged: 11:16:27

Error from stream worker: Error opening stream (HTTP_UNAUTHORIZED, Server returned 401 Unauthorized (authorization failed)) rtsp://****:****@192.168.1.5:554/h264Preview_01_sub 
xannor commented 3 months ago

It does not need to stay less secure, it just shows that an encoding issue is the problem and needs to be corrected in the integration. Also the "complexity" of a password is not the strength, but the variance and length. The more possible combinations makes it harder to brute-force. So a password of 16 (a)'s is more secure than any combination of 10 or less characters. Special characters just slow down humans.

@Stephan-4711 I dont think the RTMP stream can be proxied correctly outside of HA, In fact this was one of the areas that I was trying to work on over winter, but they only "proxy" capability HA provides is the Stream integration, and the playback does not work well in it. Plus newer cameras that are HD dont play well with RTMP anyway. I had built some code to do an actual download, but limitations in HA (namely a hard 30sec connection limit) would break the download after 30 seconds. The only way to work around it was to pass the dl url to the client, which breaks any remote connectivity.

I wish a viable general proxy integration would be built for HA so other types on pass-thru connections could be provided to clients regardless of how they are connected (Browser, app, remote, local, external service, etc.)

xannor commented 3 months ago

@sezlony give it some time to refresh, or restart HA, it could be something is caching the old password, or the cameras limited defenses fired up when you changed it and it is denying the auth. The some cameras do have a limited attack protection where they would start denying connections from a particular client after to many failed attempts.

Stephan-4711 commented 3 months ago

a general proxy sound very cool, sadly I'm not a coder just an admin. I`m not able to code such things :-(

Stephan-4711 commented 3 months ago

I gues * ^doesn't make problems in encoding. the password with this signs where working

sezlony commented 3 months ago

It does not need to stay less secure, it just shows that an encoding issue is the problem and needs to be corrected in the integration. Also the "complexity" of a password is not the strength, but the variance and length. The more possible combinations makes it harder to brute-force. So a password of 16 (a)'s is more secure than any combination of 10 or less characters. Special characters just slow down humans.

@xannor: wow, that was useful, thank you for clarifying!

majkers commented 3 months ago

@xannor did you read my last comment https://github.com/home-assistant/core/issues/110939#issuecomment-1953653259? Can You comment on that?

sezlony commented 3 months ago

@sezlony give it some time to refresh, or restart HA, it could be something is caching the old password, or the cameras limited defenses fired up when you changed it and it is denying the auth. The some cameras do have a limited attack protection where they would start denying connections from a particular client after to many failed attempts.

@xannor: just as you said, the error messages were cleared up after a HA restart!

thank you!

etrochim commented 3 months ago

I'm encountering this issue with a Reolink Video Doorbell Wifi but I don't think the solutions presented in this issue apply to this case.

I'm running Home Assistant Core 2024.4.2 in a docker container in host networking mode.

This is the error I am seeing (no difference from the other errors here): 2024-04-08 18:56:33.396 ERROR (stream_worker) [homeassistant.components.stream] Error from stream worker: Error opening stream (ERRORTYPE_5, I/O error) rtmp://10.0.0.151:1935/vod/Mp4Record%202024-04-08%20RecS03_DST20240408_113128_113204_3914C08_1B6A17.mp4?channel=0&stream=1&user=****&password=****

  1. I'm not using a password that requires URL encoding; I'm just using alphanumeric characters and underscores.
  2. The URL in the error message should be the correct URL. I can copy that URL directly into VLC, change the username and password, and VLC will play it without issue. So, at least for the video doorbell, it doesn't appear to be the case of a wrong URL as noted by @majkers. The other URL (http://IP_NO_PORT/cgi-bin/api.cgi?cmd=Playback&source=filename.mp4&output=filenam.mp4&user=USER&password=PASS) does not seem to work.
sezlony commented 3 months ago
  1. I'm just using alphanumeric characters and underscores.

not that I'm an expert in this, but I'm quite sure that this is the very problem! (just as in my case!) please try a password without ANY special characters other than letters and numbers and try again!

xannor commented 3 months ago

That second url is a NVR playback url, i beleive, and only works with an NVR. (hopefully the IP_NO_PORT, USER, and PASS are just your obsfucation, and not the actual url as those would be invalid.)

When you loaded the stream in VLC, in the stream info, did it say what type of stream it was? The sream component of HA only supports HLS, and if the doorbell uses a different structure, it chould cause that component to fail. Unfortunately, this is not something that is part of this integration, but a core part of HA and if the camera so not follow its rules, it will refure to work with it.

majkers commented 3 months ago

No it not NVR only. It is a link taken from HTTP web page accesible for every cam in playback mode. For example from my Duo 2 WiFi:

image

For VLC I just have to replace token with user and password and stream has info like this:

image

And it doesn't mind special chars....

etrochim commented 3 months ago
  1. I'm just using alphanumeric characters and underscores.

not that I'm an expter in this, but I'm quite sure that this is the very problem! (just as in my case!) please try a password without ANY special characters other than letters and numbers and try again!

It appears you're exactly right! I convinced myself that my password couldn't be the problem because an underscore is an unreserved character. But I just changed my password to only alphanumeric characters and it works.

sezlony commented 3 months ago

And it doesn't mind special chars....

you have to understand, that VLC is not Home Assistant (and vice versa), so what is working with VLC will not necessarliy work in HA.

as I learned from your posts you have never tried changing your password avoiding special chars as suggested, so you should try that first! (the playback links are probably just fine as they are)

majkers commented 3 months ago

No I did not cause I don't think that it is OK that integration forces someone to change password to IMHO less secure one even though Reolink itself doesn't mind special chars.

starkillerOG commented 2 weeks ago

@etrochim thank you very much for reporting the underscore "" in the password was the problem in your case. I will be looking into this (changing my own password to include a "") and hopefully figure out how to get the encoding of the password right.

It is fairly hard for me to try out all the possible special chars in a password and the encoding that reolink requires is not very well documented or obvious....

Luckely the normal API does not need a password in the URL, but only once in the json body of the login command which does not require any encoding (special chars are fine there). Then you get a nice short lived token which only has plain letters....

That beeing said, I changed the way in which recordings work for HA 2024.7.0 It will now be using diffrent URLs which use the token instead of password. Hopefully that will improve the situation.

Please report back if it is working after HA 2024.7.0

sven337 commented 2 days ago

HA 2024.7.1 works for me to view the videos while 2024.5.5 did not. However, I only see the "low resolution" ones.

starkillerOG commented 2 days ago

@sven337 glad to hear it is now working for you!

If you only see the low resolution playback videos and not the high resolution, that is because the high resolution are encoded with h265. Unfortunately almost all browser do not support playing h265 encoding.... also the companion app does not support h265 as far as I know.

The low resolution is encoded with h264.

homecb commented 1 day ago

HA 2024.7.1 works for me to view the videos while 2024.5.5 did not. However, I only see the "low resolution" ones.

Still. not working for me on 2024.7.1. Any particular configuration / setting that you've changed or suggest that I check?

homecb commented 1 day ago

The issue appears to be with https / SSL. I'm getting the following errors:

Using the browser

Logger: homeassistant.components.reolink
Source: helpers/update_coordinator.py:344
integration: Reolink IP NVR/camera (documentation, issues)
First occurred: 7:28:03 PM (1 occurrences)
Last logged: 7:28:03 PM

Error fetching reolink.Garden Cam data: Host 192.168.3.230:443: connection error: Cannot connect to host 192.168.3.230:443 ssl:default [Connect call failed ('192.168.3.230', 443)]
Logger: reolink_aio.api
Source: components/reolink/camera.py:151
First occurred: 7:28:22 PM (1 occurrences)
Last logged: 7:28:22 PM

Error while logging out: Host 192.168.3.230:443: connection error: Cannot connect to host 192.168.3.230:443 ssl:default [Connect call failed ('192.168.3.230', 443)]

Using the mobile app Screenshot_20240709_192850_Home Assistant

Anyone can help?

starkillerOG commented 1 day ago

I think this is because of the SSL certificate of the camera. I will look into this, but it may take some time before I figure this out since it has to do with code outside the reolink integration. (How the frontend loads the video).