Centralised motion detection

498 views
Skip to first unread message

Michael Pope

unread,
Jan 25, 2016, 7:29:40 PM1/25/16
to mlu...@googlegroups.com
At last nights meeting there was a lot of discussion about centralising
motion detection instead of doing it on the camera itself.

Here is how I did motion detection using vlc

First I created a log file using vlc to detect motion

# Create the log file using vlc
def create_log(path)
# Use Xvfb which opens up a virtual desktop to dump a GUI screen
we don't want to see.
# -a = select the next available display
`xvfb-run -a cvlc --no-loop --play-and-exit
--video-filter=motiondetect -vvv #{path}.mjpeg > #{path}.log 2>&1`
end

Then I just read through that log file and look for the number of changes


# Read in the log file and return the motiondetect lines
def read_log(path)
results = []
if File.exists?(path)
File.readlines(path).each do |line|
results.push line.chomp if line =~ /motiondetect filter/
end
end
results
end

This code is from my electric_eye recording tool
https://github.com/map7/electric_eye

I would love to change this program so that it uses something more
robust, faster and not as hacky. The vlc solution has to work in
realtime, uses a lot of resources and it's that good at motion
detection. I also found myself splitting each of my video streams into
1minute lengths so that I could process them in the background and
either keep or discard. It's all very messy.

It would be nice to have a tool which could detect motion much faster
than real time, do it in the background, automated through scripts on
the server and properly edit the videos. For instance I could record in
1hr lots and pass that file over to be processed and then the 'tool'
could remove the parts which are not needed, ie: nothing is moving.

from
Michael

Robin Garen Aaberg

unread,
Jan 25, 2016, 7:51:14 PM1/25/16
to mlu...@googlegroups.com
Im just thinking it might be better to perform live motion detection
on the streams in the central, using opencv?
> --
> You received this message because you are subscribed to the Google Groups
> "mlug-au" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mlug-au+u...@googlegroups.com.
> To post to this group, send email to mlu...@googlegroups.com.
> Visit this group at https://groups.google.com/group/mlug-au.
> For more options, visit https://groups.google.com/d/optout.
>

Cameron

unread,
Jan 25, 2016, 7:58:50 PM1/25/16
to mlug-au
Not quite relevant, but to monitor you pi's temperature in a nice format:-
awk '{printf "%3.1f°C\n", $1/1000}' /sys/class/thermal/thermal_zone0/temp


Cameron

unread,
Jan 25, 2016, 11:18:48 PM1/25/16
to mlug-au
ffmpeg can do scene detection - where you can specify the amount of change in a scene.

ffmpeg -i input.mp4 -an -vf "select=gt(scene\,0.0005),setpts=N/(25*TB)" output.mp4
- This grabs an input video, and cuts out all frames that have no movement, and renders that to an mp4 file.

To increase rendering speed, we can specify ffmpeg's h264 encoding option to be faster:-
ffmpeg -i input.mp4 -an -vf "select=gt(scene\,0.0005),setpts=N/(25*TB)" -c:v libx264 -preset ultrafast output.mp4

It should be possible to use hardware to encode with ffmpeg (using video card, or some intel CPUs have video encoding acceleration), but in practice I've found actually achieving this is difficult - due to annoying reasons, such as: ffmpeg not being compiled with support for it, ffmpeg requiring weird dependencies, non-gpl code, and other such silly things.
Upon further research, when ffmpeg uses libx264, it can use openCL to offload some processing - so be sure to have openCL libraries installed.

To get ffmpeg to grab a webcam's video stream, have a look at some of the examples:
https://trac.ffmpeg.org/wiki/StreamingGuide#Pointtopointstreaming
https://www.wowza.com/forums/content.php?213-How-to-use-FFmpeg-with-Wowza-Media-Server-%28MPEG-TS%29

I'll have to install motionpie on my pi and test this out sometime :)
Cam.

Cameron

unread,
Jan 25, 2016, 11:23:53 PM1/25/16
to mlug-au
ffmpeg -i input.mp4 -an -vf "select=gt(scene\,0.0005),setpts=N/(25*TB)" output.mp4
Increase the value (0.0005) for less sensitivity, and decrease it for more motion sensitivity.
Reply all
Reply to author
Forward
0 new messages