Commit Graph

52 Commits

Author SHA1 Message Date
Maurice ONeal
6ffe80b672 v1.6.t5
Added a signal handler that will print out signal details upon receiving
them. This should give up some hint to the cause of crashes for
debugging reasons.

The root index web page will now only be updated once. Hopefully this
reduces chance of multiple instances clashing with each other.
2023-02-11 20:59:19 -05:00
Maurice ONeal
f4f1f62d25 v1.6.t4
Updated the documentation.

The test machine had a mystery crash that needs to be investigated. In
mean time, the timeout run code has been refactored and will not run
thread cancel unless is it absolutely needed at the individual thread
level (hopefully that fixes the crash issue).

post_cmd shall also now run via timeout. With that, no external commands
should cause this application to stall. Timeout protection should
prevent that.
2023-02-07 23:19:41 -05:00
Maurice ONeal
23e0ae935e v1.6.t3
Added string trimming to the vid_container parameter to filter out bad
user input.

Added detection_stream url to the config file and made it so the
application can now use a smaller/lower bit rate stream for motion
detection separate from the recording stream. This can significantly
lower CPU usage.

Moved away from using system() and the explicit timeout command. Instead
opted to using popen() and cancelable pthreads. Doing this pulls back
more control over ffmpeg than before and the app will now properly
respond term signals and even the CTRL-C keyboard interrupt.
2023-02-05 14:05:56 -05:00
Maurice ONeal
80f8ec07e3 v1.6.t2
The app was still cutting out last command line arg of my test setup.
Later found out it was the run script limiting the command line arg
count to 3. I extended it out to 8 but I'll need to find a better option
to make it limitless.
2023-01-18 21:55:17 -05:00
Maurice ONeal
62a6139f3a v1.6.t1
The is not currently parsing multiple config files properly. Changed up
the parser function without complicated check ahead logic. Will test if
this works.
2023-01-18 20:51:16 -05:00
Maurice ONeal
528b4105f7 v1.6
The app can be considered in stable state, releasing to master branch.
2022-12-24 21:16:49 -05:00
Maurice ONeal
62b2bfd76b v1.5.t19
Added the ability to read multiple config files so it's now possible to
load a singular global config and then load a camera specific config in
another.

Many elements in the web interface are coming out too small. Added meta
viewport device width in hopes that the web interface will self adjust
to device it is being displayed on.

Changed duration to num_of_clips and added clip_len so the amount of
seconds in each clip and the amount of clips to be processed for motion
are now adjustable.

Adjusted a several default values.
2022-12-24 13:48:51 -05:00
Maurice ONeal
4e44111ea8 v1.5.t18
Discovered that the "ffmpeg stall" is still an issue so I put the
timeout call back into the ffmpeg command.

Changed the default pix_thresh to 10000.
2022-12-22 20:15:14 -05:00
Maurice ONeal
736b8c5ec4 v1.5.t17
Fixed an invalid argument in the ffmpeg command from vcodec to -vcodec.

Also added a 10sec delay to simulate a running ffmpeg if it fails for
what ever reason.
2022-12-21 20:44:58 -05:00
Maurice ONeal
b470915276 v1.5.t16
The app is still failing with intermittent moov atom failures on trying
to open the video clips with opencv VideoCapture. I suspect it is trying
to open the files while ffmpeg is not done finalizing them. Reformed the
detection loop to spawn dedicated motion detection threads for each
video clip and only when ffmpeg confirmed finished.
2022-12-21 20:30:37 -05:00
Maurice ONeal
ad4a6357b4 v1.5.t15
Thanks the debug messages, in found a potential issue with the video
clips being pulled from the in house test cameras. Sometimes the video
clips are being pulled with incomplete meta information causing opencv
to fail to open the clips. Added "-movflags faststart" to the ffmpeg
command that should hopefully fix this and should help the app to handle
unreliable camera streams more gracefully.

max_clips now defaults to 90 instead of 30.
2022-12-20 20:25:54 -05:00
Maurice ONeal
4667cf2e96 v1.5.t14
Added another debug clause for opencv videoio so it will provide even
more debug information. Going back to implicitly defining FFMPEG as the
videoio for opencv, turns out FFMPEG is the only real stable option to
use when it comes to reading video files with opencv. Any other option
would just severely limit codec and container support.
2022-12-20 19:29:36 -05:00
Maurice ONeal
2e10d31ab6 v1.5.t13
Added the ability change the video codec via the config file.

