thirtythreeforty / neolink

An RTSP bridge to Reolink IP cameras
https://www.thirtythreeforty.net/posts/2020/05/hacking-reolink-cameras-for-fun-and-profit/
GNU Affero General Public License v3.0
893 stars 151 forks source link

Swann DVR (Crashes with 3+ streams) #284

Open RyanTheTide opened 2 years ago

RyanTheTide commented 2 years ago

Description Swann DVR wont display more then two concurrent streams, stream channels can be mish mashed in config file as long as it's only two cameras.

Steps To Reproduce

  1. Create this configuration file:

    bind = "0.0.0.0"
    
    [[cameras]]
    name = "backyard"
    username = "admin"
    password = "PASSWD"
    address = "10.1.1.6:9000"
    stream = "mainStream"
    channel_id = 0
    
    [[cameras]]
    name = "backfence"
    username = "admin"
    password = "PASSWD"
    address = "10.1.1.6:9000"
    stream = "mainStream"
    channel_id = 1
    
    [[cameras]]
    name = "sidegate"
    username = "admin"
    password = "PASSWD"
    address = "10.1.1.6:9000"
    stream = "mainStream"
    channel_id = 2
    
    [[cameras]]
    name = "backdeck"
    username = "admin"
    password = "PASSWD"
    address = "10.1.1.6:9000"
    stream = "mainStream"
    channel_id = 3
  2. Launch Neolink: neolink rtsp --config config.toml

