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

master
dezhihuang 2017-10-17 15:01:06 +08:00
parent 8b38b7861b
commit f4e98fdb41
5 changed files with 80 additions and 3622 deletions

View File

@ -1,26 +1,35 @@
# 视音频数据处理入门
<br />
<br>
<br>
## 准备
yuv视频下载
>http://trace.eas.asu.edu/yuv/
yuv播放器[修改了一个YUV/RGB播放器](http://blog.csdn.net/leixiaohua1020/article/details/50466201)
>注意:<br />
>本文中像素的采样位数一律为8bit。由于1Byte=8bit所以一个像素的一个分量的采样值占用1Byte。<br />
>输出的U、V分量在YUV播放器中也是当做Y分量进行播放的。<br />
<br>
<br>
## 分离YUV420P像素数据中的Y、U、V分量
> 如果视频帧的宽和高分别为w和h那么一帧YUV420P像素数据一共占用w*h*3/2 Byte的数据。其中前w * h Byte存储Y接着的w * h * 1/4 Byte存储U最后w * h * 1/4 Byte存储V。
yuv视频下载
>http://trace.eas.asu.edu/yuv/
yuv播放器[修改了一个YUV/RGB播放器](http://blog.csdn.net/leixiaohua1020/article/details/50466201)
yuv420_split.cpp 程序中的函数可以将YUV420P数据中的Y、U、V三个分量分离开来并保存成三个文件。
调用方法:
> ./yuv420_split lena_256x256_yuv420p.yuv 256 256
> ./yuv420_split ./mediadata/lena_256x256_yuv420p.yuv 256 256
如果视频帧的宽和高分别为w和h那么一帧YUV420P像素数据一共占用w*h*3/2 Byte的数据。
其中前w*h Byte存储Y接着的w*h*1/4 Byte存储U最后w*h*1/4 Byte存储V。
上述代码运行后将会把一张分辨率为256x256的名称为lena_256x256_yuv420p.yuv的YUV420P格式的像素数据文件分离成为三个文件
- output_420_y.y纯Y数据分辨率为**256x256**。注意播放时设置播放器分辨率。
@ -29,14 +38,21 @@ yuv420_split.cpp 程序中的函数可以将YUV420P数据中的Y、U、V三个
>注意:<br />
>本文中像素的采样位数一律为8bit。由于1Byte=8bit所以一个像素的一个分量的采样值占用1Byte。<br />
>输出的U、V分量在YUV播放器中也是当做Y分量进行播放的。<br />
<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。
调用方法:
> ./yuv444p_split ./mediadata/lena_256x256_yuv444p.yuv 256 256
上述代码运行后将会把一张分辨率为256x256的名称为lena_256x256_yuv444p.yuv的YUV444P格式的像素数据文件分离成为三个文件
- output_444_y.y纯Y数据分辨率为**256x256**。
- output_444_u.y纯U数据分辨率为**256x256**。
- output_444_v.y纯V数据分辨率为**256x256**。

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

47
yuv444p_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 yuv444p_split(const char *file, int width, int height)
{
if (file == NULL) {
return FALSE;
}
FILE *fp = fopen(file, "rb+");
FILE *fp0 = fopen("./out/output_444p_yuv.y", "wb+");
FILE *fp1 = fopen("./out/output_444p_y.y", "wb+");
FILE *fp2 = fopen("./out/output_444p_u.y", "wb+");
FILE *fp3 = fopen("./out/output_444p_v.y", "wb+");
unsigned char *data = (unsigned char *)malloc(width*height*3);
memset(data, 0, width*height*3);
fread(data, 1, width*height*3, fp);
fwrite(data, 1, width*height*3, fp0);
fwrite(data, 1, width*height, fp1); //Y
fwrite(data+width*height, 1, width*height, fp2); //U
fwrite(data+width*height*2, 1, width*height, fp3); //V
free(data);
fclose(fp);
fclose(fp1);
fclose(fp2);
fclose(fp3);
return TRUE;
}
int main(int argc, char *argv[])
{
if (argc == 4) {
yuv444p_split(argv[1], atoi(argv[2]), atoi(argv[3]));
}
return 0;
}