keshavdv / unifi-cam-proxy

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

any way to set the vcodec = "copy" #189

Closed mrMiimo closed 2 years ago

mrMiimo commented 2 years ago

Is there any way to set the vcodec = "copy"? At the moment i have set only one hikvision camera, but the CPU of my pi4 works is constantly at 90 Β° c and "load average" at 4.0. I think i don't need to transcode the video

btw: this project is great! amazing, thanks so much βœ‹πŸΌ

Camera: Hikvision DS-2CD2046G2-I (it would support ISAPI motion detection)

Additional context my docker-compose.yml config:

version: "3.9"
services:
  unifi-cam-proxy:
    restart: unless-stopped
    image: keshavdv/unifi-cam-proxy
    volumes:
      - "./client.pem:/client.pem"
    command: unifi-cam-proxy --host XXX.XXX.XXX.XXX --cert /client.pem --token XXXXXXXXXXXX rtsp -s rtsp://XXXX:XXXXX@XXX.XXX.XXX.XXX:554/Streaming/Unicast/channels/401
keshavdv commented 2 years ago

By default, the video stream isn't transcoded. The high cpu usage when using the rtsp implementation is usually do the decoding that happens for the snapshot generation and can usually be fixed by providing a '--snapshot-url' argument.

mrMiimo commented 2 years ago

awesome!!! ! it works!!! Tnks so so much I was suspicious of the snapshot when I saw the process in top ...

one more question: is there a similar option to specify the ISAPI address? so I can activate the movements.

I have an NVR (which works as a virtual host) so to access each camera I have a port, for example: 65001 -> cam 1 65002 -> cam 2 65003 -> cam 3 ...

So my ISAPI url for each camera would be:

http://user:password@IP-NVR:65001/ISAPI/Event/notification/alertStream for camera 1

keshavdv commented 2 years ago

At the moment, it's not possible to pass in a port to the Hikvision implementation, but from what I remember, if you have a Hikvision NVR that manages the cameras, you can use the NVR IP and pass along the correct --channel:

unifi-cam-proxy --host XXX.XXX.XXX.XXX --cert /client.pem --token XXXXXXXXXXXX  --ip <nvr IP>  hikvision -u <nvr username> -p <nvr password> --channel <1 for camera 1, 2 for camera 2, etc>

If that doesn't work, I think allowing an explicit port to be passed in seems reasonable.

mrMiimo commented 2 years ago

yes, I have configured just like that. I just added the stream as you suggest above. This is the complete configuration:

unifi-cam-proxy -H <Unifi IP> -i <nvr IP> -c /client.pem -t XXXXXXXX hikvision -u <nvr username> -p <nvr password> -c 4 -s 1

The curious thing is from the log, it seems like API connected, but i cant see the URL destination. Log:

2022-02-28 00:15:01 33e54a648014 HikvisionCam[1] INFO Processing [UpdateFirmwareRequest] message
2022-02-28 00:15:01 33e54a648014 HikvisionCam[1] INFO Reconnecting...
2022-02-28 00:15:01 33e54a648014 HikvisionCam[1] INFO Cleaning up instance
2022-02-28 00:15:01 33e54a648014 HikvisionCam[1] INFO Stopping stream video1
2022-02-28 00:15:01 33e54a648014 HikvisionCam[1] INFO Stopping stream video2
2022-02-28 00:15:01 33e54a648014 HikvisionCam[1] INFO Stopping stream video3
2022-02-28 00:15:01 33e54a648014 Core[1] INFO Backing off connect(...) for 2.0s (True)
2022-02-28 00:15:03 33e54a648014 Core[1] INFO Creating ws connection to wss://192.168.1.1:7442/camera/1.0/ws?token=XXXXXXXXXXXX
2022-02-28 00:15:03 33e54a648014 HikvisionCam[1] INFO Adopting with token [CONm47qbPdp8c7O8KB9qZxJJZ5ba3lVK] and mac [AABBCCDDEEFF]
2022-02-28 00:15:03 33e54a648014 HikvisionCam[1] INFO Processing [ubnt_avclient_hello] message
2022-02-28 00:15:03 33e54a648014 HikvisionCam[1] INFO Processing [ubnt_avclient_hello] message

