最近,我一直在修改Grafika的TextureMovieEncoder,以创建我在屏幕上显示的内容的记录:两个重叠的Sprite2ds。使用CameraCaptureActivity示例作为参考点,我有效地将为呈现线程创建的内容移植到TextureMovieEncoder中,但是输出在屏幕上是锯齿状的。我想我知道出了什么问题,但我不知道怎么解决:
一些代码:
private void prepareEncoder(EGLContext sharedContext, int width, int height, int bitRate,
File outputFile) {
try {
mVideoEncoder = new VideoEncoderCore(width, height, bitRate, outputFile);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
mEglCore = new EglCore(sharedContext, EglCore.FLAG_RECORDABLE);
mInputWindowSurface = new WindowSurface(mEglCore, mVideoEncoder.getInputSurface(), true);
mInputWindowSurface.makeCurrent();
textureProgram = new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT);
backgroundDrawable = new Drawable2d(Drawable2d.Prefab.RECTANGLE);
backgroundRect = new Sprite2d(backgroundDrawable);
frontDrawable = new Drawable2d(Drawable2d.Prefab.RECTANGLE);
frontRect = new Sprite2d(frontDrawable);
backgroundRect.setTexture(backTextureId);
frontRect.setTexture(frontTextureId);
updateGeometry();
}
private void handleFrameAvailable(Transform transform, long timestampNanos) {
if (VERBOSE) Log.d(TAG, "handleFrameAvailable tr=" + transform);
mVideoEncoder.drainEncoder(false);
backgroundRect.draw(textureProgram, transform.movieMatrix);
frontRect.draw(textureProgram, transform.cameraMatrix);
mInputWindowSurface.setPresentationTime(timestampNanos);
mInputWindowSurface.swapBuffers();
}我认为问题在于我对如何在WindowSurface上为VideoEncoder建立正确的投影缺乏了解。在Grafika示例中,使用了FullFrameRect,这比较容易,因为您只需使用标识矩阵将给定的纹理拉伸到表面积。但是,由于我希望创建重叠效果,所以需要使用Sprite2d。这个问题是共享的EGLContext吗?我是否需要创建一个新的视图以使其与WindowSurface大小相匹配?有点不知所措。
发布于 2014-11-15 01:18:17
原来上面的代码的功能很好。问题在于TextureEncoder与调用父级之间的交互。
我在backTextureId和frontTextureId之后初始化成员变量prepareEncoder,因此它将垃圾数据记录到输出中。
https://stackoverflow.com/questions/26866875
复制相似问题