用mediacodec对4k分辨率视频进行h.264\h.265\vp8的编码和解码的问题?
找到个demo程序:https://github.com/pingu342/android-app-mediacodectest
是对1920*1080 h.264进行编码和解码的。
原理是:app界面有2个surfaceview,通过camera获取图像,然后编码,再解码显示到第二个surface上面;
原先版本的现象:1920*1080 h.264情况下,是可以正常运行的。
现在的问题是:
1)原先的代码有颜色不正常,有偏差。这个找到原因了,是u和v的转换问题,目前有个函数,但是不知道在哪里调用来实现转换,NV21toYUV420SemiPlanar(stillImageFrame, stillImageFrame, Width,Height);
2)为什么我将1920*1080修改为3840*2160分辨率,程序就报错;
02-10 17:45:51.522: D/sakalog(11363): create decoder.
02-10 17:45:51.552: I/OMXClient(11363): Using client-side OMX mux.
02-10 17:45:51.552: D/sakalog(11363): Configuring decoder with input format : {csd-0=java.nio.DirectByteBuffer[position=0,limit=26,capacity=12533760], height=2160, width=3840, mime=video/avc}
02-10 17:45:51.562: I/ACodec(11363): [OMX.qcom.video.decoder.avc] DRC Mode: Dynamic Buffer Mode
02-10 17:45:51.562: E/ACodec(11363): [OMX.qcom.video.decoder.avc] configureCodec returning error -2147483648
02-10 17:45:51.562: E/ACodec(11363): signalError(omxError 0x80001001, internalError -2147483648)
02-10 17:45:51.562: E/MediaCodec(11363): Codec reported err 0x80001001, actionCode 0, while in state 3
02-10 17:45:51.562: E/MediaCodec(11363): configure failed with err 0x80001001, resetting...
02-10 17:45:51.562: I/OMXClient(11363): Using client-side OMX mux.
02-10 17:45:51.572: E/AndroidRuntime(11363): FATAL EXCEPTION: Thread-19740
02-10 17:45:51.572: E/AndroidRuntime(11363): Process: jp.saka.mediacodectest, PID: 11363
02-10 17:45:51.572: E/AndroidRuntime(11363): android.media.MediaCodec$CodecException: Error 0x80001001
02-10 17:45:51.572: E/AndroidRuntime(11363): at android.media.MediaCodec.native_configure(Native Method)
02-10 17:45:51.572: E/AndroidRuntime(11363): at android.media.MediaCodec.configure(MediaCodec.java:577)
02-10 17:45:51.572: E/AndroidRuntime(11363): at jp.saka.mediacodectest.MediaCodecTest$EncDecThread.startEncodeDecodeVideo(MediaCodecTest.java:808)
02-10 17:45:51.572: E/AndroidRuntime(11363): at jp.saka.mediacodectest.MediaCodecTest$EncDecThread.run(MediaCodecTest.java:473)
我查了代码中的这个config,没有问题啊;
encoder.configure(
outputFormat, //the desired format of the output data (encoder).
null, //a surface on which to render the output of this decoder. (encoderのためnull指定)
null, //a crypto object to facilitate secure decryption of the media data.
MediaCodec.CONFIGURE_FLAG_ENCODE //configure the component as an encoder.
);
理论上,只改变分辨率是可以的,我尝试将1920*1080缩小一倍,是可以的。是手机太卡的原因吗,我用的是小米4c测试的。