Home > Software design >  How to concat three YUV buffers to one array?
How to concat three YUV buffers to one array?

Time:01-16

I'm working with Android SDK for IoT camera. I want to implement taking snapshots from the camera and save it to the external storage. SDK provides a method for that which takes absoluteFilePath as a parameter.

int snapshot(String absoluteFilePath, Context context, OperationDelegateCallBack callBack);

Unfortunately because of scope storage introduced in Android 10 this method is not working. There is info that If I want to use scope storage I need to implement this feature by myself. In this case, I need to get raw frame data in YUV420SP (NV21) format. SDK provides callback for that:

fun onReceiveFrameYUVData(
            sessionId: Int,
            y: ByteBuffer,
            u: ByteBuffer,
            v: ByteBuffer,
            videoFrameInfo: TuyaVideoFrameInfo?,
            camera: Any?,
        )

I would like to use YuvImage class from android graphics package to convert this image to JPEG (it provides method compressToJpeg). Constructor of that class takes only a single byte array as a parameter. Callback from SDK provides YUV components as separate buffers. How should I concat those three buffers into one array to use YuvImage class?

BTW Is this the proper approach or maybe should I use something else?

SDK documentation: https://developer.tuya.com/en/docs/app-development/avfunction?id=Ka6nuvucjujar#title-3-Video screenshots

CodePudding user response:

Unfortunately because of scope storage introduced in Android 10 this method is not working.

Of course it still works if you use a normal writable and readable full path.

For Android 10 you dont have to change your usual path. (I do not understand that you have any problem there).

For Android 11 use public image directories like DCIM and Pictures.

  • Related