Testing zones against stored events?

Discussions related to the 1.36.x series of ZoneMinder
Post Reply
haus
Posts: 213
Joined: Thu Oct 11, 2007 5:10 am

Testing zones against stored events?

Post by haus »

I am wondering if there is a way to use stored events (that have already happened and created alarms) to go back and refine zone settings? When my cameras switch from IR to daylight mode they always set off "false" alarms. Since my alarms get sent to a loudspeaker, false alarms are kind of annoying. I have tried changing the overload frame count but when I do that I seem to start missing real events.

If there was a way to replay an event and in a manner of speaking, "pipe" that video through different zone settings to see the outcome, I think I'd be able to understand better how things work. For example I could use videos of a person walking in the zone and the camera mode switching to get the proper balance of settings to remove false alarms.
User avatar
kitkat
Posts: 193
Joined: Sun Jan 27, 2019 5:17 pm

Re: Testing zones against stored events?

Post by kitkat »

Interesting...

Maybe you could simply use the URL of an existing event's video as the source host/path? Ideally a direct link to the .mp4 so as to avoid any ZM overhead, or perhaps copy it to another directory accessible to the web server first.

Or is that too easy?! :?
haus
Posts: 213
Joined: Thu Oct 11, 2007 5:10 am

Re: Testing zones against stored events?

Post by haus »

kitkat wrote: Tue Oct 05, 2021 12:58 am Or is that too easy?! :?
Huh. Mind blown. That's just the kind of big brain thinking I come here for - I'll give it a shot and see what happens. I did see a post from a couple of years ago saying the file source type was broken and probably not much of a priority since no one uses it, but it's worth poking around. I'll also look at event statistics and see if I can get a better handle on things that way.
User avatar
kitkat
Posts: 193
Joined: Sun Jan 27, 2019 5:17 pm

Re: Testing zones against stored events?

Post by kitkat »

haus wrote: Tue Oct 05, 2021 1:19 am
kitkat wrote: Tue Oct 05, 2021 12:58 am Or is that too easy?! :?
Huh. Mind blown. That's just the kind of big brain thinking I come here for - I'll give it a shot and see what happens. I did see a post from a couple of years ago saying the file source type was broken and probably not much of a priority since no one uses it, but it's worth poking around. I'll also look at event statistics and see if I can get a better handle on things that way.
I wasn't thinking of using a File source - I imagined Remote or FFMpeg with something like http://myserver/path/to/event.mp4 as it's host/path.

I suspect though, having thought a little more, that the webserver will simply dump the entire file and the framerate seen by ZM will be super-high and that'll be the stumbling block.

The File source might work though - It takes a single image at a time so it should be possible to dump the video frames to individual jpegs and then set up a looping script to copy them to the File source path at (or close to) the correct rate. Maybe not even dump the the frames as jpegs - Just extract one at a time with FFMpeg and dump it directly into the path each time around the loop.

Or maybe streaming via VLC or something might work?
haus
Posts: 213
Joined: Thu Oct 11, 2007 5:10 am

Re: Testing zones against stored events?

Post by haus »

You're right - "file" expects a single file that updates. I tried "web site", and I can get it to load the URL of the MP4 file, but the size is way too small despite setting the pixel dimensions, and the monitor name and source are red in the console, so it looks like it can't or won't do any analysis.

I don't have the energy for this right now to experiment, but you had a really cool idea and I think it could probably work with the right parameters. I'll keep in the back of my mind as something to experiment with!
User avatar
kitkat
Posts: 193
Joined: Sun Jan 27, 2019 5:17 pm

Re: Testing zones against stored events?

Post by kitkat »

Here's a quick-n-dirty Bash script that'll take a video file as input and save the individual frames one-by-one to a single output file, with each frame overwriting the previous one. Speed is limited to how fast FFMpeg runs, and it'll probably push the server load up whilst it's running.

If you can get the File source to work then this should be able to feed it.

You'll need mediainfo installed to get the frame count - Most distros should have it in their repos somewhere (mine's from epel). (FFMpeg can probably do this, but I don't know how.)

Change INPUT to the path of the input video; OUTPUT to the path and filename of where you want to write the frames; and set LOOP to 1 if you want to repeat the video continuously rather than it just going through it one time and then quitting.

Code: Select all

# video2jpg.sh

INPUT="/home/zoneminder/events/1/2021-10-04/159356/159356-video.mp4"
OUTPUT="/home/zoneminder/zm-test.jpg"

LOOP="0" # Set this to 1 to loop the video

FRAMECOUNT=`mediainfo --Output="Video;%FrameCount%" "$INPUT"`

if [ -z "$FRAMECOUNT" -o "$FRAMECOUNT" -eq "0" ]; then
        echo "Can't get frame count"
        exit
fi

THIS_FRAME=1

while [ "$THIS_FRAME" -le "$FRAMECOUNT" ]; do
        eval ffmpeg -y -hide_banner -i "$INPUT" -vf select=$THIS_FRAME -vframes 1 -vsync 0 "$OUTPUT"
        THIS_FRAME=$(( THIS_FRAME + 1 ))
        if [[ "$LOOP" == "1" && "$THIS_FRAME" == "$FRAMECOUNT" ]]; then
                THIS_FRAME="1"
        fi
done
haus
Posts: 213
Joined: Thu Oct 11, 2007 5:10 am

Re: Testing zones against stored events?

Post by haus »

Amazing, thank you again. I'll see if I can do it this weekend. I can probably just grab framecount from ZM; I only capture around 4fps and the events are usually only a couple of seconds, so that part isn't too hard.
User avatar
kitkat
Posts: 193
Joined: Sun Jan 27, 2019 5:17 pm

Re: Testing zones against stored events?

Post by kitkat »

I made a mistake - That version saves the first frame over and over again.

This is the one that worked:

Code: Select all

INPUT="/home/zoneminder/events/1/2021-10-05/159739/159739-video.mp4"
OUTPUT="/var/www/html/zm-test.jpg"
OUTPUT_TEMP="$OUTPUT-tmp.jpg"

LOOP="0" # Set this to 1 to loop the video

FRAMECOUNT=`mediainfo --Output="Video;%FrameCount%" "$INPUT"`

if [ -z "$FRAMECOUNT" -o "$FRAMECOUNT" -eq "0" ]; then
        echo "Can't get frame count"
        exit
fi

echo "Frames: $FRAMECOUNT"

THIS_FRAME=0

while [ "$THIS_FRAME" -lt "$FRAMECOUNT" ]; do
        echo "Frame $THIS_FRAME"
        eval ffmpeg -y -hide_banner -i "$INPUT" -vf select='eq\(n\\,$THIS_FRAME\)' -vframes 1 -vsync 0 "$OUTPUT_TEMP"
        mv -f "$OUTPUT_TEMP" "$OUTPUT"
        THIS_FRAME=$(( THIS_FRAME + 1 ))
        if [[ "$LOOP" == "1" && "$THIS_FRAME" == "$FRAMECOUNT" ]]; then
                THIS_FRAME="1"
        fi
done



Edited a few minutes later to save to a temporary file and then move it, so as to eliminate tearing and partial images.
User avatar
kitkat
Posts: 193
Joined: Sun Jan 27, 2019 5:17 pm

Re: Testing zones against stored events?

Post by kitkat »

I reckon I've cracked this :)

See here: viewtopic.php?f=11&t=31355
Post Reply