motion – Motion Detection Software On Ubuntu


I had tried (and failed) before to setup a motion detection camera using Linux (Ubuntu) and a USB webcam. The 2 most popular choices seemed to be zoneminder or motion.


sudo apt-get install motion

To test motion use the command:
sudo motion
The default port is 8081 so open a browser on the machine with motion installed and enter the address http://localhost:8081

Run As User

Initially to test motion use the following command in the terminal:
sudo motion
The default configuration should work but it’s also a good way to test the output and settings before enabling daemon mode. Running it in the terminal gives all the logging information where as running in daemon mode doesn’t seen to have logging.

Use Ctrl+C to exit motion.

This could also be used full time by using screen (assuming screen is already installed):
sudo motion

Run As a Daemon

I had instability issues running motion in daemon mode so I used screen and ran it in commandline.

To run motion in the background or on startup edit the file /etc/default/motion and change start_motion_daemon=no to yes.

Next enable daemon mode in /etc/motion/motion.conf daemon on

Motion can then be started and stopped using the service commands:
sudo service motion start
sudo service motion stop


All the settings reside in /etc/motion/motion.conf The thread1.conf, thread2.conf etc are used when more than one camera is being used to set each camera’s individual settings. This goes beyond the scope of this article.

I will use x|y for the values where x is the default and y is my setting below.

width 352|640 = number of pixels wide.
height 288|480 = number of pixels high.
framerate 2|30 = maximum frames per second the camera will support.
pre_capture 0|5 = Number of images to save before an event was triggered.
post_capture 0|5 = Number of images to save when the event finishes.
quality 75|100 = Image quality by percentage. Higher the number, better the image quality (less compression).
ffmpeg_cap_new off|on = Records a video to file in MPEG format. To turn on requires ffmpeg_timelapse to be set (see below).
ffmpeg_timelapse 0|3 = 0 value means its not recording, 1 is real time recording. Any higher value than 1 it will record a time lapse video.
ffmpeg_bps 400000|500000 = bit rate of the video recording. Higher the better but also more resource intensive.
ffmpeg_video_codec swf|mpeg4 = Defaults to flash video format but I prefer MPEG Layer 4.
snapshot_interval 0|900 = Set the time how often it will take a picture. By default this is called latestsnap.jpg.
locate off|on = if on it will draw a square of where the movement was detected.
target_dir = set this to where the pictures and movies are saved (more details below).
snapshot_filename %v-%Y%m%d%H%M%S-snapshot|%Y%m%d%H%M%S-%v-snapshot = Moved the prefix %v (some number not quite figured out) so that the pictures can be ordered in date time order.
jpeg_filename %v-%Y%m%d%H%M%S-%q|%Y%m%d%H%M%S-%v-%q = Same as above.
movie_filename %v-%Y%m%d%H%M%S|%Y%m%d%H%M%S-%v = Same as above.
webcam_quality 50|100
webcam_maxrate 1|1 = The rate at which the image refreshes when viewed from a webpage. I did not make a change to this value but I found 30 FPS (max my camera will do) crashed the browser when left on the page for too long so consider lowering this value if it happens.
webcam_localhost on|off = turn this off to view live feed from a different computer (including Internet if network allows so be careful!)

File Location

I used Dropbox to store the snapshots and timelapse video as a way to view events from other computers. Whilst this works it should only be used as a temporary solution because:


Unfortunately the daemon wasn’t stable enough for me but others have reported success. I now run it through screen in a terminal window and it works very well.

The next step is to manage the recordings and maybe do some post processing to filter out unlikely events.

Setup a webcam security system with Ubuntu Linux and Motion

Setting up Motion with FTP and Email! support

About Danny

I.T software professional always studying and applying the knowledge gained and one way of doing this is to blog. Danny also has participates in a part time project called Energy@Home [] for monitoring energy usage on a premise. Dedicated to I.T since studying pure Information Technology since the age of 16, Danny Tsang working in the field that he has aimed for since leaving school. View all posts by Danny → This entry was posted in Linux, Software and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply