Support for Security Camera System via NVR - ESeeCloud/dvr163

Thanks for your reply :smiley:
Ok so if the link is related to the NVR and no the cameras i think we have found some good thing :smiley:

Searching on the web i have found this but won’t work, i need we need fo fix some code.

If i try with my cameras works very well, with NVR lost some frames but i think is not so difficult to adapt :smiley:

Do you know python?
Best regards
Stefano

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!

Hello @pgross,
From what I have seen I know that in the “unknown request” there is the channel and the main and substream.

The /bubble/live channel won’t work so you could just use bubble/live.

This is the details for the 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’)

The value after xdf is the channel (x00, x01, x02, ecc)

After this value you need to count 4 x00 and the fourth is the main and substream (x00 main, x01 sub)

But how can we make this more simple for integration with HA?

P.S.:
And also did someone could implement an RTSP server in the NVR firmware? I have found also this but I’m not e per unfortunately:(

Best regards
Stefano

@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!

1 Like

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… :frowning:

So works also for you the stream? If you want you could enter here (Telegram) so we can speak more simple:
https://t.me/joinchat/VTgYk81SmxQ2YTlk

Best Regards
Stefano

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 :slight_smile: . 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.

@pgross
This is wonderful, I have also found the link for set H264 or H265 but only if the cameras are in the same network.

From what I have seen all devices from “EseeCloud/Juan/DVR163” using the same method so with this python we could stream every Chinese camera/NVr.

If you want some help write to me and we could make some wonderful thing together for bypassing this shit software.

For now I have all my cameras in HA thanks to ShinobiCCTV and this stream link (Form me works only with cameras no NVR)

Main Stream

ffplay -headers "Authorization: Basic YWRtaW46" -i "http://<IPCAM>/livestream/11" 

SubStream

ffplay -headers "Authorization: Basic YWRtaW46" -i "http://<IPCAM>/livestream/12" 

Bye
Stefano

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:

pad = lambda string, length: string.ljust(length, b'\0') 
s.send(b'\xaa\x00\x00\x00' + pad(b'\x00\x0a', 6) + pad(bytes([CHANNEL_NUMBER]), 4) + pad(bytes([STREAM]), 4) + pad(bytes([1]), 8))

Here is the full script with the extra requests commented out. Please test it and let me know if it works for you! hassio-addons/stream.py at 4c5f7f1afdf4c02481469bf1e81c664f517c8614 · pgross41/hassio-addons · GitHub

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 :frowning:
Yes works very well for me also!!! :smiley: just some warning but also with other script i have this:

Best Regards
Stefano

@pgross
For handle the video we could use something like this:

We have a group in telegram so I think that using this with your addon and we should have a video in HA

Best regards
Stefano

@pgross
Hello again :smiley: do you have some news about the addon?

@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.

@pgross hello again :smiley:
Could you try with this link? Telegram: Join Group Chat
I hope all togheter could find a way for using this :smiley:

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:

ffmpeg: 

camera: 
 - platform: ffmpeg
   name: Test cam
   input: -rtsp_transport tcp -i http://localhost:8080/test

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.

1 Like

Hello @pgross
I here again :smiley:
I have some times and i want to test again your proxy script.
How did you have exposed the script to port 8080?

Best Regards
Stefano

Dear All,
I’m a newbie here, however, I have also such NVR device:
image
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?

1 Like

We don’t have a solution for displaying high quality streams within HA but I made an add-on that is able to receive motion detection events.

hassio-addons/dvr163 at main · pgross41/hassio-addons · GitHub (see DOCS.md).

You can add choppy low quality streams with a generic camera: Update the host and port as well as the chn (channel number) and p (password) arguments.

camera:
  - platform: generic
    name: Front Porch
    still_image_url: http://nvrhost:port/cgi-bin/snapshot.cgi?chn=0&u=admin&p=XXXXXX&q=0&d=1
1 Like

Hey wes93. I basically have a heimvision cameras ca01 which real model is 575016 for the NVR model K8208-W, and was able to use your link

ffplay -headers "Authorization: Basic YWRtaW46" -i "http://<IPCAM>/livestream/11"

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?