2022-02-28 00:15:03 33e54a648014 HikvisionCam[1] INFO Connecting to motion events API

2022-02-28 00:15:04 33e54a648014 HikvisionCam[1] INFO Processing [ubnt_avclient_paramAgreement] message
2022-02-28 00:15:04 33e54a648014 HikvisionCam[1] INFO Processing [ubnt_avclient_paramAgreement] message
2022-02-28 00:15:04 33e54a648014 HikvisionCam[1] INFO Processing [StopService] message
2022-02-28 00:15:04 33e54a648014 HikvisionCam[1] INFO Processing [ChangeDeviceSettings] message
2022-02-28 00:15:04 33e54a648014 HikvisionCam[1] INFO Processing [NetworkStatus] message
2022-02-28 00:15:04 33e54a648014 HikvisionCam[1] INFO Processing [GetSystemStats] message
2022-02-28 00:15:09 33e54a648014 HikvisionCam[1] INFO Processing [GetRequest] message
2022-02-28 00:15:10 33e54a648014 HikvisionCam[1] INFO Processing [ChangeIspSettings] message
2022-02-28 00:15:10 33e54a648014 HikvisionCam[1] INFO Processing [ChangeOsdSettings] message
2022-02-28 00:15:10 33e54a648014 HikvisionCam[1] INFO Processing [ChangeAudioEventsSettings] message
2022-02-28 00:15:10 33e54a648014 HikvisionCam[1] INFO Processing [ChangeSoundLedSettings] message
2022-02-28 00:15:10 33e54a648014 HikvisionCam[1] INFO Processing [ChangeVideoSettings] message

2022-02-28 00:15:10 33e54a648014 HikvisionCam[1] INFO Processing [ChangeSmartMotionSettings] message

2022-02-28 00:15:10 33e54a648014 HikvisionCam[1] INFO Processing [EnableLogging] message
2022-02-28 00:15:10 33e54a648014 HikvisionCam[1] INFO Processing [ChangeDeviceSettings] message
2022-02-28 00:15:10 33e54a648014 HikvisionCam[1] INFO Processing [ChangeDeviceSettings] message

2022-02-28 00:15:10 33e54a648014 HikvisionCam[1] INFO Processing [SmartMotionTest] message

2022-02-28 00:15:10 33e54a648014 HikvisionCam[1] INFO Processing [ChangeVideoSettings] message
2022-02-28 00:15:10 33e54a648014 HikvisionCam[1] INFO Processing [UpdateUsernamePassword] message
2022-02-28 00:15:10 33e54a648014 HikvisionCam[1] INFO Processing [ChangeVideoSettings] message
keshavdv commented 2 years ago

Do motion events work when using this? In general, the motion event URL won't change based on the channel id, it will just filter out events that don't match the given ID.

mrMiimo commented 2 years ago

unfortunately it doesn't work, but I can't understand why. Even set --verbose I can't find why it doesn't work From the log it seems to connect to the API ...

mrMiimo commented 2 years ago

NOW WORKS!!! πŸ’ͺ🏼πŸ’ͺ🏼πŸ’ͺ🏼 you are absolutely right! you can connect to the ISAPI URL of the NVR and with the channel identify the cam you want.

I'm not a developer (unfortunately) but looking at your code and, if I understand correctly, you identify "VMD" in XML ISAPI. So I tried to download xml and didn't find "VMD", just: "<eventType> linedetection </eventType>" and "<eventType> field detection </eventType>"

For VMD it is also necessary to activate "Notification of Surveillance Center" on the NVR.

NVRactivateVMD

Now I add the other 4 cameras!! Tnks so so so much!

mrMiimo commented 2 years ago

When unifi-camera-proxy is active, UDM CPU usage increases. The process that increases CPU usage is /lib/systemd/systemd-journald

Top-UDMP

and everything came from the unifi-camera-proxy host

journalctl-UDMP

is there any way to handle this?

mrMiimo commented 2 years ago

solved, it depended on the log level set in the UDM πŸ€¦πŸ»β€β™‚οΈ