完整代码
#include <stdio.h>
#include<stdlib.h>
#include<malloc.h>
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检查选为否
参考链接
https://blog.csdn.net/leixiaohua1020/article/details/50534150