alexeyvasilyev / rtsp-client-android

Lightweight RTSP client library for Android
Apache License 2.0
210 stars 54 forks source link

Decoded byetbuffer to bitmap #30

Closed sam21abc closed 2 years ago

sam21abc commented 2 years ago

I tried to get bitmap

val byteBuffer: ByteBuffer? = decoder.getInputBuffer(inIndex)

                val imageBytes = ByteArray(byteBuffer!!.remaining())
                byteBuffer!!.get(imageBytes)
                val bmp = BitmapFactory.decodeByteArray(
                    imageBytes,
                    0,
                    imageBytes.size
                )

or

bytes = ByteArray(byteBuffer.remaining())

                byteBuffer[bytes, 0, bytes.size]

                byteBuffer.clear()
                bytes = ByteArray(byteBuffer.capacity())
               byteBuffer[bytes, 0, bytes.size]

                val bmp: Bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size)

but every time bitmap returns null. is there any way to get bitmap.

alexeyvasilyev commented 2 years ago

BitmapFactory creates Bitmap from byte arrays already containing bitmap RGB data. Buffers are in YUV format. The easiest way to create Bitmap is to use PixelCopy API. See how it is done at https://github.com/alexeyvasilyev/rtsp-client-android/blob/43a6b20de60683edc83aade76c2a89c8e3464088/app/src/main/java/com/alexvas/rtsp/demo/live/LiveFragment.kt#L80

sam21abc commented 2 years ago

I want generate bitmap/image from raw(h264/h265) frames. without using surface.