How to Use Motion to manipulate Linux surveillance cameras
Motionhttp: // www. lavrsen. dk/foswiki/bin/view/Motion/) is a small, lightweight, but powerful application software that can be used to manipulate surveillance cameras on Linux. It works with any camera that supports Linux, including all V4L network cameras, many IP cameras, and anxun Axis cameras. It also controls the translation and tilt functions. Motion allows you to record short clips and snapshots in JPEG, PPM, and MPEG formats. You can remotely view these videos in a Web browser, thanks to the built-in HTTP server of Motion. It stores image files in a directory of your choice and does not require databases. However, it supports MySQL and PostgreSQL if you really want to use one of them.
Figure 1: The Foscam webcam monitors all people entering my website.
First, let's take a look at how to use my very reliable Foscam FI8905W figure 1). With Motion, let the IP camera work, and then we will add a USB webcam.
The installation process is very easy In Debian and Debian derivative versions, because Motion is included in the standard software library. Therefore, you only need to run apt-get install motion. You also need libav-tools, which is a branch of ffmpeg. Many months ago, Debian discarded ffmpeg and replaced it with libav-tools. On other releases, refer to the download page http://www.lavrsen.dk/foswiki/bin/view/Motion/DownloadFiles) and Installation Guide http://www.lavrsen.dk/foswiki/bin/view/Motion/MotionGuideInstallation) to learn about the operation instructions. In addition, most releases still include ffmpeg.
The installer should create a motion group and user and add the motion user to the video group. If the installer does not create a motion group or user, you must create the group by yourself. You must add the video group to avoid annoying permissions.
Run motion now to see if it works:
- $ sudo motion
- [0] Processing thread 0 - config file /etc/motion/motion.conf
- [0] Motion 3.2.12 Started
- [0] ffmpeg LIBAVCODEC_BUILD 3547904 LIBAVFORMAT_BUILD 3544067
- [0] Thread 1 is from /etc/motion/motion.conf
- [1] Thread 1 started
- [0] motion-httpd/3.2.12 running, accepting connections
- [1] Failed to open video device /dev/video0: No such file or directory
- [0] motion-httpd: waiting for data on port TCP 8080
- [1] Could not fetch initial image from camera
- [1] Motion continues using width and height from config file(s)
- [1] Resizing pre_capture buffer to 1 items
- [1] Started stream webcam server in port 8081
- [...]
It will display many lines until you see the following content:
- [1] Failed to open video device /dev/video0: No such file or directory
- [1] Video signal lost - Adding grey image
Point your Web browser to localhost: 8081 and you will see a gray image:
Figure 2: If Motion cannot find the camera, a gray image is displayed.
This is good, because it indicates that Motion has been correctly installed; all you need to do is configure it. Press Ctrl + C to stop running. Then, create a. motion directory under your home directory, copy the default configuration file to this directory, and change the ownership to yours:
- ~$ mkdir .motion
- ~$ sudo cp /etc/motion/motion.conf .motion/
- ~$ sudo chown carla:carla .motion/motion.conf
You also need a directory to store the images taken by motion:
- ~$ mkdir motion-images
After you start Motion, it looks for the configuration file, first searches for it in the current directory, and then ~ /. Motion Search, and finally/etc/motion search. Now, edit your ~ /. Motion/motion. conf file-this example includes the basic configuration and lines related to my Foscam IP camera:
- # Start in daemon background) mode. If you open 2, the default value is off)
- Daemon on
- # After the motion is detected, the "normal" image is output. Default Value: on)
- [...]
- Output_normal off
- # The file that stores the process number, also known as the pid file. Default Value: Undefined ).
- Process_id_file/var/run/motion. pid
- # Image Width pixel ). Valid range: Depends on the camera. Default Value: 352 pixels
- Width 640
- # Image Height pixels ). Valid range: Depends on the camera. Default Value: 288 pixels
- The height is 480.
- # The number of frames taken per second.
- # Valid range: 2-100. The default value is 100 ).
- Framerate 7
- # If you use a web camera URL, the size will be automatically checked including http: //, ftp: //, or file :///)
- # It must be the URL that returns a single JPEG image or the original MJPEG Stream. Default: Undefined
- Netcam_url value http: // 192.168.10.250: 8080/videostream. cgi
- # The user name and password of the webcam as long as they are needed ). Default: Undefined
- # Syntax: User: Password
- Netcam_userpass admin: mypassword
- # Basic directory for storing images and short clips
- # Recommended absolute path. Default Value: current working directory)
- Target_dir/home/carla/motion-images
- # Ffmpeg: the decoder used for video compression.
- [...]
- Ffmpeg_video_codec mpeg4
You need to create a directory to store the PID file, because it indicates in motion. conf:
- $ sudo mkdir /var/run/motion
Now try again to start it:
- $ sudo motion
- [0] Processing thread 0 - config file /home/carla/.motion/motion.conf
- [0] Motion 3.2.12 Started
- [0] Motion going to daemon mode
So far, it's good. Now try localhost: 8081:
Figure 3: Motion shot my private driveway.
Well, that's my private driveway. Now, if someone comes in, an alarm will be issued, so that I can open the door and put my dog in the room. When your camera is running, you can trigger the motion detection system. When you come back, there should be some. avishort clips in the image directory. You should also find a simple Motion control panel on localhost: 8080.
IP camera settings
On Linux, how does one use ZoneMinder to control Linux surveillance cameras? Part 1) This article details how to set your camera. For more information, see camera -. In the initial setup process, you must follow the instructions of the camera vendor, such as entering the logon information and password, and setting the IP address. You can also have other options, such as frame size, motion sensitivity, and color depth or black/white.
Obtaining accurate netcam_url is sometimes troublesome. For my Foscam, I bring up the control panel in Firefox, right-click the Image 4), and then left-click View Image Info to View the Image information ). This opens the screen similar to Figure 5, which shows the precise URL of the video stream. In Chrome, use "Inspect element" to check the element ).
Figure 4: Foscam control panel in Firefox.
Figure 5: Find the URL of the video stream from the camera.
Fine-tune configuration values
You can adjust various parameters in the configuration file, it is more sensitive than image size, image quality, frame rate, motion sensitivity, higher sensitivity of the area selected in the frame, file path, HTTP server, and timestamp format. The Motion Guide: Option reference manual in alphabetical order provides details about each option. Remember to make your Motion settings consistent with those in the camera control panel, if the camera has a control panel.
USB camera
Any USB Network Camera that supports V4l can work without much effort. The video device will be/dev/video0. Only the camera is connected to your computer's directory,/dev/video0 will appear. This is a basic example of my Logitech webcam Configuration:
- videodevice /dev/video0
- width 640
- height 480
- framerate 24
- output_normal off
- ffmpeg_video_codec mpeg4
- target_dir /home/carla/motion
Remember that settings such as frame rate and frame size depend on the standard supported by your camera.
Enable Motion to run in the background
Once you get everything done, let the Motion program run as a background program, so you only need to edit/etc/default/motion, and then change start_motion_daemon = no to start_motion_daemon = yes. Now, when you turn on your computer, the Motion will automatically start. You can start and stop it like any other background program.
Control Multiple Cameras
Motion allows you to easily manage multiple cameras-you only need to allocate configuration files for each camera, named thread1.conf and thread1.conf, and so on. Common options such as daemon and file paths still require your primary motion. conf. Then, each "Thread" file is configured specifically for each camera.
Http://www.linux.com/learn/tutorials/780055-how-to-operate-linux-spycams-with-motion.