Ring: Please expand samples to include rtsp streaming

Created on 21 Sep 2019  路  19Comments  路  Source: dgreif/ring

@dgreif - any chance you could expand your examples (here: https://github.com/dgreif/ring/tree/master/examples) to include getting an actual rtsp stream? My node skills are not enough to understand how to get that done. Your example streams to disk, which is awesome but as discussed here (https://github.com/tchellomello/python-ring-doorbell/pull/133?_pjax=%23js-repo-pjax-container) I am looking to turn it into a proper stream.

enhancement

Most helpful comment

Agreed. thanks for all your efforts.

All 19 comments

@dgreif any update? Is it feasible to make an example that would not stream to disk but return an rtsp stream? I am stuck :) Thanks!

@jeroenterheerdt sorry for the lack of communication. I started on this earlier in the week but haven't had much time to look into it. It's mainly a matter of getting the right ffmpeg config for setting up RSTP

hi @dgreif - thanks. Well, it's not only that, since your code does a lot of interesting things with IPs and ports that I do not get but apparently works. It would be great if somehow you could wrap it into a easy to call method or provide an example of how to do this :) Appreciate all the effort!

@dgreif - I was able to get an RTSP camera to work in Home Assistant, so basically, where I need help with is to retrieve the RTSP URL for Ring. If you can include an example that will return that URL and anything else that is needed that would be awesome. Right now I am not sure how to retrieve that URL. All I see is the sipSession but that does not seem to include the RTSP URL.

You will need to use ffmpeg to create an rtsp url. Ring does not support it, so you have to let the sipSession get the raw packers and pass them on the ffmpeg, which can then bind to a local port and serve an rtsp endpoint. Everything is set up so that you can pass wherever options you want to ffmpeg, I just haven鈥檛 had time to look up the arguments for rtsp as an output

ok, so what do I pass to FFMPEG to get the RTSP URL? Just the SipSession? All the example I've found pass an RTSP URL to FFMPEG and that is the one thing that I do not have ;)

The sipSession uses ffmpeg internally. You can pass options to it via the start method. I don鈥檛 know what options you need to pass because I haven鈥檛 had time to look into it

ok - thanks. let me know if you found anything. I'll keep poking at it from my end. thanks.

hey - any guidance here? do you happen to have doc pages or some other community place where I can take this? I don't want to burden you too much.

@jeroenterheerdt sorry for the lack of communication. I started looking into this a few weeks ago but got pulled off on other issues. I'm not sure an rtsp server is going to be extremely reliable since the streams from Ring aren't great over long periods of time. They theoretically stay connected, but it's all going through Ring servers, causing lots of video to be stored, and can be cut off at any point on their end. Does HA support any other into for cameras, or just rtsp?

I think in general HA allows streams (MJPEG for example). At least that's what I see being used by other components for cameras.

@dgreif any guidance on how to use alternative connections next to RTSP with your component?

right now I am trying using the browser-example and running it in a container. see #220 for how to make the browser example work.

@jeroenterheerdt sorry but I just don't have the time to figure out RTSP. If you get it working, you are welcome to open a PR. I think the best solution - by far- would be for you and @bhden2007 to work together and get a true port to python. Closing this issue in favor of that solution. Some discussion in #217

Agreed. thanks for all your efforts.

@jeroenterheerdt not sure if this is still relevant to you but I figured out how to do RTSP. I have been using the code in this repo to stream in HLS/MP4 to my Blue Iris NVR software. I checked out the code for your Hassio addon and can see you're utilising the same ffmpeg settings to pump up a segmented HLS stream using a m3u8 playlist. Its been working fine but the latency is an issue when trying to view the stream on a hall mounted tablet to check who was at the door. So today I had a go at using RTSP instead which would cut the latency. I got it working and it's not really that hard. Might package this up in a repo of my own or maybe just add here as an addition to the 'examples' section @dgreif? The only issue is it does require another piece of software running: rtsp-simple-server https://github.com/aler9/rtsp-simple-server
Also I've only done an hour or so testing but was quite pleased I got it working so just want to let you know.

@privatesam I am interested on testing this if you can get a repo going. Thanks!

@privatesam would love to see you make a PR to my hassio addon 馃槉

To be honest I think it just easier for everyone if I just explain what I did here. Basically for RTSP streaming you have to do it through a RTSP server - I don't know the technical reasons or how these work, in fact I was put off at first because all the RTSP servers were heavy, complicated code and didn't seem worth getting to grips with for this purpose. Then I discovered https://github.com/aler9/rtsp-simple-server - just download the binary and literally run it on a linux instance (prefereably the same one your using the ring-api on) using ./rtsp-simple-server and note the IP of this instance, e.g 10.0.0.15. Then simply change the code in the browser example from dgreif or whichever way your are using it from:

const sipSession = await camera.streamVideo({
output: [  
  '-preset',
  'veryfast',
  '-g',
  '25',
  '-sc_threshold',
  '0',
  '-f',
  'hls',
  '-hls_time',
  '2',
  '-hls_list_size',
  '6',
  '-hls_flags',
  'delete_segments',
  path.join(publicOutputDirectory, 'stream.m3u8'),
],})`

to:

const sipSession = await camera.streamVideo({
output: [
    '-f',
    'rtsp',
    '-c:v',
    'libx264',
    '-preset',
    'ultrafast',
    '-tune',
    'zerolatency',
    '-b',
    '600k',
    'rtsp://localhost:8554/mystream'
]

You may want to tweak those ffmpeg rtsp settings to suit you - those are working well for me.

What you are basically doing is using ffmpeg and dgreif's ring-api to send the rtp stream to the rtsp-simple-server with the line rtsp://localhost:8554/mystream. If you're running rtsp-simple-server somewhere different to the ring-api you'll obviously need to change the localhost to the IP of the instance (and then deal with firewall etc). Then the rtsp-simple-server runs a server with the rtsp stream. At least thats how I understand it.

Then you should be able to open VLC or whatever other video player your using on your network and point at rtsp://10.0.0.15:8554/mystream. Note that VLC did playback for me with a weird green overlay which I didn't bother trying to figure out because in my NVR it streamed beautifully.

If I get time I might have a look at a PR for the hassio addon but I need to think about how best to package rtsp-simple-server.

Also big footnote - be careful how long and frequently you hit Ring servers with this api for streaming - they don't like 24/7 streaming and we don't want to break this for everyone so be clever with how and when you pull a stream.

Was this page helpful?
0 / 5 - 0 ratings