1# Neolink 2 3![CI](https://github.com/thirtythreeforty/neolink/workflows/CI/badge.svg) 4 5Neolink is a small program that acts as a proxy between Reolink IP cameras and 6normal RTSP clients. 7Certain cameras, such as the Reolink B800, do not implement ONVIF or RTSP, but 8instead use a proprietary "Baichuan" protocol only compatible with their apps 9and NVRs (any camera that uses "port 9000" will likely be using this protocol). 10Neolink allows you to use NVR software such as Shinobi or Blue Iris to receive 11video from these cameras instead. 12The Reolink NVR is not required, and the cameras are unmodified. 13Your NVR software connects to Neolink, which forwards the video stream from the 14camera. 15 16The Neolink project is not affiliated with Reolink in any way; everything it 17does has been reverse engineered. 18 19## Supported cameras 20 21Neolink intends to support all Reolink cameras that do not provide native RTSP. 22Currently it has been tested on the following cameras: 23 24- B800/D800 25- B400/D400 26- E1 27- Lumus 28 29Neolink does not support other cameras such as the RLC-420, since they already 30[provide native RTSP](https://support.reolink.com/hc/en-us/articles/360007010473-How-to-Live-View-Reolink-Cameras-via-VLC-Media-Player). 31 32## Usage 33 341. First, write a configuration yaml file describing your cameras. See the 35Configuration section below or the provided sample config. 36 372. Launch Neolink: 38```bash 39neolink rtsp --config=your_config.yaml 40``` 41 423. Then, connect your RTSP viewer to `rtsp://127.0.0.1:8554/your_camera_name`! 43 44### Additional commands 45 46Neolink also has some additional command line tools 47for controlling the camera. They are all used through neolink subcommands like this: 48 49```bash 50neolink subcommand --config=... 51``` 52 53The currently supported subcommands are 54 55- **rtsp**: The standard neolink rtsp bridge 56- **status-light**: Control the LED status light 57- **reboot**: Reboot a camera 58- **talk**: Enable talk back through either the microphone or by 59 reading a sound file. 60 61For a full list of commands use `neolink help`, or use 62`neolink help <subcommand>` for details on a subcommand of interest. 63 64## Download & Installation 65 66In the future Neolink will be much easier to install. 67For now, follow these steps. 68Builds are provided for the following platforms: 69 70- Windows x86_64 ([download][win-ci-download]) 71- macOS x86_64 ([download][macos-ci-download]) 72- Ubuntu x86_64 ([download][ubuntu-ci-download]) 73- Debian x86 ([download][debian-x86-ci-download]) 74- Debian aarch64 (Raspberry Pi 64-bit) ([download][debian-aarch-ci-download]) 75- Debian armhf (Raspberry Pi 32-bit) ([download][debian-armhf-ci-download]) 76- Arch Linux ([AUR](https://aur.archlinux.org/packages/neolink-git/)) 77- Docker x86 (see below) 78 79### Windows/Linux 80 811. [Install Gstreamer][gstreamer] from the most recent MSI installer on Windows, 82or your package manager on Linux. 83 84 On Ubuntu/Debian machines gstreamer can be installed with: 85 86 ```bash 87 sudo apt install \ 88 libgstrtspserver-1.0-0 \ 89 libgstreamer1.0-0 \ 90 libgstreamer-plugins-bad1.0-0 \ 91 gstreamer1.0-plugins-good \ 92 gstreamer1.0-plugins-bad 93 ``` 94 95 962. If you are using Windows, add the following to your `PATH` environment variable: 97 98 ``` 99 %GSTREAMER_1_0_ROOT_X86_64%\bin 100 ``` 101 102 **Note:** If you use Chocolatey to install Gstreamer, it does this 103 automatically. 104 1053. Download and unpack Neolink from the links above. 106 1. Note: you can also click on [this link][ci-download] to see all historical builds. 107 You will need to be logged in to GitHub to download directly from the builds page (wget doesn't work) 108 109 Raspberry Pi OS x64 example: 110 111 ```bash 112 unzip release-arm64-buster.zip 113 sudo cp neolink /usr/local/bin/ 114 sudo chmod +x /usr/local/bin/neolink 115 ``` 1164. Write a configuration file for your cameras. See the section below. 117 1185. Launch Neolink from a shell, passing your configuration file: 119 120 ```bash 121 neolink rtsp --config my_config.toml 122 ``` 123 1246. Connect your NVR software to Neolink's RTSP server. 125 126 The default URL is `rtsp://127.0.0.1:8554/your_camera_name` if you're running 127 it on the same computer. 128 If you run it on a different server, you may need to open firewall ports. 129 See the "Viewing" section below for more troubleshooting. 130 131[gstreamer]: https://gstreamer.freedesktop.org/documentation/installing/index.html 132[ci-download]: https://github.com/thirtythreeforty/neolink/actions?query=workflow%3ACI+branch%3Amaster+ 133 134[win-ci-download]: https://nightly.link/thirtythreeforty/neolink/workflows/build/master/release-windows-2019.zip 135[macos-ci-download]: https://nightly.link/thirtythreeforty/neolink/workflows/build/master/release-macos-10.15.zip 136[ubuntu-ci-download]: https://nightly.link/thirtythreeforty/neolink/workflows/build/master/release-ubuntu-18.04.zip 137[debian-x86-ci-download]: https://nightly.link/thirtythreeforty/neolink/workflows/build/master/release-i386-buster.zip 138[debian-armhf-ci-download]: https://nightly.link/thirtythreeforty/neolink/workflows/build/master/release-armhf-buster.zip 139[debian-aarch-ci-download]: https://nightly.link/thirtythreeforty/neolink/workflows/build/master/release-arm64-buster.zip 140 141### Docker 142 143A Docker image is also available containing Neolink and all its dependencies. 144The image is `thirtythreeforty/neolink`. 145Port 8554 is exposed, which is the default listen port. 146You must mount a configuration file (see below) into the container at 147`/etc/neolink.toml`. 148 149Here is a sample launch commmand: 150 151```bash 152docker run \ 153 -p 8554:8554 \ 154 --restart=on-failure \ 155 --volume=$PWD/config.toml:/etc/neolink.toml \ 156 thirtythreeforty/neolink 157``` 158 159Here is an example docker-compose: 160 161```yml 162--- 163version: "2" 164services: 165 neolink: 166 image: thirtythreeforty/neolink 167 container_name: neolink 168 ports: 169 - 8554:8554 170 volumes: 171 - $PWD/neolink.toml:/etc/neolink.toml 172 restart: unless-stopped 173``` 174 175The Docker image is "best effort" and intended for advanced users; questions 176about running Docker are outside the scope of Neolink. 177 178## Configuration 179 180**Note**: for a more comprehensive setup tutorial, refer to the 181[Blue Iris setup walkthrough in `docs/`][blue-iris-setup] (which is probably 182 also helpful even with other NVR software). 183 184[blue-iris-setup]: docs/Setting%20Up%20Neolink%20For%20Use%20With%20Blue%20Iris.md 185 186Copy and modify the `sample_config.toml` to specify the address, username, and 187password for each camera (if there is no password, you can omit that line). 188 189Each `[[cameras]]` block creates a new camera; the `name` determines the RTSP 190path you should connect your client to. 191Currently Neolink cannot auto-detect cameras like the official clients do; you 192must specify their IP addresses directly. 193 194By default, the HD stream is available at the RTSP path `/name` or 195`/name/mainStream`, and the SD stream is available at `/name/subStream`. 196You can use only the HD stream by adding `stream = "mainStream"` to the 197`[[cameras]]` config, or only the SD stream with `stream = "subStream"`. 198 199**Note**: The B400/D400 models only support a single stream at a time, so you 200must add this line to sections for those cameras. 201 202By default Neolink serves on all IP addresses on port 8554. 203You can modify this by changing the `bind` and the `bind_port` parameter. 204You only need one `bind`/`bind_port` setting at the top of the config file. 205 206You can enable `rtsps` (TLS) by adding a `certificate = "/path/to/pem"` to the 207top section of the config file. This PEM should contain by the certificate 208and the key used for the server. If TLS is enabled all connections must use 209`rtsps`. You can also control client side TLS with the config option 210`tls_client_auth = "none|request|require"`; in this case the client should 211present a certificate signed by the server's CA. 212 213TLS is disabled by default. 214 215You can password-protect the Neolink server by adding `[[users]]` sections to 216the configuration file: 217 218``` 219[[users]] 220name: someone 221pass: somepass 222``` 223 224you also need to add the allowed users into each camera by adding the following 225to `[[cameras]]`. 226 227``` 228permitted_users = ["someone", "someoneelse"] 229``` 230 231Anywhere a username is accepted it can take any username or one of the 232following special values. 233 234- `anyone` means any user with a valid user/pass 235- `anonymous` means no user/pass required 236 237The default `permitted_users` list is: 238 239- `[ "anonymous"]` if no `[[users]]` were given in the config meaning no 240authentication required to connect. 241 242- `[ "anyone" ]` if `[[users]]` were provided meaning any authourised users can 243connect. 244 245You can change the Neolink log level by setting the `RUST_LOG` environment 246variable (not in the configuration file) to one of `error`, `warn`, `info`, 247`debug`, or `trace`: 248 249```sh 250set RUST_LOG=debug 251``` 252 253On Linux: 254 255```bash 256export RUST_LOG=debug 257``` 258 259## Viewing 260 261Connect your RTSP client to the stream with the name you provided in the 262configuration file. 263 264Again, the default URL is `rtsp://127.0.0.1:8554/your_camera_name` if you're 265running it on the same computer as the client. 266The smaller SD video is `rtsp://127.0.0.1:8554/your_camera_name/subStream`. 267 2684K cameras send large video "key frames" once every few seconds and the client 269must have a receive buffer large enough to store the entire frame. 270If your client's buffer size is configurable (like Blue Iris), ensure it's set 271to 20MB, which should ensure plenty of headroom. 272 273## Stability 274 275Neolink has had minimal testing, but it seems to be very reliable in multiple 276users' testing. 277 278The formats of all configuration files and APIs is subject to change as required 279while it is pre-1.0. 280 281## Development 282 283Neolink is written in Rust, and binds to Gstreamer to provide RTSP server 284functionality. 285 286To compile, ensure you have the Rust compiler, Gstreamer, and gst-rtsp-server 287installed. 288 289Then simply run: 290 291```bash 292cargo build 293``` 294 295from this top directory. 296 297### Baichuan Protocol 298 299The "port 9000" protocol used by Reolink and some Swann cameras is internally 300referred to as the Baichuan protocol; this is the company based in China that 301is known internationally as Reolink. 302 303This protocol is a slightly convoluted header-data format, and appears to have 304been upgraded several times. 305 306The modern variant uses obfuscated XML commands and sends ordinary H.265 or 307H.264 video streams encapsulated in a custom header. 308 309More details about the on-the-wire protocol will come later. 310 311### Baichuan dissector 312 313A Wireshark dissector is available for the BC wire protocol in the `dissector` 314directory. 315 316It dissects the BC header and also allows viewing the deobfuscated XML in 317command messages. 318To use it, copy or symlink it into your Wireshark plugin directory; typically 319this is `~/.local/lib/wireshark/plugins/` under Linux. 320 321Currently the dissector does not attempt to decode the Baichuan "extension" 322messages except `binaryData`. 323This will change in the future as reverse engineering needs require. 324 325## License 326 327Neolink is free software, released under the GNU Affero General Public License 328v3. 329 330This means that if you incorporate it into a piece of software available over 331the network, you must offer that software's source code to your users. 332