From 584fbe15654650905f82c05319aceba36ed4cc47 Mon Sep 17 00:00:00 2001 From: dezhihuang Date: Tue, 17 Oct 2017 16:01:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=A6=BBYUV422P=E5=83=8F=E7=B4=A0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=B8=AD=E7=9A=84Y=E3=80=81U=E3=80=81V?= =?UTF-8?q?=E5=88=86=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 24 ++++++++++++++++++++++++ yuv422p_split.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 yuv422p_split.cpp diff --git a/README.md b/README.md index f052b1c..bcb0231 100644 --- a/README.md +++ b/README.md @@ -38,10 +38,13 @@ yuv420_split.cpp 程序中的函数可以将YUV420P数据中的Y、U、V三个 +

+ + ## 分离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三个 +
+
+ + + + +## 分离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) diff --git a/yuv422p_split.cpp b/yuv422p_split.cpp new file mode 100644 index 0000000..11f174d --- /dev/null +++ b/yuv422p_split.cpp @@ -0,0 +1,47 @@ +#include +#include +#include + +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; +} \ No newline at end of file