I've been thinking about webcams for a while after I read about numerous pieces about how terrible laptop built-in webcams are in the day and age of zooming-from-home. People seem to have problems with laptop built-in webcams on the following aspects:
- The webcams that come with your laptops (even the most expensive ones) have terrible picture quality.
- They can't be trusted: People put tapes on them. You are advised against doing it, though.
There are a couple of remedies people came up with for the built-in webcam quality:
- Buy an external webcam. Cons: They only give marginally better results on picture quality.
- Use your phone to do meetings. Cons: Small phone screen, impossible to see shared meeting screens well, impossible to share screens, impossible to access work documents at the same time, limited by the functionalities that the mobile app provides.
- Use your phone as a webcam. Cons: Cumbersome software setup, lags.
- Use a professional camera + HDMI capture card as a webcam.
Many "professional" streamers choose the last solution, and I have tried to do it myself too. It took me two months to wait for my $50 capture card from China to arrive. Then when it finally came, I realized this is a very cumbersome setup. First, my camera (a Sony NEX-5R) cannot output a "clean" HDMI output (i.e. without the GUI elements). The only way to get rid of that stupid overlay is to buy another newer camera (say, a Sony A7 is $500+ used). Second, the camera does not charge or stay charged on USB, so I have to buy another dummy battery that feeds from a DC source. Third, this setup is not portable.
Moreover, none of the above solutions allow us to trust, control, and improve on them (At least, physically disconnecting them solves the privacy concern, which isn’t something you can do with a laptop built-in camera).
Raspberry Pi as a webcam?
So I set out to build a webcam of my own. Recently, I noticed that the Raspberry Pi Foundation released a high-quality camera, which is a fantastic candidate. It's a professional camera with a very big sensor and an assortment of interchangeable lenses. Being in the right hands, this can be a very powerful tool to achieve many things. Can it be a webcam to use with my ordinary computer though?
I know it is possible to stream the webcam over the network, and then use a computer to turn the network stream back to a virtual webcam. However, because this setup depends on the operating system, the setup is not portable. It also introduces lags which makes the voice trails behind the images.
So in short, I want the Pi Camera to appear as just an ordinary USB webcam to my laptop.
With a bit of googling, I learned that it is possible to make the Pi appear as a USB webcam! There is a mode on the Pi 0 USB port called USB gadget mode, which makes that port a guest port for the system it's plugged in to. I got a good start with Dave Hunt's post. However, there are things to be desired with his software solution. First, it uses Raspbian as a base, which means you have a writable root, and an abrupt disconnection of power (we will do that with a webcam) will cause filesystem corruption. Second, the camera takes a long time to start. Those are the two main barriers to this approach: It works as a hack, but it works less well as a solution you'd depend on. And what you need your webcam to do? To work every time when you need it, right?
Making the webcam boot quickly is a challenge: You'd have to build a dedicated linux system that can boot as quickly as possible. This makes using just Raspberry Pi OS a unviable choice. It needs to, also, makes unclean shutdowns not corrupt the filesystem. That means the filesystem needs to be read-only.
So, I set out to build a more robust firmware for the project. The following is the documentation of what I did to get the firmware working, and I think what I went through can be helpful if you want to roll your firmware...Read more »