分离yuv420p的Y、U、V分量

完整代码

#include 
#include
#include

int simplest_yuv420_split(char* url, int w, int h, int num) {
	FILE* fp = fopen(url, "rb+");
	FILE* fp1 = fopen("DownSample_2048_2048_420p_d.y", "wb+");
	FILE* fp2 = fopen("DownSample_2048_2048_420p_d_u.y", "wb+");
	FILE* fp3 = fopen("DownSample_2048_2048_420p_d_v.y", "wb+");

	unsigned char* pic = (unsigned char*)malloc(w * h * 3 / 2);

	for (int i = 0; i < num; i++) {

		fread(pic, 1, w * h * 3 / 2, fp);
		//Y
		fwrite(pic, 1, w * h, fp1);
		//U
		fwrite(pic + w * h, 1, w * h / 4, fp2);
		//V
		fwrite(pic + w * h * 5 / 4, 1, w * h / 4, fp3);
	}

	free(pic);
	fclose(fp);
	fclose(fp1);
	fclose(fp2);
	fclose(fp3);

	return 0;
}


int main()
{
	simplest_yuv420_split("DownSample_2048_2048_420p_d.yuv", 2048, 2048, 1);
}

注意分离出的Y U V文件都是.y文件
VS中将属性—>C/C+±—>常规---->SDL检查选为否
分离yuv420p的Y、U、V分量_第1张图片
参考链接
https://blog.csdn.net/leixiaohua1020/article/details/50534150

你可能感兴趣的:(YUV,yuv)