从内存中保存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,去除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;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值