简体   繁体   English

从 MediaCodec 将相同的视频渲染到 2 个表面

[英]Rendering same video to 2 Surfaces from a MediaCodec

MediaCodec has 2 ways of operating: you either pass a Surface for it to render to, or you read the output buffer and paint it to the screen yourself. MediaCodec 有 2 种操作方式:您可以传递一个Surface进行渲染,或者您读取 output 缓冲区并自己将其绘制到屏幕上。

In the first case, where I pass a surface: is it possible to paint the same MediaCodec decoded video to 2 surfaces?在第一种情况下,我通过一个表面:是否可以将相同的 MediaCodec 解码视频绘制到 2 个表面?

The decoding loop looks something like this:解码循环看起来像这样:

int outputBufferId = codec.dequeueOutputBuffer(…);
  if (outputBufferId >= 0) {
    //Do nothing, the MediaCodec will automatically draw to our surface
    //But how to draw to 2 surfaces?
    codec.releaseOutputBuffer(outputBufferId, …);
  } else if (outputBufferId == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
    // Subsequent data will conform to new format.
    // Can ignore if using getOutputFormat(outputBufferId)
    outputFormat = codec.getOutputFormat(); // option B
  }

The only way you're going to be able to draw to multiple surfaces at once is if you're going to use OpenGL.能够一次绘制多个表面的唯一方法是使用 OpenGL。

If you want to, I could give you a couple of suggestions.如果你愿意,我可以给你一些建议。

First, you'll need a surface backed by a surface texture.首先,您需要一个由表面纹理支持的表面。 The surface texture is where the decoder will queue decoded frames and you can retrieve it from there.表面纹理是解码器将解码帧排队的地方,您可以从那里检索它。 Once a frame is available in the surface texture, you'll use OpenGL (with multiple EGLSurface(s) connected to each surface. You can create such surface using eglCreateWindowSurface).一旦表面纹理中的框架可用,您将使用 OpenGL(每个表面连接多个 EGLSurface。您可以使用 eglCreateWindowSurface 创建这样的表面)。

Once you have your surfaces connected and a valid EGL context, just use eglMakeCurrent and pass in the EGL surface you created, one for each draw operation.一旦你连接了你的表面和一个有效的 EGL 上下文,只需使用 eglMakeCurrent 并传入你创建的 EGL 表面,每个绘制操作一个。 So eglMakeCurrent will allow you to draw on one surface at a time and you can do that for each surface you have.因此 eglMakeCurrent 将允许您一次在一个表面上绘制,并且您可以为您拥有的每个表面执行此操作。 You can generally find examples of some of these in grafika您通常可以在 grafika 中找到其中一些示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM