microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
16.94k stars 799 forks source link

Include web-camera drivers to WSL2 kernel #8655

Open yurifedoseev opened 1 year ago

yurifedoseev commented 1 year ago

Is your feature request related to a problem? Please describe. I'm building a software for video processing. I use video from web-camera(s) connected to my laptop. Basically I capture video from /dev/video* and use it in my video streaming pipelines. Usbpid-win is a cool solution. However it doesn't help because there are no camera drivers in the kernel. Therefore /dev/video* files weren't created. Attaching any camera to WSL gives me nothing because my pipelines do not work.

Describe the solution you'd like Include camera drivers support to the default WSL kernel. Then /dev/video* devices must be created after attaching camera to WSL via usbpid. I believe web-cameras should be supported by default in WSL.

Describe alternatives you've considered Alternative solution is to build own kernel from scratch and inlcude necessary drivers. I've found this solution really helpful https://github.com/Katzeee/Notes/blob/master/about-programing/wsl2-using-usb.md However it takes a lot of time, easy to make a mistake and hard to explain to colleagues why they have to do such complex things.

Additional context I'm using Ubuntu 22.04

oriaj3 commented 1 year ago

I'm in the same situation, lsusb shows my built-in webcam thanks to usbipd, but there is no device in /dev/video. Have you found a solution?

azwalzaman commented 1 year ago

In the same situation. I decided to do Python dev with OpenCV in WSL2 but I can't access the webcam for it

yurifedoseev commented 1 year ago

I'm in the same situation, lsusb shows my built-in webcam thanks to usbipd, but there is no device in /dev/video. Have you found a solution?

Yes, the solution is described here https://github.com/Katzeee/Notes/blob/master/about-programing/wsl2-using-usb.md You need to rebuild a kernel for enabling necessary drivers. It sounds complicated but actually it's not that bad. Just follow carefully all steps from the instruction. The video quality of /dev/video0 is not so good (maybe I miss some drivers) but at least it works and allows to develop my app

Hvaheterdu commented 1 year ago

If anybody is still wondering about this issue, I followed this tutorial for rebuilding the kernel https://www.youtube.com/watch?v=t_YnACEPmrM.

I have permission issues when I try to run guvcview, which have not been able to resolve for some time now, but I have read that this solution has worked for others.

oriaj3 commented 1 year ago

Me ha ocurrido lo mi

Si alguien todavía se pregunta sobre este problema, seguí este tutorial para reconstruir el kernel https://www.youtube.com/watch?v=t_YnACEPmrM .

Tengo problemas de permisos cuando trato de ejecutar guvcview, que no he podido resolver desde hace algún tiempo, pero he leído que esta solución ha funcionado para otros.

Me ha ocurrido lo mismo, logro tener un dispositivo /dev/video0, pero no puedo acceder.

yurifedoseev commented 1 year ago

You can run chown command for solving permission issues sudo chown -R <user>:<user> /dev/video0 where <user> is your user name

Hvaheterdu commented 1 year ago

Hello,

I have tried it multiple times. I have changed the user from root to my <user>, changed the group from root to video, and ran guvcview with and without sudo but it always complains about permission, and the guvcview windows says "Guvcview error, no video device found". I can give provide some output and screenshots if that is preferred.

I have also tried to use cheese, and cheese says "no video device", too. I have checked that my webcam has Linux support and according to other people, the web camera that I use has worked for them (Logitech C615).

Hvaheterdu commented 1 year ago

Suddenly, guvcview found my camera, but now it says "V4L2_CORE: Could not grab image (select timeout): Resource temporarily unavailable"

phuoctan4141 commented 1 year ago

Suddenly, guvcview found my camera, but now it says "V4L2_CORE: Could not grab image (select timeout): Resource temporarily unavailable"

Here is a several problems, gucvcview and more camera app can't use webcam because they're not find V4L2. But you could use opencv to fix it. Such as in python: camera = cv2.VideoCapture(0, cv2.CAP_V4L2) // if not CAP_V4L2, not open cam camera.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')) // if not this line -> (select timeout)

https://github.com/phuoctan4141/WSL/blob/main/Connect%20USB%20devices/USB%20Camera.md

Hvaheterdu commented 1 year ago

Here is a several problems, gucvcview and more camera app can't use webcam because they're not find V4L2. But you could use opencv to fix it. Such as in python: camera = cv2.VideoCapture(0, cv2.CAP_V4L2) // if not CAP_V4L2, not open cam camera.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')) // if not this line -> (select timeout)

https://github.com/phuoctan4141/WSL/blob/main/Connect%20USB%20devices/USB%20Camera.md

I was able to make guvcview work. I just had to reduce the webcam resolution. Now it works perfectly with both guvcview, ROS and OpenCV.

phuoctan4141 commented 1 year ago

I was able to make guvcview work. I just had to reduce the webcam resolution. Now it works perfectly with both guvcview, ROS and OpenCV.

This is a good work. And I am going to try it, right now. Thank for your feedback.

tomneo2004 commented 2 months ago

Here is a several problems, gucvcview and more camera app can't use webcam because they're not find V4L2. But you could use opencv to fix it. Such as in python: camera = cv2.VideoCapture(0, cv2.CAP_V4L2) // if not CAP_V4L2, not open cam camera.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')) // if not this line -> (select timeout) https://github.com/phuoctan4141/WSL/blob/main/Connect%20USB%20devices/USB%20Camera.md

I was able to make guvcview work. I just had to reduce the webcam resolution. Now it works perfectly with both guvcview, ROS and OpenCV.

Do you know why it has to be in low resolution and low fps in order to make it work?

Hvaheterdu commented 2 months ago

Here is a several problems, gucvcview and more camera app can't use webcam because they're not find V4L2. But you could use opencv to fix it. Such as in python: camera = cv2.VideoCapture(0, cv2.CAP_V4L2) // if not CAP_V4L2, not open cam camera.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')) // if not this line -> (select timeout) https://github.com/phuoctan4141/WSL/blob/main/Connect%20USB%20devices/USB%20Camera.md

I was able to make guvcview work. I just had to reduce the webcam resolution. Now it works perfectly with both guvcview, ROS and OpenCV.

Do you know why it has to be in low resolution and low fps in order to make it work?

I am sorry, I have no idea. I only used it as a test for my master thesis, so I did not dive further into the cause

yurifedoseev commented 1 month ago

Do you know why it has to be in low resolution and low fps in order to make it work?

Recently I've reinstalled Windows11 Pro with WSL2 with Ubuntu 24.04 LTS. Surprisingly the camera started working well with enough FPS and high resolution