keshavdv / unifi-cam-proxy

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

streaming not working in 1.21.3 #199

Closed jurajs5 closed 10 months ago

jurajs5 commented 2 years ago

no streaming in version 1.21.3

snapshots are there, but streaming is KO in proxy site, looks like all is ok, but in unifi UDM pro - there is no video, 3dost all the time (loading)

Camera:

daltskin commented 2 years ago

Just a heads up..

I downgraded to 1.21.2 a while back and disabled auto-updates of apps - and everything was awesome.

image

However, at some point this week version 1.21.5 got auto-installed onto the UDM Pro regardless, causing the broken pipe errors. Downgrading again resolves the issue:

apt-get update
apt-get install --reinstall --allow-downgrades unifi-protect=1.21.2 -y

I'm not sure exactly when it stopped working to identify the cause, but see this in the logs which is possibly related:

[2022-05-06T03:31:03,581] INFO system - ====================================================================== [2022-05-06T03:31:03,582] INFO system - UniFi 7.1.61 (build atag_7.1.61_17860 - release/release) is started [2022-05-06T03:31:03,583] INFO system - ======================================================================

It's happened again..

1.21.6 was rolled out even though app updates is disabled :(

image

fblgit commented 2 years ago

yup, he upgraded himself even disabled. This is because of apt.

root@ubnt:/# apt-mark hold unifi-protect
unifi-protect set on hold.

I can't recall holding the apt but now, let's wait and see.

The new version included libwrap0-dev so I think there may be something related because mutating the communication is way more simpler than altering how an embed camera encodes the video, but for now rollback to the last supported should be enough.

UPDATE: apt hold seems working for now, but it is related with the UDM OS updates that may bring a min-default version. but so far so good

FrancescoFdd5 commented 2 years ago

Any update?

FrancescoFdd5 commented 2 years ago

Project death?

keshavdv commented 2 years ago

Definitely not! I've been traveling and haven't been able to focus on this, but I've been slowly working on trying to identify the timestamp generation issue which leads to the slow drift of the recordings. This type of analysis is a new area to me and progress has been slow.

fblgit commented 2 years ago

@keshavdv can u share how u test/dev this issue on the protect-124 branch ? how u determined the approach/changes and debugged all this ?

watson81 commented 2 years ago

I haven't been able to do much in a few weeks, but FYI that a few of us have been doing what we can to help figure out stuff and posting in the discord.

ptorsten commented 2 years ago

Can you share the discord link? Happy to try to help.

On Fri, Jun 24, 2022, 10:17 PM Patrick Watson @.***> wrote:

I haven't been able to do much in a few weeks, but FYI that a few of us have been doing what we can to help figure out stuff and posting in the discord.

— Reply to this email directly, view it on GitHub https://github.com/keshavdv/unifi-cam-proxy/issues/199#issuecomment-1165904709, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMTLTQQRVIJF4OMLVGB733VQYJUHANCNFSM5QFNMCAA . You are receiving this because you commented.Message ID: @.***>

watson81 commented 2 years ago

https://discord.gg/Bxk9uGT6MW

Can you share the discord link? Happy to try to help.

jurajs5 commented 2 years ago

Any updates?

arjankuijpers commented 2 years ago

any updates or thoughts? Is it true that recording on the protect-124 branch doesn't work?

EasternIndustries-IT commented 2 years ago

I saw there was a commit a few days ago. Any Idea what that was for? I was tempted to update but we would lose 17 cameras if recording doesn't work.

arjankuijpers commented 2 years ago

I saw there was a commit a few days ago. Any Idea what that was for? I was tempted to update but we would lose 17 cameras if recording doesn't work.

Looking at the merge, it’s only docs.. so updating is useless.

jurajs5 commented 2 years ago

I am giving up on this project and going full UniFi. Was hoping that this project can help me but after almost 1/2 year of waiting for fix….

FrancescoFdd5 commented 1 year ago

Any updates?

apadua commented 1 year ago

I’m giving up and never touching protect again. What a miserable ecosystem - no cameras on the market and actively sabotaging alternatives. Overpriced cameras and frustrating support. Only thing I really like is the protect iPhone app video scrolling.

viniciusvillas commented 1 year ago

I am giving up on this project and going full UniFi. Was hoping that this project can help me but after almost 1/2 year of waiting for fix….

I found this project by accident, and I got really interested in how it works. I've been thinking for a while about buying generic cameras based on Ambarella tech (S2L) and copying the firmware from the original Cams, so I could integrate it with cheaper cameras, but I've never found a generic one.

So I went full UniFi and never looked back. Works like a charm. But the low-level developer in me really wants to mess with this ecosystem 😁

It's interesting how this project works. If I've understood correctly, we're getting the RTSP feed from the generic camera through ffmpeg, then piping it to a Python script to fix some kind of time synchronization, and then piping it again via netcat (or nc) to the UniFi Protect Host (in my case, a UniFi Cloud Key G2+). It's very interesting, and it got me thinking about what are the issues that @keshavdv is facing to make the streaming work again. Maybe I could help.

codevski commented 1 year ago

same issues with those cheap tapo cameras

Danimal4326 commented 1 year ago

Is this project still under active development or is it dead w/ new Unifi Protect versions?

keshavdv commented 1 year ago

It's been slow and painful, but I have been making meaningful headway on this and hope to have a version that works with the latest Protect soon. The more Protect evolves, the more it diverges from existing open-source implementations into bespoke Ubiquiti implementations that are becoming more difficult to emulate on non-Unifi hardware.

Danimal4326 commented 1 year ago

No worries, thanks for the update. And please let the community know if you need testing and/or coding help.

arjankuijpers commented 1 year ago

Could it be a possibility that you can share some of your thoughts/headaches/problems. what are you running into? Maybe we can help you with it. you don't have to burden yourself.

fblgit commented 1 year ago

It's been slow and painful, but I have been making meaningful headway on this and hope to have a version that works with the latest Protect soon. The more Protect evolves, the more it diverges from existing open-source implementations into bespoke Ubiquiti implementations that are becoming more difficult to emulate on non-Unifi hardware.

@keshavdv IMHO would be better to just pin into a new version and see if the PR illustrates others how to contribute further that point. I think that @arjankuijpers and some others are falling into the same situation: how to contribute, some more background.. a CONTRIBUTE.md explaining how to set a dev-env, triage, etc.

Personally, better put the efforts on scaling up the project instead of toiling with the patch..

sabey commented 1 year ago

If 1.21.2 is the last supported version, how can I upgrade to it (I'm on 1.20.3)?

I've tried apt-get install unifi-protect=1.21.2 but I got the following error:

The following packages have unmet dependencies:
 unifi-protect : Depends: ubnt-opencv4-libs but it is not installable
E: Unable to correct problems, you have held broken packages.
geiz123 commented 1 year ago

If 1.21.2 is the last supported version, how can I upgrade to it (I'm on 1.20.3)?

I've tried apt-get install unifi-protect=1.21.2 but I got the following error:

The following packages have unmet dependencies:
 unifi-protect : Depends: ubnt-opencv4-libs but it is not installable
E: Unable to correct problems, you have held broken packages.

Have you tried this suggestion? https://github.com/keshavdv/unifi-cam-proxy/issues/199#issuecomment-1066003241

I've installed the latest version to test and was able to revert back with the commands in the above link.

Farjad commented 1 year ago

It seems like this might be the issue. I'm not entirely sure what audio codec unifi protect is expecting.

==> ems.00.log <==
2022-10-29T03:08:17.351Z 2 :568:ValidateCodecs - Audio codecs not supported by stream type ONFMP4 on stream INLFLV(2) with name `AABBCC000001_0` from protocol ILFL(14)
2022-10-29T03:08:17.351Z 2 :2293:GetVideoFMP4Track - Invalid codecs: VIDEO:\n   H264 90.000KHz 0 b/s 704x480 0.00 fps SPS/PPS: 10/5 L/P: 30/77\nAUDIO (0):\nAUDIO (1):\nTransfer rate: 0 b/s
2022-10-29T03:08:17.351Z 2 :2269:GetAudioFMP4Track - Invalid codecs: VIDEO:\n   H264 90.000KHz 0 b/s 704x480 0.00 fps SPS/PPS: 10/5 L/P: 30/77\nAUDIO (0):\nAUDIO (1):\nTransfer rate: 0 b/s

I produced this error on cleanup-snapshots branch btw

Orotusso commented 1 year ago

Doesn't seem to only affect Protect, running Video 3.10.13 on Debian Bullseye and getting the same issue. Camera is at 20FPS, so not an FPS issue, certificate is valid, cam-proxy successfully adopted. The thumbnails show up on the dashboard but getting,

Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.9/dist-packages/unifi/clock_sync.py", line 167, in <module>
    main()
  File "/usr/local/lib/python3.9/dist-packages/unifi/clock_sync.py", line 157, in main
    write(read_bytes(source, payload_size))
  File "/usr/local/lib/python3.9/dist-packages/unifi/clock_sync.py", line 87, in write
    sys.stdout.buffer.write(data)
BrokenPipeError: [Errno 32] Broken pipe
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
BrokenPipeError: [Errno 32] Broken pipe
av_interleaved_write_frame(): Broken pipe
Error writing trailer of pipe:: Broken pipe

when trying to view stream. Looking into Unifi Video logs reveals that Evostream is seeing the connection but closing it.

2022-11-01T20:50:52.912Z 3::0::Stream ONFMP4(1) with name ``AABBCC000001_1`` from protocol PT(22) registered to origin application ``evostreamms``
2022-11-01T20:50:52.913Z 3::0::(Far: 10.0.254.18:20138; Near: X.X.X.X:7446) CTCP(17) <-> TCP(18) <-> ISSL(19) <-> IWS(20) <-> [IWSFMP4(21)] protocol linked to stream ONFMP4(1) with name ``AABBCC000001_1`` from protocol PT(22)
2022-11-01T20:50:53.007Z 3::0::command: getstreaminfo
2022-11-01T20:50:53.344Z 6::0::Handlers count changed: 13->14 IOHT_TIMER
2022-11-01T20:50:53.344Z 6::0::Handlers count changed: 14->15 IOHT_TCP_CARRIER
2022-11-01T20:50:53.344Z 3::0::Inbound connection accepted: (Far: X.X.X.X:37202; Near: X.X.X.X:6666) CTCP(18) <-> TCP(23) <-> [ILFL(24)]
2022-11-01T20:50:58.344Z 2::0::Waiting for metadata finished. Closing the connection
2022-11-01T20:50:58.344Z 6::0::Protocol (Far: X.X.X.X:37202; Near: X.X.X.X:6666) CTCP(18) <-> TCP(23) <-> [ILFL(24)] unregistered from application: evostreamms
2022-11-01T20:50:58.348Z 6::0::Handlers count changed: 15->14 IOHT_TCP_CARRIER
2022-11-01T20:50:58.348Z 6::0::Handlers count changed: 14->13 IOHT_TIMER
karlchaffey commented 1 year ago

apt-get update apt-get install --reinstall --allow-downgrades unifi-protect=1.21.2 -y

Seems no longer the case, I'm on UCK G2 Plus v3.0.12 but now getting Version '1.21.2' for 'unifi-protect' was not found so can't downgrade

AngellusMortis commented 1 year ago

Yeah, you will not be able to run pre-2.6.x versions on a 3.x console. It is a different Linux distro, so it has a different apt repo.

mihaiturcu commented 1 year ago

not really sure what's up but I somehow got it to work by upgrading ffmpeg

I basically cloned the repo and edited the docker file to change the following FROM python:3.9.15-alpine3.16 RUN apk add --update ffmpeg netcat-openbsd git

Build it, replace the image in the docker-compose file with my locally built one and it seems to work fine-ish, except for the live view. I also experimented with passing in a different camera model that supports more FPS - 50 + I matched the FPS on my dahua camera. --model 'UVC G4 Pro'

I'll try swapping from rtsp to dahua flag and see if that improves things a bit.

j-syn commented 1 year ago

I basically cloned the repo and edited the docker file to change the following FROM python:3.9.15-alpine3.16 RUN apk add --update ffmpeg netcat-openbsd git

Tried this using the origin/clean-snapshots branch as my base and it seems to be working in the latest iOS app, for the most part. I also have a Unifi Talk phone and the Protect app that runs on the Unifi Talk desktop phone seems to be working fine as well. Protect is recording and I can skim through the past record using the iOS app. I can see what's going on right now (minus about a 5 second delay). However It does not work in a web browser visiting my UMP Pro directly. Attempting to view a live feed via the web or to edit/modify detection zones (which uses a live feed while you're working) causes Protect to completely crash and restart (on my UDM Pro running 1.12.33).

Some notes: I have 1 hikvision camera and 3 axis cameras. Using the "hikvision" specific flag on that camera worked before, but does not work using this custom docker image. I had to switch to using the standard/generic rtsp option. This works, but the hikvision camera proxy is using 5x the CPU that the other three proxies are. It did not when I previously used the hikvision option.

For now my hikvision camera my docker command is: unifi-cam-proxy --host {protect ip} -i {camera ip} --mac '{custom random mac}' --cert /client.pem --token '{custom token for each camera}' rtsp -s 'rtsp://{username}:{password}@{camera ip}:554'

For the my axis cameras it is: unifi-cam-proxy --host {protect ip} -i {camera ip} --mac '{custom random mac}' --cert /client.pem --token '{custom token for each camera}' rtsp -s 'rtsp://{username}:{password}@{camera ip}:554/axis-media/media.amp'

altodd commented 1 year ago

I tried j-syn's update and doesn't seem to help for me, it is just always saying "Camera Updating" for me now.

Florian-Stern commented 1 year ago

I tried mihaiturcu's update... the recording works perfectly. the live view is not possible.

Florian-Stern commented 1 year ago

I also noticed that when I run the proxy without docker works recording and live view!!!!

system Ubuntu/amd64 latest version

Code run without docker:

apt install ffmpeg netcat python3 python3-pip pip3 install unifi-cam-proxy unifi-cam-proxy --host 192.168.201.179 --cert /client.pem --token {Adoption token} rtsp -s rtsp://192.168.201.15:8554/cam'

EasternIndustries-IT commented 1 year ago

Which version of Unifi protect are you running? Does it work with the latest version?

Florian-Stern commented 1 year ago

I'm running version 2.2.6

ptorsten commented 1 year ago

What version of ffmpeg? I suspect that is the main fix vs docker.

On Wed, Dec 21, 2022 at 10:18 AM Florian-Stern @.***> wrote:

I'm running version 2.2.6

— Reply to this email directly, view it on GitHub https://github.com/keshavdv/unifi-cam-proxy/issues/199#issuecomment-1361812260, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMTLTSMZKOPIYK2GO4YG3DWONCXLANCNFSM5QFNMCAA . You are receiving this because you commented.Message ID: @.***>

EasternIndustries-IT commented 1 year ago

Does it work with the latest version of protect 2.6.17

Florian-Stern commented 1 year ago

2.6.17? My latest early access update is 2.2.6!

elafargue commented 1 year ago

2.6.17 was released some time ago: https://community.ui.com/releases/UniFi-Protect-Application-2-6-17/165cd5e2-d1b7-46c2-8ac8-fc16c5c6d1bf

Florian-Stern commented 1 year ago

As I said my last update is the 2.2.6 an update via ssh is also not possible...hmm...funny

root@ubnt:/# apt-cache policy unifi-protect unifi-protect: Installed: 2.2.6 Candidate: 2.2.6 Version table: *** 2.2.6 500 500 https://apt.artifacts.ui.com stretch/release arm64 Packages 500 https://apt-beta.artifacts.ui.com stretch/beta arm64 Packages 100 /var/lib/dpkg/status

Florian-Stern commented 1 year ago

What version of ffmpeg? I suspect that is the main fix vs docker.

ffmpeg version 4.3.1

EasternIndustries-IT commented 1 year ago

2.6.17 was released some time ago: https://community.ui.com/releases/UniFi-Protect-Application-2-6-17/165cd5e2-d1b7-46c2-8ac8-fc16c5c6d1bf

This was released last month and I found out it is an early access update.

Florian-Stern commented 1 year ago

But it also says from unifi os 3.0. So only for the UDM SE.

The UDM Pro is early on the version v1.12.33

hawaaiianmiraclecreel commented 1 year ago

I also noticed that when I run the proxy without docker works recording and live view!!!!

system Ubuntu/amd64 latest version

Code run without docker:

apt install ffmpeg netcat python3 python3-pip pip3 install unifi-cam-proxy unifi-cam-proxy --host 192.168.201.179 --cert /client.pem --token {Adoption token} rtsp -s rtsp://192.168.201.15:8554/cam'

I just tried this (creating a fresh ubuntu VM, install unifi cam proxy, etc) and its showing a snapshot in live view but its not actually working. Same broken Pipe errors image

here is ffmpeg output for me image

gianmarco-mameli commented 1 year ago

Hi, me too same broken pipe errors, I tried with a rtsp from a raspberry pi camera and from another rtsp test stream in arm64 architecture

henningpeter commented 1 year ago

I basically cloned the repo and edited the docker file to change the following FROM python:3.9.15-alpine3.16 RUN apk add --update ffmpeg netcat-openbsd git

Tried this using the origin/clean-snapshots branch as my base and it seems to be working in the latest iOS app, for the most part. I also have a Unifi Talk phone and the Protect app that runs on the Unifi Talk desktop phone seems to be working fine as well. Protect is recording and I can skim through the past record using the iOS app. I can see what's going on right now (minus about a 5 second delay). However It does not work in a web browser visiting my UMP Pro directly. Attempting to view a live feed via the web or to edit/modify detection zones (which uses a live feed while you're working) causes Protect to completely crash and restart (on my UDM Pro running 1.12.33).

Some notes: I have 1 hikvision camera and 3 axis cameras. Using the "hikvision" specific flag on that camera worked before, but does not work using this custom docker image. I had to switch to using the standard/generic rtsp option. This works, but the hikvision camera proxy is using 5x the CPU that the other three proxies are. It did not when I previously used the hikvision option.

For now my hikvision camera my docker command is: unifi-cam-proxy --host {protect ip} -i {camera ip} --mac '{custom random mac}' --cert /client.pem --token '{custom token for each camera}' rtsp -s 'rtsp://{username}:{password}@{camera ip}:554'

For the my axis cameras it is: unifi-cam-proxy --host {protect ip} -i {camera ip} --mac '{custom random mac}' --cert /client.pem --token '{custom token for each camera}' rtsp -s 'rtsp://{username}:{password}@{camera ip}:554/axis-media/media.amp'

I managed to get it to work as well on bare metal. I have the same to report that it works only in the mobile Protect app. Doesn't crash Protect though when trying via the web interface. Just can't connect to the live stream. I can only see the snapshot image.

I managed to get hikvision flag to work as well by disabling https on my camera as it crashes with it on when trying to get the snapshot: unifi-cam-proxy --host x.x.x.x --ip y.y.y.y --cert client.pem hikvision -u user -p pass

Traceback (most recent call last):
  File "/usr/local/bin/unifi-cam-proxy", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/dist-packages/unifi/main.py", line 146, in main
    loop.run_until_complete(run())
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.9/dist-packages/unifi/main.py", line 141, in run
    await c.run()
  File "/usr/local/lib/python3.9/dist-packages/unifi/core.py", line 81, in run
    await connect()
  File "/home/god/.local/lib/python3.9/site-packages/backoff/_async.py", line 76, in retry
    ret = await target(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/unifi/core.py", line 72, in connect
    await asyncio.gather(*tasks)
  File "/usr/local/lib/python3.9/dist-packages/unifi/cams/base.py", line 81, in _run
    force_reconnect = await self.process(msg)
  File "/usr/local/lib/python3.9/dist-packages/unifi/cams/base.py", line 882, in process
    res = await self.process_snapshot_request(m)
  File "/usr/local/lib/python3.9/dist-packages/unifi/cams/base.py", line 778, in process_snapshot_request
    path = await self.get_snapshot()
  File "/usr/local/lib/python3.9/dist-packages/unifi/cams/hikvision.py", line 50, in get_snapshot
    async for chunk in self.cam.Streaming.channels[source].picture(
  File "/home/god/.local/lib/python3.9/site-packages/hikvisionapi/hikvisionapi.py", line 289, in opaque_request
    await self._detect_auth_method()
  File "/home/god/.local/lib/python3.9/site-packages/hikvisionapi/hikvisionapi.py", line 246, in _detect_auth_method
    response.raise_for_status()
  File "/home/god/.local/lib/python3.9/site-packages/httpx/_models.py", line 749, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Redirect response '302 Moved Temporarily' for url 'http://192.168.0.101/ISAPI/System/status'
Redirect location: 'https://192.168.0.101/ISAPI/System/status'
For more information check: https://httpstatuses.com/302

For those who want to try, make sure you take the files from the clean-snapshots branch! (Installing from The Python Package Index (https://pypi.org/) with pip install unifi-cam-proxy gets you version 0.2.0 from February that doesn't have the October fixes from @keshavdv)

Danimal4326 commented 1 year ago

Can confirm clean-snapshots version works bare-metal in the iPhone and AppleTV apps.

hawaaiianmiraclecreel commented 1 year ago

I basically cloned the repo and edited the docker file to change the following FROM python:3.9.15-alpine3.16 RUN apk add --update ffmpeg netcat-openbsd git

Tried this using the origin/clean-snapshots branch as my base and it seems to be working in the latest iOS app, for the most part. I also have a Unifi Talk phone and the Protect app that runs on the Unifi Talk desktop phone seems to be working fine as well. Protect is recording and I can skim through the past record using the iOS app. I can see what's going on right now (minus about a 5 second delay). However It does not work in a web browser visiting my UMP Pro directly. Attempting to view a live feed via the web or to edit/modify detection zones (which uses a live feed while you're working) causes Protect to completely crash and restart (on my UDM Pro running 1.12.33). Some notes: I have 1 hikvision camera and 3 axis cameras. Using the "hikvision" specific flag on that camera worked before, but does not work using this custom docker image. I had to switch to using the standard/generic rtsp option. This works, but the hikvision camera proxy is using 5x the CPU that the other three proxies are. It did not when I previously used the hikvision option. For now my hikvision camera my docker command is: unifi-cam-proxy --host {protect ip} -i {camera ip} --mac '{custom random mac}' --cert /client.pem --token '{custom token for each camera}' rtsp -s 'rtsp://{username}:{password}@{camera ip}:554' For the my axis cameras it is: unifi-cam-proxy --host {protect ip} -i {camera ip} --mac '{custom random mac}' --cert /client.pem --token '{custom token for each camera}' rtsp -s 'rtsp://{username}:{password}@{camera ip}:554/axis-media/media.amp'

I managed to get it to work as well on bare metal. I have the same to report that it works only in the mobile Protect app. Doesn't crash Protect though when trying via the web interface. Just can't connect to the live stream. I can only see the snapshot image.

I managed to get hikvision flag to work as well by disabling https on my camera as it crashes with it on when trying to get the snapshot: unifi-cam-proxy --host x.x.x.x --ip y.y.y.y --cert client.pem hikvision -u user -p pass

Traceback (most recent call last):
  File "/usr/local/bin/unifi-cam-proxy", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/dist-packages/unifi/main.py", line 146, in main
    loop.run_until_complete(run())
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.9/dist-packages/unifi/main.py", line 141, in run
    await c.run()
  File "/usr/local/lib/python3.9/dist-packages/unifi/core.py", line 81, in run
    await connect()
  File "/home/god/.local/lib/python3.9/site-packages/backoff/_async.py", line 76, in retry
    ret = await target(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/unifi/core.py", line 72, in connect
    await asyncio.gather(*tasks)
  File "/usr/local/lib/python3.9/dist-packages/unifi/cams/base.py", line 81, in _run
    force_reconnect = await self.process(msg)
  File "/usr/local/lib/python3.9/dist-packages/unifi/cams/base.py", line 882, in process
    res = await self.process_snapshot_request(m)
  File "/usr/local/lib/python3.9/dist-packages/unifi/cams/base.py", line 778, in process_snapshot_request
    path = await self.get_snapshot()
  File "/usr/local/lib/python3.9/dist-packages/unifi/cams/hikvision.py", line 50, in get_snapshot
    async for chunk in self.cam.Streaming.channels[source].picture(
  File "/home/god/.local/lib/python3.9/site-packages/hikvisionapi/hikvisionapi.py", line 289, in opaque_request
    await self._detect_auth_method()
  File "/home/god/.local/lib/python3.9/site-packages/hikvisionapi/hikvisionapi.py", line 246, in _detect_auth_method
    response.raise_for_status()
  File "/home/god/.local/lib/python3.9/site-packages/httpx/_models.py", line 749, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Redirect response '302 Moved Temporarily' for url 'http://192.168.0.101/ISAPI/System/status'
Redirect location: 'https://192.168.0.101/ISAPI/System/status'
For more information check: https://httpstatuses.com/302

For those who want to try, make sure you take the files from the clean-snapshots branch! (Installing from The Python Package Index (https://pypi.org/) with pip install unifi-cam-proxy gets you version 0.2.0 from February that doesn't have the October fixes from @keshavdv)

Thank you for this tip, i was running the .2 from pip! I need to figure out how to run this specific branch, any help is appreciated. I got git repo downloaded, checkout’ed to clean-snapshots but a little bit of a loss as to waht happens next.

henningpeter commented 1 year ago

I basically cloned the repo and edited the docker file to change the following FROM python:3.9.15-alpine3.16 RUN apk add --update ffmpeg netcat-openbsd git

Tried this using the origin/clean-snapshots branch as my base and it seems to be working in the latest iOS app, for the most part. I also have a Unifi Talk phone and the Protect app that runs on the Unifi Talk desktop phone seems to be working fine as well. Protect is recording and I can skim through the past record using the iOS app. I can see what's going on right now (minus about a 5 second delay). However It does not work in a web browser visiting my UMP Pro directly. Attempting to view a live feed via the web or to edit/modify detection zones (which uses a live feed while you're working) causes Protect to completely crash and restart (on my UDM Pro running 1.12.33). Some notes: I have 1 hikvision camera and 3 axis cameras. Using the "hikvision" specific flag on that camera worked before, but does not work using this custom docker image. I had to switch to using the standard/generic rtsp option. This works, but the hikvision camera proxy is using 5x the CPU that the other three proxies are. It did not when I previously used the hikvision option. For now my hikvision camera my docker command is: unifi-cam-proxy --host {protect ip} -i {camera ip} --mac '{custom random mac}' --cert /client.pem --token '{custom token for each camera}' rtsp -s 'rtsp://{username}:{password}@{camera ip}:554' For the my axis cameras it is: unifi-cam-proxy --host {protect ip} -i {camera ip} --mac '{custom random mac}' --cert /client.pem --token '{custom token for each camera}' rtsp -s 'rtsp://{username}:{password}@{camera ip}:554/axis-media/media.amp'

I managed to get it to work as well on bare metal. I have the same to report that it works only in the mobile Protect app. Doesn't crash Protect though when trying via the web interface. Just can't connect to the live stream. I can only see the snapshot image. I managed to get hikvision flag to work as well by disabling https on my camera as it crashes with it on when trying to get the snapshot: unifi-cam-proxy --host x.x.x.x --ip y.y.y.y --cert client.pem hikvision -u user -p pass

Traceback (most recent call last):
  File "/usr/local/bin/unifi-cam-proxy", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/dist-packages/unifi/main.py", line 146, in main
    loop.run_until_complete(run())
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.9/dist-packages/unifi/main.py", line 141, in run
    await c.run()
  File "/usr/local/lib/python3.9/dist-packages/unifi/core.py", line 81, in run
    await connect()
  File "/home/god/.local/lib/python3.9/site-packages/backoff/_async.py", line 76, in retry
    ret = await target(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/unifi/core.py", line 72, in connect
    await asyncio.gather(*tasks)
  File "/usr/local/lib/python3.9/dist-packages/unifi/cams/base.py", line 81, in _run
    force_reconnect = await self.process(msg)
  File "/usr/local/lib/python3.9/dist-packages/unifi/cams/base.py", line 882, in process
    res = await self.process_snapshot_request(m)
  File "/usr/local/lib/python3.9/dist-packages/unifi/cams/base.py", line 778, in process_snapshot_request
    path = await self.get_snapshot()
  File "/usr/local/lib/python3.9/dist-packages/unifi/cams/hikvision.py", line 50, in get_snapshot
    async for chunk in self.cam.Streaming.channels[source].picture(
  File "/home/god/.local/lib/python3.9/site-packages/hikvisionapi/hikvisionapi.py", line 289, in opaque_request
    await self._detect_auth_method()
  File "/home/god/.local/lib/python3.9/site-packages/hikvisionapi/hikvisionapi.py", line 246, in _detect_auth_method
    response.raise_for_status()
  File "/home/god/.local/lib/python3.9/site-packages/httpx/_models.py", line 749, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Redirect response '302 Moved Temporarily' for url 'http://192.168.0.101/ISAPI/System/status'
Redirect location: 'https://192.168.0.101/ISAPI/System/status'
For more information check: https://httpstatuses.com/302

For those who want to try, make sure you take the files from the clean-snapshots branch! (Installing from The Python Package Index (https://pypi.org/) with pip install unifi-cam-proxy gets you version 0.2.0 from February that doesn't have the October fixes from @keshavdv)

Thank you for this tip, i was running the .2 from pip! I need to figure out how to run this specific branch, any help is appreciated. I got git repo downloaded, checkout’ed to clean-snapshots but a little bit of a loss as to waht happens next.

What you need to do first is simply overwrite the already installed files with the ones you downloaded via cloning. Essentially, if I remember right, there are 5 or 6 .py files that changed between the versions. You can get the installed location with: pip show unifi-cam-proxy. Then take the files and overwrite the ones already installed.

Second is that there were some dependencies added (take a look via GitHub version control) so you need to install those: sudo pip3 install pyunifiprotect, sudo pip3 install packaging, sudo pip3 install reolinkapi, sudo pip3 install git+https://github.com/zkonge/flvlib3.git. That should be it.