简体   繁体   English

视频解码器使用MediaCodec进行配置

[英]Video decoder Configure using MediaCodec

I am trying to decode video samples using MediaCodec API. 我正在尝试使用MediaCodec API解码视频样本。 I am using surfaceView to show rendered samples. 我使用surfaceView来显示渲染的样本。 If i press home button, app going into pause state and surface destroyed. 如果我按下主页按钮,应用程序进入暂停状态并且表面被破坏。 When i coming back to resume state, new surfaceView reference is creating, but decoder is unable to pump samples on surfaceView. 当我回到恢复状态时,新的surfaceView参考正在创建,但解码器无法在surfaceView上抽样。 so screen appearing as black. 因此屏幕显示为黑色。 video configure: videoDecoder.configure(format, surface, null, 0); 视频配置:videoDecoder.configure(format,surface,null,0); So how can i reconfigure videoDecoder in above statement. 那么如何在上面的语句中重新配置videoDecoder。 It is similar to the following problem How to keep decoding alive during screen orientation? 它类似于以下问题如何在屏幕方向期间保持解码活动?

The MediaCodec API does not currently (API 19) provide a way to replace the output Surface . MediaCodec API目前没有(API 19)提供替换输出Surface

As in the other question you refer to, I think the way to deal with this will be to decode to a Surface that isn't tied to the view hierarchy (and, hence, doesn't get torn down when the Activity is destroyed). 正如你提到的另一个问题,我认为处理这个问题的方法是解码到一个没有绑定到视图层次结构的Surface (因此,当Activity被销毁时不会被拆除) 。

If you direct the output of the MediaCodec to a SurfaceTexture , you can then render that texture onto the SurfaceView . 如果将MediaCodec的输出SurfaceTextureSurfaceTexture ,则可以将该纹理渲染到SurfaceView This will require a bit of GLES code. 这将需要一些GLES代码。 You can find the necessary pieces in the Grafika sources , but there isn't currently a full implementation of what you want (eg PlayMovieActivity decodes video to a SurfaceTexture , but that ST is part of a TextureView , which will get torn down). 您可以在Grafika源中找到必要的部分,但目前还没有完全实现您想要的内容(例如, PlayMovieActivity视频解码为SurfaceTexture ,但该ST是TextureView一部分,它将被拆除)。

The additional rendering step will increase the GPU load, and won't work for DRM-protected video. 额外的渲染步骤将增加GPU负载,并且不适用于受DRM保护的视频。 For most devices and apps this won't matter. 对于大多数设备和应用程序,这无关紧要。

See also the bigflake examples . 另请参阅bigflake示例

Update: I've added this to Grafika , with a twist. 更新:我已将此添加到格拉菲卡 ,但有一个转折点 See the "Double decode" example. 请参阅“双重解码”示例。 The output goes to a SurfaceTexture associated with a TextureView . 输出转到与SurfaceTexture关联的TextureView If the screen is rotated (or, currently, blanked by hitting the power button), decoding continues. 如果旋转屏幕(或者,当前通过按下电源按钮消隐),则继续解码。 If you leave the activity with the "back" or "home" button, decoding stops. 如果您使用“后退”或“主页”按钮退出活动,则解码将停止。 It works by retaining the SurfaceTexture , attaching it to the new TextureView . 它的工作原理是保留SurfaceTexture ,将其附加到新的TextureView

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

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