Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Live view proxy #23

Open
anthonyangel opened this issue Mar 13, 2017 · 81 comments
Open

Feature request: Live view proxy #23

anthonyangel opened this issue Mar 13, 2017 · 81 comments

Comments

@anthonyangel
Copy link

Hi, would it be possible to use this library to allow a continuous live view stream to be exposed locally as an IP camera feed (either ONVIF or just an mp4 stream), so that it could be recorded by an NVR?

Ideally this would bypass Rings servers and just stay within the LAN (would reduce the overheads in terms of data transmission), but that doesn't seem possible at the moment, but this would allow Ring to be integrated into an existing CCTV installation instead of existing as a separate system.

Thanks,
Anthony

@tchellomello
Copy link
Owner

@anthonyangel if you call the function live_streaming_json you will get a JSON output with the data to connect to the SIP streaming. Maybe we could use this function to implement this proxy, however not sure if that would lock the device for other notifications.

@anthonyangel
Copy link
Author

Thanks, I'd had a look at that already for 1-off uses it works well. The initial issues I can foresee are:

  • Timeout on the live stream, I think that the URL needs to be refreshed every 10 minutes
  • Whether having this connected locks out the device

@Klathmon
Copy link

I'm looking into this a bit more. I'm able to grab the video and audio using an SIP program (interestingly enough the stream only works without encryption... so i'm guessing that these videos are being sent across the net entirely un-encrypted...)

The stream returned from live_streaming_json expires in about 3 minutes for me. It seems that the expires_in field is in seconds, and it varies, requiring you to grab a new stream when it expires and maybe stitch them together at some point?

The doorbell still works while it's streaming, however i'm not sure if notifications will still go off on the phone when you are using it. I'll have to see if I can test this at another point, but I have a feeling it will work the same as I have been watching the stream on my phone (through the official app) while my wife tests it and it rang her phone, so I'm assuming it will work correctly.

I'm not the most versed in python, but there does seem to be a library for SIP in python that could be possibly used here. With that it might be possible to grab a raw video stream out.

So TL;DR: it does look like this is possible, but it's not going to be all that easy, and it's probably way outside my ability in python.

@jlippold
Copy link
Contributor

@Klathmon What SIP client did you use? There's are some sip libraries that support WebRTC with websockets but I'm shooting in the dark because I can't even get a simple player going.

@Klathmon
Copy link

Klathmon commented Apr 23, 2017

I used the Blink client to do my testing. I was also looking at the WebRTC players that interface with SIP but decided to hold off as they wouldn't integrate as well with a python project like this (or home assistant).

By calling the SIP line I was able to get 2-way audio working instantly, but in order to get video working I had to go into Blink's Preferences and under "Accounts", switch the tab to "Media" and deselect "Encrypt audio and video" under "RTP Options"(i also unchecked "Send inband DTMF" but I don't think that applies here).

FYI if you have neighbors, the second you connect you will be broadcasting your computer's microphone to the ring speakers until you hang up! I think I scared the hell out of mine with a very loud "Holy shit it works!" the first time it connected!

@tchellomello
Copy link
Owner

That is very cool. Would be awesome to have this working in home assistant.

@jlippold
Copy link
Contributor

That blink SIP client is expensive, let me know if you get video working, if you do then it's worth looking into an open source python lib

@Klathmon
Copy link

Klathmon commented Apr 23, 2017

@jlippold I'm using the free/trial version and it is working well enough for now. It was also the first one I tried so others might work.

And I forgot to finish that sentence, it works with video if you uncheck using encryption. Both video and audio work great.

@jlippold
Copy link
Contributor

I assume you're on windows maybe? the mac app isn't free

@Klathmon
Copy link

Yes, windows.

It does seem to be bone-stock SIP so any client that let's you disable encryption should work for both audio and video.

@jlippold
Copy link
Contributor

yea man, this works well.. For anyone wondering the sip address, is the sip_to property on the json. No other config needed, just that address. The SIP address expires after 10 seconds or so

@haimiko
Copy link

haimiko commented Apr 24, 2017

In the sip_to, is the is username-password@sipurl:port ?

@jlippold
Copy link
Contributor

There's no password needed, just that sip_to property value... The "security" is that the sip to address expires frequently. FWIW, I only got it working with the windows version of that blink software/

@haimiko
Copy link

haimiko commented Apr 24, 2017 via email

@jlippold
Copy link
Contributor

if you can dynamically pull the sip recording, let us know. I spent a whole day trying and gave up

