Solution if the android sdk emulator can't access the /dev/video2 file created with the v4l2loopback module to use it as a virtual web cam in case you are capturing the screen for x utility.
If for example your pc represents the video capture devices with /dev/video0 and /dev/video1, you need to give the user read and write permissions to those files because the emulator iterates through each file /dev/video* and when it finds that it doesn't have the necessary permissions it stops iterating and fails to get to /dev/video2.
So you have to give read and write permissions to all files referred to /dev/video* if you are using them.
In case you are not using it you can do the following:
sudo mv /dev/video0 /dev/~video0
sudo mv /dev/video1 /dev/~video12.- Remove v4l2loopback kernel module if one exists. Create a file with the v4l2loopback module to use as a virtual web cam. Even if you use the option video_nr=0, it still creates it as /dev/video2.
sudo modprobe --remove v4l2loopback
sudo modprobe v4l2loopback video_nr=0 exclusive_caps=13.- Give the the user read and write permissions to /dev/video2 and create a symbolic link for to get access as /dev/video0.
sudo setfacl -m u:"$USER":rw /dev/video2
sudo ln -s /dev/video2 /dev/video0You can run this part in a new terminal, if you end the execution and run it again it will throw an error. The way I saw to fix it is to repeat the steps from step 2.
ffmpeg -f x11grab -r $FPS -s 640x480 -i $DISPLAY+0,0 -vcodec rawvideo -pix_fmt yuv420p -f v4l2 /dev/video05.- To check if the emulator detects the virtual web cam. The command related to ffmpeg -f x11grab -r $FPS -s 640x480 ... needs to be running.
$ANDROID_SDK/emulator/emulator -webcam-listIn the example in this script there is only one capture device represented as /dev/video0, because the other files were renamed to /dev/~video0 and /dev/~video1
6.- You need to modify the virtual machine configuration file which is located in the following path ~/.android/avd/$NAME_OF_YOUR_ANDROID_VM/.config
hw.camera.back=webcam0That's all !!!!
You must abort the process the command related to ffmpeg -f x11grab -r $FPS -s 640x480 ...
sudo modprobe --remove v4l2loopbacksudo unlink /dev/video0sudo mv /dev/~video0 /dev/video0
sudo mv /dev/~video1 /dev/video1