IllegalStateException at MediaCodec.dequeInputBuffer / dequeOutputBuffer

99封情书 提交于 2019-12-03 05:39:05

First, I don't expect the emulator codecs to work at all. If they do work, I'm pleasantly surprised. This outlook helps me avoid disappointment.

Second, my guess would be that the size of the frame being passed into the encoder is wrong. You're taking an RGBA frame decoded from a Bitmap and stuffing it into a YUV 420 buffer. This doesn't work. The amount of data you're passing in should be exactly width * height * 1.5 bytes for YUV420 (where stride==width and the planes are packed together). On an Android 4.3+ device this behavior is confirmed via the CTS EncodeDecodeTest; older devices are not guaranteed to work.

Also, you're setting the format to COLOR_FormatYUV420SemiPlanar; in general you can't assume that. You need to query the codec for the list of supported formats, determine whether the input needs to be planar or semi-planar, and then format the buffer input accordingly. The buffer-to-buffer and buffer-to-surface tests in the EncodeDecodeTest demonstrate how to do this.

Alternatively, on Android 4.3 and later, you can upload the bitmap to a texture, configure the codec for Surface input, and render the texture with GLES (which lets the hardware take care of any scaling issues if the bitmap size doesn't match your video size). This takes a lot more code though.

Having said all that, the MediaCodec diagnostics are generally useless, so this is all guesswork.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!