实现分离YUV420P像素数据中的Y、U、V分量。

master
dezhihuang 2017-10-16 13:47:29 +08:00
commit a70f0e8d5a
4 changed files with 3682 additions and 0 deletions

28
README.md Normal file
View File

@ -0,0 +1,28 @@
# 视音频数据处理入门
<br />
## 分离YUV420P像素数据中的Y、U、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
如果视频帧的宽和高分别为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格式的像素数据文件分离成为三个文件<br />
output_420_y.y纯Y数据分辨率为256x256。<br />
output_420_u.y纯U数据分辨率为128x128。<br />
output_420_v.y纯V数据分辨率为128x128。<br />
注:<br />
本文中像素的采样位数一律为8bit。由于1Byte=8bit所以一个像素的一个分量的采样值占用1Byte。<br />
输出的U、V分量在YUV播放器中也是当做Y分量进行播放的。<br />
<br />
##

BIN
tools/yuvplayer.exe Normal file

Binary file not shown.

3607
videos/akiyo_cif.yuv Normal file

File diff suppressed because one or more lines are too long

47
yuv420_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 yuv420_split(const char *file, int width, int height)
{
if (file == NULL) {
return FALSE;
}
FILE *fp = fopen(file, "rb+");
FILE *fp0 = fopen("output_420_yuv.y", "wb+");
FILE *fp1 = fopen("output_420_y.y", "wb+");
FILE *fp2 = fopen("output_420_u.y", "wb+");
FILE *fp3 = fopen("output_420_v.y", "wb+");
unsigned char *data = (unsigned char *)malloc(width*height*3/2);
memset(data, 0, width*height*3/2);
fread(data, 1, width*height*3/2, fp);
fwrite(data, 1, width*height*3/2, fp0);
fwrite(data, 1, width*height, fp1);
fwrite(data+width*height, 1, width*height/4, fp2);
fwrite(data+width*height*5/4, 1, width*height/4, fp3);
free(data);
fclose(fp);
fclose(fp1);
fclose(fp2);
fclose(fp3);
return TRUE;
}
int main(int argc, char *argv[])
{
if (argc == 4) {
yuv420_split(argv[1], atoi(argv[2]), atoi(argv[3]));
}
return 0;
}