Home Assistant release with the issue:
0.91.3
Last working Home Assistant release (if known):
Probably no one
Operating environment (Hass.io/Docker/Windows/etc.):
FreeNAS 11.2 Jail
Component/platform:
stream
onvif
Description of problem:
I have been using some chinese cameras (Yoose) that support Onvif standard. Everything (including PTZ control) works fine if I do not enable stream component. When I enable stream component, preview in the frontend is OK, but streaming doesn't work.
Looking at the log I see the following error:
ERROR (stream_worker) [libav.rtsp] Nonmatching transport in server reply
Testing with ffmpeg from command line I found out that my cameras support UDP rtsp streaming, but not TCP. In fact, when I test with the following command line:
ffmpeg -f rtsp -rtsp_transport udp -i rtsp://192.168.1.*:554/onvif1 -an -f null -
I do not see any error, while if I use:
ffmpeg -f rtsp -rtsp_transport tcp -i rtsp://192.168.1.*:554/onvif1 -an -f null -
I see exactly the same error.
Looking at the source code of the stream component in the Github repository, I see (lines 52-55):
# For RTSP streams, prefer TCP
if isinstance(stream_source, str) \
and stream_source[:7] == 'rtsp://' and not options:
options['rtsp_flags'] = 'prefer_tcp'
If I comment out these lines, stream component automatically selects UDP protocol and streaming works perfectly.
Is there any reason why TCP protocol is prefered/forced in the stream component? I searched the documentation but I didn't found any way to select UDP from the configuration (adding "-rtsp_transport udp" under extra_arguments in onvif component doesn't seem to work).
I think it would be useful to modify the stream component leaving the possibility to select between TCP and UDP in order to enhance compatibility. Probably the best way to do it would be to pass the extra_arguments in the camera component specification to the stream component, in order to be able to specify it on a per camera basis,
Problem-relevant configuration.yaml
entries and (fill out even if it seems unimportant):
stream and/or onvif: need to add option to choose between rtsp TCP or UDP protocol for live streaming
I also have an issue with the viewing the live stream on the web interface. i have a yoosee camera. if i disable the stream component i can see live stream.
I tried disabling the lines related to tcp transport but that didn't solve the issue. only by disabling the stream component the video will show on web interface.
if you can provide any advise to have the camera working with the stream component that would be great.
@engrbm87 Can you try again disabling the lines I have commented out and appending "?latest" (without quotes) to your HomeAssistan IP/domain?
It seems it is needed also for other users, it should tell the interface to use the latest Javascript engine.
Let me know if it works for you.
I also have an issue with the viewing the live stream on the web interface. i have a yoosee camera. if i disable the stream component i can see live stream.
I tried disabling the lines related to tcp transport but that didn't solve the issue. only by disabling the stream component the video will show on web interface.
if you can provide any advise to have the camera working with the stream component that would be great.
@engrbm87 Could you also confirm that you see the same error I see in the log and that error goes away when you comment out those lines?
Hi @Veda82 Thanks for the tip. It is working fine now. and yes i was seeing that error before i commented the lines and now there is no error anymore.
Hi @engrbm87 good to have an additional confirmation that it is working!
So it looks like your camera doesn鈥檛 properly broadcast what inputs are available.
FFMPEG Docs -> prefer_tcp "Try TCP for RTP transport first, if TCP is available as RTSP RTP transport."
I will look into if we can support explicitly setting this via another method.
@hunterjm thanks for your support!
Hi, same here with an Hikam S5.
My errors are:
2019-05-02 16:08:24 ERROR (stream_worker) [libav.rtsp] Nonmatching transport in server reply
2019-05-02 16:08:48 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
If I can help in any capacity, just ping me.
Hi @GuenMat you can try the solution I've provided above (modifying the following file in your local installation):
# For RTSP streams, prefer TCP
if isinstance(stream_source, str) \
and stream_source[:7] == 'rtsp://' and not options:
options['rtsp_flags'] = 'prefer_tcp'
After the modification, have a look at the log to see if the error disappears and if streaming works for you. Remember also to append "?latest" (without quotes) to your HomeAssistan IP/domain.
Hi @Veda82, thanks for the answer.
I copied the full steam component in my custom_components folder. I commented the lines you specified, and added a log to check if it is used.
_LOGGER.error("BOUH BOUH BOUH BOUH")
When hassio restarts, I get the messages:
2019-05-02 18:14:30 INFO (SyncWorker_6) [homeassistant.loader] Loaded stream from custom_components.stream
2019-05-02 18:14:30 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for stream which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
So all seems good.
But I get the same error, and I do no see my log line even though I added a log config in configuration.yaml :
logger:
default: info
logs:
homeassistant.components.stream: debug
I am afraid I do not really understant the ?latest tag.
When I connect to my server, for exemple http://192.168.0.141:8123?latest
It get replaced. Is it enough ?
Hi @GuenMat,
I would try adding a / before ?latest, that is:
http://192.168.0.141:8123/?latest
Anyhow, this shouldn't affect the log, so if you are still seeing the error it won't work.
I would try one last thing: instead of putting it in the custom component directory, I would modify the original file.
You can search for it with something like: find / -name "stream"
The path you're searching for should end like this (more or less):
python3.6/site-packages/homeassistant/components/stream/
Let me know if it works.
Hi @Veda82, thanks for the answer.
I copied the full steam component in my custom_components folder. I commented the lines you specified, and added a log to check if it is used.
_LOGGER.error("BOUH BOUH BOUH BOUH")
When hassio restarts, I get the messages:
2019-05-02 18:14:30 INFO (SyncWorker_6) [homeassistant.loader] Loaded stream from custom_components.stream 2019-05-02 18:14:30 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for stream which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
So all seems good.
But I get the same error, and I do no see my log line even though I added a log config in configuration.yaml :logger: default: info logs: homeassistant.components.stream: debug
I am afraid I do not really understant the ?latest tag.
When I connect to my server, for exemple http://192.168.0.141:8123?latest
It get replaced. Is it enough ?
Thank you again for the answer. That is very nice. I'll try that tomorrow, it is a bit late tonight.
I discovered hassio last week-end, and it is abolutely wonderful : the software AND the community.
I was able in a few hours to automatise everything at home. But I still have to familiarised myself with python ;) I come from the "heavy" Java world :)
I have two very dodgy Hikam S5 cameras :(
It works with vlc, but with hassio I can only get the picture preview with ffmpeg, no video flux.
Same with onsif.
I still think my cameras are at fault, because I never found a way with zoneminder. And it seems I was not alone ....
hi any update on fix on this , i am unable to find the componets folder, i have homeassistant running in docker in unraid, and also how to disable the components
Hi @Veda82, thanks again for the answer.
It works now !!! Thanks a lot !!! Trying to override the stream component was not the right idea.
I followed your instructions, and now, it works flawlessly, whenever I use the onvif configuration or the ffmpeg one.
For @lokifr3k, or anybody else having the issue, this is what I did.
In my configuration.yaml, this is how I configured my cameras (both Hikam S5)
ffmpeg:
ffmpeg_bin: /usr/bin/ffmpeg
camera:
- platform: ffmpeg
name: Cuisine
input: "rtsp://192.168.0.171:554/onvif1"
- platform: onvif
name: Salon
host: 192.168.0.170
username: admin
password: XXXXXXXXX
Now I guess we have to wait for a fix to specify the udp transport option. It never worked for me when I passed "-rtsp_transport udp" as extra arguments, or directly in the input command.
I suppose if hassio gets an update, the modification will be lost.
It is nice it is not too hard to put back.
Thank you again.
@hunterjm Are there any news? Do you think it's possible to add an option for this?
Thanks in advance!
I have the same issue, manually fixed now. Will this be fixed in the next release of homeassistant?
@hunterjm I wouldn't want to be annoying, but is there any chance of implementing this?
@hunterjm @veda82 I agree, I do not want to bother you either, I understand that you have other priority. But it is quite annoying to have to do the changes at each home assistant update.
It is not up to you to fix the lazy camera manufacturers, but as the same time, they do not aswer when you report the issue :(
@GuenMat @Veda82 the beautiful thing is that this project is open source, and you appear to have already found the issue. I鈥檒l keep tracking this, but please feel free to submit a PR with the fix (taking into account cameras that do support the feature) and I can review it and merge.
Edit: sorry, on mobile and just scrolled back up. Some cameras only support tcp, others only udp, so it鈥檚 not an easy fix and needs to be made a config option.
@GuenMat
Hello! I have the same problem. Who uses Hass.io?
I have access via SSH and via FTP. I do not know how to get to stream files. Do I need a program?
The most I could get was:
/ usr / share / bash-completion / completions / stream
Thank you in advance for your attention.
I have hassio 0.95 installed and i located the stream folder under /src/usr/homeassistant/homeassitant/compnents/stream.
I'm using HA with VirtualBox, how do I access it to make these modifications?
@wsjunior1985 if you have installed hassio then you need to follow the same commands mentioned in this reply.
@wsjunior1985 if you have installed hassio then you need to follow the same commands mentioned in this reply.
I'm using the vmdk image provided and VirtualBox. Is there any user and password that I could use to make login and type those commands or any way to execute this using the web user interface? When I log in with root account without password it doesnt give me a normal bash shell, just some HA restricted commands avaliabe..
I have hassio 0.95 installed and i located the stream folder under /src/usr/homeassistant/homeassitant/compnents/stream.
I can not execute this item:
$ docker exec -it homeassistant bash
Through FTP or SSH ecnontr this path:
/ usr / share / bash-completion / completions / stream
strem is a shortcut pointing to the convert file
When editing does not bring anything to the aforementioned. I can not find the .py file
Will this be fixed? I dont have the knowledge to make a fix, now I have to fix it manualy every time I update HA...
Edit: Since 0.97.x manual editing does not work anymore with the method above... :-(
I use this entrypoint script for disable prefer_tcp
option
#!/bin/sh
### entrypoint.sh
sed -i -e 's/^ options\[\"rtsp_flags\"\] = \"prefer_tcp\"$/ #options\[\"rtsp_flags\"\] = \"prefer_tcp\"/' /usr/src/app/homeassistant/components/stream/__init__.py
python -m homeassistant --config /config
docker-compose.yml:
version: '3'
services:
hass:
image: homeassistant/home-assistant
volumes:
- ./hass/config:/config
- ./hass/entrypoint.sh:/entrypoint.sh
command: /bin/sh -c "/entrypoint.sh"
restart: always
network_mode: host
or run this command
sed -i -e 's/^ options\[\"rtsp_flags\"\] = \"prefer_tcp\"$/ #options\[\"rtsp_flags\"\] = \"prefer_tcp\"/' /usr/src/app/homeassistant/components/stream/__init__.py
before start home-assistant
following discussion, same issue there
I have hassbian in venv,
Same issue, solved it change __init__.py in /srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/stream
following discussion for options to change it in my configuration.yaml
Hi! I just comment all the IF instruction en works well.
+1
Hi! I just comment all the IF instruction en works well.
- I add de scream component to custom_component
- a comment line 75-92 in _init_.py
- restart
hello, sorry it's been a while since I tried to make my yoosee camera work but they don't work in live streaming, you added strem component in custom_component and you edited those lines? can i ask you what you put in? Thanks
Using Hassio (HassOS)
if (
isinstance(stream_source, str)
and stream_source[:7] == "rtsp://"
and not options
):
options["rtsp_flags"] = "prefer_tcp"
options["stimeout"] = "5000000"
try:
streams = hass.data[DOMAIN][ATTR_STREAMS]
stream = streams.get(stream_source)
if not stream:
stream = Stream(hass, stream_source, options=options, keepalive=keepalive)
streams[stream_source] = stream
else:
# Update keepalive option on existing stream
stream.keepalive = keepalive
# Add provider
stream.add_provider(fmt)
Home Assistant release with the issue:
0.91.3
Last working Home Assistant release (if known):
Probably no one
Operating environment (Hass.io/Docker/Windows/etc.):
FreeNAS 11.2 Jail
Component/platform:
stream
onvifDescription of problem:
I have been using some chinese cameras (Yoose) that support Onvif standard. Everything (including PTZ control) works fine if I do not enable stream component. When I enable stream component, preview in the frontend is OK, but streaming doesn't work.
Looking at the log I see the following error:
ERROR (stream_worker) [libav.rtsp] Nonmatching transport in server reply
Testing with ffmpeg from command line I found out that my cameras support UDP rtsp streaming, but not TCP. In fact, when I test with the following command line:
ffmpeg -f rtsp -rtsp_transport udp -i rtsp://192.168.1.*:554/onvif1 -an -f null -
I do not see any error, while if I use:
ffmpeg -f rtsp -rtsp_transport tcp -i rtsp://192.168.1.*:554/onvif1 -an -f null -
I see exactly the same error.
Looking at the source code of the stream component in the Github repository, I see (lines 52-55):
# For RTSP streams, prefer TCP if isinstance(stream_source, str) \ and stream_source[:7] == 'rtsp://' and not options: options['rtsp_flags'] = 'prefer_tcp'
If I comment out these lines, stream component automatically selects UDP protocol and streaming works perfectly.
Is there any reason why TCP protocol is prefered/forced in the stream component? I searched the documentation but I didn't found any way to select UDP from the configuration (adding "-rtsp_transport udp" under extra_arguments in onvif component doesn't seem to work).
I think it would be useful to modify the stream component leaving the possibility to select between TCP and UDP in order to enhance compatibility. Probably the best way to do it would be to pass the extra_arguments in the camera component specification to the stream component, in order to be able to specify it on a per camera basis,
Problem-relevant
configuration.yaml
entries and (fill out even if it seems unimportant):stream and/or onvif: need to add option to choose between rtsp TCP or UDP protocol for live streaming
how did you solve? I also have Yoosee rooms that I couldn't get to go PTZ and live streaming, to disable TCP like you did? I use Hassio with HassOS. Thanks
Since there are to use PTZ how did you configure it?
@GuenMat @Veda82 the beautiful thing is that this project is open source, and you appear to have already found the issue. I鈥檒l keep tracking this, but please feel free to submit a PR with the fix (taking into account cameras that do support the feature) and I can review it and merge.
Edit: sorry, on mobile and just scrolled back up. Some cameras only support tcp, others only udp, so it鈥檚 not an easy fix and needs to be made a config option.
@hunterjm It seems that not passing that flag works fine with both TCP and UDP cameras:
ffmpeg -rtsp_flags prefer_tcp -i <camera URL> test.mp4
results in the same Nonmatching transport in server reply
error for my camera, but ffmpeg -rtsp_flags none -i <camera URL> test.mp4
works well. Can anyone confirm that passing none
as the flag also works for TCP-only cameras? My guess is that it does.
It seems that https://github.com/home-assistant/home-assistant/blob/bb5da77f2c6535754d6aeef4c6b21c71784ee7b9/homeassistant/components/stream/__init__.py#L51 takes an options
parameter that could override the prefer_tcp
flag. However, it's not passed down in https://github.com/home-assistant/home-assistant/blob/8a28d5fbee3de131508bd2f5c9701586ccd587cf/homeassistant/components/camera/__init__.py#L140, so with my limited knowledge of HA internals, it would take me weeks to figure out how to pass an option from configuration.yaml
under the stream:
or camera:
keys all the way down to https://github.com/home-assistant/home-assistant/blob/bb5da77f2c6535754d6aeef4c6b21c71784ee7b9/homeassistant/components/stream/__init__.py#L51.
That's not to say your work on creating this component is not appreciated. It is, indeed, beautiful code, as @balloob mentioned. However, for someone with zero HA commit experience (such as myself and others in this thread) to jump in and make significant changes to this component's core is a bit unrealistic.
Hello I'm new here, I have the same problem with Hassio and a Sricam SP012 cam.
It seems the source code of init.py has been changed since the 1st post date. Exactly what lines has to be commented?
And other question, I access my raspberry through putty and see a black screen with the promt "core-ssh:~#"
From here, what commands do I need to edit the file init.py?
Than you for your patience and sorry my english
happy new year!!!
yust use custom_component. copy the folder stream. edit de ini.py file as its was mentioned before.
comment line 75-92 in init.py
restart
Hi! With custom_component/custom_stream i get the following raise error:
if DOMAIN not in hass.config.components:
raise HomeAssistantError("Stream integration is not set up.")
This issue has been fixed only for Onvif camera but you can setup a rtsp stream_source in generic camera. And if this camera only supports UDP, you fall into the 461 Unsupported Transport
error in log.
Is it possible to fix that also generic cameras ?
Most helpful comment
So it looks like your camera doesn鈥檛 properly broadcast what inputs are available.
I will look into if we can support explicitly setting this via another method.