BUG: Network Camera snapshots every 60 seconds frequently MISSING
I have six network cameras (DCS-900) with the snapshot interval set to 60 seconds.
That should therefore be 360 snapshots per hour.
Motion fails to take a snapshot on what seems to be for random reason and random time.
Looks like I am missing between 10% and 20% of the expected 360 per hour.
They simply are not being snapshotted.
I use: on_picture_save /security/scripts/make_snapshot_thumbnail.sh %v %q %D %f
and that script writes a log line to a file. The file shows that the picture is not being saved,
and when I look into the target_dir for the snapshot_filename I confirm that the file is missing.
Most of the snapshots are generated and logged correctly.
Why are some missing (frequently).
Test case
Environment
Motion version: |
3.2.4 snap 5 |
ffmpeg version: |
not used |
Shared libraries: |
ffmpeg, mysql, postgresql |
Server OS: |
Fedora Core 4 kernel 2.6.11 |
--
GregSwift - 07 Feb 2006
Follow up
UPDATE -- I made some small changes to the motion.c which resolves my problem.
Note that the machine that motion runs on is VERY slow and I suspected that the six cameras were not all able to get a snapshot taken at exactly xx:xx:00 every 60 seconds .
I am not sure how to make a "patch" so I will describe and give the code fix here as best as I can.
There is a line in motion.c in the "SNAPSHOT FEATURE SECTION" which was part of a big IF that said: cnt->currenttime % cnt->conf.snapshot_interval == 0 , and was checking to see if a snapshot should be made.
If the processor is VERY slow, then the current time MOD snapshot_interval might be 1 or 2 and not exactly 0.
I changed that line to allow some slop of up to five seconds, thus: if .... && cnt->currenttime % cnt->conf.snapshot_interval < 5 ... but in some cases when the processor was lucky, several snapshots would get made, so I had to add a field to motion.h in the struct context which added one new integer: int shotsnapepoch; , I placed this right after int shots. Then I fixed motion.c again to only take the snapshot for the proper minute, so that entire section now looks like this:
/***** MOTION LOOP - SNAPSHOT FEATURE SECTION *****/
/* Did we get triggered to make a snapshot from control http? Then shoot a snap
* If snapshot_interval is not zero and time since epoch MOD snapshot_interval = 0 then snap
* Note: Negative value means SIGALRM snaps are enabled
* httpd-control snaps are always enabled.
*/
/* GS */
if (
(
cnt->conf.snapshot_interval > 0 &&
cnt->shots==0 &&
cnt->currenttime % cnt->conf.snapshot_interval < 5 &&
cnt->shotsnapepoch != cnt->currenttime / cnt->conf.snapshot_interval /* GS */
) ||
cnt->snapshot
)
{
cnt->currenttime_tm->tm_sec = 0; /* GS */
event(cnt, EVENT_IMAGE_SNAPSHOT, newimg, NULL, NULL, cnt->currenttime_tm);
cnt->snapshot = 0;
cnt->shotsnapepoch = cnt->currenttime / cnt->conf.snapshot_interval; /* GS */
}
/* GS */
Note that the line: cnt->currenttime_tm->tm_sec = 0; is necessary because I have some other php scripts that build custom web pages that need the file name of the file
to be the "intended" timestamp rather than the "actual" timestamp. That line causes the filename to have 00 in the seconds field because I use:
snapshot_filename %Y%m%d-snapshots/%Y%m%d_%H%M%S-snapshot-cam1
I suppose I could have just coded "00" rather than use the %S on my snapshot_filename,
but the fix to the code seemed more proper.
Also note that the line: cnt->shotsnapepoch = cnt->currenttime / cnt->conf.snapshot_interval; is what prevents the possibility of multiple snapshots during the first five seconds
of any minute and is used in the if with the line: cnt->currenttime % cnt->conf.snapshot_interval < 5 && cnt->shotsnapepoch = cnt->currenttime / cnt->conf.snapshot_interval
which forces the snapshot for the current minute but only one time.
Also note that this fix will likely break if someone were to use a snapshot_interval value less than 5, but do people really do that ? ? ! ??
This DOES fix my problem and I have been running this code for several days now successfully.
Please Please add this (or something like it) to your "master" copy of the code. If you want me to attempt to create a patch file and send it to you I will, just tell me what to do.
Thanks again for a GREAT program. I look forward to many more years of usage from it.
Greg Swift email: swiftga at-sign comcast dot net
Fix record
Fixed in SVN 44 - motion-daily 20050231
Fix implemented not same as suggested above. Do not want to hardcode 00 as seconds. And reused the method used for timelapse including variables.
--
KennethLavrsen - 21 Feb 2006