Issue with snapshot.cgi on Ubiquiti Cameras or NVR

Forum for questions and support relating to the 1.29.x releases only.
Locked
GreatWhiteOne
Posts: 4
Joined: Fri Mar 18, 2016 12:17 am

Issue with snapshot.cgi on Ubiquiti Cameras or NVR

Post by GreatWhiteOne »

ZM Version 1.29.0 on Ubuntu 14.04 - Main Release, not compiled.

I am trying to add some Ubiquiti camera to Zoneminder, and have been for a couple years, but each time I give up. This time, I am really trying hard.

RTSP is to unstable, and has to many glitches, both from the camera (which the added back in the 3.2 beta firmware) or from the NVR.

There is API access to snapshots, from the NVR, and there is a CGI script that produces an image. I can get to them unauthenticated from a browser, but when I load them into the ZM monitor, I get the following in the logs;

03/17/16 17:55:55.789219 zmc_m9[28652].ERR-zm_remote_camera_http.cpp/1040 [Unable to read content]
03/17/16 17:55:55.810501 zmc_m9[28652].ERR-zm_remote_camera_http.cpp/1141 [Unable to get response, disconnecting]

So I turned on debugging. It is accessing the camera, but seems to have an issue reading from the camera, then after trying, the camera shuts out the monitor. Here is the debugging output.

03/17/16 17:55:55.608829 zmc_m9[28652].DB3-zm_remote_camera_http.cpp/124 [Connected to host, socket = 5]
03/17/16 17:55:55.608841 zmc_m9[28652].DB2-zm_remote_camera_http.cpp/138 [Sending request: GET /api/2.0/snapshot/camera/0a665d09-f0ba-32ea-a78d-f8cde28de971?force=true&apiKey=EHKDifNngCoCiCr6 HT
TP/1.0
User-Agent: ZoneMinder/1.29.0
Host: 172.23.4.191
Connection: Keep-Alive

]
03/17/16 17:55:55.608862 zmc_m9[28652].DB3-zm_remote_camera_http.cpp/147 [Request sent]
03/17/16 17:55:55.788814 zmc_m9[28652].DB3-zm_remote_camera_http.cpp/207 [Just getting 14480]
03/17/16 17:55:55.788991 zmc_m9[28652].DB3-zm_remote_camera_http.cpp/210 [Expecting 14480 bytes]
03/17/16 17:55:55.789045 zmc_m9[28652].DB3-zm_remote_camera_http.cpp/232 [Read 14480 bytes]
03/17/16 17:55:55.789060 zmc_m9[28652].DB4-zm_remote_camera_http.cpp/238 [HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: image/jpg
Date: Thu, 17 Mar 2016 21:55:37 GMT
Connection: close

▒▒▒▒]
03/17/16 17:55:55.789071 zmc_m9[28652].DB3-zm_remote_camera_http.cpp/773 [Got status '200' (OK), http version 1.1]
03/17/16 17:55:55.789076 zmc_m9[28652].DB3-zm_remote_camera_http.cpp/780 [Got connection 'close']
03/17/16 17:55:55.789080 zmc_m9[28652].DB3-zm_remote_camera_http.cpp/814 [Got content type 'image/jpg']
03/17/16 17:55:55.789089 zmc_m9[28652].DB3-zm_remote_camera_http.cpp/205 [Just getting 32K]
03/17/16 17:55:55.789093 zmc_m9[28652].DB3-zm_remote_camera_http.cpp/210 [Expecting 32768 bytes]
03/17/16 17:55:55.789148 zmc_m9[28652].DB3-zm_remote_camera_http.cpp/232 [Read 32768 bytes]
03/17/16 17:55:55.789155 zmc_m9[28652].DB4-zm_remote_camera_http.cpp/238 [▒▒▒▒]
03/17/16 17:55:55.789161 zmc_m9[28652].DB3-zm_remote_camera_http.cpp/205 [Just getting 32K]
03/17/16 17:55:55.789164 zmc_m9[28652].DB3-zm_remote_camera_http.cpp/210 [Expecting 32768 bytes]
03/17/16 17:55:55.789181 zmc_m9[28652].DB3-zm_remote_camera_http.cpp/232 [Read 32768 bytes]
03/17/16 17:55:55.789185 zmc_m9[28652].DB4-zm_remote_camera_http.cpp/238 [▒▒▒▒]
03/17/16 17:55:55.789190 zmc_m9[28652].DB3-zm_remote_camera_http.cpp/207 [Just getting 11743]
03/17/16 17:55:55.789194 zmc_m9[28652].DB3-zm_remote_camera_http.cpp/210 [Expecting 11743 bytes]
03/17/16 17:55:55.789206 zmc_m9[28652].DB3-zm_remote_camera_http.cpp/232 [Read 11743 bytes]
03/17/16 17:55:55.789210 zmc_m9[28652].DB4-zm_remote_camera_http.cpp/238 [▒▒▒▒]
03/17/16 17:55:55.789215 zmc_m9[28652].DB3-zm_remote_camera_http.cpp/197 [Socket closed remotely]
03/17/16 17:55:55.789219 zmc_m9[28652].ERR-zm_remote_camera_http.cpp/1040 [Unable to read content]
03/17/16 17:55:55.810501 zmc_m9[28652].ERR-zm_remote_camera_http.cpp/1141 [Unable to get response, disconnecting]
03/17/16 17:55:55.838106 zmc_m9[28652].DB3-zm_remote_camera_http.cpp/132 [Disconnected from host]

