<p>FFMPEG doesn't really have the tools to do motion detection out of the box. You can certainly do the cropping using the <a href="https://ffmpeg.org/ffmpeg-filters.html#crop" rel="nofollow">crop filter</a>: <code>-vf crop=w:h:x:y</code> where <code>w:h</code> is the size of your cropped area and <code>x:y</code> its coordinates in the original image. So your ffmpeg script might look like:</p>

<pre><code>ffmpeg -i input.avi -c:v libx264 -crf 20 -vf crop=123:45:67:89 output.mp4
</code></pre>

<p>Then you could find a frame of the output that contains no movement, export it to a still image, invert it and add it back to the video using <a href="https://ffmpeg.org/ffmpeg-filters.html#overlay-1" rel="nofollow">overlay</a> so that only parts of frames that are different would show up. Then use the <a href="http://ffmpeg.org/ffmpeg-filters.html#blackdetect" rel="nofollow">blackdetect</a> filter to find frames that are black. Then you could use some shell-fu to delete those parts of the video and finally concatenate the remainder into one clip. Whew.</p>

<p>…or you could use openCV. Here's a ready-rolled script that does motion detection: <a href="https://github.com/RobinDavid/Motion-detection-OpenCV" rel="nofollow">https://github.com/RobinDavid/Motion-detection-OpenCV</a></p>

CC BY-SA 3.0
2015-01-28T10:15:57.033Z
when you say `-vf crop=w:h:x:y`, you're talking about [`ffmpeg` cropping](http://video.stackexchange.com/q/4563/4601), right?  When you say an "empty frame", I'm not sure how I would find that in a video file... I'm thinking the github project you mentioned might be the way to go
Mike Pennington
CC BY-SA 3.0
2015-01-28T12:09:43.067Z
"empty frame" meaning a frame where nothing is happening. Yeah, use the script, unless you really want a learning excercise.
stib
CC BY-SA 3.0
2015-01-28T00:56:33.883Z
2015-01-28T12:18:06.753Z
2015-01-28T12:18:06.753Z
stib
<p>I might have an unusual problem for this site; among other duties, I manage the wireless network for a large corporate campus.  As part of an upgrade to our wireless access-points, I used a metal bracket to mount an AP on a rail about 10 feet off the ground.  When it was mounted, the bottom part of the access-point was parallel with the floor.</p>

<p>A week later, our cabling technicians noticed that someone had bent the AP about 70 degrees upward; given the strength of the bracket, it took a lot of force to do this.  We have a security camera about 90 feet away from this AP, but the relevant area I care about is about 3% of the camera's image area.</p>

<p>Due to the fuzziness and small area in the video, our security team said it would take about 30 man-hours to search the video (one person watching it for 3.5 days... given restrictions in playback, they can't zoom in during fast forward); as such, they weren't interested in going farther.</p>

<p><em>QUESTION</em>:</p>

<p>It seems like there might be some way to build a list of candidate time slots in the video, where this 3% area drastically changed from normal for a given time-frame... let's say at least 20-seconds.</p>

<p>TBH, the bracket is only $30; however, since our old-crusty security guy swore it couldn't be automated, I took it as a point of curiosity to see whether that's true.  Obviously there are commercial solutions... I'm looking for "free" in linux.</p>

<p>The file would be about 6GB.  Is there a linux CLI solution to this problem?  I just need to reduce the times we look at to something manageable.  Even if I had to use a python image analytics library like <a href="http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_video/py_table_of_contents_video/py_table_of_contents_video.html" rel="noreferrer">OpenCV-python</a>, that's a possibility but I'm hoping to (ab)use something like <a href="https://www.ffmpeg.org/" rel="noreferrer"><code>ffmpeg</code></a> for this purpose.  If there isn't such a tool, which <a href="http://docs.opencv.org/trunk/modules/video/doc/video.html" rel="noreferrer">Open-CV</a> function would be best for this job?</p>

<video><post-production><filter>
Search mpeg / avi frames in linux
Mike Pennington
# Search mpeg / avi frames in linux

(Asked by: username_0 on 2015-01-26)

I might have an unusual problem for this site; among other duties, I manage the wireless network for a large corporate campus. As part of an upgrade to our wireless access-points, I used a metal bracket to mount an AP on a rail about 10 feet off the ground. When it was mounted, the bottom part of the access-point was parallel with the floor.

A week later, our cabling technicians noticed that someone had bent the AP about 70 degrees upward; given the strength of the bracket, it took a lot of force to do this. We have a security camera about 90 feet away from this AP, but the relevant area I care about is about 3% of the camera's image area.

Due to the fuzziness and small area in the video, our security team said it would take about 30 man-hours to search the video (one person watching it for 3.5 days... given restrictions in playback, they can't zoom in during fast forward); as such, they weren't interested in going farther.

*QUESTION*:

It seems like there might be some way to build a list of candidate time slots in the video, where this 3% area drastically changed from normal for a given time-frame... let's say at least 20-seconds.

TBH, the bracket is only $30; however, since our old-crusty security guy swore it couldn't be automated, I took it as a point of curiosity to see whether that's true. Obviously there are commercial solutions... I'm looking for "free" in linux.

The file would be about 6GB. Is there a linux CLI solution to this problem? I just need to reduce the times we look at to something manageable. Even if I had to use a python image analytics library like [OpenCV-python](http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_video/py_table_of_contents_video/py_table_of_contents_video.html), that's a possibility but I'm hoping to (ab)use something like [`ffmpeg`](https://www.ffmpeg.org/) for this purpose. If there isn't such a tool, which [Open-CV](http://docs.opencv.org/trunk/modules/video/doc/video.html) function would be best for this job?

**Tags:** video, post-production, filter


---

## 1 answers

### Answer by username_1 on 2015-01-28. Score: 4 | Accepted answer

FFMPEG doesn't really have the tools to do motion detection out of the box. You can certainly do the cropping using the crop filter: -vf crop=w:h:x:y where w:h is the size of your cropped area and x:y its coordinates in the original image. So your ffmpeg script might look like:
ffmpeg -i input.avi -c:v libx264 -crf 20 -vf crop=123:45:67:89 output.mp4

Then you could find a frame of the output that contains no movement, export it to a still image, invert it and add it back to the video using overlay so that only parts of frames that are different would show up. Then use the blackdetect filter to find frames that are black. Then you could use some shell-fu to delete those parts of the video and finally concatenate the remainder into one clip. Whew.
…or you could use openCV. Here's a ready-rolled script that does motion detection: https://github.com/RobinDavid/Motion-detection-OpenCV

> **Comments:**
> **username_0**: when you say `-vf crop=w:h:x:y`, you're talking about [`ffmpeg` cropping](http://video.stackexchange.com/q/4563/4601), right?  When you say an "empty frame", I'm not sure how I would find that in a video file... I'm thinking the github project you mentioned might be the way to go  
> **username_1**: "empty frame" meaning a frame where nothing is happening. Yeah, use the script, unless you really want a learning excercise.  

---

