Hacking together a nice webcam over USB with a Nikon D3300 DSLR and Ubuntu Focal 20.04 to work from home.
With covid forcing me to work remotely, I needed to find a webcam and with the crisis hitting the entire world the stock available for a quality camera was limited. When the WFH orders were given, I immediately began setting up my new office and command center.
My daily life pre-covid typically had me attending meetings most of the day, and now that they are remote getting “Face-To-Face” can be difficult. My search for a webcam online was not panning out. Nothing with more than a one star rating and a lot of pissed off customers in the comments was turning up at the major re-sellers.
I simply refuse to buy crap, and I already have a very nice camera we bought a few years ago for vacations and family photo ops. I thought to my self, “I Wonder if I can use the Nikon DSLR for this?”
Off to Google I go, searching for any juicy keywords I can think of…
Nikon D3300 Ubuntu Webcam To my surprise I actually hit some results on a few people trying various setup s and having some luck with other Nikon models, perhaps there is hope!
I owe my success to this Blog post how-to-use-your-dslr-as-a-webcam-in-linux/ which goes into great detail how and why this all works. All credit to Ben Chapman, thanks for posting that great write up. Seriously go there and read that!
For this to work well I picked up some hardware that helped me along.
First I found the battery would last about an hour or less if I was constantly using the camera. To solve this I picked up a tricky power supply that replaces the battery, and plugs into mains voltage powering the camera.
The added benefit of the new cable is that it is longer, removing the need for one of these great USB extension cables. I use these everywhere I need to add a few feet of USB to a connection.
While I was there I also picked up a new “cold shoe” mountable light to add to the quality of the video. You can grab the ESDDI 176 LED Video Light here
This thing is great, plenty bright and it comes with swappable lenses in different colors to allow color balancing. I ended up using the amber lens as it seems to work the best in my space.
I did need to find an old power supply to keep the light on without the battery. Luckily I keep old transformers around for just this occasion. Again, it just does not last for constant video.
Applicable DC adapter: 6.5-17V(DC Plug Dimension : 5.5mm x 2.1mm)
Ubuntu Install Steps
Following the directions from the blog I found, I installed the required dependencies and began looking for my camera in the supported list for Gphoto2. This was actually much easier than I expected it to be!
I’m running Ubuntu Studio on my desktop PC, so I followed the Ubuntu/Debian setup steps. Refer to the original blog By Ben for the additional installation methods.
sudo apt-get install gphoto2 v4l2loopback-utils v4l2loopback-dkms ffmpeg
Loading the Kernel Module
This command will load the need kernel modules for this login session. Once you reboot you will need to run this again. Instead add to
modprobe and load the kernel persistently.
One Time Load
sudo modprobe v4l2loopback exclusive_caps=1 max_buffers=2
Add to modprobe and modules.
echo "dslr-webcam" |sudo tee -a /etc/modules && echo -e "alias dslr-webcam v4l2loopback \noptions v4l2loopback exclusive_caps=1 max_buffers=2" | sudo tee -a /etc/modprobe.d/dslr-webcam.conf
Discovering the Camera
To find your camera type
gphoto2 --auto-detect which should show your camera if plugged in and turned on.
Streaming From Camera
This assumes the camera was found with the step above. See the original blog for more details and trouble shooting.
gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video0
For ease the next time you want to launch the camera and stream some sweet video of you to your local
/dev/video0 interface we need to add a line to our
echo -e "# Nikon DSLR Webcam Stream, Camera should be connected, switched off 'auto' mode and not mounted as a drive \nalias DSLR-WebCam='gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video0' |tee -a ~/.bash_aliases" && source ~/.bash_aliases
Now you can issue the
DSLR-WebCam command to launch the camera stream and begin using your nice camera fro a webcam.
Video Chat with DSLR
Now that you have a video stream at your
/dev/video0 address you should be able to utilize this camera in all of the popular video chat applications. Obviously you will need a microphone and speaker still for the chat but your video feed will be the sharpest in the group.
You can open VLC and monitor the
/dev/video0 interface to see your camera feed and tune anything needed like zoom and focus.
There are a ton of factors that lead to a quality video feed. Too many to list here but I will hit the top few.
Don’t risk your fancy camera to some shoddy placement. You can only really drop these one time. Get a nice tripod to mount the camera to and ensure it is not going to be knocked over
Here are my picks for a quality tripod:
Lighting is a must! Those nasty Fluorescent lights need thrown out, and new led lights put in their place. Pay attention to the color of the light and shoot for options to adjust to your complexion and room lighting conditions
Using my already existing camera ended up saving me money and got em up and running in no time. I’m not sure if the added stress and heavy use will end up costing more than it’s worth, only time will tell.
I can say that as soon as stock levels are back to normal I will be looking for a replacement purpose built camera for this. I find the Nikon camera body gets warm after a few hours of use and I don’t want to explain how I broke the nice camera running web meetings.