I am encoding NV21
frames coming from camera preview. For some reason schema which is working fine on other devices works incorrectly on Sony Xperia Z1
with Android 4.3
. It sends back encoded frames with incorrect (low) quality.
MediaCodec
's format is COLOR_FormatYUV420SemiPlanar
which is NV12
(I convert NV21
to NV12
by swapping U and V components). Output buffers sent back to me by MediaCodec
are with very low size which don't correspond to resolution (1280x720
) and bitrate (1000000
) I am using. First few frames are coming with a good quality, but then it's dropping significantly:
int encoderStatus = mMediaCodec.dequeueOutputBuffer(mBufferInfo, TIMEOUT_USEC);
// a few encoderStatus checks skipped
ByteBuffer encodedData = outputBuffers[encoderStatus];
Log.i(Constants.TAG, "Buffer size " + mBufferInfo.size);
Which gives me the following log on Xperia Z1:
Buffer size 26
Buffer size 52172
Buffer size 23650
Buffer size 14394
Buffer size 3591
Buffer size 1849
Buffer size 3908
...
Buffer size 1043
Buffer size 248
Buffer size 836
Buffer size 518
Buffer size 1112
Example log from Sony Xperia ZR
on which this works properly:
Buffer size 21
Buffer size 51048
Buffer size 21063
Buffer size 24228
Buffer size 28040
...
Buffer size 44959
Buffer size 44972
Buffer size 44957
Buffer size 45004
Buffer size 44999
Buffer size 44957
Any advice would be appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…