使用GLSurfaceview的媒体编解码器和渲染,OnDrawFrame的优化 [英] Media Codec and Rendering using GLSurfaceview, Optimization for OnDrawFrame

查看:516
本文介绍了使用GLSurfaceview的媒体编解码器和渲染,OnDrawFrame的优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用媒体编解码器对来自相机的帧进行编码,并使用gl曲面视图对其进行渲染.

I am using media codec for encoding frame coming from camera and render it using gl surface view.

我的ondrawframe看起来像这样

my ondrawframe looks like this

public void onDrawFrame(GL10 unused)
{
        float[] mtx = new float[16];
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
        surface.updateTexImage();
        surface.getTransformMatrix(mtx); 

        mDirectVideo.draw(surface);
        saveRenderState();

        delegate.mInputSurface.makeCurrent();
        mDirectVideo.draw(surface);
        delegate.swapBuffers();
        restoreRenderState();

}

因此,这里我们执行两次Draw(surface),这将渲染到曲面.这会增加系统开销.有什么地方我只能做一次Ondraw吗?使用着色器两次是昂贵的操作 有什么方法可以在渲染器和编码器之间共享曲面?

So here we are doing Draw(surface) two times which will render to surface. This will make overhead in system. Is there any where i can do Ondraw once only ? two times using shadder is costly operation Is there any way we can share the surfaces between render and encoder?

推荐答案

如果您的draw()函数很昂贵-除了使视频帧模糊化之外,您还渲染了复杂的场景-您可以使用以下方式渲染为纹理FBO,然后将纹理两次涂抹.如果您的draw()主要只是视频纹理模糊,那么您将无法使其更快.

If your draw() function is expensive -- you're rendering a complex scene in addition to blitting the video frame -- you can render to a texture using an FBO, and then just blit that texture twice. If your draw() is primarily just the video texture blit, then you can't make it any faster.

最重要的是,您要渲染到两个不同的表面,并且目前(Android 4.4)无法将相同的缓冲区发送给两个不同的使用者.最新设备上的硬件应该没有问题.

The bottom line is that you're rendering to two different surfaces, and there's currently (Android 4.4) no way to send the same buffer to two different consumers. The hardware on recent devices should have no trouble keeping up.

(无论如何,渲染屏幕和编码后的视频在某种程度上都受到限制,除非您正在录制屏幕,并希望显示器的尺寸和视频的尺寸完全相同.通常,将屏幕上的显示器放到屏幕上很方便.用户界面,而编码后的视频与相机发出的内容匹配.)

(Rendering the screen and encoded video is somewhat limiting anyway, unless you're recording the screen and so want the display size and video size to be exactly the same. It's usually convenient to have the on-screen display fit into the UI, while the encoded video matches what's coming out of the camera.)

顺便说一句,请注意此问题.

更新: Grafika 现在包括使用+进行绘图和录制的示例两种方法(绘制两次,绘制到FBO并blit).参见RecordFBOActivity.

Update: Grafika now includes an example of drawing + recording using both methods (draw twice, draw to FBO and blit). See RecordFBOActivity.

这篇关于使用GLSurfaceview的媒体编解码器和渲染,OnDrawFrame的优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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