@Klathmon
Copy link

Klathmon commented Apr 24, 2017

You should be able to use any client that allows "Direct SIP dialing".

So when you setup a new SIP app, it will ask you for server, username, password, etc... You don't need any of that. You just need to be able to dial an SIP URI directly.

Other than that, you need to make sure you are using TCP not UDP (might be a setting in the options), and you need to ensure that you are not using any encryption (might be under a setting labeled RTP or something similar)

I just tried it with an android app MizuDroid and got it to work once, but you only have like 10 seconds from when you get the address till when you can't dial it any more.

I'm still looking into how the SIP protocol works and how to grab the RTP stream directly and mess with it. I'm confident we can get this working.

@Klathmon
Copy link

Klathmon commented Apr 24, 2017

Okay, i'm finally beginning to get this figured out.

So I've been doing some reading up on SIP (RFC 3261 and RFC 6665 are the big ones used).

I also managed to capture a full session using wireshark while i was testing with the Blink SIP client (don't want to share that publicly as i'm pretty sure the ring exposes enough info to let anyone connect to my camera in this communication).

A few things i've found out:

SIP is just an "initiation" protocol, all it does is setup another protocol which actually streams the data. that protocol seems to be RTP (which from a preliminary look, should be easy to convert to just about any video format). The SIP messaging responds with information on how to access this RTP stream, and it seems like it's randomized somewhat so we can't just skip the whole SIP messaging step and grab the stream.

It also looks like the version of SIP here uses some extensions (the second RFC I linked) to "subscribe" to something. That subscription request is being denied which is why i'm guessing these streams always end like 30 seconds after I start them.

I'm fairly sure we can get the SUBSCRIBE stuff to work by just impersonating the ring client, which means we can get a full stream (including 2-way audio if you want it) working.

All that being said, I'm gonna give this a shot. I haven't worked with python for like 7 years, so i'm hoping if I can get a "proof-of-concept" working, someone else can take the reins and actually get it working well.

My next step is to get some of this SIP messaging working in python. I'm going to use the Twisted library which does seem to have some support for SIP (here's the protocol definition in twisted).

@haimiko
Copy link

haimiko commented Apr 24, 2017 via email

@Klathmon
Copy link

Sorry to say but I think i'm throwing in the towel here (at least for a while).

I just don't know python well enough to be able to get anywhere, and i really don't think it will be very beneficial to this project if I spent the time to implement it in another language...

Here's some stuff I found, hopefully it's useful for someone to pick up:

  • p2p-sip seems to have a pure-python sip implementation in it. at the very least it's inspiration.
  • SIPPing a SIP packet forging tool. This was what I got the furthest with, but still can't get a full send->response working even for the initial "INVITE" packet.
  • Twisted's SIP class. It does seem like this will work great, but I spent like an hour trying to figure out how to send the request before giving up.
  • Blink the SIP client i've been using to do all of the exploration and testing. As long as you disable encryption in the settings as described further up in the thread, it works great. Make sure to make the request within like 30 seconds of calling live_streaming_json

Also, wireshark has proven to be super helpful in tracking down what is being requested and the responses.

I might pick this up in a week or so, but as of right now i'm just spinning and not getting anywhere.

@tchellomello
Copy link
Owner

@Klathmon you helped a lot already. Thank you so much for studying the protocol.

I want to get back to this RFE too which will be awesome to have this support.

Thanks everyone involved and let's try to get this working. I'll try to look at the libraries you pointed out too.

@Klathmon
Copy link

If you or anyone else are able to get the python plumbing started, I can muddle my way through the actual implementation of the back-and-forth and grabbing the stream data.

I actually love reverse engineering like that, it's just trying to do this in a language I haven't used for years is biting off more than I can chew.

@IanMitchell77
Copy link

I can get the alert and decode the JSON string but what did you put in the Blink SIP client to get the video? sip_to?

Many thanks in advance!

@Klathmon
Copy link

Klathmon commented May 30, 2017

I believe it's the sip_to field (going from memory here). You do need to make sure you do this to get video working in the Blink SIP client:

go into Blink's Preferences and under "Accounts", switch the tab to "Media" and deselect "Encrypt audio and video" under "RTP Options"

Also you gotta be fast, once you get the JSON back you have like 30 seconds to get the URL and open the video feed before it expires.

@IanMitchell77
Copy link

Thanks!

Did you find a Linux cli or gui that worked?

@IanMitchell77
Copy link

I can get AV with the Blink software!

