MediaCodec对两种yuv格式进行编码
COLOR_FormatYUV420SemiPlanar 对应NV12
COLOR_FormatYUV420Planar 对应I420
用Camera.PreviewCallback onPreviewFrame()出来的yuv有两种
NV21和YV12
所以送编码器之前需要进行yuv格式转换
-
private void swapNV21toI420(byte[] nv21bytes, byte[] i420bytes, int width, int height)
-
{
-
final int iSize = width*height;
-
System.arraycopy(nv21bytes, 0, i420bytes, 0, iSize);
-
-
for(int iIndex = 0; iIndex <iSize/2; iIndex+=2) {
-
i420bytes[iSize + iIndex/2 + iSize/4 ] = nv21bytes[iSize + iIndex]; //U
-
i420bytes[iSize + iIndex/2] = nv21bytes[iSize + iIndex +1]; //V
-
}
-
}
-
-
private void swapNV21toNV12(byte[] nv21bytes, byte[] nv12bytes, int width, int height) {
-
byte bTmp = 0;
-
final int iSize = width*height;
-
for (int i = iSize; i < iSize+iSize/2; i += 2) {
-
bTmp = nv21bytes[i+1];
-
nv21bytes[i+1] = nv21bytes[i];
-
nv21bytes[i] = bTmp;
-
}
-
System.arraycopy(nv21bytes, 0, nv12bytes, 0, nv21bytes.length);
-
}
阅读(3974) | 评论(0) | 转发(0) |