DEV Community

Mohammed Chami
Mohammed Chami

Posted on • Edited on

Turn Your Android Phone into a Virtual Webcam for OBS on Linux (Without DroidCam)

If you're tired of dealing with DroidCam's WiFi-only limitations or want a more reliable USB connection for streaming, this guide will show you how to transform your Android phone into a high-quality virtual webcam for OBS Studio on Linux systems like Pop!_OS.

Why This Method Works Better

After struggling with DroidCam's WiFi connectivity issues, I discovered this USB-based approach that delivers near-zero latency and crisp video quality. While you'll need a separate microphone for audio (or can set up PulseAudio loopback), the video quality improvement is worth it.

example:

I used custom camera app to change the scene mode

in OBS:

video on obs

This solution creates a proper virtual webcam device (/dev/videoX) that OBS and other applications can recognize as a standard camera input.

The Technical Stack

Our setup uses three key components working together:

scrcpy - Originally designed for Android screen mirroring and remote control, we're repurposing it to stream your phone's camera feed over USB with minimal latency.

v4l2loopback - This kernel module creates a virtual video device that acts as a bridge between scrcpy's output and OBS's input expectations.

ffmpeg - While optional, it helps with video format conversion when needed.

Installation and Setup

Installing Required Packages

Start by updating your system and installing the necessary tools:

sudo apt update
sudo apt install scrcpy v4l2loopback-dkms ffmpeg
Enter fullscreen mode Exit fullscreen mode

Setting Up the Virtual Camera Device

Load the v4l2loopback kernel module to create your virtual webcam:

sudo modprobe v4l2loopback
Enter fullscreen mode Exit fullscreen mode

To make this persistent across reboots, add it to your modules list:

echo "v4l2loopback" | sudo tee -a /etc/modules
Enter fullscreen mode Exit fullscreen mode

Preparing Your Android Device

Enable USB debugging on your Android phone by following these steps:

  1. Navigate to Settings → About Phone
  2. Tap "Build Number" seven times to unlock Developer Options
  3. Go to Developer Options and enable USB Debugging
  4. Connect your phone via USB cable
  5. Allow debugging access when prompted on your phone

Starting the Camera Stream

Launch scrcpy with virtual webcam output using this command:

scrcpy --v4l2-sink=/dev/video2
Enter fullscreen mode Exit fullscreen mode

This redirects your phone's display (including camera apps) to the virtual webcam device at /dev/video2.

Configuring OBS Studio

In OBS Studio:

  1. Click the "+" button in Sources
  2. Select "Video Capture Device" or "Window Capture"
  3. Name your source (e.g., "Android Camera")
  4. Choose /dev/video2 as the device
  5. Adjust resolution and frame rate settings as needed

If your video appears rotated, add the rotation parameter:

scrcpy --v4l2-sink=/dev/video2 --rotation=1
Enter fullscreen mode Exit fullscreen mode

Troubleshooting Common Issues

Virtual Device Not Found

If /dev/video2 doesn't appear, verify the module loaded correctly:

ls /dev/video*
Enter fullscreen mode Exit fullscreen mode

If missing, reload the v4l2loopback module:

sudo modprobe -r v4l2loopback && sudo modprobe v4l2loopback
Enter fullscreen mode Exit fullscreen mode

Black Screen in OBS

Try limiting the resolution to improve compatibility:

scrcpy --v4l2-sink=/dev/video2 --max-size=1024
Enter fullscreen mode Exit fullscreen mode

Make sure to restart OBS after launching scrcpy.

Phone Connection Issues

Check if your device is properly connected:

adb devices
Enter fullscreen mode Exit fullscreen mode

If your phone isn't listed, reconnect the USB cable and re-enable USB debugging.

Streamlining Your Workflow

Create a simple script to avoid typing the full command each time:

nano ~/android_cam.sh
Enter fullscreen mode Exit fullscreen mode

Add this content:

#!/bin/bash
scrcpy --v4l2-sink=/dev/video2 --max-size=1024
Enter fullscreen mode Exit fullscreen mode

Make it executable:

chmod +x ~/android_cam.sh
Enter fullscreen mode Exit fullscreen mode

Now you can start your Android webcam with:

~/android_cam.sh
Enter fullscreen mode Exit fullscreen mode

Final Thoughts

This method provides a reliable, low-latency solution for using your Android phone as a webcam without relying on potentially unstable WiFi connections. The USB connection ensures consistent performance, making it ideal for important streams or recordings where reliability matters most.

The setup works with any camera app on your phone, giving you flexibility in how you want to frame and control your video feed. Just remember to keep your phone charged or use a longer USB cable that supports both data and charging if you plan on extended recording sessions.

Top comments (0)