The Registrar for Bash for cameras with rtsp

Hello world!

Since the child is already at that age when he goes to school and comes from my own, has broken training schedule, and began the task of monitoring how he does the lessons, how much time does piano and the other tasks of parenting.

But not a lot of money to buy some specialized solutions, so they decided to scrape the piles of stuff in the server and with permission to drag home IP camera Xblitz iSee P2P WiFi IP.

image

Camera Xblitz iSee P2P WiFi IP

The camera was claimed to support ONVIF, which automatically suggested the idea that we need to set ZoneMinder to control the device through it.

Installed it, but as it turned out, this camera is under any settings it would not work with him.
In the web interface of the camera it turned out that the manufacturer of the camera to the branding for the Polish market is the Chinese manufacturer netcam360.

the

Web camera interface


image

After the determination of the manufacturer, via a search engine, it turned out that not only I have problems with the above format. And not only I failed to configure to work with the specified Protocol. Apparently, the inclusion of ONVIF interface is nothing but a joke from the programmers from China.

the

Enable ONVIF interface


image

It was decided that the capture will be via RTSP. Fortunately, this method worked.
But, as I became interested in writing a service in systemd, determined not to make a simple bash script to capture the stream, and such a service.

As it turned out, the writing service is very simple procedure. Here is the code simple service called "camera@.service" which is placed in /etc/systemd/system

the

Service "camera"


the
[Unit]
Description=Camera Service on %I
After=network.target

[Service]
Type=simple
KillSignal=HUP
User=camera
SyslogIdentifier=camera_%i
ExecStart=/bin/bash -a-c '</dev/tcp/%i/10554 && source /etc/camera.conf && mkdir -p /home/camera/%i && cd /home/cam
era/%i && exec /usr/bin/openRTSP -D 5-F $DATE -K -4 -P 3600 -l-b 200000 rtsp://%i:10554/TCP/av0_0'
Restart=always
RestartSec=10
#Restart=on-failure

[Install]
WantedBy=multi-user.target

As you can see, the service runs the command "systemctl start camera@IP-address".
In /etc/camera.conf with just one line, it was done in order to conform to the canons Linux service

the

Content configuration file


the
DATE=$(date "+%Y_%m_%d_%H_%M_%S")

For convenience ordered in /etc/hosts on that IP name is "eye01".
It is assumed that the cameras in the future, maybe three.

It remains only to add a cron to remove stale files as one hour record is a file of about 1.5 GB.

the
find /home/camera/eye01 -mtime +2-delete

And you can safely monitor.

But in a few days I found that the camera sometimes stops responding and video is choppy.

I had to schedule it in the cron check in the camera script, informing about this in the slack and restart the camera. It was empirically found that it may hang once in 10-12 hours. Therefore, the scheduler checks whether the camera writes every half hour. Loss half an hour of recording for me is not critical.

the

the test script with the camera


the
#!/bin/bash -e
exec 1> >(logger -s-t "$(basename $0) $1") 2>&1
SIZE1=$(du-sb /home/camera/$1 | cut-f1)
sleep 5
SIZE2=$(du-sb /home/camera/$1 | cut-f1)

if [ $SIZE1 -eq $SIZE2 ]
then
echo "Size of $1 is not increasing, probably not recording"
if [ ! -f /tmp/$1 ]
then
touch /tmp/$1
/usr/local/bin/slackcat -n beholder "Size of $1 is not increasing, probably not recording. Rebooting."
/usr/local/bin/reboot_camera.sh $1
fi
exit 1
else
echo "Size of $1 is increasing, probably recording"
if [ -f /tmp/$1 ]
then
rm-f /tmp/$1
/usr/local/bin/slackcat -n beholder "Size of $1 is increasing, probably recording"
fi
exit 0
fi

the

Script restart camera


the
#!/bin/bash
exec 1> >(logger -s-t "$(basename $0) $1") 2>&1
if [ "$1" == "eye01" ]; then
curl "http://$1/reboot.cgi?loginuse=admin&loginpas=PASSWORD"
elif [ "$1" == "eye02" ]; then
curl "http://$1/reboot.cgi?loginuse=admin&loginpas=PASSWORD"
elif [ "$1" == "eye03" ]; then
curl "http://$1/reboot.cgi?loginuse=admin&loginpas=PASSWORD"
else
echo "Not recognized camera $1"
exit 1

Actually all. I hope someone else my solution will help you quickly and inexpensively organize the surveillance.

I would be grateful for any criticism and suggestions for improvement.

the

References and used publications


Repository
Integrate Slack with slackcat
How to write a systemd service

Thank you for your attention.
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

ODBC Firebird, Postgresql, executing queries in Powershell

Installation LivestreetCMS on MODX Revolution package 10 clicks

The Ministry of communications wants to ban phones without GLONASS