mAx*_*mAx 4 android textures android-mediacodec
I am referring to this excellent example of how to encode the preview frames of the camera directly into an mp4 file: http://bigflake.com/mediacodec/CameraToMpegTest.java.txt
I have adopted the code in the way that I also would like to render the preview image on the screen. Therefore I got something like a GLTextureView with its own EGLContext. This Context is then used as shared EGLContext when I create the EGLContext for the encoder rendering:
mEGLContext = EGL14.eglCreateContext(mEGLDisplay, configs[0], sharedContext == null ? EGL14.EGL_NO_CONTEXT : sharedContext,
attrib_list, 0);
Run Code Online (Sandbox Code Playgroud)
In my render-loop I followed the tip of fadden... for every frame I do the following:
This looks something like that:
mFrameWatcher.awaitNewImage();
mSurfaceTexture.updateTexImage();
_textureView.getEGLManager().makeCurrent();
_textureView.requestRender();
mInputSurface.makeCurrent();
mInputSurface.requestRender();
Run Code Online (Sandbox Code Playgroud)
This worked well while I tested it only on my Nexus 4 with Android 4.3.
然而,由于我使用 Android 4.4 获得了新的 Nexus 5,编码器每秒只能从 SurfaceTexture 获取 2 个不同的帧...但是这 2 个帧是重复绘制的...所以他对同一帧编码了 15 次。尽管帧以每秒 30 个不同的帧的速度正确渲染到我的 GLTextureView 中。我首先认为这可能是 Nexus 5 的问题 - 所以我将另一台 Nexus 4 更新到 Android 4.4...但现在 Nexus 4 上也是一样。
我玩了一下 - 最后我能够通过在切换 SurfaceTexture 时将 SurfaceTexture 分离并重新附加到不同的上下文来解决问题。这看起来像这样:
mFrameWatcher.awaitNewImage();
mSurfaceTexture.updateTexImage();
_textureView.getEGLManager().makeCurrent();
_textureView.requestRender();
mSurfaceTexture.detachFromGLContext();
mInputSurface.makeCurrent();
mSurfaceTexture.attachToGLContext(_textureViewRenderer.getTextureId());
mInputSurface.requestRender();
mSurfaceTexture.detachFromGLContext();
_textureView.getEGLManager().makeCurrent();
mSurfaceTexture.attachToGLContext(_textureViewRenderer.getTextureId());
Run Code Online (Sandbox Code Playgroud)
我现在的问题是:这是正确的方法吗?老实说,我认为当我使用共享上下文时,不需要重新附加 SurfaceTexture。此外,重新附加需要相当长的时间...每帧 3-6 毫秒,窥视 12 毫秒,这可以更好地用于渲染。我在这里做/理解错误吗?为什么它在 Nexus 4 4.3 上运行得非常顺利,无需重新连接 SurfaceTexture?
看来这实际上与这个问题是同一个问题。我在那里放了一些细节;简而言之,您应该能够通过取消绑定和重新绑定纹理来修复它,这本质上就是您对尴尬的附加/分离序列所做的事情。
在我的代码中,我可以通过更改以下内容来修复它:
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID);
Run Code Online (Sandbox Code Playgroud)
对此:
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0);
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID);
Run Code Online (Sandbox Code Playgroud)
在我的纹理渲染器中。我稍后会更新 bigflake 示例。
| 归档时间: |
|
| 查看次数: |
5477 次 |
| 最近记录: |