我在 bigflake.com/mediacodec 中遵循 DecodeEditEncodeTest.java 的示例 我的应用程序中唯一的区别是我解码了一个真实的视频文件(而不是内存中的块数据),并编码为一个真实的视频文件(而不是内存中的块数据)
日志显示在执行 swapBuffers 时发生错误。
03-22 10:54:51.111: D/ExtractMpegFramesTest(5375): decoder output format changed: {height=240, what=1869968451, color-format=2141391875, slice-height=256, crop-left=0, width=320, crop-bottom=239, crop-top=0, mime=video/raw, stride=384, crop-right=319}
03-22 10:54:51.121: I/ExtractMpegFramesTest(5375): encoder.dequeueOutputBuffer(info_encoder, = 0
03-22 10:54:51.121: D/ExtractMpegFramesTest(5375): no output from encoder available
03-22 10:54:51.121: D/ExtractMpegFramesTest(5375): surface decoder given buffer 0 (size=147456)
03-22 10:54:51.121: D/OutputSurface(5375): new frame available
03-22 10:54:51.121: D/ExtractMpegFramesTest(5375): awaiting frame
03-22 10:54:51.131: D/ExtractMpegFramesTest(5375): swapBuffers
03-22 10:54:51.131: W/Adreno-EGL(5375): <qeglDrvAPI_eglSwapBuffers:3526>: EGL_BAD_SURFACE
03-22 10:54:51.131: E/InputSurface(5375): eglSwapBuffers: EGL error: 0x300d
从错误信息来看,什么样的可能性可以对错误负责?
[更新 1] 在我的代码的原始版本中,我使用所需的参数设置了编码器。现在我使用来自 DecodeEditEncodeTest.java 的相同代码来确定参数。代码如下:
MediaFormat inputFormat = extractor.getTrackFormat(trackIndex);
// ...
outputFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
outputFormat.setInteger(MediaFormat.KEY_BIT_RATE, inputFormat.getInteger(MediaFormat.KEY_BIT_RATE));
outputFormat.setInteger(MediaFormat.KEY_FRAME_RATE, inputFormat.getInteger(MediaFormat.KEY_FRAME_RATE));
outputFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, inputFormat.getInteger(MediaFormat.KEY_I_FRAME_INTERVAL));
当程序执行 inputFormat.getInteger(MediaFormat.KEY_BIT_RATE) 时,它简单地退出,进入 finally 块。它不能被“catch”捕获,所以我无法打印出错误信息。
[更新 2] 好的,我找到了原因。未正确创建 outputSurface。[Update 1] 中的问题仍然成立。