Guys, I’m trying to capture video using my webCam and have it rendered in my scene.
I’m using Linux and the texture that my camera captures is YUYV. However I believe that I must transform it into RGB32.
I can do this rendering on Android and Windows, but when it is for me to test on Linux, the screen is completely dark and I get 1 Warning and 1 Error.
Logs:
Warning:
YUYV unavailable - falling back to RGB32
UnityEngine.WebCamTexturePlay()
ERROR:
No usable formats available!
UnityEngine.WebCamTexturePlay()
What the message it telling you is that Unity is first asking the webcam to produce YUYV images (aka YUV 4:2:2) - a common format for webcams - and Unity would then convert to RGB32 internally. In your case, the webcam doesn’t seem to support YUYV so we take our chances and ask RGB32 directly, which your webcam also doesn’t seem to support. So it means the 2 formats for which there is a known conversion path in Unity are not working, therefore there is nothing to do on your part, conversion-wise.
But maybe it’s a setup issue.
On Linux, Unity uses Video For Linux 2 (v4l2) for webcam support. So the first thing would be to make sure that this webcam is indeed supported on Linux. You can see if the dmesg command reveals information about what the device is and whether it usable (you can use this for tips on how to find out: Enabling Support for Your (Webcam) Hardware in Linux).
Assuming the webcam is supported, you can then see what image formats are actually supported by the webcam. Another command-line tool, ffmpeg, lets you inspect this. Look at the linux section in here for how to query this: Capture/Webcam – FFmpeg. If it turns out it uses formats that Unity doesn’t support yet, we’ll have to see if this can be added to a future version, or if maybe the linux driver for this webcam can be improved/updated to support one of the formats supported by Unity.
It could also be that it’s the specific combination of frame rate and resolution that you’re asking for which is not supported by the device. So if the device appears to be supported on your machine and the reported formats include YUYV, then see if you can use one of the listed supported resolutions reported by ffmpeg using the commands given in the link I provided above.
If nothing helps, you can give it a try with a different camera if you happen to have other devices available. You can also see if this webcam is supported by other applications on Linux. If it is, maybe we can learn something by inspecting what other apps are doing (maybe by looking at documentation, logs or config panels).
Well hello, I apologize for the delay in answering some results of other tests: D And I also start by thanking you for your help!
I checked here if the pixel format of my device seemed to be compatible, so…
This is the pixel format of my device, so I think it is not compatible with Unity, but it does work in other applications like Cheers, it appears and is rendered.
However, I asked a friend of mine to test the application he was doing on his webcam, here the print he sent me from the pixel formats of his device, and it is the same pixel format that Unity asks for.
In my code I also forced the resolution to be 1280x720 and I also requested 10 frames, however in his system it was also not possible to render the webcam video yet: / Maybe I’m taking the capture of Index 1 which is MJPG … Honestly still do not know…
So I still haven’t figured out what’s going on, I can’t keep doing a lot of tests for not having a compatible device. In case I can find what was the problem, I come in this post to make an edit and report: D
Thanks for reporting back. Indeed, the YUV 4:2:0 format, although fairly common for video devices, is currently not supported by Unity. I’d be curious to know what is the brand and model of the device so we know what to use if we ever want to work on supporting this format.
In the mean time, you’ll have to find a webcam that supports the YUYV format like your friend’s device does. If you want to experiment with this, I suggest first not forcing any frame rate or resolution. At least you will know if things work with the default resolution/frame rate. As for choosing the format, this is not a control you have so Unity will currently always choose YUYV by default.
Let us know if you can’t seem to get things going; and you can always share some code here or file a bug so that we can test internally that the exact usage you’re making is indeed correct and in working order.
Today I run into an similar issue. I develop on Windows and everything worked fine. Now testing the runtime on a linux machine and the webcam does not play.
The webcam model is: Razer KIYO X
Unity 2023.3.15
With the command: v4l2-ctl -d /dev/video0 --list-formats-ext
I get:
So in my case I want a high resolution, which in this case uses MJPG. But I can’t access. The only way I get a texture is to request a 640x… so it seem only to use the [1] device.
And before some advices to switch the camera: the camera is part of a “scanner” implemented in 3D print with microcontroller and buttons… so no. It will go live this month and not time for hardware changes.
Any chance that Unity also support MJPG under Linux? Or other ideas?