UPDATE: This method is now implemented in to the IpCamera binding and is easy to use, just follow the bindings documentation for more information.
I have had good results doing this, however as none of my cameras need this I am not interested in testing this for months on end hence this thread will hopefully collect the results from users that are keen to do this. Wanted to document it and give a thread for people to post what works for them and also why you don’t want to do this. You can easily do this via a script (plenty of scripts using this method are on GitHub for ideas) as Openhab allows a simple REST call to move any control inside of Openhab from your script very easily…
Do I recommend this?
Short answer is no I don’t. Slightly longer answer, I recommend you buy a better camera that has motion ability available by an API or at least Onvif as that makes a camera that costs slightly more be far better “value”. See the IpCamera binding and what cameras have better support in that binding if you have not purchased a camera yet. If you already own a camera and you most likely have Openhab sitting at 2% CPU usage then why not try it.
How much CPU?
How much CPU this uses depends on the FPS of the stream and how many pixels the camera has. It is a good idea to not bother trying unless your stream is 1080p maximum and you reduce the framerate to 10fps. Trying to do this on a 4k camera with 30 FPS is going to need a serious CPU but with 1080p and 10fps I found a cpu load of 25% average on my Odriod C2 ARM processor based system. My newer Odroid N2+ can do 1080p and 25fps with only 8% extra load on the system. An additional power draw of 1-2 watts is nothing to worry about.
The Alarm is lagging behind real time
This is a clue you have not read the above question and answer as big lags occur when your CPU can not keep up to real time. When working correctly it is around 1-2 seconds behind realtime due to processing a RTSP stream. FFmpeg will tell you when you are at or above speed=1.0x and if your CPU can not keep up the longer you have the stream running, the longer the lag gets.
Can I exclude areas that have movement?
Only watching a section of the cameras view for motion can be done with these crop filter examples. This allows it to ignore a tree that moves in the wind or people that walk past on a footpath. You may need to do this to remove a clock that ticks over on top of the video footage. I got it working fine without cropping out the clock but I did not try to optimize for day and night conditions.
https://ffmpeg.org/ffmpeg-filters.html#Examples-52
What command to use?
You can test the ffmpeg detection with this command via putty, ctrl+c closes the stream, then if you press your UP arrow the command is re-called so you can edit it with any tweaks you want to test without having to retype it each time. Also the right hand button of your mouse will PASTE the text into the terminal of putty.
ffmpeg -rtsp_transport tcp -i rtsp://user:pass@192.168.0.6:554/streamurl -vf select='gte(scene\,0.005)',metadata=print -an -f null -
Adjust the 0.005 value up and down to set how sensitive it is and this is just a good starting point to have a play. You may want to try noise reduction filters first if your camera has poor picture quality, the options are huge with ffmpeg. The results will need to be parsed by filtering how many detections occur in a set time frame and how close together. So when set right you will see more lines getting reported when you have movement.