determine yuv pixel format in capture use.case

50 views
Skip to first unread message

Christian Günther

unread,
Nov 22, 2022, 10:31:38 AM11/22/22
to Android CameraX Discussion Group
Hi there,

I use yuv image format for image capture to avoid jpeg compression. Sadly there is no uncrompressed rgb format here. At the moment i convert therefore the yuv using renderscript. I try to migrate to libyuv with this project:
https://github.com/crow-misia/libyuv-android

Therefore i need to know the underlying pixel format that i get from camerax in the yuv buffer. In all my local tests (Galaxy S8 and Redmi Note 10 Pro) the image format reports me:
image.getFormat() == ImageFormat.YUV_420_888 --> true
nevertheless it seems that the internal format is nv21 instead of i420_8888 buffer type to get correct conversions. The the question that comes up in my mind is: "How do i robustly determine which pixel-format is really internally used, to be able to select the correct corresponding conversion function?"

best,
Christian

Kailiang Chen

unread,
Nov 22, 2022, 1:47:56 PM11/22/22
to Android CameraX Discussion Group, christian...@authentic.network
Hi Christian,

The ImageFormat.YUV_420_888 is a generic YCbCr forma, capable of describing any 4:2:0 chroma-subsampled planar or semiplanar buffer (but not fully interleaved), with 8 bits per color sample.
It only guarantees
1. that plane #0 is always Y, plane #1 is always U (Cb), and plane #2 is always V (Cr)
2. pixel stride is always 1 in yPlane.getPixelStride()
3. uPlane.getRowStride() == vPlane.getRowStride() and uPlane.getPixelStride() == vPlane.getPixelStride()

So YUV_420_888 could be nv21, nv12, I420, etc,.
To determine which pixel format is being used internally, you could refer to the code here 

Unfortunately there is no public API to determine the format yet.

Best,
Kailiang

Christian Günther

unread,
Nov 23, 2022, 4:58:18 AM11/23/22
to Android CameraX Discussion Group, kail...@google.com, Christian Günther
Thanks a lot for the clarification here.
Reply all
Reply to author
Forward
0 new messages