Introduction: How to Make Raspberry Pi Webcam Server and Stream Live Video || Motion + Webcam + Raspberry Pi
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:
- How to install OS in a Raspberry pi. ( link - https://www.instructables.com/id/HOW-TO-INSTALL-RA... )
- How to use your Laptop Screen a monitor for Raspberry pi. ( link - https://www.instructables.com/id/How-to-Use-Window... )
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 - www.youtube.com/c/being_engineers1
Our Website - www.being-engineers.com
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.
- Open your browser on laptop or mobile. ( laptop or mobile has to be in the same network as the pi )
- Go to your Router settings by typing in the default IP address of your router. ( written somewhere on your router. )
- Find the list of connected devices.
- Find the corresponding IP address of the device named raspberry.
In our case, it is 192.168.0.107
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:
- Make sure 'daemon' is ON.
- Set 'framerate' anywhere in between 1000 to 1500.
- Keep 'Stream_port' to 8081.
- 'Stream_quality' should be 100.
- Change 'Stream_localhost' to OFF.
- Change 'webcontrol_localhost' to OFF.
- Set 'quality' to 100.
- Set 'width' & 'height' to 640 & 480.
- Set 'post_capture' to 5.
- 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:
192.168.0.107:8081 (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 - https://www.youtube.com/c/being_engineers1
Peace.
14 People Made This Project!
- tcozier made it!
- NicoH1991 made it!
- WilliamL90 made it!
- alex77k12. made it!
- denco780 made it!
- paolo marinelo made it!
- mark15963 made it!
- benbenson2004 made it!
- Perto56 made it!
See 5 More
67 Comments
Question 25 days ago
I have got the webcam up and running. How do I access the live feed without being on the same network?
Question 4 months ago on Step 3
How can I grab an rtsp or rtmp stream from my network and output it on USB without using OSB or VLC I want to use Networked camera stream for Teams and Zoom
12 months ago
Great article . helped me out a lot to get my octoprint working with my old webcam. If you want to get octoprint timelapse working with motion video package checkout my comment (van-ant) in git hub https://github.com/bchanudet/OctoPrint-Octorant/issues/24
1 year ago
Thanks for this! Decided rather than purchasing a baby monitor, I'd use a spare pi 3 I had floating around and create my own. Seems to be working fine at the moment.
To get a smooth image, I lowered the width and height in motion.conf to 512 and 288, set frame rate to 30, added "stream_quality" variable setting it to 35 and "stream_maxrate" variable setting that to 30.
That gave a video stream with fairly good response.
Without those settings, the image was laggy by a few seconds and also stuttered (low frame rate)
Question 1 year ago
can we access this remotely, i.e. if pi and my mobile are not connected to same network?
1 year ago
how do you stop the live stream????
2 years ago on Step 1
I am getting error message "Unable to open video device". I am using Logi webcam and Wyze Cam, for Wyze Cam I downloaded their webcam software. I also am using Raspberry Pi 4.
Reply 1 year ago
I am also getting the same error - Unable to open video device. I noticed that the USB camera is not connecting to /dev/video0. The device changes to /dev/video1 sometimes. How do I fix it to always connect to /dev/video0.
2 years ago
Hi,
Due to the fact that I don't need the stream all the time, 24/7, can someone suggest me a way to start the service as soon as I type in the address and access the server?
5 years ago
How to do "just forward port 8081 to the pi in your router and vala, your camera is on the internet."
Reply 2 years ago
I would better go for a VPN. this is how I use it.
Tip 2 years 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.
Reply 2 years ago
thanks!
2 years 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.
Question 2 years ago on Step 6
How do you turn on daemon in pUTTY?
Answer 2 years 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 2 years 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.
Thanks!
Answer 2 years ago
It is possible to turn that on in the config files of motion.
Reply 2 years ago
Found it in the config! Thanks!
Question 2 years 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