+++ title = 'How to setup a phone as wireless webcam on linux' date = 2025-01-20T18:16:55+01:00 tags = ['linux', 'android', 'scrcpy'] +++ Anybody else need to have a webcam nowdays because of all the remote stuff that has started happening since covid, getting forced into having a webcam so that your boss/teacher/professor can follow what you are doing but don't wanna spend money on getting one and you are luckilly using linux? Then look no further because if you have a decent phone ( S24 in my case ) you can have use it as a wireless webcam ( or usb if your android version is lover than 14 ). I will now show you the steps and some basic settings and a script to simplify the steps. # 1. Enable Wireless/Usb Debugging on your phone First you will have to enable wireless/usb debugging on your phone. The steps can somewhat differ depending on your phone and as such I will use my phone as an example. 1. Enter your settings 2. Enter "About phone" 3. Enter "Software Information" 4. Click on "Build number" until a popup tells you developer mode has been enable 5. Exit back to main menu of settings and enter "Developer Options" 6. Enable Wireless/Usb debugging Note that for Wireless Debugging you will have to enable it again every time you wanna use your phone as a webcam. To help with that you can ebale wireless debugging as a tile by going to developer options>"Quick settings for developer tiles" and enabling wireless debugging. # 2. Installing necesarry software on your linux system Now we have to install the needed software on your linux system to make all this work. I will use arch as an example but will first list the software you need: - android-tools (adb) - v4l2loopback - scrcpy > example command ```bash sudo pacman -S android-tools v4l2loopback-dkms scrcpy ``` # 3. Pair your phone with your pc using adb Now we will need to pair your phone using adb wirelessly with your pc. Go to wireless debugging settings on your phone, make sure it's enable and click the pair with code option. Take note of the ip and port, you will have to use it on your pc. Next you have to run this command: `adb pair IP:PORT`. After running the command you have to enter the pair code and press enter. And we are done, you are now connected to your phone. # 4. Setup video dummy device and output camera feed to it. Now we need to setup a dummy video device using v4l2loopback driver, using this command : `sudo modprobe -v v4l2loopback exclusive_caps=1 card_label="Virtual Webcam"`. Now we need to use the command `v4l2-ctl` to get which number the video device is, in my case it's `/dev/video2` > example ```bash ❯ v4l2-ctl --list-devices Virtual Webcam (platform:v4l2loopback-000): /dev/video2 HD User Facing: HD User Facing (usb-0000:05:00.3-1): /dev/video0 /dev/video1 /dev/media0 ``` Now we can use scrcpy to get our phone's camera and show it on your pc in a nice little window, in my case I use this command which is pretty long but will explain it: ```bash scrcpy --video-source=camera --no-audio --camera-facing=front --v4l2-sink=/dev/video2 --camera-fps=60 --video-codec=h265 --camera-ar=4:3 -m1920 --capture-orientation=flip90 ``` Now to explain the options: - `--video-source=camerate` makes sure scrcpy uses your camera as the source - `--no-audio` makes sure to not catch phone mic audio, - `--camera-facing=front` uses front camera, you can change it to use back camera also - `--v4l2-sink=/dev/video2` make sure to use the video output to your "Virtual Webcam" - `--camera-fps=60` uses 60fps mode of the camera - `--video-coded=h265` provides better quality than `h264`, but higher latency - `--camera-ar=4:3` and `-m1920` limits resolution to 1920 and makes it 4:3, for more caught on camera - `--capture-orientation=flip90` flips the picture and rotates it by 90 degrees, you don't need the 90 and can use just flip0 if you make your phone stand landscape And now you have a nice little window showing of your phone camera wirelessly on your pc. It is also accebible with software like zoom/obs/discord/... --- Hope you had a decent time reading this and have managed to get it all working with your nice new webcam ;)