Changed the install script to now install the application in the /opt
directory and then symm link to /usr/bin. Doing this allowed me to
create a run script to start the application and enable the
OPENCV_VIDEOIO_DEBUG parameter for opencv. This should make it easier to
diagnose video-io issues with opencv.

Updated the README documentation with all of the changes done to the
application since v1.5.
2022-12-18 10:25:46 -05:00
Maurice ONeal
f8f7564911 v1.5.t12
Turned off caching for all web interface pages. Opencv will no longer be
compiled from source as part the setup.sh script, instead the
libopencv-dev package will be installed.
2022-12-17 20:40:52 -05:00
Maurice ONeal
523ff57215 v1.5.t11
Found the infinite loop issue in moDetect(), turns out the frame
parameters at some point were never returning empty, hence moDetect()
would continue into perpetuity. Changed the loop structure to use a
fixed frame count instead of relying on frameFF() to return empty on
EOF.
2022-12-17 10:34:40 -05:00
Maurice ONeal
c153fdcd21 v1.5.t10
Somewhere in the code is causing an infinite loop, root cause still
undermined. added more logging statements to help me find misbehavior.
imgDiff() will now handle empty frames on the parameters more
gracefully.

enforceMaxClips() will no longer assume all video clips are accompanied
by html and jpg files but will now instead "delete if exists."
2022-12-16 18:30:27 -05:00
Maurice ONeal
a5ee164b4e v1.5.t9
The app is hard crashing now but I was able to determine the cause this
time. Must functions in filesystem tend to abort if the filesystem
object doesn't exists. Added protection where needed to prevent crashing
2022-12-13 21:13:10 -05:00
Maurice ONeal
954fdfba0b v1.5.t8
Logs are still being cutoff, I'm assuming the app is crashing but can't
locate the problem without any logs. Reformed logging to never overwrite
the logs and will instead append only. Size control will be in the form
of the byte size of the log files.
2022-12-13 20:27:32 -05:00
Maurice ONeal
651ec96083 v1.5.t7
Moved logging out of it's own loop, hopefully this fixes the issue with
it not outputting all log lines. recLoop() and detectLoop() will now
update logs synchronously.

The setup.sh script will now include gstreamer and pkg-config. This
should help fix opencv video-io format support.
2022-12-11 21:00:53 -05:00
Maurice ONeal
89129ad3f4 v1.5.t6
Can't get opencv to work with FFMPEG to open the buff file on the test
machine. I've given up on trying to figure out why. Testing out video
capture without explicitly specifying FFMPEG to see how that works out.
2022-12-11 16:10:04 -05:00
Maurice ONeal
2bd600bd51 v1.5.t5
Fixed a bug that caused the buffDir to get deleted before the app did
any work. Apparently the filesystem lib crashes the app if the directory
doesn't exists. Might need to add protection against that in the future.

Directory pages with now explicitly link to index.html since implicit
does not work for apache2.
2022-12-11 15:06:09 -05:00
Maurice ONeal
5ab50433cf v1.5.t4
The error checking with ffmpeg is not working. Learned that it doesn't
always return 0 on success. Decided to remove the error checking
altogether. Instead ffmpeg failures should be checked manually using
stderr.

Dirent includes .. and . so I decided to switch to the filesystem entry
listing that should hopefully exclude those special directories.

The camera webroot was not generating .index files. those files would
only get generated if motion was detected. Copied the code that does
that onto recLoop() to execute regardless of motion.
2022-12-11 12:33:56 -05:00
Maurice ONeal
baeaabbd55 v1.5.t3
Fixed the default webroot directory to apache's correct webroot. Also
renamed separated outDir from webRoot and made webRoot changeable on the
config file.

Added logging the recorder and detection loops to help with debugging
and troubleshooting. Just like the video clips, max log lines were added
to control the size of the data being saved to storage.
2022-12-11 10:25:22 -05:00
Maurice ONeal
ce4a326b24 v1.5.t2
The camera folder will now be auto created and eventually will cause the
app to auto create the webroot regardless if motion was detected or not.
2022-12-04 20:07:20 -05:00
Maurice ONeal
9816ba339f v1.5.t1
Decided to switch using opencv's builtin pixel diff motion detection via
absdiff and thresh. Doing this should increase efficiency instead of
using the home brewed pixel loops and threads.

