No matter how expensive your webcam is, it will never be as good as your old phone’s camera.
In this guide, we will give a second life to your old phone by using it as a webcam.
All software used in this guide is free.
Android phone
We will need to install the following software on your mobile phone:
- IP Camera to stream
video from your phone’s camera to your desktop computer over WiFi.
- (Optional) droidVNC-NG VNC Server
to control your phone remotely from your desktop computer.
Desktop computer
This guide is written for Fedora, but it should give you a general idea of how to
set it up on other distributions.
We will need to install v4l2loopback
to create a virtual camera device and ffmpeg
to stream video from remote camera of the mobile phone to the virtual camera device.
v4l2loopback
is a kernel module that allows you to create “virtual video devices”.
It is available in rpmfusion repository.
- Enable rpmfusion repository:
sudo dnf install https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
- Install dependencies:
sudo dnf install ffmpeg v4l2loopback akmod-v4l2loopback
- Verify that v4l2loopback is loaded:
lsmod | grep v4l2loopback
- If it is not loaded, run this command:
akmods --kernels $(uname -r) --rebuild
# Confirm that it was loaded
lsmod | grep v4l2loopback
Add the following helper function to your .bashrc
file to start streaming from your phone:
webcam () {
ffmpeg -i http://192.168.2."$1":4747/videofeed -vf format=yuv420p -f v4l2 /dev/video0
}
Assuming that your phone’s IP address is 192.168.2.38
and IP Camera is running on port 4747
,
you can start streaming by running webcam 38
in your terminal. I keep my phone’s IP assress dynamic as it
changes once in a while, if I don’t use it for a long time.
Hardware setup
I have an old Google Pixel 3a phone which is mounted on the top of my monitor. The
phone is attached to the mount with magnetic ring. At the time of writing, the setup
cost me around 25 EUR:
How to use
- On mobile phone, start
IP Camera
and select “Start server” from the menu.
In the bottom part of the screen, you will see the IP address and port number.
- On desktop, run the following command, providing the IP address of your phone and the port number:
ffmpeg -i http://192.168.2.26:4747/videofeed -vf format=yuv420p -f v4l2 /dev/video0
## or use the helper function
webcam 26
You can confgiure video resolution and other settings of your phone’s camera by
navigating to http://192.168.2.26:4747/ in your browser.
If you install droidVNC-NG VNC Server
, you can start IP Camera
remotely from your desktop.
This is useful if you want to start streaming from your phone without touching it. On the desktop computer,
use Connections
app (comes by default in GNOME) to connect to your phone.
Troubleshooting
If for some reason v4l2loopback
module is not compiled correctly, you can
compile it manually by following this instruction.