4

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?

Joel L
  • 3,031
  • 1
  • 20
  • 33
  • something like this? http://www.unixmen.com/how-to-turn-your-webcam-into-a-motion-detecting-security-spy-camera-in-linux/ – Kornel Feb 04 '15 at 11:54
  • 1
    please define what it means that a video "contains movement" – Micka Feb 04 '15 at 11:54
  • 1
    @Micka — 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" – Joel L Feb 04 '15 at 11:57
  • 1
    @Kornel — 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. – Joel L Feb 04 '15 at 11:59
  • 1
    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 ;) – Micka Feb 04 '15 at 12:00
  • @Micka — 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 :) – Joel L Feb 04 '15 at 12:04
  • You can directly read a static file with [motion](https://motion-project.github.io/motion_config.html#basic_setup_static). – Farid Cheraghi Jul 07 '20 at 14:36

4 Answers4

4

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/

user1558113
  • 146
  • 1
  • 5
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.

user85363
  • 31
  • 3
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

Kornel
  • 5,264
  • 2
  • 21
  • 28
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).

cyriel
  • 3,522
  • 17
  • 34