Expected behavior All 4 streams are connected, replicated and fully connectable via rtsp protocol (tested in VLC with rtsp://localhost:8553/backyard/mainStream), in turn can be added to HomeAssistant, Blue Iris, etc...

Versions Neolink software: Latest precompiled on GitHub for Windows DVR Model Name/s: DVR4-1580/DVR4-720P/DVR-6904AU414001000200000 DVR Build No: 1606160 DVR HW Ver: H2MB15 DVR Config Ver: v2.0.0.0

Neolink Output/Log

[2022-06-19T08:40:35Z INFO  neolink] Neolink cab43d0b0946e3669a49146ee2db96076099e15f release
[2022-06-19T08:40:35Z INFO  neolink::rtsp] backyard: Connecting to camera at Address: 10.1.1.6:9000
[2022-06-19T08:40:35Z INFO  neolink::rtsp] backyard: Logging in
[2022-06-19T08:40:35Z INFO  neolink::rtsp] sidegate: Connecting to camera at Address: 10.1.1.6:9000
[2022-06-19T08:40:35Z INFO  neolink::rtsp] sidegate: Logging in
[2022-06-19T08:40:35Z INFO  neolink::rtsp] backdeck: Connecting to camera at Address: 10.1.1.6:9000
[2022-06-19T08:40:35Z INFO  neolink::rtsp] backdeck: Logging in
[2022-06-19T08:40:35Z INFO  neolink::rtsp] backfence: Connecting to camera at Address: 10.1.1.6:9000
[2022-06-19T08:40:35Z INFO  neolink::rtsp] backfence: Logging in
[2022-06-19T08:40:35Z INFO  neolink::rtsp] backyard: Connected and logged in
[2022-06-19T08:40:35Z INFO  neolink::rtsp] backdeck: Connected and logged in
[2022-06-19T08:40:35Z INFO  neolink::rtsp] sidegate: Connected and logged in
[2022-06-19T08:40:35Z INFO  neolink::rtsp] backfence: Connected and logged in
[2022-06-19T08:40:35Z INFO  neolink::rtsp] backdeck: Camera time is already set: 2022-06-19 18:50:38 +10
[2022-06-19T08:40:35Z INFO  neolink::rtsp] backyard: Camera time is already set: 2022-06-19 18:50:38 +10
[2022-06-19T08:40:35Z INFO  neolink::rtsp] backdeck: Camera reports firmware version
[2022-06-19T08:40:35Z INFO  neolink::rtsp] sidegate: Camera time is already set: 2022-06-19 18:50:39 +10
[2022-06-19T08:40:35Z INFO  neolink::rtsp] backdeck: Starting video stream Main Stream (Clear)
[2022-06-19T08:40:35Z INFO  neolink::rtsp] backfence: Camera time is already set: 2022-06-19 18:50:39 +10
[2022-06-19T08:40:35Z INFO  neolink::rtsp] backyard: Camera reports firmware version
[2022-06-19T08:40:35Z INFO  neolink::rtsp] backyard: Starting video stream Main Stream (Clear)
[2022-06-19T08:40:35Z INFO  neolink::rtsp] sidegate: Camera reports firmware version
[2022-06-19T08:40:35Z INFO  neolink::rtsp] sidegate: Starting video stream Main Stream (Clear)
[2022-06-19T08:40:35Z INFO  neolink::rtsp] backfence: Camera reports firmware version
[2022-06-19T08:40:35Z INFO  neolink::rtsp] backfence: Starting video stream Main Stream (Clear)
[2022-06-19T08:40:40Z ERROR neolink_core::bc_protocol::connection::bcconn] Deserialization error: Deserialization error
[2022-06-19T08:40:40Z ERROR neolink_core::bc_protocol::connection::bcconn] caused by: I/O error
[2022-06-19T08:40:40Z ERROR neolink_core::bc_protocol::connection::bcconn] Deserialization error: Deserialization error
[2022-06-19T08:40:40Z ERROR neolink_core::bc_protocol::connection::bcconn] caused by: I/O error
[2022-06-19T08:40:40Z ERROR neolink_core::bc_protocol::connection::bcconn] caused by: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (os error 10060)
[2022-06-19T08:40:40Z ERROR neolink_core::bc_protocol::connection::bcconn] caused by: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (os error 10060)
[2022-06-19T08:40:40Z ERROR neolink::rtsp] Error streaming from camera backfence, will retry in 1s: Error while streaming backfence

    Caused by:
        0: Media Deserialization error
        1: I/O error
        2: channel is empty and sending half is closed
[2022-06-19T08:40:40Z ERROR neolink::rtsp] Error streaming from camera sidegate, will retry in 1s: Error while streaming sidegate

    Caused by:
        0: Media Deserialization error
        1: I/O error
        2: channel is empty and sending half is closed

Additional Note As prior stated, Neolink works flawlessly with any & all of the cameras listed as long as it's only two in the config, any more and the program will establish and immediately halt within seconds. I have attempted running two instances of the program simultaneously with two configs & received the same error. If anyone has any suggestions or would like any additional files, logs, or configuration files just let me know.

Thanks, Ryan Murray.

RyanTheTide commented 2 years ago

I spoke too soon it seems, the lack of errors fooled me šŸ¤£

Did some additional testing and moved Neolink to my Proxmox install for HAOS (Debian 11).

Exact same config, works flawlessly no issues, seems to be isolated to Windows?

RyanTheTide commented 2 years ago

Running on Debian 11 I am still encountering the same issue just with a lack of error messages.

RyanTheTide commented 2 years ago

Guessing this has something to do with it? Dropping all streams to the subStream option fixes all issues however it's in fluent mode as apposed to clear. Is there any work around here?

twistedddx commented 2 years ago

The official client handles the multiple camera connections with a single login. Neolink does each channel/camera with its own login. I believe this causes resource issues with NVR's, but there may be other reasons it fails.

There is no plans for this to change unfortunately.

twistedddx commented 2 years ago

Actually this is what you would want to test: https://github.com/thirtythreeforty/neolink/pull/151

Enables Single login and dynamically sets the handle number to be unique per camera.

The test builds are expired however: https://github.com/QuantumEntangledAndy/neolink/actions/runs/762854394

@QuantumEntangledAndy Any chance to get a new test build of single_login_streams?

QuantumEntangledAndy commented 2 years ago

@QuantumEntangledAndy Any chance to get a new test build of single_login_streams?

Perhaps, I'm about to get some sleep but I can fire of a rebuild in the morning. Would be better though if I spent the hour or two merging master into it, but I don't remember all of that code as it is rather an old branch.

@thirtythreeforty any chance we can add some of these some of features into master? I could gate it behind some config params if you think it's too experimental.

RyanTheTide commented 2 years ago

Happy to test, debug and provide any additional help where necessary.

Thanks, Ryan Murray.

QuantumEntangledAndy commented 2 years ago

So I did a full rewrite based off of the current master, build should end up here once ready

RyanTheTide commented 2 years ago

Hey @QuantumEntangledAndy, any luck? I see the build was attempted a few times but failed.

QuantumEntangledAndy commented 2 years ago

Hey @QuantumEntangledAndy, any luck? I see the build was attempted a few times but failed.

Oh really thanks for letting me know. I have been working on other stuff and haven't really checked in on this. I'll add it to my morning tasks.

QuantumEntangledAndy commented 2 years ago

@RyanTheTide here give this a go https://github.com/QuantumEntangledAndy/neolink/actions/runs/2558840040

RyanTheTide commented 2 years ago

Hi @QuantumEntangledAndy, as I've recently moved, I haven't had the time to test. Would you be able to re-run the build?

Also, what command or configuration arguments would be needed?

QuantumEntangledAndy commented 2 years ago

Rebuilding here takes about half an hour

RyanTheTide commented 2 years ago

Thanks Andy, tested and no luck. Do I need any specific changes to the config or any command line arguments?

RyanTheTide commented 2 years ago

@QuantumEntangledAndy same config,

[2022-09-26T09:14:27Z INFO  neolink::rtsp] backdeck: Connecting to camera at Address: 192.168.1.54:9000
[2022-09-26T09:14:27Z INFO  neolink::rtsp] backdeck: Logging in
[2022-09-26T09:14:27Z INFO  neolink::rtsp] backyard: Connecting to camera at Address: 192.168.1.54:9000
[2022-09-26T09:14:27Z INFO  neolink::rtsp] backyard: Logging in
[2022-09-26T09:14:27Z INFO  neolink::rtsp] backdeck: Connected and logged in
[2022-09-26T09:14:27Z INFO  neolink::rtsp] backyard: Connected and logged in
[2022-09-26T09:14:27Z INFO  neolink::rtsp] backdeck: Camera time is already set: 2022-09-26 19:20:05 +10
[2022-09-26T09:14:27Z INFO  neolink::rtsp] backyard: Camera time is already set: 2022-09-26 19:20:05 +10
[2022-09-26T09:14:27Z INFO  neolink::rtsp] backdeck: Camera reports firmware version
[2022-09-26T09:14:27Z INFO  neolink::rtsp] backdeck: Starting video stream Main Stream (Clear)
[2022-09-26T09:14:27Z INFO  neolink::rtsp] backyard: Camera reports firmware version
[2022-09-26T09:14:27Z INFO  neolink::rtsp] backyard: Starting video stream Main Stream (Clear)
[2022-09-26T09:14:32Z ERROR neolink_core::bc_protocol::connection::bcconn] Deserialization error: Deserialization error
[2022-09-26T09:14:32Z ERROR neolink_core::bc_protocol::connection::bcconn] caused by: I/O error
[2022-09-26T09:14:32Z ERROR neolink_core::bc_protocol::connection::bcconn] caused by: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (os error 10060)
[2022-09-26T09:14:32Z ERROR neolink_core::bc_protocol::connection::bcconn] Deserialization error: Deserialization error
[2022-09-26T09:14:32Z ERROR neolink_core::bc_protocol::connection::bcconn] caused by: I/O error
[2022-09-26T09:14:32Z ERROR neolink_core::bc_protocol::connection::bcconn] caused by: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (os error 10060)
QuantumEntangledAndy commented 2 years ago

So although this changes the login method to do muliple connects on a single login it still however tries to pull the data all the time from all cameras. Maybe pulling full HD and SD from multiple cameras at once is just too much load. There's another build that only pulls the data when a client is connected but it's a bit hacky in the way it detects client connected. But it's quite old and I would need to update it again. Not sure if I have the energy for that right now

RyanTheTide commented 2 years ago

Thanks Andy, completely understand. I can pull all 4 concurrent HD streams on the app before if that means much. Does the configuration require any changes as it does look to still request all four streams individually.

 bind = "0.0.0.0"

 [[cameras]]
 name = "backyard"
 username = "admin"
 password = "~~~"
 address = "192.168.1.54:9000"
 stream = "mainStream"
 channel_id = 0

  [[cameras]]
 name = "backfence"
 username = "admin"
 password = "~~~"
 address = "192.168.1.54:9000"
 stream = "mainStream"
 channel_id = 1

   [[cameras]]
 name = "sidegate"
 username = "admin"
 password = "~~~"
 address = "192.168.1.54:9000"
 stream = "mainStream"
 channel_id = 2

  [[cameras]]
 name = "backdeck"
 username = "admin"
 password = "~~~"
 address = "192.168.1.54:9000"
 stream = "mainStream"
 channel_id = 3

Would it need to be something along the lines of, but obviously modified, this?

 bind = "0.0.0.0"

  [[cameras]]
 name = "backyard","backfence","sidegate","backdeck"
 username = "admin"
 password = "~~~"
 address = "192.168.1.54:9000"
 stream = "mainStream"
 channel_id = 0,1,2,3

Either way, thank you for all your help, let me know if I can help in any way.

QuantumEntangledAndy commented 2 years ago

No changes are required config wise. It is all under the hood type changes in how the data is requested form the camera

RyanTheTide commented 2 years ago

Understood, appreciate the help. Let me know how things go & if you require anything. Thanks!

eddbeale commented 1 year ago

Rebuilding here takes about half an hour

Came across Neolink at the weekend just before dumping my Swann DVR8-4750 in favour of something that streams RTSP. I got it going quickly on my Mac as a test :), but quickly hit the 2 camera limit mentioned in this Issue. I tried this build ^, and got 4 streams working, but it seems to fail above 4 (I have 6 cameras, tho the DVR is capable of 8).

I was wondering if there are plans to take this rewrite forwards and merge it back? I'd be happy to test further builds as I get mine set up on a RPi over the next few days.

QuantumEntangledAndy commented 1 year ago

@eddbeale I'm currently doing a rewrite of some rtsp code on my own fork that will include these changes and some more but it is not ready yet. I'm not sure if anything will get merged into this repo anymore ThirtyThreeForty has been absent for awhile and my PRs have been open for years.

eddbeale commented 1 year ago

Thanks for the quick reply @QuantumEntangledAndy. I've successfully got my old Swann DVR streaming through Scrypted into HKSV this morning, using Neolink to bridge the gap into RTSP, so I'm definitely keen to get future builds and that overcome those limitations.