However I only get a few seconds before it disconnects - does anyone have any idea on what I need to do to make it last longer?

@jlippold
Copy link
Contributor

you have to requery the endpoint everytime it expires to get a new sip address

@IanMitchell77
Copy link

Maybe it is that, I'll check - Thanks!

It's seems that the sip token in the JSON response may be relevant here but I'm not experienced in SIP and don't have an idea what to do with it.

It takes me about 5 seconds to put the sip_to string in blink, I then call and video lasts for a few seconds. I thought it expires much later than that but has anyone automated getting the sip_to string in to blink and getting a new string when it finishes?

@Doudy
Copy link

Doudy commented Jan 27, 2019

Hello,
There may be ideas to find here!
If it does not interest someone.
https://medium.com/@jeffhollan/serverless-doorbell-azure-functions-and-ring-com-f24b44e01645

@Niek
Copy link

Niek commented Jan 28, 2019

Leaving this here, since the page itself is no longer available: https://web.archive.org/web/20180403003637/http://www.kidder.io/2017/07/04/ring-doorbell-api/

@kirantpatil
Copy link

Hi, I would like to know any opensource sip servers which is same as Ring servers.

@alekslyse
Copy link

Anyone got any further of connecting to the live stream. I cant see why it should be impossible as it is there - though even the windows app connects to 3.121.122.91 for auth. Just wish it would be a hidden rtsp stream or something running on the camera

@dgreif
Copy link

dgreif commented Jul 24, 2019

@rpavez @Sfinx I know I am really late to this thread, but I am working on implementing live video from Ring in my homebridge-ring plugin. I am very close to having it working, but can't quite crack it. I am successfully negotiation the SIP setup and am receiving RTCP packets on the port that I give to Ring, but am not receiving any RTP packets for some reason. What I really need at this point is a wireshark dump of the SIP and RTP dialog similar to the image that @rpavez posted a couple years ago. Would either of you be willing to supply one, or better yet, walk me through how you managed to capture the live session from the app? Feel free to respond over on dgreif/ring#35. Thanks to everyone here who supplied info and links on this issue as it has gotten me 95% of the way there!

@cdoublejj
Copy link

cdoublejj commented Aug 19, 2019

@rpavez @Sfinx I know I am really late to this thread, but I am working on implementing live video from Ring in my homebridge-ring plugin. I am very close to having it working, but can't quite crack it. I am successfully negotiation the SIP setup and am receiving RTCP packets on the port that I give to Ring, but am not receiving any RTP packets for some reason. What I really need at this point is a wireshark dump of the SIP and RTP dialog similar to the image that @rpavez posted a couple years ago. Would either of you be willing to supply one, or better yet, walk me through how you managed to capture the live session from the app? Feel free to respond over on dgreif/ring#35. Thanks to everyone here who supplied info and links on this issue as it has gotten me 95% of the way there!

well for wifi ring idk but, for PoE RING like the Elite I have, wouldn't one mirror the port on the switch and collect packets and data with Wireshark? i'v never done it before my self. I do have a managed switch and a VM running Wireshark.

@dgreif
Copy link

dgreif commented Aug 19, 2019

I managed to get the SIP messages using a capture tool on android. I have live streaming video fully functional in my homebridge-ring plugin now. Currently working on some refactoring to get audio working as well, but the basic SIP setup is solid at this point. Once the call is established, Ring's servers will send H264 video and PCMU audio over UDP to the ip/ports you give them in the SIP invite. Should be fairly portable to python if anyone has a good grasp of javascript and python.

@rpavez
Copy link

rpavez commented Aug 20, 2019

@rpavez @Sfinx I know I am really late to this thread, but I am working on implementing live video from Ring in my homebridge-ring plugin. I am very close to having it working, but can't quite crack it. I am successfully negotiation the SIP setup and am receiving RTCP packets on the port that I give to Ring, but am not receiving any RTP packets for some reason. What I really need at this point is a wireshark dump of the SIP and RTP dialog similar to the image that @rpavez posted a couple years ago. Would either of you be willing to supply one, or better yet, walk me through how you managed to capture the live session from the app? Feel free to respond over on dgreif/ring#35. Thanks to everyone here who supplied info and links on this issue as it has gotten me 95% of the way there!

I used just used the official Ring Desktop App https://ring.com/gettheapp connected to my ring device and then https://www.wireshark.org/download.html to check traffic filtered by SIP traffic only.

@cdoublejj
Copy link

So once it's captured i assume it would take some serious doing and CPU power to convert to ONVIF or RTSP or the likes for say sending over to Blue Iris?

