Motion

is a software package able to use cameras to detect motion.

It supports different camera types:
 * Network cameras via RTSP, RTMP and HTTP
 * V4L2 webcams
 * Video capture cards
 * Existing movie files

Once detects motion it can write picture files and/or movie files to a storage location.

Kernel
The linux kernel needs to be configured for V4L in case such cameras are being used.

Emerge
is in portage, emerge it as per normal:

OpenRC conf.d
As of motion-4.3.1 there are new configuration parameters in :

Motion application configuration files
After emerging sample configuration files are placed in :

These configuration files are well documented, and can be used for creating the actual configuration files. The actual configuration files do not have "-dist" in their name. Note that simple renaming the files will not yield a working configuration. It may be better to create the configuration files from scratch, taking note of the individual settings needed for camera(s), and desired output options.

The structure of the configuration files is as follows:


 * : contains the general and daemon settings.
 * contains the settings per camera.

looks for the configuration files in the following order:


 * in the current directory
 * in
 * in

An example working set of configuration files for two cameras, one laptop webcam and one IP-camera is as follows.

General settings:

First camera, a webcam using V4L:

Second camera, an IP camera:

Make sure to update credentials and the URL. Please refer to 's documentation for further details for the configuration.

Optimization
can be quite taxing on your hardware, especially if it is continuously receiving a stream of pictures, which it might need to process into video files, stream to client devices, and store somewhere on disk. It might be worth spending some time on optimization.

Video codec
supports different codecs. Some considerations for the choice of codec might be:
 * CPU load for the encoding: hardware acceleration might be configured to ease the load
 * Amount of disk space needed for storing the videos: some codecs are more efficient then others
 * Codec support on the devices that are used to view the video files: not all client devices support all codecs

Hardware acceleration
Various CPUs and GPUs have support for offloading the task of encoding videos. A choice needs to be made, depending on the video codec, the type of CPU and GPU available.

Follow the instructions at GCC_optimization to at least set the proper march and the CPU_FLAGS. This will configure the system to use specific instructions that can optimize video encoding, e.g. instructions like [//en.wikipedia.org/wiki/SSSE3 SSSE3], [//en.wikipedia.org/wiki/SSE4#SSE4.2 SSE4.2], [//en.wikipedia.org/wiki/Advanced_Vector_Extensions AVX], [//en.wikipedia.org/wiki/FMA_instruction_set FMA3], [//en.wikipedia.org/wiki/Bit_Manipulation_Instruction_Sets#BMI2 BMI2], and [//en.wikipedia.org/wiki/Advanced_Vector_Extensions#AVX2 AVX2].

Evaluate the following articles to establish the support for hardware acceleration:
 * Intel CPUs:
 * [//en.wikipedia.org/wiki/Intel_Quick_Sync_Video#Hardware_decoding_and_encoding Intel Quick Sync Video] hardware support
 * AMD GPUs:
 * AMDGPU
 * [//en.wikipedia.org/wiki/Video_Coding_Engine AMD's Video Coding Engine]
 * [//en.wikipedia.org/wiki/Video_Core_Next AMD's Video Core Next]
 * NVIDIA GPUs:
 * [//developer.nvidia.com/video-encode-decode-gpu-support-matrix Nvidia's encode/decode support matrix]

uses for video encoding. Check [//trac.ffmpeg.org/wiki/HWAccelIntro ffmpeg's hardware accellation] for support.

Ffmpeg USE flags to consider include:
 * opencl
 * vaapi
 * vdpau

Support for Intel's libmfx is currently lacking in Gentoo, see for details. Note that hardware acceleration might require additional linux kernel configuration.

Motion tuning parameters
supports various configuration parameters which can be used for tuning purposes. These include:
 * framerate
 * movie_quality
 * movie_passthrough

Play around with it to establish the optimum between quality and resource utilization

Commandline
can be simply run from the commandline for testing purposes:

Once runs, it provides a webpage at. The webpage will show the live stream of the cameras, and allows for some basic control.

OpenRC
can also run as a system daemon, once satisfied with the configuration:

Security
Whenever one uses cameras it should be done in a safe manner:
 * avoid to aim cameras at privacy sensitive areas,
 * use specific usernames or passwords on IP cameras; do not use default ones.

version 4.2 features a few security enhancements:
 * webcontrol_tls
 * webcontrol_auth_method
 * webcontrol_authentication
 * tream_tls
 * stream_auth_method
 * stream_authentication.

Make sure to implement these features once version 4.2 is available. Monitor for updates. Until then it might be better to prevent  from being controlled by, and streaming to, other computers. Add the following to the configuration files:
 * webcontrol_localhost on
 * stream_localhost on

Housekeeping
Be aware that can produce many large files each day, which can take up a lot of storage. It might be a good idea to purge older files. Consider running a purging command like:

from a daily cron job, which would remove files older then time from a folder .