从内存中保存yuv文件

数据是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
	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;

 

发布了15 篇原创文章 · 获赞 7 · 访问量 9538
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览