将MediaCodec解码的视频帧绘制到屏幕上的最快方法? [英] Fastest way to draw a MediaCodec-decoded video frame to screen?

查看:478
本文介绍了将MediaCodec解码的视频帧绘制到屏幕上的最快方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找最快的方法来拍摄从MediaCodec解码器接收到的图像帧并将其绘制到Android设备屏幕上.重要的约束条件和解释如下:

I'm looking for the fastest way to take an image frame received from the MediaCodec decoder and draw it to the Android device screen. The important constraints and explanations are:

  1. 无法使用MediaPlayer.不允许使用中间应用程序.

  1. Cannot use MediaPlayer. No intermediate app allowed.

必须尽快将MediaCodec解码器的输出帧绘制到屏幕上(以最小化延迟).

Must draw output frames from the MediaCodec decoder to the screen as quickly as possible (minimize latency).

可用的解码器输出格式如下:
ColorFormat [0] 0x00000013 COLOR_FormatYUV420Planar
ColorFormat [1] 0x00000015 COLOR_FormatYUV420SemiPlanar
ColorFormat [2] 0x7F000001 OMX_SEC_COLOR_FormatNV12TPhysicalAddress
ColorFormat [3] 0x7FC00002 OMX_SEC_COLOR_FormatNV12Tiled

The available decoder output formats are as follows:
ColorFormat[0] 0x00000013 COLOR_FormatYUV420Planar
ColorFormat[1] 0x00000015 COLOR_FormatYUV420SemiPlanar
ColorFormat[2] 0x7F000001 OMX_SEC_COLOR_FormatNV12TPhysicalAddress
ColorFormat[3] 0x7FC00002 OMX_SEC_COLOR_FormatNV12Tiled

视频分辨率以及每个输出帧的分辨率为960x720.

The video resolution, and thus the resolution of each output frame, is 960x720.

目标平台是Galaxy Note II,该方法可以特定于该平台(例如,利用可用的硬件功能).这不需要在其他平台上运行或成为通用解决方案.

The target platform is Galaxy Note II and the approach can be specific to that platform (e.g. take advantage of available hardware functionality). This does not need to work on other platforms or be a generic solution.

一种少于66ms的方法会很好.少于33ms会很棒.我当前的方法需要80-90毫秒,这很糟糕. (因为我不想在任何特定方向上歪曲答案,所以我不会打扰描述它.)

An approach that takes less than 66ms would be good. Less than 33ms would be great. My current approach takes 80-90ms, which sucks. (I won't bother describing it since I don't want to skew the answers in any particular direction.)

推荐答案

您最好的选择是直接解码为Surface.解码为ByteBuffer会大大降低您的速度. bigflake 上的许多示例(例如ExtractMpegFramesTest)将解码器的输出发送到屏幕外的表面并使用GLES进行检查,但这是一个简单的更改,使其可以在屏幕上 SurfaceView .

Your best bet is to decode directly to a Surface. Decoding to a ByteBuffer is going to slow you down quite a bit. A number of examples on bigflake (e.g. ExtractMpegFramesTest) send the output of a decoder to an off-screen surface and examine it with GLES, but it's a simple change to make it work with an on-screen SurfaceView.

更新: Grafika 具有两个不同的基于MediaCodec的视频播放器,它们可以发送分别输出到SurfaceView和TextureView.

Update: Grafika has two different MediaCodec-based video players that send the output to SurfaceView and TextureView, respectively.

这篇关于将MediaCodec解码的视频帧绘制到屏幕上的最快方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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