首发:成功解决MediaCodec中decoder超过720出错的问题

  吾有两个安卓代码,用于安卓MediaCodec测试,非常完善:

  • MediaCodec。对安卓的MediaCodec进行了封装,使用非常简单。
  • CodecTest。自编自解。可以任意改变分辨率。

  然而,有一个怪事,解码超过720时即卡死。今天网上查找范例,找到了一个能够在720解码的范例:

https://github.com/pingu342/android-app-mediacodectest

  区别在哪里?吾将decoder部分分离出来,发现多了一个csd0参数。吾将此参数打印出来,然后整合到自己的代码中,终于能够正确运行了。大体代码如下:

    private final byte[] csd0 = 
        {
            0x0, 0x0, 0x0, 0x1, 0x67, 0x42, 0x0, 0x29, (byte)0x8d, (byte)0x8d, 0x40, 0x28, 0x2, (byte)0xdd, 0x0, (byte)0xf0, (byte)0x88, 0x45, 0x38,
            0x0, 0x0, 0x0, 0x1, 0x68, (byte)0xca, 0x43, (byte)0xc8 
        };


    decoder = MediaCodec.createDecoderByType("video/avc");
    MediaFormat format = MediaFormat.createVideoFormat("video/avc", Width, Height);
    format.setByteBuffer("csd-0", ByteBuffer.wrap(csd0));
    decoder.configure(
                    format,
                    mSurface,
                    null,
                    0
                    );
    decoder.start();

  吾有完整的代码运行范例,需要的朋友自行参考:

https://github.com/quantum6/Android-Mediacodec

https://github.com/quantum6/Android-CodecTest

发布了2677 篇原创文章 · 获赞 362 · 访问量 215万+

猜你喜欢

转载自blog.csdn.net/quantum7/article/details/105607318