After updating the video server under debian, it was decided to remake the video surveillance system.
It was decided to leave Motion, but it became necessary to have a more human interface for viewing archived records.
Regular searches on the Internet have not yielded any acceptable results, as a result of which it was decided to create their own product.
After some hesitation, the choice fell on Rails. No religion, I just wanted to better study this framework and a great programming language. PostgreSQL is used as a DBMS.
The result of the work under the hood ...
For a start, a little more detail about the setting of motion.
Due to the fact that I wanted, if possible, to get by with pure HTML5, I had to reinstall motion manually, enabling it to write files to ogg. Fortunately, the authors of this program have implemented it, for which many thanks to them. The build and installation process is described well on the project page, so I will not paint it here, especially since it will be different for different distributions. Link to homepage
www.lavrsen.dk/foswiki/bin/view/Motion/MotionGuideInstallation .
Will focus only on setting up the product.
Since motion was originally installed from packages, after reinstalling, I did not transfer the configuration folder from / etc to / usr / local / etc.
And one more point, the motion itself is started with the help of runit, therefore in the config it is turned off daemon mode.
The alignment of forces is as follows:
1. The motion configs are in / etc / motion.
2. The video is written on a separate hard disk mounted in the / video directory, in folders with camera names.
3. Records are stored in the database that store information about the time of the event, the full path to the event file, the type of file (in my case, video).
Table structure
CREATE TABLE records
(
id serial NOT NULL,
thread integer,
filename character varying(255),
frame integer,
file_type integer,
event_timestamp timestamp without time zone,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
CONSTRAINT records_pkey PRIMARY KEY (id )
)
WITH (
OIDS=FALSE
);
ALTER TABLE records
OWNER TO motion;
-- Index: thread
-- DROP INDEX thread;
CREATE INDEX thread
ON records
USING btree
(thread );
4. For live viewing (in real time) from the cameras using the interface motion.
The main changes in the config are the following:
/etc/motion.conf
ffmpeg_video_codec ogg
')
webcontrol_port 8080
webcontrol_localhost off (if the web-interface will be launched on another server)
webcontrol_html_output on
webcontrol_authentication login: pass
sql_query insert into records (thread, filename, frame, file_type, event_timestamp, created_at, updated_at) values ('% t', '% f', '% q', '% n', '% Y-% m-% d % T ', NOW (), NOW ())
And accordingly, the settings for connecting to the database.
Next, connect the camera
thread /etc/motion/thread1.conf
thread /etc/motion/thread2.conf
...
thread /etc/motion/threadN.conf,
where N depends on the number of our cameras.
The main points in threadX.conf, where X is any number
stream_port PortNumber - this port will need to be written in the "Streaming Port" field when setting up cameras in the web-interface.
These are major changes when setting up motion. How to set the motion itself in this article will not paint.
Rails configuration is well-written in the
habrahabr.ru/post/140910 article. You may also need to install NodeJS -
github.com/joyent/node/wiki/Installing-Node.js-via-package-managerNow let's proceed directly to setting up the interface:
1. Clone using git site.
Bitbucket:
git clone
webdev4u@bitbucket.org/webdev4u/motion_web.gitGithub:
git clone
github.com/webdev4u/motion_web.git2. Rename config / settings.local.yml to config / settings.yml and enter the address of the server on which motion is running.
3. Rename config / database.yml.example to config / database.yml and enter the settings for your database there.
4. Change the db / seeds.rb data for the admin user.
5. rake db: migrate
6. rake db: seed
7. For verification, you can run rails s. The server will listen on port 3000. If everything is normal, you can work.
8. And finally, set up the task for the crown to clean the base. By default, records are stored for 21 days, but you can change this parameter in the file app / models / record.rb 12 line, but better in the lib / tasks / crontask.rake line
Record.clean_old_records
replaced by
Record.clean_old_records Required_number_days.
Then drive the team
whenever --update-crontab from under the user on whose behalf the site will run.
Screenshot of the main page:

Login page:

Live view:

Camera list:

View archive:

Add user:

Add Camera:
