数据是NV12
YYYY
YYYY
YYYY
YYYY
UVUV
UVUV
frame_y_buf = (u8 *)malloc(width * height);
if (frame_y_buf == NULL) {
printf("allocate frame_y_buf error, line:%d!\n", __LINE__);
rval = -1;
break;
}
frame_uv_buf = (u8 *)malloc(width * height / 2);
if (frame_uv_buf == NULL) {
printf("allocate frame_uv_buf error, line:%d!\n", __LINE__);
rval = -1;
break;
}
// Read the frame,去除pitch
for(i = 0; i < yuv_height; i++) {
memcpy(frame_y_buf + i * yuv_width , y_addr + pitch * i, yuv_width);
if (i < yuv_height / 2) {
memcpy(frame_uv_buf + i * yuv_width, uv_addr + pitch * i, yuv_width);
}
}
/* "wb+" 读写打开或建立一个二进制文件,允许读和写。*/
FILE *fp = fopen("/sdcard/111.yuv", "wb+");
fwrite(frame_y_buf, 1, yuv_width * yuv_height, fp);
fwrite(frame_uv_buf, 1, yuv_width * yuv_height / 2, fp);
fclose(fp);
fp = NULL;
//
memset(frame_y_buf, 0, yuv_width * yuv_height);
memset(frame_uv_buf, 0, yuv_width * yuv_height / 2);
FILE *pFile = fopen("/sdcard/YUVSemiPlanar.yuv", "rb");
fread(frame_y_buf, sizeof(unsigned char), 640 * 480, pFile);
fread(frame_uv_buf, sizeof(unsigned char), 640 * 480 / 2, pFile);
fp = fopen("/sdcard/222.yuv", "wb+");
fwrite(frame_y_buf, 1, yuv_width * yuv_height, fp);
fwrite(frame_uv_buf, 1, yuv_width * yuv_height / 2, fp);
fclose(fp);
fp = NULL;