scrcpy icon indicating copy to clipboard operation
scrcpy copied to clipboard

Does scrcpy support YUYV 422 format?

Open BarleyXu opened this issue 3 years ago • 7 comments

  • [ ] I have checked that a similar feature request does not already exist.

Is your feature request related to a problem? Please describe. I use scrcpy --v4l2-sink to project screen to virtual camera. ffplay work well, but unity can not work well with the virtual camera. It seems that unity does not support YUV 420. So I want to know whether scrcpy support YUYV 422 format?

Describe the solution you'd like A clear and concise description of what you want to happen.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

BarleyXu avatar Jul 19 '22 07:07 BarleyXu

It seems that unity does not support YUV 420.

That would be surprising, that's the most common format (by far).

So I want to know whether scrcpy support YUYV 422 format?

Nope.

rom1v avatar Jul 19 '22 08:07 rom1v

@rom1v Thanks for your reply. There are some guys meet the same problem. https://forum.unity.com/threads/webcamtexture-yuyv-in-videocapture.982866/

Are there any solutions to convert YUV4:2:0 output by scrcpy to YUYV4:4:2? Looking forward to your proposal

BarleyXu avatar Jul 19 '22 08:07 BarleyXu

There are some guys meet the same problem. https://forum.unity.com/threads/webcamtexture-yuyv-in-videocapture.982866/

Indeed:

Indeed, the YUV 4:2:0 format, although fairly common for video devices, is currently not supported by Unity.

Are there any solutions to convert YUV4:2:0 output by scrcpy to YUYV4:2:2?

You could try to send 4:2:2 to V4L2 (it doubles the bandwidth, but that's probably not a problem):

diff --git a/app/src/v4l2_sink.c b/app/src/v4l2_sink.c
index 9a0011f2..e695afc9 100644
--- a/app/src/v4l2_sink.c
+++ b/app/src/v4l2_sink.c
@@ -227,7 +227,7 @@ sc_v4l2_sink_open(struct sc_v4l2_sink *vs) {
 
     ostream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
     ostream->codecpar->codec_id = encoder->id;
-    ostream->codecpar->format = AV_PIX_FMT_YUV420P;
+    ostream->codecpar->format = AV_PIX_FMT_YUV422P;
     ostream->codecpar->width = vs->frame_size.width;
     ostream->codecpar->height = vs->frame_size.height;
 

rom1v avatar Jul 19 '22 09:07 rom1v

@rom1v I rebuilt the scrcpy after change format. ffplay -i /dev/video show green screen.

BarleyXu avatar Jul 19 '22 09:07 BarleyXu

You might need to configure your v4l2-loopback device correctly: https://github.com/umlaeute/v4l2loopback#forcing-format

rom1v avatar Jul 19 '22 10:07 rom1v

For AV_PIX_FMT_YUV422P, which format I should set? what is the difference of AV_PIX_FMT_YUV422P and AV_PIX_FMT_YUYV422?

BarleyXu avatar Jul 19 '22 15:07 BarleyXu

@rom1v Hello, I really need your help. So far, I have not solve this problem. For the same virtual camera created with v4l2loopback-ctl, I tried to use the virtual camera function of OBS. The Unity player can play normally, I made the following modifications, `app/src/v4l2_sink.c:

//ostream->codecpar->format = AV_PIX_FMT_YUV420P; ostream->codecpar->format = AV_PIX_FMT_YUYV422; ` but there is a big color problem when using unity to play. I want to know the difference between the v4l2sink code in this part of scrcpy and obs-v4l2sink? Or do I need to modify other parts of the source code?

BarleyXu avatar Aug 02 '22 06:08 BarleyXu