My goal was to record every suspected situation with my three Foscam camera’s and also integrate it with OpenHAB. After a lot of very, very, very frustrating hours experimenting with video recording software like ZoneMinder, Shinobi, BlueIris, etc. I experienced that software like these are too heavy, too much overhead for such a simple task. Everything went slow, heavy, complicated and so on. I tried software motion detection but this takes hour to configure and so on. The final solution is very fast and solved with OpenHAB without a camara binding.
My slogan is: Keep is simple…!
- Software motion detection? Too complicated and generates so much cpu load. Just some relaible PIR sensors in the neighborhood of the camera’s.
- Camera database with fancy tools? Not nesessary, just drop every cameyra recording as a mp4 file in a folder on my server with the name format: YYYYMMDD_HHMMSS_CameraName. If nescessary, you can query the standard OpenHAB persist binding like MySQL
My configuration:
- OpenHAB on linux Ubuntu server 18.x.x. (on a small dedicated Intel NUC computer)
- 3 Foscam camera’s IP9900
How does it work? Quite simple! The only small tool you need to have is ’ ffmpeg’. This tool is able to capture a live stream from any camera and save it to a file.
- The PIR motion detector detects … wel motion;
- a rule is triggerd after the motion detection;
- this rule fires a small linux script which calls ffmpeg
- ffmpeg stores the live camera stream to disk for a specified time.
That’s all. The only hassle was file permissions on linux. A hassle because I’m a linux newbee… After all, everything is working fine now.
rule "Camera recording Oprit"
when
Item CameraOprit changed from OFF to ON
then
{
if(TimerCameraOprit === null)
{
val result = executeCommandLine("/etc/openhab2/scripts/record_oprit.sh 60",500)
logInfo("record_oprit.sh",result)
TimerCameraOprit = createTimer(now.plusMinutes(1))
[|
CameraOprit.sendCommand(OFF)
TimerCameraOprit = null
]
}
}
end
The ExecuteCommandLine calls the linux script with ffmpeg.
#!/bin/bash
CameraName=Oprit
InputStream=rtsp://admin:password@ipaddress:88/videoMain
OutputDirectory=/mnt/data/Camera/
OutputFile=$(date "+%Y%m%d")_$(date+"%H%M%S")_$CameraName.mp4
ffmpeg -i $InputStream -t $1 -b 900k -vcodec copy -r 25 $OutputDirectory$OutputFile >$OutputDirectory$CameraName.log 2>&1 </dev/null
# -i : input file url
# -t : duration time
# > Redirect stdout to logfile
# 2>&1 Redirect stderr to stdout (so it ends up in the logfile and not in the terminal)
# < /dev/null Redirect stdin (which ffmpeg thinks it needs) to /dev/null (which gives an empty stream).
That’s all.