(Image credit: Tom's Hardware)
As I write this, there’s a shortage of USB webcams and industry-leader Logitech has said that it will be four to six weeks before there’s adequate supply. However, it’s still easy to get a Raspberry Pi camera module, if you don’t already have one, and use your Raspberry Pi as a webcam for your PC.
While there are a few potential ways to get video from your Raspberry Pi to appear on your PC in Skype, Meet, Zoom or other conferencing apps, the only method I’ve found that works is to stream the Pi’s video using mjpg_streamer and then receive it on the Windows (or Linux or macOS) side where another app makes the OS think that the stream is a webcam. After combing through a lot of resources, including this very helpful thread, I see that there was at one time a way to have a Pi Zero become a literal USB webcam in Windows, but it doesn’t appear to work with recent builds of Raspbian.
If you already have a Raspberry Pi camera module installed or know how to use one, then you can skip down to the next section and step 6.
Raspberry Pi 3 and 4 have two different serial interface (ribbon cable) ports, one for the camera and another that can be used for some displays. On the 3 and 4, the CSI (camera serial interface) port is the one located between the 3.5mm audio jack and the HDMI port(s).
(Image credit: Tom's Hardware)
On Pi Zero / Zero W, the camera port is the only ribbon-cable port and it’s located on the opposite side of the board from the microSD card slot.
(Image credit: Tom's Hardware)
The standard-size ribbon cable that comes with most camera modules is too wide to fit into the narrower port on the Pi Zero / Zero W. So, if you plan to use one of those, you’ll need a camera cable that’s designed specifically for Pi Zero (some cameras come with them and others require you to buy them separately).
Inserting the cable into the port is a very delicate operation.
1. Lift and loosen the plastic cuff on top of the port, without pulling it out. If you pull the cuff out, you should be able to pop it back in, but on one Pi Zero where I did this, the plastic broke.
2. Slide the ribbon cable into the port with the metal teeth facing the HDMI ports on Pi 3 / 4 or facing down on a Pi Zero.
3. Snap the cuff down to hold the cable in place. You should keep pushing the cable into the port while you push the cuff in. If the cable is even a little loose, it will slide out or it may just not work.
(Image credit: Tom's Hardware)
4. Activate the camera module in Raspbian. To do that, launch raspi-config at the command line, navigate to the Interfaces menu and toggle Camera to on. You will be asked to reboot.
(Image credit: Tom's Hardware)
5. Take a picture to make sure the camera works. Do this by typing this at the command line.
raspistill -o mytest.jpg
If you are in the windowed environment, you’ll see an image pop up on screen for a couple of seconds. If not, you can always try viewing the JPG file you created.
(Image credit: Tom's Hardware)
6. Connect your PC to your Pi. There are four main ways to connect your Raspberry Pi to your PC:
If you’re using a direct USB or Ethernet connection to your desktop or laptop, you will need to share your PC’s Internet connection with the Raspberry Pi. To do this in Windows, navigate the network connections menu in control panel, first right click on your PC’s Ethernet connection, select properties.
(Image credit: Tom's Hardware)
Then enable sharing in the Share tab and select the Ethernet connection your Pi is using (even the Pi Zero’s USB connection is labeled as an Ethernet connection here).
(Image credit: Tom's Hardware)
7. Enter the code below at the command prompt to install a required library.
sudo apt-get install cmake libjpeg8-dev -y
8. Enter the following code to install more prerequisite software. There’s a good chance it is already installed, particularly if you have the latest version of Raspbian.
sudo apt-get install gcc g++ -y
9. Clone, Compile and install mjpg-streamer by typing the following commands
git clone https://github.com/jacksonliam/mjpg-streamer
cd mjpg-streamer/mjpg-streamer-experimental && make && sudo make install
10. Test different mjgp_streamer settings to see what works. At this point, the mjpg_streamer is installed but you need to figure out what camera resolution and framerate work best with your Raspberry Pi model and level of network connectivity.
Start with the lowest-level settings, which you can invoke by entering the following:
mjpg_streamer -i “input_raspicam.so” -o output_http
You should get a message that shows it is active.
(Image credit: Tom's Hardware)
To test the quality of your broadcast, go to your PC, open a browser and navigate to http://[raspberrypihostname]:8080?action=stream. If you haven’t changed the default hostname on your Pi, it will be http://raspberrypi:8080/?action=stream.
(Image credit: Tom's Hardware)
Now, it’s time to try turning up the resolution and frame rate. You can stop the mjpg_stream by hitting CTRL + C in the terminal window. However, if you test a resolution and you get an error message, you’ll need to reboot the Raspberry Pi before you try again. Even if you don’t get an error, your Pi may not exit the app and you’ll need to restart.
You can set the resolution by adding the parameters -x [horiz res] ] -y [vertical res] -fps [frames per second]. To get a 720p, 30 fps stream, enter:
mjpg_streamer -i "input_raspicam.so -x 1280 -y 720 -fps 30" -o output_http.so
I found that 1920 x 1080 (full HD) worked on my camera on a Raspberry Pi Zero W, but it was sluggish, even at 30 fps. I also was able to do 60 fps at 720p, but the image was dark. So 720p at 30 fps might be the best bet for most people.
Once you’ve settled on the settings you like, you should create a bash script that makes it easy to launch with a simple command.
11. Create a new file called startcam.sh by entering:
sudo nano startcam.sh
12. Enter your code. It’s #!/bin/bash in the top line, followed by your mjp_streamer launch line. For example:
#!/bin/bash
mjpg_streamer -i "input_raspicam.so -x 1280 -y 720 -fps 30" -o output_http.so
(Image credit: Tom's Hardware)
Hit CTRL+X to exit and hit Y to save
13. Make startcam.sh executable by typing:
sudo chmod a+x startcam.sh
You can now launch it anytime you want by typing the following at the command prompt when you’re in your home directory.
./smartcam.sh
14. Add startcam.sh to the bottom of your /etc/rc.local file, above the exit 0 command, if you want it to run every time you boot the Raspberry Pi. Remember to use the full path name (ex: /home/pi/startcam.sh).
(Image credit: Tom's Hardware)
15. Download and Install IP Camera Adapter.
16. Launch Configure IP Camera Adapter.
17. Enter the camera feed URL, most likely http://raspberrypi:8080?action=stream and click the Autodetect button to test it and grab the resolution.
(Image credit: Tom's Hardware)
18. Select MJPEG Camera in the settings for your favorite video conferencing apps.
(Image credit: Tom's Hardware)
MJPEG Camera should appear as an option in most conferencing apps, including Skype, Google Meet and Zoom. Note that, for Skype, I found that MJPEG Camera was available in version 8.58 of Skype Desktop, but not in Skype for Windows 10.
You may find that, when you’re chatting, the video isn’t perfectly synchronized with your audio. The more you turn down the resolution and fps, the smoother the video is likely to be. Also, a better connection between your PC and your Raspberry Pi will improve the quality.
More Raspberry Pi Tutorials
Want more information on Raspberry Pi Cameras? Click the link below to contact us.