How To: Rasperry PI Camera Module web streaming and motion detector

In this post I am going to describe how to setup a web streaming server and motion detector using a Raspberry PI with the PI Camera Module.

Before to start, I am assuming that you have already your Raspberry PI Camera Module setup and working.

Step 1: Download the software

The software that we are going to install is called Motion; this is both a motion detector and streaming software. You could potentially install Motion using the apt-get command from the terminal. However, if you want to use Motion with the Raspberry PI Camera Module you need a special version of Motion (called Motion – MMAL Camera) – see this post for more info and credits.

Therefore, what you are going to do is the following:

  1. Install motion using apt-get command so it will install all the required dependencies;
  2. Remove Motion that we have just installed leaving all the dependencies
  3. Download Motion – MMAL Camera

Ok then, let’s start..

sudo apt-get install motion

Press Y when it is requested to install all the required dependencies.  Now, we can remove Motion because, as I wrote above, we are going to use Motion – MMAL Camera.

sudo apt-get remove motion

At this point, we can download the pre-compiled version of Motion – MMAL Camera:

wget https://www.dropbox.com/s/xdfcxm5hu71s97d/motion-mmal.tar.gz

Unzip:

tar zxvf motion-mmal.tar.gz

Step 2: Config the software

As you can see, the archive contains two files: the executable and a config file.  Before running the software you need to make some changes to the config file. Make sure you are in the same directory where the config file is and open it:

sudo nano motion-mmalcam.conf

The config contains a lot of settings that you are free to modify as you like. However the most important ones are the following:

  • Image width and height: I suggest to set 640×480;
  • Framerate should be between 2 and 5 in order to not overload the Raspberry PI;
  • output_pictures: set to on if you want to generate a picture when a motion is detected;
  • ffmpeg_output_movies: set to on if you want to generate a movie when a motion is detected;
  • target_dir: set the folder where do you want to save the videos or the pictures. Example: /home/pi;
  • Under the section Live Stream Server set stream_port 8081 if you want to enable the web streaming video; moreover, set stream_localhost to off if you want to be able to access the streaming from any host other than the localhost. If you do not want the web streaming set stream_port to 0;
  •  Under the section HTTP Based Control set webcontrol_port 8082 if you want to access the Motion config from the web browsers. This is a very useful capability that allows you to change all the setting of Motion directly from the browsers. Set stream_localhost to off if you want to access the configs  from any host;

As you can see, Motion offers a lot of setting that you can play with…

Step 3: Run the software

Once you are happy with your config you can run motion using the following command:

sudo ./motion -n -c motion-mmalcam.conf

Now, if you want see the streaming open a browser (use Firefox or Opera but do not use Chrome because it does not work for me) and go to the following address:

http://IP_ADDRESS_OF_YOUR_RASPBERRYPI:8081

and you should be able to see the streaming! If you want to see the config tool go to:

http://IP_ADDRESS_OF_YOUR_RASPBERRYPI:8082

You can access to the web streaming from different devices such as iPhone, Android, etc..

That’s it. When a motion is detected Motion will generate pictures and/or videos according to what you chose in the config file.

Advertisements

One thought on “How To: Rasperry PI Camera Module web streaming and motion detector

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s