惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
N
Netflix TechBlog - Medium
V
Visual Studio Blog
博客园 - Franky
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 三生石上(FineUI控件)
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
宝玉的分享
宝玉的分享
量子位
大猫的无限游戏
大猫的无限游戏
人人都是产品经理
人人都是产品经理
V
V2EX
The Cloudflare Blog
月光博客
月光博客
Last Week in AI
Last Week in AI
雷峰网
雷峰网
WordPress大学
WordPress大学
博客园 - 【当耐特】
博客园 - 聂微东
IT之家
IT之家
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

Homepage on Aditya Telange

One Year with evil-winrm-py - A Retrospective Bypassing LinkedIn's Connection Privacy with a Simple Search Filter Making Dynamic Instrumentation Accessible with Frida UI Breaking Payload Encryption in Web Applications HackTheBox (HTB) - Escape HackTheBox (HTB) - Resolute HackTheBox (HTB) - Certified State of VMWare Workstation (Pro?) on Linux Android App Security Testing Lab with MobSleuth Breaking down Reverse shell commands HackTheBox (HTB) - Photobomb Merging AOSP Security Patches into Custom ROMs Primer on HTTP Security Headers Image Zoom-In effect with HUGO HackTheBox (HTB) - Legacy HackTheBox (HTB) - Lame Cryptohack - Keyed Permutations [5 pts] Cryptohack - Resisting Bruteforce [10 pts] Cryptohack - RSA Starter 1 [10 pts] Cryptohack - Base64 [10 pts] Cryptohack - Bytes and Big Integers [10 pts] Cryptohack - Hex [5 pts] Cryptohack- XOR Starter [10 pts] HackTheBox (HTB) - Horizontall HackTheBox (HTB) - Forge HackTheBox (HTB) - Previse HackTheBox (HTB) - BountyHunter HackTheBox (HTB) - Explore HackTheBox (HTB) - Cap HackTheBox (HTB) - Pit
Android phone as a Webcam on Linux
[Aditya Telange](https://x.com/adityatelange) · 2024-02-17 · via Homepage on Aditya Telange

In this guide, we’ll learn how to create a virtual webcam on a Linux device using an Android device’s camera. We’ll go through the installation of key packages like adb, v4l2loopback, and scrcpy, allowing us to utilize an Android device’s camera as a virtual webcam.

Pre-requisites

  • An Android phone (Android 12+)
  • Linux Desktop (scoping to any Debian-based distro for this guide)

Installing required packages

1. adb

adb, which stands for Android Debug Bridge, is a versatile command-line tool used for communicating with Android devices directly from your computer. 1

2. v4l2loopback

v4l2loopback is a kernel module (software program) for Linux that allows you to create virtual video devices. 2

$ sudo apt install v4l2loopback-dkms

Load the kernel module, setting the exclusive_caps option to 1, and label it as “Virtual Webcam.”

Note: Setting exclusive_caps to 1 is important for Chromium/WebRTC-based tools like Google Meet or Zoom, which requires a webcam device with only capture capabilities

# Load the `v4l2loopback` kernel module
# and set `exclusive_caps` option to `1`
# (important for Chromium/WebRTC-based tools like Google Meet or Zoom,
# which require a webcam device with only capture capabilities)
$ sudo modprobe -v v4l2loopback exclusive_caps=1 card_label="Virtual Webcam"

Verify the creation of the virtual webcam device:

$ v4l2-ctl --list-devices    # or you may `ls /dev/video*`
Dummy video device (0x0000) (platform:v4l2loopback-000):
  /dev/video0

3. scrcpy

scrcpy stands for “screen copy” and is a free and open-source tool that allows you to mirror and control your Android device from your computer. It works on Linux, Windows, and macOS, making it a cross-platform solution. 3

# Install pre-requisites for Debian/Ubuntu
sudo apt install ffmpeg libsdl2-2.0-0 adb wget \
                 gcc git pkg-config meson ninja-build libsdl2-dev \
                 libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev \
                 libswresample-dev libusb-1.0-0 libusb-1.0-0-dev
$ git clone --depth 1 --branch v2.3.1 https://github.com/Genymobile/scrcpy
$ cd scrcpy
$ ./install_release.sh  # may ask for your sudo password

Connecting your phone via with adb

  • Enable Developer options using this guide from developer.android.com
  • Enable USB debugging using this guide from developer.android.com
  • Connect your Android phone to your Linux computer.
  • When prompted on your Android device, click on ALLOW to grant USB debugging access.
  • Verify that your device is detected (device ID may vary):
    $ adb devices
    List of devices attached
    978a27c9  device
    

Using scrcpy

Now that our device is connected properly we can list the cameras 4 we can utilize:

Example output:

scrcpy 2.3.1 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO:     -->   (usb)  978a27c9                        device  DEVICEX
/usr/local/share/scrcpy/scrcpy-server: 1 file pushed. 0.6 MB/s (66007 bytes in 0.100s)
[server] INFO: Device: [make] make DEVICEX (Android 12)
[server] INFO: List of cameras:
    --camera-id=0    (back, 4608x3456, fps=[10, 15, 28, 30])
    --camera-id=1    (front, 3264x2448, fps=[15, 30])
    --camera-id=2    (back, 3264x2448, fps=[15, 28, 30])
    --camera-id=3    (back, 1600x1200, fps=[15, 30])
    --camera-id=4    (back, 1600x1200, fps=[15, 27])
    --camera-id=5    (back, 4608x3456, fps=[10, 15, 28, 30])
    --camera-id=6    (back, 4608x3456, fps=[10, 15, 28, 30])

Start scrcpy with the desired camera source and output to the virtual webcam device:

$ scrcpy --video-source=camera --no-audio --camera-facing=front \
    --v4l2-sink=/dev/video0
  • v4l2-sink outputs the received video stream into v4l2 device /dev/video0, which we had created earlier.
  • You may check more available options here scrcpy - camera mirroring

Example output:

scrcpy 2.3.1 <https://github.com/Genymobile/scrcpy>
INFO: Video orientation is locked for v4l2 sink. See --lock-video-orientation.
INFO: Camera video source: control disabled
INFO: ADB device found:
INFO:     -->   (usb)  978a27c9                        device  DEVICEX
/usr/local/share/scrcpy/scrcpy-server: 1 file pushed. 6.9 MB/s (66007 bytes in 0.009s)
[server] INFO: Device: [make] make DEVICEX (Android 12)
INFO: Renderer: opengl
INFO: OpenGL version: 4.6 (Compatibility Profile) Mesa 23.3.2-blah-blah
INFO: Trilinear filtering enabled
[server] INFO: Using camera '1'
INFO: v4l2 sink started to device: /dev/video0
INFO: Texture: 3264x2448
# A new window will pop up which will serve as a viewfinder.

We can now use our newly added Virtual Webcam for video calls and conferences. 🎉