0

MediaCodec has a limitation FPS of decoding, I want to break that, so I need to render frames by myself, instead of internal feature of MediaCodec.

I assume that only RGB565 can be render to SurfaceView on Android platform. I've been searching for many solutions of YUV420->RGB565 on Android, but all solutions need separated Y U V data, but separating YUV420SP data into Y U V would cost much time.

How do i fix that?

Thanks for all who helps.

@Codo

                                if(colorFmt == 21) {
                                int nSize = bufferInfo.size / 6;
                                byte[] buf = new byte[bufferInfo.size];
                                byte[] y = new byte[nSize * 4];
                                byte[] u = new byte[nSize];
                                byte[] v = new byte[nSize];
                                ByteBuffer decoded = mc.getOutputBuffer(outputBufferIndex);
                                if(decoded != null) {
                                    decoded.get(buf);
                                    System.arraycopy(buf, 0, y, 0, nSize * 4);
                                    for(int i = 0; i < nSize; ++i) {
                                        u[i] = buf[nSize*4 + i*2];
                                        v[i] = buf[nSize*4 + i*2 + 1];
                                    }
                                }
  • Why do you think separating YUV420SP into YUV would cost a lot of time? Compared to any media decoding and compared even to the YUV to RGB conversion, it's a trivial and inexpensive step. – Codo Aug 25 '16 at 11:09
  • @Codo I've tried that in java. Code was posted in the desc of question. – Herlin Drew Aug 26 '16 at 02:53
  • If you want to improve the speed of this code, you need to first analyze where most of the time is spent. But the low hanging fruit is probably to get rid of the multiplications within the for-loop. – Codo Aug 26 '16 at 06:28
  • @Codo you're right, much thanks to you first. Multiplications costs lot of time. I re-coded and found that cost of this part reduced to 2000 ms from 5000 ms. But this is not good enough for my application... – Herlin Drew Aug 26 '16 at 06:53

1 Answers1

0

You don't need to produce RGB for display. You can use OpenGL with an appropriate shader instead, this saves a lot of time.

But if you really want to convert NV21 frames to RGB as fast as possible, consider renderscript.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307