I want to make my own recording system. Because the cam is unreliable. The cam has a feature of motion detection recording. It can record maximum 5 seconds before the event occurred. I think the 5 seconds are enough. But sometimes it does not work properly. Some recordings do not have pre-event scenes totally.
The cam supports HTTP API made by Dahua. The cam pushes HTTP messages to attached clients when events occur. This can be tested by wget, easily. But I use curl instead of wget, because curl has options for TCP_KEEPINTVL and TCP_KEEPIDLE. It helps to find connection problems. I cannot find the options for wget from the manpage.
I made a simple event listener script.
https://git.io/vbQME
OK. Next step is how to record.
The first idea is the buffered(delayed) stream.
http://archive.is/KhOMD
http://archive.is/NpNOI
http://archive.is/E2Kf4
But the above solution requires high processor power on RaspberryPi B2. I want to run my own recording system on RaspberryPi. I could not improve it.
In addition, FFmpeg has long initializing time from command beginning to real recording. If the command is run when an event message is received, there can be unrecorded time before the real recording. So I have given up the above method.
You can see the followings for segmented recording with ffmpeg.
http://archive.is/PN3dN
http://archive.is/HwzCd
I wrote my own command like the following.
https://git.io/vbd91
Someone says long-time running ffmpeg can use a lot of resources of the system.
http://archive.is/9UND8
But my ffmpeg of RaspberryPi has not shown problems yet.
I use systemd timer.
Write .service file.
https://git.io/vNwFT
http://archive.is/gSDCN
Reload systemd.
systemctl --user daemon-reload
Test .service before enabling.
systemctl --user start xxx.service
See log.
journalctl --user -f
Write .timer file.
https://git.io/vNwb3
http://archive.is/2n5NC
Enable timer and then reboot.
systemctl --user enable xxx.timer
Recording file move configurations.
https://git.io/vNo8g
https://git.io/vNo82
https://git.io/vNo8a
Script to remove old records.
https://git.io/vN6MM
You should setup systemd/timer for this.
Script to synchronize time of camera.
https://git.io/vNXig
References
https://goo.gl/pFuaQp