2017-12-27

How to make my own recording system for the ip camera

My camera is Dahua IPC-HDW5231R-Z. Its firmware is 2.460.0000.7.R(Build Date: 2017-03-06).

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.

I thought another idea. Recording is segmented into a series of small chunks like N seconds videos. When an event message is arrived, useless videos are removed and the usefuls are stored. Motion detection of the cam is not reliable. So 24/7 continuous recording should be made. The motion detection messages are logged because they are helpful.

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.

So a process to do segmented recording should have max running time. And the scheduler like cron repeats the process.
http://archive.is/1z3pM

Still, this way has unrecorded-time problem as I mentioned above. So two different recording processes should have intentional overlap duration.

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

No comments:

Post a Comment