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




Introduction: 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.

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 -


11 People Made This Project!


  • The 1000th Contest

    The 1000th Contest
  • Battery Powered Contest

    Battery Powered Contest
  • Hand Tools Only Challenge

    Hand Tools Only Challenge

56 Discussions


6 weeks ago

I followed the instructions and I can get a stream. Using one of the official cameras on a Pi 4. However, as someone else said they had to increase the stream_maxrate setting from 1 to 30 to get smooth images. When I do that I can no longer connect to the camera (after reboots even). I have to lower it back down. Currently set at 3. Another issue i've been seeing is the occasional purple flickering on the screen. Only the lowest settings seem to not be affected by it. It sometimes causes the camera to freeze up and I have to reboot to get it properly reset. Defective camera? Any ideas on either of these issues? Happy to post the specs and motion.conf if needed.


Tip 2 months ago on Step 8

After installing Motion the frame rate displayed was like 1 frame per second. To fix I did this:
stream_maxrate 30
Now streams without hesitation.


Question 3 months ago on Step 6

How do you turn on daemon in pUTTY?


Answer 3 months ago

Had the same question myself, if you are running Buster and the latest version of motion, you do not need start_motion_daemon in your config. Once you have you're configs set, just run "sudo motion" to start it.


Question 6 months ago

This is a great tutorial, followed it exactly and it works great!

Does anyone know if the video is stored and recorded? The docs don't mention it - im just curious as i dont have much space. I'm not interested in recording at the moment anyways.



Answer 5 months ago

It is possible to turn that on in the config files of motion.


Reply 5 months ago

Found it in the config! Thanks!


Question 5 months ago

Anyone have any success viewing the stream on iphone? Any iphone device i've tested is in a continuous loop of asking for username/password. Also, is there a limit on how many devices can access the stream? I trialled it with some family and some got it working on android, others not


Question 7 months ago on Step 8

I have followed the instruction strictly. I am using a Raspi 3 with an Logitech webcam.
It works but the update rate is very very slow. less than a frame per second.
I do not have another camera to try (dont think it is the camera causing this)
Is this an expected video performance?



Answer 7 months ago

You might see this behavior if either your Pi or the computer you're using to connect to its web server are on WiFi instead of wired ethernet.

With a Pi 3, I've had good luck with saving 15fps video (maybe 30fps) on motion events, but even wired, I think I get exactly 1 fps via a web browser looking at the Pi's web server running on port 8081. If you change stream_maxrate to something higher than 1, you should be able to get more fps (if your network is fast enough -- a wired network will remove doubt about that).

There are probably settings in the motion.conf file that could change this. I'm running a raspicam v1 at a video resolution suitable for night time with these settings:

# Annotate 92 is date/time/shutter/gain
mmalcam_control_params --settings --annotate 92 --mode 4 --contrast 20 --awb off --awbgains 0.98,1.28 --nopreview --verbose --rotation 180 --saturation 25 -ex night
# 1296x972 matches rpicam v1 mode 4 (full FOV, 2x2 binning)
# Image width in pixels.
width 1296
# Image height in pixels.
height 972
# Maximum number of frames to be captured per second.
framerate 15

Good Luck!


Question 8 months ago on Step 8

I am using 3 low light HD USB cameras (details on the link below) for my application.
The application requires me to have all 3 cameras live streaming simultaneously on 3 different local host ports of a PC. For the controller, I am using a Nanopi M4 (it is connected to my laptop by a 20m long, CAT-6 ethernet cable)
I am using the motion package to work the cameras
These are the problems I faced -
  1. When all 3 cameras are connected to controller and stream is checked, at any given time I am able to see the livestream of only 2 of the streams. On restarting motion, any one of the hosts shows a grey screen while the other two give me the proper stream. I have tested this multiple times and would appreciate if help on how to go about this issue
    We also tried connecting the cameras to my laptop directly using threads in my motion package and all the 3 streams were visible to me simultaneously
  2. A few of the times the port number (seen on dev in the form - video0) have changed while the cameras have been plugged in and left as it is. If anyone has come across this problem, please tell me how you went about this
  3. Attached below is a screenshot of the Tcptrack app when all three cameras were connected at 100% stream quality (set in the motion.conf file)
The first three rows represent each camera and the rates are unequal for all of them which is not expected. Can anyone help me with a possible explanation to this?
Also when that screenshot was taken, the camera streaming to localhost 8083, was showing up as a grey screen on my laptop, so what is the rate signifying?
Also, to make sure there were no problems with the Nanopi M4 USB ports sourcing the current drawn by the cameras, we gave an external 5V power supply to them – We could only see any 2 out of 3 streams
I have also attached a screenshot from my Nanopi M4 Top showing the CPU usage when all three cameras were connected to stream at 100% quality

  1. As a last resort, if we are only able to work 2 cameras at a time, please advise if anyone has used switching between the three cameras to choose which ones stay on at any given time
Thank you for your time
raj pandey143
raj pandey143

Answer 8 months ago

How did you run 3 cameras simultaneously using motion? I have Raspberry PI 4 and have 3 cameras I would like to try this? Can you share how did you do it?


12 months ago

Nice, I used another raspberry pi (RPi1B) with a small monitor.
Running Raspbian Buster with nodm.

(RPi Setup: Graphical Application without desktop environment):

Command line used in the ~/.xsession file:
omxplayer -r --live -b ''

Sinjin Jang
Sinjin Jang

1 year ago

Thanks for good article :-)
I have a question. Is it possible to control pan-tilt-zoom webcam?
I want to stream webcam video with pan-tilt-zoom functionality.


1 year ago

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


Reply 1 year ago

Yes. The easiest way is to get a dynamic IP address ( (there is a free plan) ). This will generate a domain for you to view your webcam, and of course set up a dynamic IP address( which is what you need because your ISP will charge you $200+ per month for a static IP address ) . Install the software onto your single board computer. In your router (in a web browser goto add a rule that forwards the internal port of the motion stream (default 8081, but you can configure motion.conf to almost any port you wish) to external port 80. Alternatively... you can forward multiple ports (port 80 for http and port 8081 for webcam) and embed several webcams into an html document and use your single board computer as a server ( google flask server for a simple to use one.. flask also allows you to easily control GPIO over the internet ). To do this in the html you would use <iframe src="xx.xx.x.x:8081></iframe>" where 8081 is obviously the port motion is sending to. It should be noted that in order for external networks to access iframe from your local network you must use your external ipv4 address within the iframe src. I hope this helps! And God bless


2 years 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.


Reply 1 year ago

edit file /etc/motion/motion.conf
change parameter webcam_localhost on to off


1 year 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!


1 year 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 :-)