How to Make Raspberry Pi Webcam Server and Stream Live Video || Motion + Webcam + Raspberry Pi




About: We run YouTube channel and provide some video tutorials on electronics and programming and also videos on cool projects - how to make them, tech news and more. Subscribe to our channel. :)

Hello and welcome to Being Engineers.

If you are watching this, then you might know how to work with Raspberry Pi and you may want to make a Webcam server that can stream live video over the internet ( local network ).

This is what we will be doing today. The process will be very simple but the result is pretty impressing and useful. Before starting you have to know 2 things:

  1. How to install OS in a Raspberry pi. ( link - )
  2. How to use your Laptop Screen a monitor for Raspberry pi. ( link - )

So before we get started, we want to clarify that the process is not the only process to achieve this result. I am showing this to you because I found this most convenient to the user.

You can check out our YouTube channel -

Our Website -

We have made a video tutorial on it.So do have a look. :)

Now let's begin.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Gather the Components

In this project, you will need the following:

  • Raspberry Pi 3 Model B (Any version will work, but in PI 3 we have the provision for WiFi that can make this server wireless)
  • USB Webcam (I will use my old Logitech Webcam. Use a better camera for better results.)
  • 5V 2A Power Source (I will use my Honor 13000mah Power Bank )
  • Lan Cable ( RJ - 45 Cable )
  • Minimum 8 GB Class 10 SD Card ( I will use Sandisk 32GB class 10 SD Card )

If you haven't install the Raspbian OS on the SD card, then you will need a memory card reader and checkout our tutorial on how to install the OS in Raspberry Pi.

Step 2: Set Up Your Raspberry Pi

We assume you have the SD Card with the raspbian OS installed.

Then insert the SD Card in the Pi.

Connect the USB camera to any one of the four available USB port.

Connect the ethernet cable aka LAN cable to your Pi and connect the other end to your router.

Then Power Up the Raspberry Pi.

The next step is only for Raspberry Pi 3 users. Others. go to step 4.

Step 3: Connect Your Pi to Internet Through WiFi (only for Raspberry Pi 3 Users)

Open the desktop of Raspbian and connect to WiFi by putting the correct password.

When the raspbian is connected to the network by WiFi, then shut down the system.

Now detach the LAN cable and restart. Then you must be connected to the Internet via WiFi only.

This will help to move your webcam and the pi anywhere without the RJ-45 cable.

Step 4: Know Your Raspberry Pi IP Address

Do the following steps to view Pi IP address.

  1. Open your browser on laptop or mobile. ( laptop or mobile has to be in the same network as the pi )
  2. Go to your Router settings by typing in the default IP address of your router. ( written somewhere on your router. )
  3. Find the list of connected devices.
  4. Find the corresponding IP address of the device named raspberry.

In our case, it is

Step 5: Connect to Your Pi by SSH Connection ( PUTTY )

Open up Putty and type in the IP address of your Pi and connect.

'pi' & 'raspberry' is the default 'login as' and 'password' in Raspbian.

It is always a good practice to Update and Upgrade the system as soon as you log in.

To do it, type in the command 'sudo apt-get update' and 'sudo apt-get upgrade' one at a time.

Step 6: Install the Software and Do the Necessary Settings

Type in the command 'sudo apt-get install motion ' to start the installation.

Now to make sure that the camera is correctly detected.

Type in the command 'lsusb' and enter. You should see the name of your camera. If it is NOT there, then there is some problem in your camera or the camera is not supported in 'motion'.

After the installation is complete, type in the command ' sudo nano /etc/motion/motion.conf ' and press enter.

Then you have to change some settings in the .conf file. It might be difficult sometimes to find the settings but use 'ctrl + w' to find it. So follow the steps:

  1. Make sure 'daemon' is ON.
  2. Set 'framerate' anywhere in between 1000 to 1500.
  3. Keep 'Stream_port' to 8081.
  4. 'Stream_quality' should be 100.
  5. Change 'Stream_localhost' to OFF.
  6. Change 'webcontrol_localhost' to OFF.
  7. Set 'quality' to 100.
  8. Set 'width' & 'height' to 640 & 480.
  9. Set 'post_capture' to 5.
  10. Press ctrl + x to exit. Type y to save and enter to conform.

Again type in the command 'sudo nano /etc/default/motion ' and press enter.

Set ' start_motion_daemon ' to yes. Save and exit.

Step 7: Start the Server

First of all your have to restart the motion software. To do it type in the command 'sudo service motion restart' and press enter.

Again type in the command 'sudo motion' and press enter. Now your server is ready.

Step 8: It's DONE!!

Now open up your browser. Type in the IP address of your raspberry Pi and the port number in this way: (First there is the IP address, then a ':', then the port number). Press Enter.

Now you can see the Live feed coming from your webcam directly on your laptop or mobile or both at the same time.

Hope you have enjoyed this tutorial. If yes then please do SUBSCRIBE to our channel Being Engineers. It really helps us a lot on seeing your support and interest towards our channel and don't forget to share :)

Channel link -


