WebCam on Raspberry Pi 4

Setting up a WebCam using USB on a Raspberry Pi 4 turns out to be quite easy. This setup that involves building the application MJPG Streamer will stream the webcam to a web browser that you can access from anywhere you want it to be accessed from. The main homepage for this application is at

First update/upgrade the RPi using

sudo apt update; sudo apt upgrade -y

Now install a set of libraries and applications that allow us to build the application:

sudo apt -y install libjpeg62-turbo-dev imagemagick libv4l-dev libjpeg-dev cmake

Change Directory into your home directory where you would build applications.

cd <enter>

Download the source code from github


Unzip the zip file and change into the created directory


cd mjpg-streamer-master/mjpg-streamer-experimental/

Now build the application and install it.

make clean all

sudo make install

Make it work

Check that your webcam is being seen by the OS

ls -al /dev/ | grep video

You should see some video0, video1, video2. If you don’t see single digit video, there is a problem to fix.

v4l2-ctl --list-devices

You should see /dev/video0 and maybe more /dev/video* with single digits which is good. No single digit /dev/video is a problem to fix.

Now create a bash script file somehwere in the path. I did mone using:

sudo nano /usr/local/sbin/

Paste the following into the script:


mjpg_streamer -i "/usr/local/lib/mjpg-streamer/ -y -d /dev/video0 -n -f 6 -r 640x480" -o "/usr/local/lib/mjpg-streamer/ -p 8084 -w /usr/local/share/mjpg-streamer/www"

To start the application, run the bash script and use your browser to go to http://<ip address of rpi>:8084

Leave a Reply