This post exists to collect my notes on displaying a USB webcam on the Raspberry Pi HDMI outputs. This is not the same as streaming the webcam (easy), and this is not for use with the Raspberry Pi camera module. This is specifically for USB UVC webcams.
Install Raspberry Pi OS Lite, you don't want the full desktop environment.
Once you boot the Pi, install VLC and the X windows environment:
sudo apt install vlc xinit
Configure your Pi to boot to the command line already logged in, using the tool raspi-config.
Create the file ~/.bash_profile with the following contents which will start X on boot:
if [ -z $DISPLAY ] && [ $(tty) = /dev/tty1 ]
Create the file ~/.xinitrc to launch VLC streaming the webcam when X launches:
cvlc v4l2:// :v4l2-dev=/dev/video0
Now you can reboot the Pi with a webcam plugged in and you'll get a full screen view of the camera.
If your webcam isn't recognized when it first boots up, you'll need to quit VLC and start it again. You can quit by pressing ctrl-Q, then type startx to restart it after you plug the camera back in. If that doesn't work, you might have to SSH in and kill the process that way.
There are many problems with this approach:
- It seems VLC is not hardware accelerated so there is pretty bad tearing of the image
- Sometimes the webcam isn't recognized when the Pi boots up and I have to unplug it and plug it back in when it boots and restart the script
- The image tearing and stuttering is completely unusable for pretty much anything
Do you know of a better solution? Let me know!
So far I haven't found anything that actually works, and I've searched all the forums and tried all the solutions with guvcview and omxplayer with no luck so far.
For some other better solutions, check out my blog post and video How to Convert USB Webcams to HDMI.