繁体   English   中英

调用 mediaCodec.configure 时手机崩溃,出现错误 MediaCodec$CodecException: Error 0x80001001

[英]Phone crashes when calling mediaCodec.configure with error MediaCodec$CodecException: Error 0x80001001

我正在开发的应用程序通过 Surface 从相机获取视频并将其编码为视频/avc (H264) 我正在成功地做到这一点并且它在 galaxy Note 10+ 等手机上运行良好但在小米 note 10s 等手机上运行良好一部新手机 我遇到了这个问题。 这是我在做什么:

  1. 创建格式:
    format = MediaFormat.createVideoFormat(
        H264, videoWidth, videoHeight
        ).apply {

        setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 0)
        setInteger(MediaFormat.KEY_BIT_RATE, bitrate)
        setInteger(MediaFormat.KEY_FRAME_RATE, videoFrameRate)
        setInteger(
            MediaFormat.KEY_COLOR_FORMAT,
            CodecCapabilities.COLOR_FormatSurface
        )
        setFloat(MediaFormat.KEY_I_FRAME_INTERVAL, 1f)
    }```

  1. 然后创建编码器名称:
    val encoderName = MediaCodecList(
        MediaCodecList.ALL_CODECS
    ).findEncoderForFormat(format) //using the format I shared in the first step
  1. 然后创建:

codec = MediaCodec.createByCodecName(encoderName)

Then.setCallback(callback) //不重要,因为我们不会做到这一点,它会在此之前崩溃。

4. 这是它崩溃的地方。 codec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE) //CRASH => MediaCodec$CodecException: Error 0x80001001

  1. rest
codec.setInputSurface(surface)
codec.start()

我怀疑

    setInteger(
        MediaFormat.KEY_COLOR_FORMAT,
        CodecCapabilities.COLOR_FormatSurface
    ) //I tried changing the value and completely removing this setInteger, no luck :/

错误0x80001001也称为OMX_ErrorUndefined表示:“出现错误,但无法确定错误原因”。

此错误的最可能原因是资源不足。 例如,如果您尝试配置硬件编解码器但目前没有足够的图形 memory 可用,就会发生这种情况。

建议 1:确保在使用完编解码器后释放它们。 您需要检查所有代码路径。

建议 2:知道这可能发生,您可以过滤MediaCodecList ,保留所有支持给定格式的编码器。 然后将configure()调用包装在try / catch块中。 并且,如果调用失败,请尝试编解码器列表中的下一个选项。

请注意,在大多数设备上,至少有两种H264编解码器:硬件编解码器和软件编解码器。 前者性能更好,后者更具弹性。

暂无
暂无

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

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