Anyone have any ideas? I am use the following to pull and it is the exact same results:
http://[NVR IP]:7080/api/2.0/snapshot/camera/[camera UUID]?force=true&apiKey=EHKDifNngCoCiCr6
or
http://[Camera IP]:80/snapshot.cgi

Thanks for any thoughts.
User avatar
knight-of-ni
Posts: 2406
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: Issue with snapshot.cgi on Ubiquiti Cameras or NVR

Post by knight-of-ni »

GreatWhiteOne wrote: I am trying to add some Ubiquiti camera to Zoneminder, and have been for a couple years, but each time I give up. This time, I am really trying hard.
Exactly which Ubiquiti camera?
Have you tried the zoneminder wiki? https://wiki.zoneminder.com/Ubiquiti

I see other hits when Googling like this one:
https://community.ubnt.com/t5/UniFi-Vid ... -p/1314129
GreatWhiteOne wrote: RTSP is to unstable, and has to many glitches, both from the camera (which the added back in the 3.2 beta firmware) or from the NVR.
Please clarify what you mean by "RTSP". RTSP is both a protocol and a ZoneMinder source type. From the context, I can't tell exactly which you are referring to. If you are referring to the ZoneMinder RTSP source type, then you should try the ffmpeg source type instead (see the wiki).

I'd try to get it working as a video stream first, rather than in snapshot mode. If your camera is fairly modern and supports h264 rtsp streams, then you should be able to get it to work with ZoneMinder. First, though, get the rtsp url working with vlc. Then use that known-good url in ZoneMinder.
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/
GreatWhiteOne
Posts: 4
Joined: Fri Mar 18, 2016 12:17 am

Re: Issue with snapshot.cgi on Ubiquiti Cameras or NVR

Post by GreatWhiteOne »

Thank you for the response.

Sorry, should have added the Camera types. This actually applies to any of them, but specifically, I am using UVC, UVC-Mini, and UVC-Dome. They all run on the same firmware. Version 3.0 through 3.1.4 (latest) do not have the ability to produce camera based RTSP streams, so you have to go the the NVR to get that stream. Version 3.2betaX (currently 9) adds back in the ability to do stand-alone mode and RTSP locally.

Additional detail. By doing some firmware changes via SSH, you can enable snapshot mode, remove HTTPS, and disable authentication on the 3.0 until latest 3.1 firmware. But it is is a CGI based snapshot, and the ZM does not like it. That is what the debug I attached is showing.

Yes I have been through the forums, and google. The zoneminder wiki is for pretty old Ubiquiti stuff. Most of that is pre version 3.x of the Ubiquiti cameras.

I have no problems getting this to work with RTSP either through the NVR and then pushing the stream to ZM, or from the beta standalone mode, but RTSP from the NVR or from the camera's seems to have too much artifacting, and tearing, plus it is about 15 seconds behind live. That is the main reason that I do not want to use it. Instead, I am trying to find a way to pull the images from the camera's though the snapshot mode. I can load the snapshots in a browser, but ZM does not seem to like them at all.

If I can figure this out, I can help update the wiki on this as I have figured out alot of things that are possible, just dealing with this one last issue of getting ZM to read the snapshot properly.

Thanks for any help you can provide.
User avatar
knight-of-ni
Posts: 2406
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: Issue with snapshot.cgi on Ubiquiti Cameras or NVR

Post by knight-of-ni »

