Warm tip: This article is reproduced from serverfault.com, please click

How can I send a virtual camera to Genymotion or Android Studio Emulator in Ubuntu?

发布于 2020-11-25 15:06:01

I created a virtual camera using v4l2loopback and ffmpeg. The command I use for ffmpeg is: ffmpeg -re -l oop 1 -i vin.png -vf format=yuv420p -f v4l2 /dev/video2

vin.png is the image I want to stream to the webcam and /dev/video2 is the virtual webcam I created with v4l2loopback. The virtual webcam works and I can see it e.g. with onlinemicetest.com/webcam-test. I'm using the Genymotion emulator with the newest Android API (I tried 7.0, 8.1 and 10.0) on Ubuntu 20.40. Genymotion detects the virtual camera but only displays a dummy image: Wrong dummy Image from Genymotion I also tried (and would prefer to use) the android studio emulator. But I can only select Webcam0 in the configuration of the device camera and that points to the real integrated camera and not to my virtual webcam.

I don't need to use ffmpeg, but I do need to use a tool that lets me control which image to stream from the command line.

Is there a way to solve this? Many thanks in advance!

Update 17.11.2020: The Genymotion support answered me, that they plan to support virtual cameras in the future. They might be ready to add this in mid 2021.

Questioner
ykasur
Viewed
11
ykasur 2020-11-30 18:46:18

Solution using OBS and Android Emulator:

  1. follow this tutorial: https://blog.jbrains.ca/permalink/using-obs-studio-as-a-virtual-cam-on-linux
  2. use these commands to change your obs scenes: https://gist.github.com/nooitaf/9aabf72d00e16a61ea301c69ff38d804
  3. check which /dev/video you are using: v4l2-ctl --list-devices
  4. check which webcam is linked to that video in your avd: ./emulator -avd Pixel2 -webcam-list
  5. use that webcam to start emulator from command line: ./emulator -avd Pixel2 -camera-back webcam2