How to Set Up Motion Detection Webcam in Ubuntu

Don’t you hate it when people use your computer without your permission? Worst still, your laptop is stolen and you have no idea who stole it. If your laptop comes with a webcam, you can easily set up motion detection software to find out who is using your computer when you are not around. If you have a spare computer at home, you can also use it as a surveillance camera. We have shown you how to do so in Windows, and this article will show you how to set up a motion detection webcam in Ubuntu.

The software that we are using is Motion. This is one useful tool that can monitor the video signal from a webcam and take screenshots when it detects a motion (i.e. when a significant part of the picture has changed). While we are dealing with Ubuntu in this article, Motion will work for most Linux distro as well.

Motion is included in the Ubuntu repository, so you can install it by clicking here, via the Ubuntu Software Center, or by simply typing the following command in the terminal:

Before we start configuring Motion, we need to copy the config file to our Home folder so that the master copy won’t be affected. Open a terminal and copy the configuration file to your Home folder.

Note: The above commands will create a hidden folder “.motion” in your Home directory.

Once you have done the copying, you can open the file for editing.

There are plenty of options that you can customize in the config file, but there are only a few things that we are interested in. Scroll down the list to find the following settings:

Daemon – Changing this to “on” will make it run in daemon mode. Applications in daemon mode will run in the background and start automatically when the computer starts. The default option is “off” where you need to start the application manually in terminal.

motion-start-in-daemon-mode

Width – This is the width of the images taken by the webcam. The default is 320, but you can set your own value here. Note that the width is limited by your webcam’s capability. My webcam is only capable of taking images up to 350px, so a value of 320 works fine for me.

Height – The height of the images taken by the webcam. Similarly, it is limited by your webcam’s capability.

framerate – how often you want the image to be captured per second. The default is 2 (2 frames/images taken per second). The higher value you set, the more computing resources it will require.

Motion detection thresold – the number of changed pixels in an image before it is captured. The default is 1500. If you want to make it more sensitive, set it to a lower value.

motion-detection-threshold

output_normal – This will determine whether it will save the motion to images. The default option is “on,” which means pictures will be saved as long as motion is detected. You can set it to “first,” “best,” “center” to get it to save only a limited number of images. This will prevent your folder from having an overwhelming number of images. If you just need the video streaming mode, you can set it to “off” to prevent it from saving any pictures.

motion-output-normal

target_dir – This is the directory where the images are saved. If you have installed Dropbox (or any other cloud storage service), you can set the target directory to be within your Dropbox folder so you can view the images from another location.

Note: There are plenty of other options that you can config, but we won’t be covering them here.

Once you are done with the configuration, press “Ctrl + o” to save the changes and “Ctrl + x” to exit.

In the terminal, type:

This will start the motion server. If everything goes well, you will start seeing pictures showing up in the target directory.

motion-pictures-in-target-directory

There is also a swf live streaming video that you can open in your media player. If you are accessing from a remote location, you can access the IP address of your computer (with port 8081) to view the video (or http://localhost:8081 in your local computer). The control center is accessible at port 8080.

motion-video-access-from-browser

As I mentioned earlier, the best way is to save the images into your Dropbox folder so you can access it anywhere you want. However, if you prefer to have the images uploaded to your own file server (via FTP), you can use the command wput to upload the images.

In the config file, scroll down the list till you see a field “on_picture_save value“. Change it to:

where the “user”, “password” and “server” are details that you need to fill in.

If you like Motion to autostart every time you boot up your computer, all you have to do is to add an entry to the Startup Application.

motion-in-startup-application

While it may seems like a complicated task, setting up a motion detection webcam in Ubuntu is actually a very easy job. What other method do you use to set up your webcam as a surveillance camera? Let us know in the comments.

Image credit: surveillance cameras

10 comments

  1. Dlink 930L wifi cam. It used to mail them to me until Google thought I was spamming. It now FTPs them to my Raspberry Pi XBMC photo folder where I collect them up and ffmpeg them together into an AVI file at 6fps.

  2. Does the motion.conf file that is copied locally to the hidden .motion folder and then edited become used as a default over the master just by creating it?

    • Yes. The Motion app will always check for the local copy of motion.conf
      first. If it can’t find the local copy, then it will default back to the
      master copy.

    • That is cool. It will definitely make the administration a much easier
      task. I will check it out.

  3. Ok, I’m using Motion, I have setup a netcam. Is it possible to save the video to a NAS and the pictures to the dropbox folder?

  4. If everything goes well …
    And there it is!
    It does NOT go well – but I guess that’s normal.
    Here’s what I get:

    root@bbb:~# motion
    [0] Processing thread 0 – config file /etc/motion/motion.conf
    [0] Motion 3.2.12 Started
    [0] ffmpeg LIBAVCODEC_BUILD 3482368 LIBAVFORMAT_BUILD 3478785
    [0] Thread 1 is from /etc/motion/motion.conf
    [1] Thread 1 started
    [0] motion-httpd/3.2.12 running, accepting connections
    [0] motion-httpd: waiting for data on port TCP 8080
    [1] cap.driver: “uvcvideo”
    [1] cap.card: “Microsoft® LifeCam Cinema(TM)”
    [1] cap.bus_info: “usb-musb-hdrc.1.auto-1”
    [1] cap.capabilities=0x84000001
    [1] – VIDEO_CAPTURE
    [1] – STREAMING
    [1] Config palette index 8 (YU12) doesn’t work.
    [1] Supported palettes:
    [1] 0: YUYV (YUV 4:2:2 (YUYV))
    [1] 1: MJPG (MJPEG)
    [1] Selected palette YUYV
    [1] Test palette YUYV (1280×720)
    [1] Using palette YUYV (1280×720) bytesperlines 2560 sizeimage 1843200 colorspace 00000008
    [1] found control 0x00980900, “Brightness”, range 30,255
    [1] “Brightness”, default 133, current 207
    [1] found control 0x00980901, “Contrast”, range 0,10
    [1] “Contrast”, default 5, current 5
    [1] found control 0x00980902, “Saturation”, range 0,200
    [1] “Saturation”, default 83, current 83
    [1] mmap information:
    [1] frames=4
    [1] 0 length=1843200
    [1] 1 length=1843200
    [1] 2 length=1843200
    [1] 3 length=1843200
    [1] Using V4L2
    [1] Resizing pre_capture buffer to 1 items
    [1] Started stream webcam server in port 8081
    [0] Thread 1 – Watchdog timeout, trying to do a graceful restart
    [0] httpd – Finishing
    [0] httpd Closing
    [0] httpd thread exit
    [0] Thread 1 – Watchdog timeout, did NOT restart graceful,killing it!
    [0] Calling vid_close() from motion_cleanup
    [0] Closing video device /dev/video0
    Segmentation fault

    No images, no diagnostics, no troubleshooting guide, no tips or advice and no chance that I get get it running. I know the borad (it’s a Beagle Board) works fine. I know the webcam is 100% operational and I know that this configuration works great with other Linux based applications. But with “motion”? Nope.

  5. Hello,

    What do I need to configure to keep motion from taking a whole bunch of pictures at once? It seems like it is taking pictures even when there is no motion taking place.

    Thanks!

    • you can play around with the “motion detection threshold” settings to make
      it less sensitive to changes.

Comments are closed.

Sponsored Stories