yuvToMat icon indicating copy to clipboard operation
yuvToMat copied to clipboard

UnsupportedImageFormatException

Open gordinmitya opened this issue 5 years ago • 6 comments

Yuv format is not supported: Yuv(resource=androidx.camera.core.SettableImageProxy@f251aa8, width=864, height=480, y=Plane(buffer=java.nio.DirectByteBuffer[pos=0 lim=430048 cap=430048], pixelStride=1, rowStride=896), u=Plane(buffer=java.nio.DirectByteBuffer[pos=0 lim=215007 cap=215007], pixelStride=2, rowStride=896), v=Plane(buffer=java.nio.DirectByteBuffer[pos=0 lim=215007 cap=215007], pixelStride=2, rowStride=896))

Hello, can you suggest what is the possible cause for this error? I noticed strange values width = 864 but rowStride = 896, may be this is the reason.

Sony Xperia XZ3 Black (H9436)

gordinmitya avatar Apr 08 '20 15:04 gordinmitya

@sellmair can you provide some info about these lines:

operator fun YuvImage.Factory.invoke(yuv: Yuv): YuvImage {
    // YuvImage.kt
    if (yuv.y.pixelStride != 1 || yuv.y.rowStride != yuv.width) { // <-- here
        throw UnsupportedImageFormatException(yuv)

// Yuv+defrag.kt
fun Yuv.defrag(): Yuv {
    val start = System.currentTimeMillis()

    require(y.pixelStride == 1)
    require(y.rowStride == width) // <--- and here

In documentation it's not stated that y.rowStride == width is always guaranteed. Why don't we just remove them and let defragPlanePadding do the job?

gordinmitya avatar Apr 09 '20 21:04 gordinmitya

Thanks for creating the issue, I have exactly the same problem using a Google Pixel 2.

com.quickbirdstudios.yuv2mat.UnsupportedImageFormatException: Yuv format is not supported: Yuv(resource=android.media.ImageReader$SurfaceImage@691a964, width=1440, height=1080, y=Plane(buffer=java.nio.DirectByteBuffer[pos=0 lim=1589728 cap=1589728], pixelStride=1, rowStride=1472), u=Plane(buffer=java.nio.DirectByteBuffer[pos=0 lim=794847 cap=794847], pixelStride=2, rowStride=1472), v=Plane(buffer=java.nio.DirectByteBuffer[pos=0 lim=794847 cap=794847], pixelStride=2, rowStride=1472))
        at com.quickbirdstudios.yuv2mat.YuvImageKt.invoke(YuvImage.kt:121)
        at com.quickbirdstudios.yuv2mat.YuvImageKt.invoke(YuvImage.kt:111)
        at com.quickbirdstudios.yuv2mat.Image_toMatKt.rgb(Image+toMat.kt:20)
        at com.quickbirdstudios.yuv2mat.Yuv$Companion.rgb(Yuv.kt:57)

m-rm avatar Apr 14 '20 09:04 m-rm

@m-rm I fixed it with commenting two lines I mentioned above

But that's not the best fix, because it will move all the pixels from NV21 format to YUV420. I'm going to create more efficient library – will post update here.

gordinmitya avatar Apr 14 '20 10:04 gordinmitya

you tried the camera2 API ?

LiorA1 avatar Apr 27 '20 22:04 LiorA1

with camera api 1 we don't need that – there's ready to use byte[]

gordinmitya avatar Apr 28 '20 19:04 gordinmitya

@LiorA1 @m-rm made a correct implementation with unit tests, demo app, benchmarks https://github.com/gordinmitya/yuv2buf

gordinmitya avatar Sep 24 '20 17:09 gordinmitya