How to real-timely render Image Data(YUV420SP) decoded by MediaCodec to SurfaceView on Android?

给你一囗甜甜゛ 提交于 2019-12-12 05:05:19

问题


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];
                                    }
                                }

回答1:


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.



来源:https://stackoverflow.com/questions/39143526/how-to-real-timely-render-image-datayuv420sp-decoded-by-mediacodec-to-surfacev

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!