如何在Android上将MediaCodec解码的图像数据(YUV420SP)实时渲染到SurfaceView? [英] How to real-timely render Image Data(YUV420SP) decoded by MediaCodec to SurfaceView on Android?

查看:624
本文介绍了如何在Android上将MediaCodec解码的图像数据(YUV420SP)实时渲染到SurfaceView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MediaCodec具有解码的FPS限制,我想打破这一点,因此我需要自己渲染帧,而不是MediaCodec的内部功能.

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.

我假设只能将RGB565渲染到Android平台上的SurfaceView. 我一直在寻找Android上YUV420-> RGB565的许多解决方案,但是所有解决方案都需要分隔Y U V数据,但是将YUV420SP数据分隔为Y U V会花费很多时间.

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.

我该如何解决?

感谢所有提供帮助的人.

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

推荐答案

您无需产生用于显示的RGB.您可以将OpenGL与适当的着色器一起使用,这样可以节省大量时间.

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

但是,如果您真的想尽快将NV21帧转换为RGB,请考虑渲染脚本.

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

这篇关于如何在Android上将MediaCodec解码的图像数据(YUV420SP)实时渲染到SurfaceView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