core: Live Streaming not working in Frontend if Camera supports only UDP rtsp protocol

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):

https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/stream/__init__.py

# 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

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 9
  • Comments: 38 (7 by maintainers)

Most upvoted comments

So it looks like your camera doesn’t 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.

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.

  • First access the home assistant bash with $ docker exec -it homeassistant bash
  • Then try to find the component with : $ find / -name “stream” The result should be something like $ /usr/local/lib/python3.7/site-packages/homeassistant/components/stream
  • Edit the file to comment the three lines specified before $ vi /usr/local/lib/python3.7/site-packages/homeassistant/components/stream/init.py
  • Exit and restart hassio (not sure it is necessary ?)

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.

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.

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 ?

Hi! I just comment all the IF instruction en works well.

  1. I add de scream component to custom_component
  2. a comment line 75-92 in init.py
  3. restart