Zend certified PHP/Magento developer

How to get motion detection on FFMPEG?

I am using FFMPEG as a surveillance CCTV system, working really well for me.

Now how can I get some form of motion detection where FFMPEG will take a pic and save it to a folder?

Would I need to use some motion detection library and need to compile it with FFMPEG?

Have anyone done such thing before?

Using Arch Linux, transcoding with two GPUs from USB capture cards.

Thanks.