@dgreif
Copy link

dgreif commented Aug 20, 2019

@cdoublejj as long as your target software supports h264, it won’t take much CPU at all. For HomeKit, I literally just pass along the video UDP packets without touching them. For audio, I have to convert from PCM to aac-eld because HomeKit is picky, but I do that with ffmpeg and it takes barely any CPU.

@jeroenterheerdt
Copy link

jeroenterheerdt commented Sep 13, 2019

I made a very quick and dirty solution for live streaming that basically wraps around the node solution made by @dgreif. Hopefully someone with more skills in Node can turn this into a proper Python solution. The PR is here if you want to try: #133. @tchellomello can we work to integrate this into the Home Assistant component as well?

@cdoublejj
Copy link

that's awesome!

Blue Iris supports H264 AND H265, I think it also supports more than just ONVIF and RTSP, think it may support a few other or at the very least it appears to have a range of protocols and camera types. It is a pretty robust solution! Heck i'd consider a bounty $$$ if wasn't a lofty goal.

@jeroenterheerdt
Copy link

I am not interested in Blue Iris :) I just want this to work in Home Assistant :)

@Devqon
Copy link

Devqon commented Jun 11, 2020

Is someone still on this in python? I was working further on the node solution by @jeroenterheerdt in a HA addon, but then thought why can't this just be done in the language of HA itself (python). I am not very much of a python developer myself, but willing to try to port the node solution to python.

@dgreif
Copy link

dgreif commented Jun 11, 2020

If anyone does decide to take this on in Python, I've documented a lot of my findings from implementing it in node: https://github.com/dgreif/ring/wiki/SIP-Communication.

@grtessman
Copy link

Hey guys... I skimmed through this thread a bit. I noticed that someone said SIP streaming URL is returned. Why would you need any client for that? All modern browsers support WebRTC using SIP in a native browser VIDEO element. The real question is, does this still work without a subscription today for the live stream? Seems like it should...

@Shamshala
Copy link

Shamshala commented Jul 17, 2020

LiveView proxy could be really cool feature! I would be twice as glad now because i've just changed ISP and it uses TDD Flexible Framing which corrupts my streams (sound primarily) on the way to Ring servers. Quite pity with four Ring cameras. 😒

@Dfbrand
Copy link

Dfbrand commented Aug 2, 2020

Any update on this at all? I am not confident enough in python unfortunately

@shadtorrie
Copy link

shadtorrie commented Jun 16, 2021

Has there been progress made on this issue? I would very much like to have access to a live feed. I have some python experience and would love to help out here.

@cryinglevi
Copy link

same here!

@goodboy
Copy link

goodboy commented Jun 17, 2022

Not to be involved too much (mostly snooping for a friend) but y'all could use SIPp probably with a script similar to this (but probably ideally with embedded SDP parsing for video) to pull out the RSTP stream deatz.

Once you have the media deats it should be as simple as connecting a media client as per:

If you really wanted to get fancy with python you probably want to use bindings to pjsip; pure python solutions for SIP died not long ago.

Anyway hope this helps those of you still hanging on this.

@dgreif
Copy link

dgreif commented Jun 18, 2022

If it helps, Ring is now using WebRTC for streaming with WebSockets as the messaging channel. Not sure if those have better support in python

@goodboy
Copy link

goodboy commented Jun 20, 2022

@dgreif i presume you sniffed such things in the dev-mode of a browser orr?

Any hot tips are highly appreciated 🏄🏼


UPDATE:

@dgreif ahh i see you've also contribbed to the js lib and i'm guessing this is what y'all would need ported to python yah?

https://github.com/dgreif/ring/blob/c074c5106ea24ccf24a94cd91bd3b26df9754c1c/api/ring-camera.ts#L583

@dgreif
Copy link

dgreif commented Jun 21, 2022

Yep, I've got a full implementation in https://github.com/dgreif/ring/tree/master/api/streaming. It functions slightly different between normal cameras and cameras connected via Ring Edge, but overall it's the same setup with WebSockets and WebRTC

Copy link

There hasn't been any activity on this issue recently. This issue has been automatically marked as stale because of that. It will be closed if no further activity occurs.
Please make sure to update to the latest ring_doorbell version and check if that solves the issue.
Thank you for your contributions.

@github-actions github-actions bot added the stale Stale PRs and Issues label Apr 18, 2024
@sdb9696 sdb9696 removed the stale Stale PRs and Issues label Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests