YUV to Bitmap
CompletedHello all!
I am struggling with MSDK 5.5.0 and Mavic 3M addYuvDataListener. Even MSDK 5.8 has improve streaming capabilities, I cannot currently update the applicaction.
I was wondering if anybody has been able to convert from YUV data listener data field to Bitmap. This is the code I am trying to use but it does not work. BitmapFactory.decodeByteArray always returns null:
videoDecoder = VideoDecoder(
context, videoChannels[0].videoChannelType, DecoderOutputMode.YUV_MODE, null
)
videoDecoder?.addYuvDataListener { mediaFormat, data, width, height ->
val bitmap = BitmapFactory.decodeByteArray(
data, 0, data.size
)
}
Thank you in advance.
Best regards.
-
Hello again!
I finally update to SDK v 5.8.0 :)
Now I have the problem that frames (frameData) is null. The code I am using is as follows:
private fun getFrame() {
MediaDataCenter.getInstance().cameraStreamManager.addFrameListener(
ComponentIndexType.LEFT_OR_MAIN,
ICameraStreamManager.FrameFormat.RGBA_8888,
object : ICameraStreamManager.CameraFrameListener {
override fun onFrame(
frameData: ByteArray,
offset: Int,
length: Int,
width: Int,
height: Int,
format: ICameraStreamManager.FrameFormat
) {
if (frameData != null) {
val bitmap: Bitmap = BitmapFactory.decodeByteArray(
frameData, offset, length
)
}
}
}
)
}and code fails when calling decodeByteArray.
I cannot find where the problem is and I would really appreciate if you can guide me to get the RGBA_8888 and copy to a bitmap.
I am using Mavic 3M and MSDK 5.8.0.
Thanks in advance.
Best regard.
-
“The BitmapFactory.decodeByteArray cannot directly accept YUV data. You can try using bitmap.copyPixelsFromBuffer to store YUV data into the bitmap.” We have previously discussed the method of converting YUV to a bitmap. You can refer to the above content. I have not encountered a situation where addFrameListener pushes null. Do you have a way to consistently trigger this issue? Can you provide us with a method?
Please sign in to leave a comment.
Comments
13 comments