This article provides step-by-step instructions to make Raspberry Pi a webcam server where we can stream live video over a local network using python scripts and some necessary packages. A software package used in this tutorial is Motion, which is open source software with several configuration options that can be changed according to our needs. Here the settings must be made so that you can create a remote webcam for your Raspberry Pi so that you can view it from any computer on the local network.
Prerequisites and equipment:
You will need the following:
-
A Raspberry Pi Model B or higher.
-
A USB WiFi adapter (Edimax – 802.11b/g/n wireless nano USB adapter is used here).
-
A USB webcam with USB microphone/microphone (Logitech USB Webcam is used here).
-
An SD card updated with the Raspbian operating system (here's a guide if you need it)
-
Access to Raspberry via keyboard and monitor or remotely.
Make sure you are up to date:
To check for updates and install them, type the following command:
sudo apt-get update
Step 1: Installing the Movement.
Now we need to install the Motion package using command line, the following command can be used
sudo apt-get install move

Fig. 2: Installing the Motion package for Raspberry Pi
This will take a few minutes to download and install. Just type “y” to proceed with the installation as some support packages will be installed during the installation process.
Note: If you are going to use the Raspberry Pi camera module, since the current version of motion does not yet support the Raspberry Pi camera module, we need to download and install a special build that supports this camera module using these commands.
cd/tmp
sudo apt-get install -y libjpeg62 libjpeg62-dev libavformat53 libavformat-dev libavcodec53 libavcodec-dev libavutil51 libavutil-dev libc6-dev zlib1g-dev libmysqlclient18 libmysqlclient-dev libpq5 libpq-dev
Step 2: Configure the software.
After installing the package, the next step is to edit some of the configuration files so that the motion service starts working and is available on the local network.
The first thing we need to edit is the motion.conf file. Enter the command below
sudo nano /etc/motion/motion.conf
This is a rather large conf file, but the points you need to edit are:

Fig. 3: Configuring Motion software for Raspberry Pi
DAEMON = OFF (switch to ON)

Fig. 4: Editing the motion configuration file
Webcam_localhost = ON (Toggle to OFF)
Next we need to enable the Daemon (service):
sudo nano /etc/default/motion

Figure 5: Command to activate the Daemon service for Raspberry Pi
start_motion_daemon = no (change to yes)
Step 3: Start the webcam server.

Figure 6: Start the webcam server for Raspberry Pi
Make sure your webcam is connected to the Raspberry Pi's USB port and start the service:
start of sudo service movement
If you want to stop the service, use the command:
sudo service movement stop
To restart the service, use the command:
sudo service movement restart
With the service started you can now open a web page on your normal computer and by accessing the Raspberry Pi IP on port 8081 (in the address bar) you should be able to view your webcam.