Partial images when using file monitoring

Support and queries relating to all previous versions of ZoneMinder
Locked
dousette
Posts: 5
Joined: Mon Jan 30, 2006 10:14 pm

Partial images when using file monitoring

Post by dousette »

I have a D-Link DCS-3220 camera that I would like to monitor (and eventually mocord), and I was having the worst time trying to get video off of the camera and into Zoneminder! 3 levels of D-Link tech support couldn't help me access the video without using their ActiveX control (mainly because I accidentally mentioned "Linux" on the phone, which prompted a standard "we don't support Linux" answer), but I got a partial solution going by having the camera upload snapshots every second to my Zoneminder server (using vsftpd to receive them). 1fps is better than 0fps. :)

My problem now is that about 25% of the time (a figure made up out of thin air) Zoneminder will try to access the image before the camera is done writing it to the server, leading to half an image and half a gray blob. Zoneminder interprets this gray blob as a significant change to the image and generates an event.

My question for the group is: does anyone know how to either have Zoneminder wait until the image is done being written to the disk, or to have vsftpd somehow buffer the file and write it all at once?

I have moved the ftp root partition (where my video.jpg file is being written and overwritten once per second) to a ram drive to ensure that the hard disk isn't slowing me down, and I have reduced the quality of the images. These things helped somewhat, but the problem is still there. The double buffering in the streaming web view helps reduce the appearance of the problem, too, though I'm not sure if it affects the event generation.

This is on a Dell Poweredge 2850, dual 3.2 Ghz Xeon's, 1 GB RAM running CentOS-4.

I appreciate any help you all can give me!

Thanks,
Dave
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

Sorry to hear you are having problems. Have you tried the paths from the other D-Link cameras? I think these are /IMAGE.JPG and /VIDEO.CGI off the top of my head though I could be wrong. Is it just an mpeg feed?

The partial write issue is perhaps best solved by having your ftp software upload to a temporary image file, and then having a script that will rename it to the image that ZM is looking for once it is complete (e.g. got to a certain size or not been written to for a short time). You may need even three levels of images, one that the ftp can write to, one intermediate one that is either complete or being finished, and one that ZM is reading from. If your ftp software can write to timestamped or incremental images then it is easier as you can just copy each image over once the next one starts to appear.

There's no very simple answer I'm afraid. Getting the streaming working would obviously be the best solution.
Phil
dousette
Posts: 5
Joined: Mon Jan 30, 2006 10:14 pm

Post by dousette »

I did a search of the forums and tried all of the paths for D-Link cameras that I could find... unfortunately, none of them work with this camera. I can see what appears to be the whole directory structure of the camera via the built-in FTP server, and there is a subdirectory called "www" that looks like the web root of the camera, but the only item of interest here is the VatDec.cab ActiveX viewer (the rest are .html and .vspx web page files that insert the ActiveX control with <object> tags). There is a video.jpg file in the FTP root, but the FTP server on the camera is not stable enough to handle me pulling that image off of there more than a few times (even at 10 second intervals!). It crashes the camera, which led to my setting up an FTP server for the camera to write to.

The ActiveX plugin that gets installed is some sort of MPEG-4 viewer, and I know that the camera is capable of streaming the MPEG video over UDP port 5003. Is there a way for Zoneminder to monitor this UDP stream directly, or is there a utility that would take this UDP stream and dump it to an MPEG file that Zoneminder could watch?

Good idea with the script... I will look into that. The camera is capable of writing a stream of timestamped JPEG's, and I could rig up a script that said, "Wait until there is more than one videoXXXXX.jpg file, take the one where XXXXX is lowest and move it to the file Zoneminder is looking at. Lather, rinse, repeat." I wonder if a move would be quicker, or if updating a symbolic link would be? With a symbolic link, I would be guaranteed the file already exists and is whole, since the next one would already be in progress. With a move, I am again writing the file, which might lead to the same problem (though with it being RAM to RAM, to a much lesser degree). I will experiment with both and let you know.

Thanks for the help!
Dave
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

It's it's just mpeg4 then you are out of luck for now I'm afraid with ZM, though it is planned for as soon as I can find tiem to do it.

Moving a file _should_ be atomic, all you are doing is updating the directory entry rather than physically copying (so use mv and not cp). A symlink would work as well as would a hard link, but a move seems simpler as then you don't need to worry about deleting the file afterwards.
Phil
dousette
Posts: 5
Joined: Mon Jan 30, 2006 10:14 pm

Post by dousette »

The script is working well, combined with correcting a duplex mismatch and some mount options on the ramdrive, I do not believe I am getting any more dropped frames in the "monitor" mode.

However, I was experimenting with the "modect" mode, and when something happens on the camera, ZM detects it and starts capturing my event, but the load on my server skyrockets to 3, 4, and sometimes up over 5 (5.67 at the moment)! It looks like the analyzer, zma, is what is chewing up the most resources. The server stats were listed in a previous message, and ZM is the only thing on it (aside from the FTP server that the cameras are writing to).

There are two cameras on the system now, with plans to add maybe 4 or 5 more (we will definitely be shopping around to get cameras that ZM likes better). Do you have any suggestions on getting the load average down? Could it have something to do with my zone settings? I am getting some false positive events (shadows tricking the camera, etc), so I fear that I may have them set too sensitively.

The high load average may also be causing my other problem, too... when ZM records an event, it seems to "stutter". When I look at the array of still shots, I see a lot of duplicates, with the exact same timestamp. Sometimes there are 8 or 10 of these in a row, and then the file picks back up where it left off (usually after the interesting event is over).

I really appreciate your taking time to help me.

Thanks,
Dave
jameswilson
Posts: 5111
Joined: Wed Jun 08, 2005 8:07 pm
Location: Midlands UK

Post by jameswilson »

have you limited the capture rate of the monitor (might be a stupid suggestion but cant see why that rig should struggle)
James Wilson

Disclaimer: The above is pure theory and may work on a good day with the wind behind it. etc etc.
http://www.securitywarehouse.co.uk
dousette
Posts: 5
Joined: Mon Jan 30, 2006 10:14 pm

Post by dousette »

The max fps for both monitors is set to 1.00.

When I did have it set to the default 0.00, my load was high all the time, even in monitor mode. After changing it to 1.00 fps a day or two ago, my load fell below 0.10 (and usually 0.01) in monitor mode, but it was still high when detecting motion.

Is there a load difference in modecting a "file" device versus a "local" or "remote"? I would think that they should all be the same, since in each case you are working with a regular jpeg, just acquiring it in different ways.
jameswilson
Posts: 5111
Joined: Wed Jun 08, 2005 8:07 pm
Location: Midlands UK

Post by jameswilson »

yes locals are better as it doesnt have to 'decode' the jpeg.
Long shot you dont have ignore max fps in alarm checked do you??
James Wilson

Disclaimer: The above is pure theory and may work on a good day with the wind behind it. etc etc.
http://www.securitywarehouse.co.uk
dousette
Posts: 5
Joined: Mon Jan 30, 2006 10:14 pm

Post by dousette »

You know, I did have that option checked... I just unchecked it, and I will let you guys know how it goes.

Thanks!
Dave
abrar
Posts: 4
Joined: Tue Feb 21, 2006 12:11 am

Can you put this script here so we can use it.

Post by abrar »

Thanks in advance.
abrar
Posts: 4
Joined: Tue Feb 21, 2006 12:11 am

Can you put this script here so we can use it.

Post by abrar »

Thanks in advance.
Locked