编译工具:CYGWIN
只要进入到openh264根目录 就能够直接根据github提供的编译步骤进行编译,之后会获得openh264相关的动态和静态库.我的openh264是15年8月下载的
编码部分:
1 从android获取摄像头数据使用的格式是NV21(yuv420sp),由于手机拍摄默认是横屏,所以获取到数据需要将数据进行旋转(是否有更好的方式处理 之后再研究).
顺时针旋转90°,从stackoverflow上找的
private byte[] rotateYUV420Degree90(byte[] data, int imageWidth, int imageHeight) {
byte[] yuv = new byte[imageWidth * imageHeight * 3 / 2];
// Rotate the Y luma
int i = 0;
for (int x = 0; x < imageWidth; x++) {
for (int y = imageHeight - 1; y >= 0; y--) {
yuv[i] = data[y * imageWidth + x];
i++;
}
}
// Rotate the U and V color components
i = imageWidth * imageHeight * 3 / 2 - 1;
for (int x = imageWidth - 1; x > 0; x = x - 2) {
for (int y = 0; y < imageHeight / 2; y++) {
yuv[i] = data[(imageWidth * imageHeight) + (y * imageWidth) + x];
i--;
yuv[i] = data[(imageWidth * imageHeight) + (y * imageWidth) + (x - 1)];
i--;
}
}
return yuv;
}