MediaCodec使用Surface进行编码在不同设备上会不稳定崩溃

4
我正在开发一款应用程序,通过将图形和文本应用于视频来对视频进行后期处理。我的代码基于Android CTS测试 DecodeEditEncodeTest ,并且在Nexus 4和Nexus 5(4.4)上表现良好,但是在我尝试的其他任何设备上都无法正常工作,甚至不包括Nexus 7 II on 4.4。例如,在Galaxy S3上,我会遇到以下错误:
E/ACodec(17651):  configureCodec multi window instance fail  appPid : 17651
E/ACodec(17651): [OMX.qcom.video.decoder.avc] configureCodec returning error -38
E/MediaCodec(17651): Codec reported an error. (omx error 0x80001001, internalError -38)

相关代码如下:
        MediaCodecInfo codecInfo = selectCodec(MIME_TYPE);
        if (codecInfo == null) {
            // Don't fail CTS if they don't have an AVC codec (not here, anyway).
            Log.e(TAG, "Unable to find an appropriate codec for " + MIME_TYPE);
            return false;
        }
        if (VERBOSE) Log.d(TAG, "found codec: " + codecInfo.getName());

        // We avoid the device-specific limitations on width and height by using values that
        // are multiples of 16, which all tested devices seem to be able to handle.
        MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, mWidth, mHeight);

        // Set some properties.  Failing to specify some of these can cause the MediaCodec
        // configure() call to throw an unhelpful exception.
        format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
                MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
        format.setInteger(MediaFormat.KEY_BIT_RATE, mBitRate);
        format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAME_RATE);
        format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
        if (VERBOSE) Log.d(TAG, "format: " + format);
        output.setMediaFormat(format);

        // Create a MediaCodec for the desired codec, then configure it as an encoder with
        // our desired properties.
        encoder = MediaCodec.createByCodecName(codecInfo.getName());
        encoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);

它在其他设备上以不同的方式失败; 我尝试了Nexus 7 II,G3和HTC One(其中HTC One没有失败但创建了垃圾视频)。
根据此错误,似乎系统对执行上述代码的片段感到不满,该片段使用MediaPlayer和SurfaceView显示原始视频。
我想保持此视图可见,因此我尝试重置(reset())和销毁(destroy())MediaPlayer。实际上,在Nexus 7上这使应用程序正常工作,但在G3和HTC One上仍然无法正常工作。
我需要释放其他东西吗?还是我必须销毁片段并使用不同的片段进行后期处理?

谢谢你发现了这个问题。这是在尝试设置更简单的DecodeEncodeEdit测试时犯的错误,而这个错误在我的代码中并不存在。然而,这让我想到问题可能与视频大小有关。因此,我尝试将大小强制设为720p,而不是源视频的1080p,结果出现了另一个错误,看起来更有用。它是:E/ACodec(17651): configureCodec多窗口实例失败appPid:17651 E/ACodec(17651): [OMX.qcom.video.decoder.avc] configureCodec返回错误-38 - pstoppani
我已经更新了我的原始问题。 - pstoppani
这个错误不是由AOSP源代码生成的。快速的谷歌搜索结果显示,还有其他几个实例,都出现在三星设备上,所以这可能是一个三星的问题。你在问题中提到原始代码在Nexus 7上失败了;修改后的代码也在那里失败了吗? - fadden
修改后的代码现在可以在N7上运行。 - pstoppani
我联系了一些人,但没有人给出明确的答案。这些表面是大尺寸的(>= 1080p)吗? - fadden
显示剩余4条评论
4个回答

3
答案是不要超过720p的输入和输出视频。

0

在进行视频解码的连续启动和停止时,我在压力测试期间遇到了完全相同的错误日志。

我的问题是我错过了释放视频解码器实例。之后,我就没有再遇到这个问题了。

当分辨率超过720p时,我没有遇到这个问题。


0
有时候,唯一的方法就是重新启动设备,编码器就能正常工作了。 Nexus 5.. Android 4.2.2。

0

以下步骤适用于我:

  1. 从手机上卸载测试应用程序。

  2. 在根文件夹位置打开命令提示符。

  3. cd ./android

  4. ./gradlew clean

  5. 现在运行项目。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接