Added a web interface of sorts by having html files output along with
the video clips. These files are designed to link together with the
assumption that the output directory is a web root like /var/www/html
that apache2 uses. The interface is crude at best but at least allow
playback of recorded footage.

Added max_clips config variable that can limit the amount of motion
events that can recorded to storage on a single day.
2022-12-04 15:13:39 -05:00
Maurice ONeal
01a11741c7 v1.5
Release candidate for merging to master.
2022-10-15 10:24:28 -04:00
Maurice ONeal
a0ee8e35f7 v1.4.t11
completely removed object detection code because I don't foresee going
back to that model anytime soon. diffs will not reset to 0 instead
decrement and the consecutive pixel diffs are now adjustable via
consec_threshold.

updated README.md for the changes to pixel diff detection.
2022-10-14 14:31:12 -04:00
Maurice ONeal
9ecace7e4b v1.4.t10
optical flow calculations use up a lot of processing power even at the
block level so I decided to take it back out. once again, no objection
detection is going to be used and will fall back to pixel diffs only.
also modified pixel diffs to decrement pixel diffs of no diff is
detected, going test how this works out.
2022-10-14 11:42:59 -04:00
Maurice ONeal
17c136b6bc v1.4.t9
Motion detection was still not scanning the entire block. potential fix
in secDiff(), correcting offsets in the for loops.
2022-10-06 19:41:47 -04:00
Maurice ONeal
4bf3672a39 v1.4.t8
AI object detection via yolov5 didn't work out too well, in fact it was
crashing the detection threads for whatever reason. I could deep dive
why it was crashing but I think the better solution is to bring back
optical flow detection at the block level. the advantage of this over
object detection is the fact that a block doesn't need to have a whole
object in it.
2022-10-04 18:12:32 -04:00
Maurice ONeal
42814ab8ca v1.4.t7
the fifo file for stat output doesn't work. switched back regular file
for stats.
2022-10-02 09:29:29 -04:00
Maurice ONeal
1e72107ff0 v1.4.t6
switched over the stat text from a regular file to a fifo file.
2022-10-02 09:01:38 -04:00
Maurice ONeal
c7a1dd3c84 v1.4.t5
Fixed the compile error in the previous commit.
2022-09-30 16:29:28 -04:00
Maurice ONeal
cd4a2d0f98 v1.4.t4
potentially fixed what was apparently a long standing bug that caused
motion detection to look at just the first block. this bug was found
thanks to the stats output.
2022-09-30 16:18:39 -04:00
Maurice ONeal
4f33c280ce v1.4.t3
Fixed a few bugs in the stat output strings so they should output to the
stat file as expected.
2022-09-29 14:52:42 -04:00
Maurice ONeal
7ab51226b2 v1.4.t2
re-formed the stats output and moved it out of the motion detect
function.

block pixel diff counts will now no longer stop at the threshold at each
block. it will now count the entire block and output the results in the
stats. the code now also pick the block with the highest pixDiff instead
of stopping at the first block with a high pixDiff.
2022-09-29 11:37:10 -04:00
Maurice ONeal
5d12855fad v1.4.t1
added object detection code base on yolov5 machine vision model. also
added a stat file so motion and object detection values can be monitored
in real time if used with the 'watch' command.
2022-09-27 18:10:04 -04:00
Maurice ONeal
d5a9d1f046 v1.4
Release candidate for merging to master.
2022-09-25 09:15:23 -04:00
Maurice ONeal
737df9a0b6 v1.3.t3
Fixed a bug in the detect loop that caused it to fail to load video
clips from ffmpeg.
2022-09-24 09:22:45 -04:00
Maurice ONeal
56bd855dbb v1.3.t2 Update
Added a -v command line option to display the application's current
version.

The application version is now defined in a single a const value called
APP_VER so bumping the version number now means updating this single
value in common.h.

Versioning scheme will now be major.minor.[test_rev]. test_rev will be
t1, 2, 3, etc... as updates are pushed to the test branch. all code
pushes to master shall bump major or minor and then remove test_rev.

Removed the detect loop's motion latching affect so it ONLY calls wrOut
if the video clip contains motion.

Fixed a bug in the recording loop that fail to create the needed sub-dir
before calling FFMPEG.
2022-09-23 21:50:06 -04:00
Maurice ONeal
bf3de932d1 v1.3 Update
Broken down the code into multiple files instead having it all in
main.cpp.

