分离YUV422P像素数据中的Y、U、V分量

master
dezhihuang 2017-10-17 16:01:13 +08:00
parent f4e98fdb41
commit 584fbe1565
2 changed files with 71 additions and 0 deletions

View File

@ -38,10 +38,13 @@ yuv420_split.cpp 程序中的函数可以将YUV420P数据中的Y、U、V三个
<br />
<br />
## 分离YUV444P像素数据中的Y、U、V分量
> 说明如果视频帧的宽和高分别为w和h那么一帧YUV444P像素数据一共占用w * h * 3 Byte的数据。其中前w * h Byte存储Y接着的w * h Byte存储U最后w * h Byte存储V。
@ -57,5 +60,26 @@ yuv420_split.cpp 程序中的函数可以将YUV420P数据中的Y、U、V三个
<br />
<br />
## 分离YUV422P像素数据中的Y、U、V分量还有问题图像显示不完整
> 说明对于YUV422P的格式表示平面格式(Planar)即Y、U、V是分开存储的每个分量占一块地方其中Y为width * height而U、V合占width * height。根据U、V的顺序分出2种格式U前V后即YUV422P也叫I422V前U后叫YV16(YV表示Y后面跟着V16表示16bit)。
调用方法:
> ./yuv422p_split ./mediadata/lena_256x256_yuv422p.yuv 256 256
上述代码运行后将会把一张分辨率为256x256的名称为lena_256x256_yuv422p.yuv的YUV422P格式的像素数据文件分离成为三个文件
- output_422p_y.y纯Y数据分辨率为**256x256**。
- output_422p_u.y纯U数据分辨率为**128x128**。
- output_422p_v.y纯V数据分辨率为**128x128**。
参考:[视音频数据处理入门RGB、YUV像素数据处理](http://blog.csdn.net/leixiaohua1020/article/details/50534150)
![](./images/leixiaohua_avDataProcess.png)

47
yuv422p_split.cpp Normal file
View File

@ -0,0 +1,47 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef int BOOL;
#define TRUE 1
#define FALSE 0
BOOL yuv422p_split(const char *file, int width, int height)
{
if (file == NULL) {
return FALSE;
}
FILE *fp = fopen(file, "rb+");
FILE *fp0 = fopen("./out/output_422p_yuv.y", "wb+");
FILE *fp1 = fopen("./out/output_422p_y.y", "wb+");
FILE *fp2 = fopen("./out/output_422p_u.y", "wb+");
FILE *fp3 = fopen("./out/output_422p_v.y", "wb+");
unsigned char *data = (unsigned char *)malloc(width*height*2);
memset(data, 0, width*height*2);
fread(data, 1, width*height*2, fp);
fwrite(data, 1, width*height*2, fp0);
fwrite(data, 1, width*height, fp1); //Y
fwrite(data+width*height, 1, width*height/2, fp2); //U
fwrite(data+width*height*3/2, 1, width*height/2, fp3); //V
free(data);
fclose(fp);
fclose(fp1);
fclose(fp2);
fclose(fp3);
return TRUE;
}
int main(int argc, char *argv[])
{
if (argc == 4) {
yuv422p_split(argv[1], atoi(argv[2]), atoi(argv[3]));
}
return 0;
}