The problem in a nutshell: there were no CTS tests for encoding video up to Android 4.3 (API 18).
As a result, the behavior of MediaCodec on different devices was inconsistent, and several errors went unnoticed. The EncodeDecodeTest tests perform the functions you ask for, and as a result, you can reliably download YUV data to the device with 4.3+ (although you still need to work -detect whether it wants to be planar or half-flat).
For your specific question, the Y plane on older Qualcomm devices should be aligned at the 2K border, which is not exactly what your code does. For 720p video, this is natural (720 * 1280 == 450 * 2048), for 176x144 you must set it to 1280 to run the UV plane at 26624 instead of 25344. You need to set the absolute alignment in the buffer, and not a fixed amount of indentation - use uvoffset = (width*height + 2047) & ~2047 .
You will need to determine the software version of the codec and the software version for Android, and if it is Qualcomm on pre-4.3, you will need to complete this setup. If your requirements change and you can target API 18+, these problems will go away. (And you can use the Surface input for MediaCodec , which avoids the U / V exchange problem, although depending on your needs, that might not be useful to you.)
source share