分离YUV422P像素数据中的Y、U、V分量
parent
f4e98fdb41
commit
584fbe1565
24
README.md
24
README.md
|
@ -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,也叫I422,V前U后,叫YV16(YV表示Y后面跟着V,16表示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)
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue