在Android中,如何通过pdefined曲面到媒体codeC的编码$ P $? [英] In Android, how to pass a predefined Surface to MediaCodec for encoding?

查看:1167
本文介绍了在Android中,如何通过pdefined曲面到媒体codeC的编码$ P $?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,管理自己的GLSurfaceView,现在我想使用Android 4.3的新媒体codeC的功能,需要一个表面的输入。

I have an app that manages its own GLSurfaceView and now I want to use Android 4.3's new MediaCodec feature that takes a Surface as input.

在所有我见过的例子,表面使用媒体codec.createInputSurface(),则GL上下文被用于该表面上创建的。这种感觉整体,令人难以置信的颠覆性改造成一个code基地已经稳定。

In all the examples I've seen, the Surface is created using MediaCodec.createInputSurface(), then the GL context is created for this Surface. This feels monolithic and incredibly disruptive to retrofit into a code base that is already stable.

是否有可能使用     媒体codec.configure(格式,                          A_ predefined_Surface,                          空值,                          媒体codec.CONFIGURE_FLAG_EN code) 代替?这允许我使用媒体codeC的插件和播放和点播的方式。该媒体codec.configure()采用曲面参数的事实表明,这应该是可能的。然而,该API指出 指定在其上表面,使本德codeR输出 <一href="http://developer.android.com/reference/android/media/Media$c$cc.html#configure(android.media.MediaFormat">http://developer.android.com/reference/android/media/Media$c$cc.html#configure(android.media.MediaFormat, android.view.Surface,android.media.MediaCrypto,INT) 这是否意味着这只是针对德code 而非连接code ?如果是这样,有什么办法能让媒体codeC使用predefined表面的编码?

Is it possible to use MediaCodec.configure(format, a_predefined_Surface, null, MediaCodec.CONFIGURE_FLAG_ENCODE) instead? This allows me to use MediaCodec in a plug-and-play and on-demand way. The fact that MediaCodec.configure() takes a Surface parameter indicates that this should be possible. However, the API states that 'Specify a surface on which to render the output of this decoder' http://developer.android.com/reference/android/media/MediaCodec.html#configure(android.media.MediaFormat, android.view.Surface, android.media.MediaCrypto, int) does this mean this is only meant for decode and not encode?. If so, is there any way to make MediaCodec use a predefined Surface for encoding?

我通过在表面已与EGL_RECORDABLE_ANDROID创建设置为true,返回的GL上下文被验证为包含所需的EGL_RECORDABLE_ANDROID属性。尽管如此,媒体codec.configure()失败与无助的异常'native_window_api_connect返回了一个错误:无效的参数(-22)':

The Surface I'm passing in is already created with EGL_RECORDABLE_ANDROID set to true and the returned GL context is verified to contain the required EGL_RECORDABLE_ANDROID attribute. Despite this, MediaCodec.configure() fails with an unhelpful exception 'native_window_api_connect returned an error: Invalid argument (-22)':

I/ACodec(32383):  Now uninitialized
I/OMXClient(32383): Using client-side OMX mux.
I/ACodec(32383): [OMX.qcom.video.encoder.avc] Now Loaded
E/MediaCodec(32383): native_window_api_connect returned an error: Invalid argument (-22)
W/System.err(32383): java.lang.IllegalStateException
W/System.err(32383):    at android.media.MediaCodec.native_configure(Native Method)
W/System.err(32383):    at android.media.MediaCodec.configure(MediaCodec.java:259)
[...]
W/System.err(32383):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520)
W/System.err(32383):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)

这是从三星Galaxy S4采用Android 4.3。

This is from a Samsung Galaxy S4 with Android 4.3.

推荐答案

没有,它不这样的。输入表面必须与 createInputSurface创建()

No, it doesn't work that way. The input surface must be created with createInputSurface().

记住,表面不是数据的一个缓冲器,它的缓冲器的量,生产者和消费者的端点往往在不同的过程的一个队列。有很多移动需要被设置件。还要注意的是表面 EGLSurface 是,虽然经常一起使用,不是密切相关,两个不同的东西。

Bear in mind that a "surface" isn't a buffer of data, it's a queue of buffers for which the producer and consumer endpoints are often in different processes. There are a lot of moving pieces that need to be set up. Also note that Surface and EGLSurface are two different things that, while often used together, aren't closely related.

该API似乎块状和奇怪,因为......它。 表面的实施,改变了不少,多年来 - 曾经是远不如一般基础,所以大部分的API改变端点不被暴露。的(尚未得以确认)媒体codeC API仍在发展。

The API seems lumpy and weird because... it is. The implementation of Surface has changed quite a bit over the years -- the underpinnings used to be far less general, so most of the APIs for altering endpoints aren't exposed. The (underspecified) MediaCodec API is still evolving.

有$ P $的psenting相同的内容(摄像头preVIEW),以 GLSurfaceView 媒体codeC Grafika 。这听起来像你试图做同样的事情。 (如果没有,请更新你的问题,我会更新的答案。)

There's an example of presenting the same content (camera preview) to GLSurfaceView and MediaCodec in Grafika. It sounds like you're trying to do something similar. (If not, update your question, and I'll update the answer.)

这篇关于在Android中,如何通过pdefined曲面到媒体codeC的编码$ P $?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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