Click

CCTV video recording + Home for Linux

I thought up and indulge in the creation of simple and cheap home video surveillance and video recording (spodvigla me on this article from the magazine "Hacker"). Naturally, the idea of ​​using a webcam and a home computer in this case is the most attractive.

Webcam for Linux

His choice of webcams for Linux, I stopped for Logitech Webcam C120 for several reasons: firstly, it has a picture of acceptable quality (image from the cameras of similar price range Genius I was not impressed at all), and secondly - the camera is via UVC, which means that its kernel support for Linux "out of the box" (standard support is added to the Linux kernel with version 2.6.26, Linux also earn a webcam, the driver managed GSPCA) and thirdly - this cam is only 500 rubles, and its I'm not sorry to make out of it a infrared camera (the camera "night vision") .

The process of creating a home video under Linux step by step.

Connecting the camera. In my case, everything is put yourself (and therefore chose this unit). If the camera is connected, but no pictures - it's worth checking whether the current user is added to the video group, and if necessary add it there.
By the way, test the camera will help ordinary mplayer , just enough to run it as follows:
mplayer -cache 128 -tv driver =v4l2: width = 640 : height = 480 : device = / dev / video0 -vo xv tv: //
If something goes wrong - carefully read the error log. For example you may need to specify a different output ( -vo x11 ) - they are on call mplayer-vo help

Using Motion for organizing video

As a software system for home video, I chose a program of Motion (present in the repository Debian, required for ffmpeg). You can try its analogues, such as ZoneMinder or AVReg, but since I completely Motion staged and that she comes first in the lists of many reviews of this software - I do not test and was just using her.

So, what can offer Motion wishing to gather video surveillance system at home:

  • Support for multiple cameras (I will discuss a variant with a single camera, support for additional cameras connected at the base of the config file, and their settings are described in separate files).
  • Continuous broadcast images from a webcam with sohraniniem transliruemgo flow to the media (supports multiple formats flux conservation) - in other words, it is nothing as constant video recording.
  • Tracking changes in the availability of images from the camera and start recording in case of detection of such changes - the program responds to motion and starts recording only in this case (for details on setting in motion detection discuss below).
  • Broadcast images from the camera to the network through its own small HTTP-server (prosmtor as possible to the local and the remote machine).
  • The execution of arbitrary script in a given condition (for example, when you can run traffic obnoruzhenii script e-mail alerts / sms / phone, or play the trumpet sound, etc.).

Motion works in daemon mode and is configured using a configuration file edits, located at /etc/motion/motion.conf and commented on in great detail in plain English.
Before making changes to recommend to copy configuration files in your home directory and continue to work with this copy, if your needs require otherwise:

.motion mkdir ~ /. motion
etc / motion / motion.conf ~ / .motion / sudo cp / etc / motion / motion.conf ~ /. motion /
.motion / motion.conf sudo chown user: group ~ /. motion / motion.conf

Configuring Motion - Edit the motion.conf

Dwell in detail on some of the settings, which, in my opinion, may require revision:

  • Running in daemon mode
    # Start in daemon (background) mode and release terminal (default: off)
    daemon on
  • A device for capturing video - if a camera - leave as is, or change to video1 ... videoN as needed
    # Videodevice to be used for capturing (default / dev/video0)
    # For FreeBSD default is / dev/bktr0
    videodevice /dev/video0
  • What is the input for video use. In the case of USB-camera left as is.
    # The video input to be used (default: 8)
    # Should normally be set to 0 or 1 for video / TV cards, and 8 for USB cameras
    input 8
  • Video resolution issued by the camera - edited to match the characteristics of his camera
    # Image width (pixels). Valid range: Camera dependent, default: 352
    width 640
    # Image height (pixels). Valid range: Camera dependent, default: 288
    height 480
  • The number of frames per second - again in accordance with the characteristics of the camera (for example, some cameras allow you to shoot high resolution, but lower frame rate or vice versa). For PAL standard value - 25 frames / sec.
    # Maximum number of frames to be captured per second.
    # Valid range: 2-100. Default: 100 (almost no limit).
    framerate 30
  • After how many seconds of the movement record will be restarted (and overwritten file).
    gap 60
  • Limiting the size of the file with a record (in seconds). In the case of non-zero value after exceeding the limit will be created a new file.
    # Maximum length in seconds of an mpeg movie
    # When value is exceeded a new mpeg file is created. (Default: 0 = infinite)
    max_mpeg_time 0
  • How much time (in seconds) to write to a file. After the limit is exceeded, a new file.
    # The file rollover mode of the timelapse video
    # Valid values: hourly (hourly), daily (daily, default), weekly-sunday (weekly, beginning the week of Sun), weekly-monday (similar to the start on Mon), monthly (monthly), manual (hand).
    ffmpeg_timelapse_mode hourly
  • Options for saving the screenshot to the motion - all in a row (on), no (off), first (first), the best (best) or with the movement toward the center of the image (center).
    output_normal best
  • Saving stream from the camera as a video file.
    # Use ffmpeg to encode mpeg movies in realtime (default: off)
    ffmpeg_cap_new on
  • The choice of codec, which will be processed stored video (supported codecs listed in detail in the config). Selected codec must be installed in the system, otherwise you start Motion will generate an error.
    ffmpeg_video_codec mpeg4
  • The path to the directory in which to store the footage.
    target_dir /home/user/camera_video
  • The port number on which to run built-in http-server Motion - if necessary, to prescribe any free port.
    # The mini-http server listens to this port for requests (default: 0 = disabled)
    webcam_port 8081
  • Percentage of quality compressed in jpeg images from a camera, which will be displayed in your browser.
    # Quality of the jpeg images produced (default: 50)
    webcam_quality 90
  • Refresh rate video in your browser (frames per second) in the absence of the registered traffic - unless you plan to view the image from the camera periodically, you can disable. When motion is detected refresh rate is equal to the parameter webcam_maxrate.
    # Output frames at 1 fps when no motion is detected and increase to the
    # Rate given by webcam_maxrate when motion is detected (default: off)
    webcam_motion 2
  • Refresh rate video in your browser in case of motion detection software.
    # Maximum framerate for webcam streams (default: 1)
    webcam_maxrate 10
  • Allow (off) or disable (on) access to view cameras from remote machines.
    # Restrict webcam connections to localhost only (default: on)
    webcam_localhost on

The other settings should be changed as needed (in great detail settings Motion described in the article, the link that was given at the beginning of this note), the above in my opinion is enough for normal operation with the Motion. The first run can be done with a key-n, so the program will not run in daemon mode - it will provide diagnostic messages directly to the console.

To test if the program can be accessed with a web browser to the address http://localhost:8081 and enjoy the result of their labors :) We should also note that the Web-based interface allows configuration of Motion (useful when several cells), which you need to modify the section HTTP Based Control configuration file.

In conclusion, I will give a link to motion.conf , which I turned in the result. And in another article about creating a home video under Linux, I want to talk about how to make the webcam camera "night vision" . See you there!

More on similar topics:

Category Filed under: Linux , Gadgets | Tag Tags: , , , , , | Comments No Comments

Leave a Reply