That Python script is very similar to what I see in Wireshark!
In Wireshark find any RTSP to or from your NVR. Right click > Follow > TCP stream. It will show the entire handshake.
This is the Python script’s handshake (the added comments are mine)
# Initial GET request
s.send(b'GET /bubble/live?ch=0&stream=0 HTTP/1.1\r\n\r\n')
# XML followed by many "#" symbols
data = s.recv(1142)
# The username (admin) with no password
s.send( b'\xaa\x00\x00\x005\x00\x0e\x16\xc2q\x00\x00\x00,\x00\x00\x00\x00admin\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
# Unknown hex response...
data = s.recv(54)
# Unknown hex request
s.send(b'\xaa\x00\x00\x00\x15\n\x0e\x16\xc2\xdf\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00')
Then it loops and reads the stream 16 bytes at a time
data = s.recv(16)
This is the Wireshark handshake with comments to line up with the Python script’s comments
Also worth noting per the Python script the following byte sequences are significant:
g711_prelude
aa 00 00 00
h264_prelude
00 00 00 01
That is as far as I can get though, the python script hangs on data = s.recv(16) after looping twice. I should try changing/removing my password to see what changes. The problem is I’m never at the NVR when I’m at my computer!
@Wes93 that seems helpful, I will keep poking it when I have some time. If I can make the stream work via Python script I think I could potentially implement it into an addon. No idea how it would work though, maybe a web server that runs that script when a request comes in. I already have this addon for handling motion events, exposing the streams could be a new feature:
That repo you found looks interesting but I can’t tell if it is applicable to our NVR. Even if it is compatible I’m afraid to flash any firmware on my mine, I don’t want to brick it!
For me is the same, i don’t like to flash FW.
I hope you could add this to your addon, i don’t have enabled motion events, there is a lot of false positive…
I have tried stream.socket solution over my techage nvr and i am able to record a video file and watch over ffplay pipe different nvr channel from win10 pc now i am trying to implement in hassio but i am not able to do it. It is possible to use stream.socket python script As input for stream? I have also tried to convert into rtsp streaming with a pipe to ffmpeg but i am not able to reach a good result. I think that using python code it is possible to generata a rtsp streaming to feed stream integration but unfortunately i am non able.
I got stream.socket.py to run on Windows! It is crystal clear, not choppy, and is using minimal cpu. I did the same steps as above for getting the python bytes by using the requests found in Wireshark but skipped the unknown request that is not in the Python script. @Wes93 you were right about the bytes for channel number and stream number.
I would share my modified script but it currently has my login hardcoded. There are also still some unknown request bytes and I’d like to identify them all. I would like to make it configurable so it can accept the following arguments:
channelNumber (0-4)
streamNumber (0-1)
username
password
At that point I will share the script . I don’t know anything about streaming video but the end goal is to pipe the stream to RTSP or something a modern web browser can handle natively and build it into the my add-on… somehow.
Okay I’ve mapped as many of the bytes as I could. A lot of the work may have been unnecessary, at the end I discovered the initial /bubble/live request and username/password request seem to be optional. It pretty much boils down to this 1 request after making a socket connection:
Now we need to figure out the best way to get it into Home Assistant. I’m thinking provide the stream from a web server and use the generic camera component. I believe VLC could also use the stream directly.
Hello @pgross,
sorry for the delay, i have seen only today your reply
Yes works very well for me also!!! just some warning but also with other script i have this:
@Wes93 I apologize, I don’t! I’m not able to successfully run the current version of HA locally for development (per Local add-on testing) I run into errors. On top of that I’ve been very busy with work lately. When I find time to dig back in I will post an update!
I like the idea of Telegram (or any chat type room) to continue discussion but nothing happens when I click JOIN CHANNEL.The console however prints an error: Failed to launch 'tg://join?invite=VTgYk81SmxQ2YTlk' because the scheme does not have a registered handler.
I’ve been watching this thread for quite a while now, as I also have DVR163 cameras/dvr (OOSSXX brand from Amazon) I’d like to be able to stream into Home Assistant. You guys have done some awesome work with the request byte mapping – I tried @pgross’s python script and it worked for me as well! Have you guys had any luck getting the stream into something readable by Home Assistant? Thanks!
@BTCanada I was able to implement the script into a plugin so that home assistant exposed the proxy but the video is in a format that doesn’t play on the web UI even with the ffmpeg component. It consumes over 50% CPU and provides a broken video, it does not look promising. This is the ffmpeg config:
The one up-side is the proxy DOES allow for ffplay to read the stream, so as long as HA and the port are available you could do ffplay <url:port>. This proxy is not as resource intensive as it doesn’t use ffmpeg.
Dear All,
I’m a newbie here, however, I have also such NVR device:
with 8 IP cams connected. For a couple of months, I’ve been trying to somehow integrate this device with my HA instance (v.2021-11-5).
However I’m not a programmer, just a HA user. Can someone help me to do this integration, please?
What has to be done to have this device integrated with HA?
to access the camera stream. It was in fact succesful, though I have one question/issue. How can I see or add this stream to Blue Iris? you mentioned adding it to ShinobiCCTV, how did you do it? would it be the same for something like ispy or blue iris?