问题描述
我正在通过MediaCodec
处理实时流,并且有一种情况,其中MediaFormat
会在中途发生变化(即:正在解码的视频的分辨率发生变化).假设我将解码器附加到Surface
以便在检测到输入流的分辨率变化后将其渲染,则在向其提供新的分辨率缓冲区(为它提供适当的新MediaFormat
)之前重新创建解码器.
I'm processing a live stream via MediaCodec
and have a scenario where the MediaFormat
changes mid-stream (ie: resolution of the video being decoded changes). Given I'm attaching the decoder to a Surface
to render it as soon as I detect the change in resolution on the incoming stream I recreate the decoder before feeding it the new resolution buffer (providing it with the proper new MediaFormat
).
我遇到了一些奇怪的错误,这些错误并没有给我太多有关可能出错的信息,例如,以新格式和相同的Surface
调用MediaCodec.configure
时:
I've been getting some weird errors which don't give me too much info as to what could be wrong, ie when calling MediaCodec.configure
with the new format and same Surface
:
android.media.MediaCodec$CodecException: Error 0xffffffea
at android.media.MediaCodec.native_configure(Native Method)
at android.media.MediaCodec.configure(MediaCodec.java:577)
提取CodecException.getDiagnosticInfo
时,它没有显示我可以真正用来理解失败原因的任何内容:android.media.MediaCodec.error_neg_22
Which when fetching the CodecException.getDiagnosticInfo
it shows nothing that I can really use to understand the reason for the failure: android.media.MediaCodec.error_neg_22
我还在日志中注意到了以下内容,发现了一些相关信息,并且想知道我是否需要对Surface
本身做一些事情(例如将其与将其交给解码器的旧解码器实例分开)新的):
I've also noted the following on the logs and found some related information and am wondering if there's something I need to do regarding the Surface
itself (like detaching it from the old instance of the decoder being giving it to the new one):
07-09 15:00:17.217 E/BufferQueueProducer( 139): [SurfaceView] connect(P): already connected (cur=3 req=3)
07-09 15:00:17.217 E/MediaCodec( 5388): native_window_api_connect returned an error: Invalid argument (-22)
07-09 15:00:17.218 E/MediaCodec( 5388): configure failed with err 0xffffffea, resetting...
推荐答案
就像调用stop()
和release()
一样,并且重新初始化我对getInputBuffers()
和getOutputBuffers()
的所有引用也能达到目的.至少我没有收到消息/异常了.现在,我只需要弄清楚Surface
参考零件,因为调整大小的流(当分辨率改变时)似乎仍然适合原始曲面尺寸,而不是针对新的分辨率调整Surface.
Looks like calling stop()
and release()
as well as reinitializing any references I had to the getInputBuffers()
and getOutputBuffers()
did the trick. At least I don't get the messages/exceptions anymore. Now I just need to figure out the Surface
reference part as it seems the resized stream (when resolution changes) is still being fit in the original surface dimensions instead of adjusting the Surface for the new resolution.
这篇关于Android MediaCodec格式/分辨率更改中期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!