Detect if video file contains movement
Asked Answered
D

4

5

I have a bunch of video clips from a webcam (duration is 5, 10, 60 seconds), and I'm looking for a way to detect "does this video clip have movement", to decide whether the file should be saved or discarded in a future processing phase.

I've looked into motion and OpenCV, but motion seems to only want to work on the raw video stream, and OpenCV seems to be way too advanced for my use.

My ideal solution would be a linux command-line tool that I can feed video files into, and get a simple "does/doesn't contain movement" answer back, so I can discard the irrelevant files. False positives (in a reasonable quantity) are perfectly acceptable for my use.

Does such a tool exist? Or any simple examples of doing this with other tools?

Dustproof answered 4/2, 2015 at 11:15 Comment(7)
something like this? unixmen.com/…Alguire
please define what it means that a video "contains movement"Below
@Below — basically, "any 'significant' change in pixels between n frames". Since the webcam is indoors, there's usually no movement whatsoever, so the tool doesn't have to be very smart about discarding wind/etc"Dustproof
@Alguire — Motion seems to want to be connected to the camera directly, and record things based on that. I would very much prefer a simpler tool to post-process already-captured video.Dustproof
what about illumination changes? Foreground extraction isnt an easy task for real world conditions in general. Depending on your conditions it might be enough to perform some simple frame differencing though ;)Below
@Below — In my use, I'd be perfectly happy with (even lots of) false positives. It's for a hobby project / personal use, so doesn't have to be perfect. I haven't done anything related to video analysis before — doing "simple frame diff" manually might be within my skillset, but probably still much more complicated than I'd like :)Dustproof
You can directly read a static file with motion.Stem
C
7

You can check dvr-scan which is simple cross-platform command line tool based on OpenCV.

To just list motion events in csv format (scan only):

dvr-scan -i some_video.mp4 -so

To extract motion in single video:

dvr-scan -i some_video.mp4 -o some_video_motion_only.avi

For more examples and various other parameters see: https://dvr-scan.readthedocs.io/en/latest/guide/examples/

Cordelia answered 1/10, 2020 at 21:58 Comment(0)
O
3

I had the same problem and wrote the solution: https://github.com/jooray/motion-detection

Should be fairly easy to use from command-line.

Ontology answered 9/6, 2015 at 11:35 Comment(0)
A
2

If you would like to post-process already-captured video then motion can be useful.

VLC allow you to stream or convert your media for use locally, on your private network, or on the Internet. So an already-captured video can be streamed over HTTP, RTSP, etc. and motion can handle it as a network camera.

Furthermore: How to Stream using VLC Media Player

Alguire answered 4/2, 2015 at 12:28 Comment(2)
If you have 2 weeks of video, you will need to stream it for 2 weeks :(.Sheridansherie
yes unfortunately after all these years VLC can't simply play the video file and write motion detected timestamps to a log file. Hard to believeInstep
R
1

If OpenCv is to advanced for you, maybe you should consider something easier which is... SimpleCV (wrapper for OpenCV) "This is computer vision made easy". There is even an example of motion detection using SimpleCV - https://github.com/sightmachine/simplecv-examples/blob/master/code/motion-detection.py Unfortunetely i can't test it(because my OpenCv version isn't compatible with SimpleCV), but generally it looks fine (and isn't complicated) - it just substract previous frame from current and calculate mean of the result. If this value is bigger than some threshold (which most likely you will have to adjust) than we can assume that there were some motion between those 2 frames. Note that setting threshold to 0 is really a bad idea, because always there is some difference between 2 consecuitve frames (changes of lighting, noises, etc).

Rheumatoid answered 5/2, 2015 at 2:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.