Webcam Surveillance Monitor

We will be using a third party application called “motion” to operate the webcam. We chose the motion application because:

·         it is free,

·         easy to setup,

·         requires a small amount of CPU processing power (good for a Raspberry Pi),

·         has video streaming built in,

·         will create pictures and video files when motion is detected,

·         will trigger the PrivateEyePi alarm system when motion is detected,

·         is highly configurable.
We did not play any part in creating motion, and full credit goes to it's makers. The motion home page is located here :
So lets get started. First we will create a new directory that we will work in. At the Raspberry Pi command prompt type:


sudo mkdir /home/webcam

sudo chmod 777 /home/webcam

cd /home/webcam

sudo apt-get install motion

Once this is completed we need to configure motion for our needs. The config file is located in the /etc/motion directory and is called motion.conf.  We need to edit this file to make some configuration changes.


sudo nano /etc/motion/motion.conf

Configure motion to run in the background. Set the Daemon configuration on:
Now continue to edit file following settings. If you want to search for a setting use the ctrl-w command, type the setting you want to find and press enter.
daemon on
framerate 30
threshold 500
gap 10
max_mpeg_time 30
output_normal center
#Choose your codex of your choice, for Windows use msmpeg4
ffmpeg_video_codec msmpeg4
target_dir /home/webcam
webcam_motion on
webcam_maxrate 30
webcam_port 8085
webcam_localhost off

To quit from the nano editor press CTRL-X, followed by “Y” and ENTER to save.  Now you need to start the motion application.


sudo motion

To test that motion is working correctly check that pictures and video are being saved in the /home/webcam directory.


dir /home/webcam

You should see a listing of files with .jpg and .avi extensions. 


Next we will test that the live webcam server is working. You will need to know the ip address of your Raspberry Pi.

How to get your IP address using Linux commands

Type the following command:



/sbin/ifconfig | less


In the output created look for the Ethernet address. Something like this:

wlan0     Link encap:Ethernet  HWaddr d8:eb:97:18:16:ef

inet addr:  Bcast:  Mask:

In the above example the ipaddress is Next enter the ip address followed by the port number you configured earlier (8085) into a web browser.

Note that Internet Explorer does not support mjpeg steaming, so you will need to use Firefox, Safari, or Chrome.  For more advanced users there is a fix for the Internet Explorer shortcoming. You can use a java applet that will stream mjpeg to any java enabled browser (explained further here

If all went well you should now have a Raspberry Pi surveillance system that is accessible anywhere on your home network.


View the Webcam from the internet

In the next section you will learn how to view the surveillance over the internet. Please be sure to read the safety section before attempting this.

The next part is more advanced and will enable you to view the live webcam video stream from the internet. The ip address we used earlier in the tutorial ( is an IP address allocated by your DHCP server in the router. This address is only accessible to devices connected to the router and not by anyone on the internet. If you want to access the live webcam video from the internet then you need to open up the port we assigned to motion, port 8085. To do this requires a configuration to your router. Getting access to your router requires you know how to do this, and may require that you contact your Internet Service Provider (ISP) or Cable Company.

You will need to know the IP address of your router. Many routers use the or address as a default. Type your router ip address into a browser. This will take you to a login page where you need to login into the router with the username and password for the router. I cannot provide you with detailed instructions for this part as there are many different routers each with their own configuration applications. Look for “port range forwarding” or “port forwarding” settings, sometimes under a “Gaming” menu (Gamers need to open port to be able to participate in peer-to-peer games over the internet).

Add a new entry called rpi-web. FromPort=8085, ToPort=8085, IpAddress=(Raspberry Pi IP address from above).

Take note of the internet IP address of the router under the Gateway settings of the router. This is the address that has been assigned to you by your ISP and you will use this address to access from the internet.

Now type http://InternetIPAddress:8085 into a browser connected to the internet. This should take you to your webcam video stream.

Security Considerations

Your webcam is now accessible to anyone the internet who knows your internet address and port number. It would be a good idea to install a firewall on your Raspberry Pi to protect your computer from port scanners and other malicious programs. A firewall is basically a set of rules that limits or blocks incoming or outgoing web requests. One more thing you may want to protect against is internet users attempting to access your SSH account by trying a dictionary attack against your password. There is a handy utility called Fail2Ban that monitors your log files for failed login attempts and temporarily blocks offending users. Detailed instruction on these precautions is beyond the scope of this tutorial.