5 People Made This Project!


  • Indoor Lighting Contest

    Indoor Lighting Contest
  • Make It Fly Challenge

    Make It Fly Challenge
  • Growing Beyond Earth Maker Contest

    Growing Beyond Earth Maker Contest

41 Discussions


1 year ago

I am having issue with the port forwarding. I created an exception for the pi in my router but it still says "ERR_INVALID_HTTP_RESPONSE" every time I try to see my feed. Anyone else have this issue? Thank you.

1 reply

4 months ago

iam trying to implement task GUi and i have done video capture using ffmpeg and capturing image using fswebcam. for stop and pause the videos is there any commands for that or ??
NOTE: iam interfacing webcam.
your help will be appreciated!


6 months ago

Is there a way to watch the video outside the wifi?


7 months ago

The same problem. Low fps. BUT!!!
"stream_maxrate 1" I was changed to 24. So no freezes absolutely, but cpu loaded over 60%. That`s why i changed this value to 6. It`s enough for me)))
p.s. sorry for my eng, but this method really works)
p.p.s. I used this logitech cam.
& hello from cold Russia :-)


8 months ago

after i entered the IP address of my rsp 3 with port name it shows me the grey scale with "unable to open device". pls help me to fix this problem.......


Question 1 year ago


Motion doesn't work from outside of the private network (internet)

2 answers

Answer 9 months ago

You need to open the port you are using on your firewall. Check your router's documentation on how to implement port forwarding. You'll also want to have a fixed IP, which you probably don't have now. Rather than paying your internet provider to give you one, you can use a free dynamic DNS service like


Reply 9 months ago

Thank you for answer me.
I think there is a problem with motion, I use now mjpg_streamer and no-ip and that is work great.


Question 11 months ago on Step 7

I tried this three times and I keep getting the same exact results. Everything is configured as you wrote it and my USB cam shows under 'lsusb'. Where am I going wrong ? I have the 3b+ model so I tried this with ethernet and with wifi because the new board is not yet well supported in the community of software and operating systems. I went to the log and it exists and has data in it. My output as follows:

motion: [0:motion] [EMG] [ALL] motion_startup: Exit motion, cannot create log file /var/log/motion/motion.log: Permission denied

Broadcast message from systemd-journald@raspberrypi (Thu 2018-09-20 07:08:01 EDT):

motion[3701]: [0:motion] [EMG] [ALL] motion_startup: Exit motion, cannot create log file /var/log/motion/motion.log: Permission denied

1 answer

Answer 9 months ago

create the log file using touch:
sudo touch /var/log/motion/motion.log
and make it brute force readable and writeable
sudo chmod 777 /var/log/motion/motion.log


Question 9 months ago

I am trying to invoke the following python script from motion using the on_movie_start hook. The script works fine when the code between the tags "# --->" and "#<---" is commented out, but not when it is left in. Both versions work when invoked from the command line. Anybody have any ideas?

#!/usr/bin/env python
# script to send a preformatted email
# with a command line argument.
# THIS VERSION IS WRITTEN FOR rpi1 front walk cam
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
import sys
import time
import logging

logging.basicConfig(filename='/var/log/motion.log', level=logging.DEBUG)" invoked " + time.strftime("%a %b %d %Y %X"))

def main():
global arg
#print arg
if __name__=="__main__":
# ---->
fh = open("/etc/motion/lastAlarm", "r+")
last = float(
if time.time() < last + 300:
# <----

fromaddr = ""
toaddr = ""

msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Alert"

body = "Front walk motion detected (rpi1). File = " + arg
#print body
msg.attach(MIMEText(body, 'plain'))
text = msg.as_string()

server = smtplib.SMTP('', 587)
server.login("", "xxx")
server.sendmail(fromaddr, toaddr, text)
server.quit()" " + body)


Question 1 year ago

I tried with Logitech webcam and it works but the dimensions of the picture in browser are just 176x144 regardless of settings. Any ideas how to use higher resolutions?

As michael109 already said - valid values for 'framerate' are 2 to 100 so it isn't possible to use parameters between 1000 and 1500 as suggested.

Sentry G A

1 year ago

thank you very much , it works great......but i need to add 1 more thing we also need to change stream_maxrate(in \etc\motion\motion.conf) to higher values like 750 etc, for proper streaming else default value was 1 fps.

2 replies
HenrikL1Sentry G A

Reply 1 year ago

I agree. Well done. As Sean said made a huge difference. Otherwise great tutorial

SeanW71Sentry G A

Reply 1 year ago

Well spotted, this made a huge difference reducing the lag. Great tutorial, worked like a charm!


1 year ago

Framerate may hace changed in motion. According to the current default /etc/motion.motion.conf, valid values for framerate are from 2 to 100, which is well below the recommended 1000 to 1500

Any advice for starting motion on reboot? This seems to be a significant oversight in the last several updates to raspbian. None of the historical methods seem to be stable


Question 1 year ago on Step 8

Even at 1500, the video is really choppy. How can I make it as smooth as a smart phone camera?


1 year ago

I do not see "reboot your pi".because it is still problem..):