如何理解 MediaCodec 的用户界面以提高编解码性能? [英] How to understand MediaCodec's user surface to improve codec performance?

查看:30
本文介绍了如何理解 MediaCodec 的用户界面以提高编解码性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mediacodec 的官方文档说:

The mediacodec's official document said:

数据类型编解码器对三种数据进行操作:压缩数据、原始音频数据和原始视频数据.所有三种数据都可以使用 ByteBuffers 进行处理,但您应该使用 Surface 处理原始视频数据以提高编解码器性能.Surface 使用原生视频缓冲区,无需将它们映射或复制到 ByteBuffers;因此,它的效率要高得多.使用 Surface 时,您通常无法访问原始视频数据,但您可以使用 ImageReader 类访问不安全的解码(原始)视频帧.这可能仍然比使用 ByteBuffers 更有效,因为一些本机缓冲区可能会映射到直接的 ByteBuffers.使用 ByteBuffer 模式时,您可以使用 Image 类和 getInput/OutputImage(int) 访问原始视频帧.

Data Types Codecs operate on three kinds of data: compressed data, raw audio data and raw video data. All three kinds of data can be processed using ByteBuffers, but you should use a Surface for raw video data to improve codec performance. Surface uses native video buffers without mapping or copying them to ByteBuffers; thus, it is much more efficient. You normally cannot access the raw video data when using a Surface, but you can use the ImageReader class to access unsecured decoded (raw) video frames. This may still be more efficient than using ByteBuffers, as some native buffers may be mapped into direct ByteBuffers. When using ByteBuffer mode, you can access raw video frames using the Image class and getInput/OutputImage(int).

如何理解这一点?您应该将 Surface 用于原始视频数据以提高编解码器性能,什么是原生视频缓冲区?如何使用 Surface 提高编码或解码性能?

How to under stande this? you should use a Surface for raw video data to improve codec performance, What is native video buffers? How do I use Surface to improve encode or decode performance?

推荐答案

您可以使用编解码器的输入表面对视频帧进行编码,您可以使用 createInputSurface() 然后(如果您不使用 NDK)您可以从表面获取画布并在其上绘制帧或者您可以使用 NDK 并将帧数据复制到表面缓冲区,结果中的这两种方法都会为您提供编码的帧数据.

You can use the input surface of a codec for ecoding video frames, you can get this surface using createInputSurface() then (if you don't use NDK) you can get the canvas from the surface and draw frames on it or you can use NDK and copy frame data to the surface buffer, both of this approaches in the result will give you encoded frame data.

至于解码,您可以在 UI 中创建一些表面并使用 configure() 它将允许解码器将解码的帧渲染到表面中,这样你就不会'不需要从解码器的输出缓冲区复制解码数据,您唯一应该做的就是将 true 作为render"传递解码器的 releaseOutputBuffer() 的参数.

As for decoding you can create some surface in your UI and pass it to decoder using configure() it will allow the decoder to render a decoded frame into the surface so you won't need to copy decoded data from output buffers of decoder the only thing you should do is to pass true as "render" argument to releaseOutputBuffer() of the decoder.

这篇关于如何理解 MediaCodec 的用户界面以提高编解码性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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