GreatWhiteOne wrote: I have no problems getting this to work with RTSP either through the NVR and then pushing the stream to ZM, or from the beta standalone mode, but RTSP from the NVR or from the camera's seems to have too much artifacting, and tearing, plus it is about 15 seconds behind live.
These two symptoms are somewhat common, with known workarounds, so I'm not sure I'd give up on acquiring a usable stream just yet.

The tearing issue can occur with udp streams when using ffmpeg.

Have you:
- tried a tcp stream instead of udp? (Changing from RTP/unicast to RTP/RTSP will use tcp)
- tried the libvlc source type? This source type was introduced specifically as a way to get around the ffmpeg tearing issue.

If you are using wifi or otherwise dropping packets on your network then that could cause this issue as well.

Note also, you may not be able to stream dual streams from the camera (one to ZoneMinder and another to your other nvr) at the same time, using the same url. Many cameras advertise multiple stream support, but many cameras support it only when each recording device is acquiring a stream through a different url.

The 15 second delay can be caused when the end user enters a value in the MAX FPS or Alarm MAX FPS fields in the camera configuration, which is lower than the frame rate coming from the camera. These fields don't work with ip streams. Make sure these fields are empty for starters. If you want to lower the frame rate then do that from the camera. The help text has more detail on this issue.

I know you asked about snapshot mode, but using a stream performs quite a bit better than snapshot mode. Just want to make sure we've exhausted all options first.
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/
GreatWhiteOne
Posts: 4
Joined: Fri Mar 18, 2016 12:17 am

Re: Issue with snapshot.cgi on Ubiquiti Cameras or NVR

Post by GreatWhiteOne »

Thank you for your response and your time.

I will continue working on this. I personally did not want to use RTSP, but I will continue working on that. RTSP has a very high CPU cost.

Just some update. It does not sound like finding a way to pull the image is a going to happen. I may continue to work on this outside of this as I am pretty good at hacking firmware. This would be my preferred method. For now, i will use the RTSP.

Just some bullet points.
-I am not limiting anything in the monitor settings.
-Network is not an issue. Ethernet connected, gigabit links, etc.
-RTSP is using TCP, not UDP already. Verified with a packet capture.

Again, thank you for your time. I will keep working on it.
User avatar
knight-of-ni
Posts: 2406
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: Issue with snapshot.cgi on Ubiquiti Cameras or NVR

Post by knight-of-ni »

Yeah, it looks like you might have to blaze a new trail.

If your hardware resources are good (multi cpu-core servers work best), one can usually reduce the load sufficiently by reducing the camera framerate in the camera. For a typical surveillance system, this is almost always an acceptable trade off. For example, 5 fps is perfect for most general surveillance applications.

The url you posted in your first post makes reference to an api, is there any documentation on that? That would likely help.

You've probably seen this, but this was interesting:
https://community.ubnt.com/t5/UniFi-Vid ... m-p/523945

Looks like there is a config file under /etc in the device which one can tinker with.
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/
GreatWhiteOne
Posts: 4
Joined: Fri Mar 18, 2016 12:17 am

Re: Issue with snapshot.cgi on Ubiquiti Cameras or NVR

Post by GreatWhiteOne »

Thanks again.

Yeah, I have seen that config file. The issue is not the snapshot image on the camera, but the ZM ability to use that image snapshot. I can pull that image in a browser, download it, but for some reason, ZM can not seem to use the snapshot.cgi image file. Just will not pull it, which is the debug that I posted in the first post. If I could figure out how to get ZM to pull that image or better why it can not use it, then I would be golden. There are multiple ways to get to snapshots, including the API, or from the camera directly, but ZM can not seem to use any of them.

Have a great sunday,
User avatar
knight-of-ni
Posts: 2406
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: Issue with snapshot.cgi on Ubiquiti Cameras or NVR

Post by knight-of-ni »

Yeah, I saw your debug output. ZoneMinder uses the standard jpeg library on your system when reading snapshots. When ZoneMinder can't read a snapshot from the camera, that can mean the camera is not sending a truly jpeg-compliant image. Despite well written standards, that happens more often than one might think. That is why I suggested finding api documentation and/or tweaking that config file. Perhaps there is a setting one can modify to get your camera to send a jpeg snapshot with properties ZoneMinder finds acceptable.

You could use wget to save one of those snapshots to disk. Then inspect it yourself to see if there is anything obviously different about it.
At a minimum, you could confirm the jpeg snapshot has the resolution you expect.
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/
Locked