How To Use Android Mediacodec Encode Camera Data(yuv420sp)
Solution 1:
I have solved the problem.As follows:
privatesynchronizedvoidencode(byte[] data)
{
inputBuffers = mMediaCodec.getInputBuffers();// here changes
outputBuffers = mMediaCodec.getOutputBuffers();
intinputBufferIndex= mMediaCodec.dequeueInputBuffer(-1);
Log.i(TAG, "inputBufferIndex-->" + inputBufferIndex);
//......
And next,you will find your encoded video color is not right, for more information,please go to here MediaCodec and Camera: colorspaces don't match
Solution 2:
The YUV420 formats output by the camera are incompatible with the formats accepted by the MediaCodec AVC encoder. In the best case, it's essentially NV12 vs. NV21 (U and V planes are reversed), requiring a manual reordering. In the worst case, as of Android 4.2, the encoder input format may be device-specific.
You're better off using MediaRecorder to connect the camera hardware to the encoder.
Update:
It's now possible to pass the camera's Surface preview to MediaCodec
, instead of using the YUV data in the ByteBuffer
. This is faster and more portable. See the CameraToMpegTest sample here.
Post a Comment for "How To Use Android Mediacodec Encode Camera Data(yuv420sp)"