Also detached recording from detection by having them now run in
separate threads instead of having motion detection inline with
recording. this will hopefully make it so there is less missed motion
events due to processing overhead.

The recording loop now take advantage of FFMPEG's "-f segment" option
instead of generating the clips implicitly in separated FFMPEG calls.
again, all in hope to reduce missed motion events.

This application have the tendency to detect motion of small insects.
to prevent this it was determined with there will need to be some means
of identifying objects via machine vision. there is an object detection
function but it doesn't currently do anything at this time. this is
something that I will be working on in the near future.

created a test branch in the repository. all early, testing code will
now go in this branch going forward. only fully tested, stable code will
be committed to master going forward.
2022-09-22 20:57:46 -04:00
Maurice ONeal
64fe9fcad0 Compile and installation method updates
created setup, build and install scripts to make it easier and
convenient to compile and install the application from source. no plans
distribute pre-compiled binaries because it's just so much easier to
guarantee the application will actually work in the target machine when
compiled by the target machine.
2022-09-17 09:53:52 -04:00
Maurice ONeal
2687b938a0 v1.2 Update
Video clips recorded from the camera are no longer append, instead the
clips are kept as is and then linked together in a playlist file in the
output_dir. this makes it much more efficient and easier to maintain
code.

Also discovered that ffmpeg have a tendency to stall mid execution of
recording from the rtsp stream every now and then. added a work around
in the form of calling ffmpeg via the timeout command instead of
directly so it will force kill ffmpeg if it goes longer than the
expected BUF_SZ.

Increased BUF_SZ to 10 secs.

Added a clause in the recording loop that will make it write out a
second clip if motion was detected.
2022-09-11 12:56:32 -04:00
Maurice ONeal
7a4555f3c3 READ.md updated to new version 2022-08-12 21:50:35 -04:00
Maurice ONeal
48e55b9721 v1.1 Update
major changes to the motion detection scheme and re-introduced
multi-threading. this further sped up the motion detection to a point
that it can now be called in line with the recording loop without
loosing any extra camera footage due to heavy cpu usage.

pixels are now read in blocks to further increase efficiency and to
filter out movements of small objects. the footage clip size is now
hard coded to 3 seconds instead of it being external adjustable.

changed the way footage with motion is now stored. its now down to
single level files with the current date. if footage of the same date
already exists, new footage will be appended to it.

the version number shall be updated going forward.
2022-08-12 21:46:36 -04:00
Maurice ONeal
a36d4e93c0 Major changes to application internals and efficiency increases
removed all threads from the application as there is no used for them at
at this time. instead, the application will now operate on a single
event loop and now directly utilize use ffmpeg to record video footage
instead of opencv's implementation.

old code pulled tons of frames the detection stream at full speed,
wasting a lot of cpu cycles. instead it will now pull frames in a steady
speed at the new detect_fps value. doing this significantly reduced cpu
usage and can potentially further reduce cpu usage for end users by
pulling the fps value lower then the default.
2022-07-28 10:30:07 -04:00
Maurice ONeal
c054356541 Changed post motion detection conditioning
The app will now count the amount of secs to record post motion
detection instead of the amount of frames. Split the main loop timer
with the motion timer in separate threads to make that happen. The
parameter was added to the config file.

Recording fps is now adjustable.
2022-07-14 10:19:37 -04:00
Maurice ONeal
072cbe269c Changed comparison functions again
decided to change frame comparison functions again from optical flow to
    a home brewed function that compares gray levels in the pixels of each
    frame. significant differences in gray levels between the frames can
    potentially trigger a motion event.

    also moved away command line arguments to an external config file to set
    app parameters.

    created a README file to get this project ready for general open source
    release.
2022-07-08 15:24:45 -04:00
Maurice ONeal
8a17b58d25 experimental trail and error changes throughout development.
all current experimentation with the code leads up to this point
for optical flow motion detection. the code as it stands will
input frames in pairs and then compare each pair of frames for
any significant changes in the optical flow distance between
points.

experiments have shown that this actual does work fairly well;
however there is significant amounts of CPU usage and video
encoding options are not flexible at all. the code still picks
up false positives but I have high confidence something that
can be adjusted through external parameters which I will
impliment in the future.
2022-06-11 08:43:19 -04:00
Maurice ONeal
f721f45fc9 removed the motion positive counter. it didn't do want i expecting it to do. 2022-04-22 10:46:19 -04:00