读取一个yuv格式的源文件,然后分别读出y u v的数据
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <malloc.h>
void readYUV(const char* path, int width, int height)
{
FILE* f = fopen(path, "rb+");
FILE* f1 = fopen("D:\\test\\pic\\yuv420y.y", "wb+");
FILE* f2 = fopen("D:\\test\\pic\\yuv420y.u", "wb+");
FILE* f3 = fopen("D:\\test\\pic\\yuv420y.v", "wb+");
char* data = (char*)malloc(width*height * 3 / 2);
fread(data, 1, width*height * 3 / 2, f);
fwrite(data, 1, width*height, f1);
fwrite(data+width*height, 1, width*height/4, f2);
fwrite(data+width*height*5/4, 1, width*height/4, f3);
free(data);
data = nullptr;
fclose(f);
fclose(f1);
fclose(f2);
fclose(f3);
}
void main()
{
readYUV("D:\\test\\pic\\9.yuv", 960, 720);
}