keshavdv / unifi-cam-proxy

Enable non-Ubiquiti cameras to work with Unifi NVR
MIT License
1.6k stars 226 forks source link

Generating a Cert #203

Closed EasternIndustries-IT closed 2 years ago

EasternIndustries-IT commented 2 years ago

Recently updated the cameras and I am running protect 1.21.2

When trying to generate a cert using scp ubnt/"device password "@<your-unifi-cam>:/var/etc/persistent/server.pem client.pem I get No such file or directory Using a client.pem generated from it being unmanaged will not show up in the nvr

Any Ideas? Would this happen to do with the latest update breaking the proxy?

kasper79 commented 2 years ago

I would ssh into the camera and run find / |grep server.pem to verify.

Mine shows up in 2 places. /var/etc/server.pem /var/etc/persistent/server.pem

Both same file..

EasternIndustries-IT commented 2 years ago

ssh connection to camera are refused. It seems this is only when the cameras are connected to nvr

kasper79 commented 2 years ago

You need to enable SSH on the cameras. To do this you will need to SSH into the NVR (https://help.ui.com/hc/en-us/articles/1500007460721) that should help you. tldr; on the NVR: ssh in to nvr cd /usr/share/unifi-protect/app/config/ edit the config.json change this line to "enableSsh": true

Then you will use ubnt/"protect password" (under protect -> settings -> reveal password)

HTH

EasternIndustries-IT commented 2 years ago

Ok I was able to get into the camera. However it won't let me copy anything. It just says permissions denied when using scp server.pem <myusr>@<myip>:/home/<myusr>/Documents/client.pem

EasternIndustries-IT commented 2 years ago

I was able to get it. Last issue is I'm getting a server returned 404 not found using a dahua camera

Proxy1_1  | [rtsp @ 0x7f2c580f5580] method DESCRIBE failed: 404 Not Found
Proxy1_1  | rtsp://admin:xxxxx@192.16xx.xx.xx:554/cam/realmonitor?channel=1&subtype=0>: Server returned 404 Not Found
Proxy1_1  | 2022-03-26 01:02:25 94971a4b7284 RTSPCam[1] WARNING Previous ffmpeg process for video3 died.
Proxy1_1  | 2022-03-26 01:02:25 94971a4b7284 RTSPCam[1] INFO Spawning ffmpeg for video3 (fstmXlyy9DOhGoAc): ffmpeg -nostdin -loglevel error -y -avoid_negative_ts make_zero -fflags +genpts+discardcorrupt -stimeout 15000000 -rtsp_transport tcp -i "rtsp://admin:xxxxxxx@192.xxx.xxx.xxx:554/cam/realmonitor?channel=1&subtype=0>" -c:v copy -ar 32000 -ac 1 -codec:a aac -b:a 32k -metadata streamname=fstmXlyy9DOhGoAc -f flv - | /usr/local/bin/python -m unifi.clock_sync | nc 192.xxx.xxx.xxx 7550

end of config is rtsp -s rtsp://admin:xxxxxx@192.XXX.XXX.XXX:554/cam/realmonitor?channel=1&subtype=0

EasternIndustries-IT commented 2 years ago

I was able to get it. Last issue is I'm getting a server returned 404 not found using a dahua camera

Proxy1_1  | [rtsp @ 0x7f2c580f5580] method DESCRIBE failed: 404 Not Found
Proxy1_1  | rtsp://admin:xxxxx@192.16xx.xx.xx:554/cam/realmonitor?channel=1&subtype=0>: Server returned 404 Not Found
Proxy1_1  | 2022-03-26 01:02:25 94971a4b7284 RTSPCam[1] WARNING Previous ffmpeg process for video3 died.
Proxy1_1  | 2022-03-26 01:02:25 94971a4b7284 RTSPCam[1] INFO Spawning ffmpeg for video3 (fstmXlyy9DOhGoAc): ffmpeg -nostdin -loglevel error -y -avoid_negative_ts make_zero -fflags +genpts+discardcorrupt -stimeout 15000000 -rtsp_transport tcp -i "rtsp://admin:xxxxxxx@192.xxx.xxx.xxx:554/cam/realmonitor?channel=1&subtype=0>" -c:v copy -ar 32000 -ac 1 -codec:a aac -b:a 32k -metadata streamname=fstmXlyy9DOhGoAc -f flv - | /usr/local/bin/python -m unifi.clock_sync | nc 192.xxx.xxx.xxx 7550

end of config is rtsp -s rtsp://admin:xxxxxx@192.XXX.XXX.XXX:554/cam/realmonitor?channel=1&subtype=0

It seems the last issue is a 15fps limit bug as described in other post. I didn't see how to define the fps any idea I have like 30 of these cameras?

kasper79 commented 2 years ago

Best thing would be to log into the web interface of the cameras and set the FPS to 15 and make sure codec's are set correctly

EasternIndustries-IT commented 2 years ago

Best thing would be to log into the web interface of the cameras and set the FPS to 15 and make sure codec's are set correctly

I just tried that I doesn't seem to solve the issue

nicoleise commented 2 years ago

Best thing would be to log into the web interface of the cameras and set the FPS to 15 and make sure codec's are set correctly

I just tried that I doesn't seem to solve the issue

To clarify, since you reference my reported #issue194; I did not get 404 due to the FPS error. 404 would only occur for me if I did something wrong. When (only) the FPS error was present, I would only get the error reported, not 404.

Suggestions:

  1. Encapsulate your stream source. Some characters in either the URL or the password can corrupt the source if not encapsulated. Instead of rtsp -s rtps://user:pass@IP:port/subpath do rtsp -s "rtps://user:pass@IP:port/subpath"

  2. Confirm with VLC or similar that you are specifying a valid stream source and that it's actually the one you want. Channel and sub-stream make no sense on Dahua as one seems to be zero-based and the other one-based. As in; for one of them, "0" = first stream and for the other "1" = first stream. I had to check and recheck several times with VLC that I would actually get the stream I intended to get (although this was while also troubleshooting the 15 FPS issue, so telling success from failure was pretty difficult).

  3. Also note discrepancy between the dahua command and the generic rtsp naming convention for substreams. With the Dahua command, you'll refer to channel and sub-stream, while the rtsp source will be channel and subtype. For me, the primary stream on my HD cams were channel 1 and substream 0. Unifi-Cam-Proxy converts this into a source command for ffmpeg as follows: "rtsp://user:password@IP.IP.IP.IP:554/cam/realmonitor?channel=1&subtype=0"

Also note that while this wont result in 404, it's a good idea to specify a (can be bogus) MAC, as unifi seems to use MAC for identifying cameras, so two cams can't have the same MAC, and it will if you don't specify one.

What worked for me was 15 FPS (as you already know) and this command as an example (no encapsulation, just as typed, redactions UPPERCASE): unifi-cam-proxy -H IP.OF.UNIFI.PROTECT -i IP.OF.IP.CAM --mac 12:34:56:AA:FF:2DIGITNUMBER -c /opt/unifi-cam-proxy/client.pem -t TOKEN dahua -u USERNAME -p PASSWORD --channel 1 --sub-stream 0