yuyv(yuv422)转yuv420p格式

YUV422图像是这样的,每个像素采集Y,每隔两个像素采集一次UV:

Packed格式的YUV420是这样的,每个像素采集Y,UV隔行采集,每行是每两个像素采集一次:

代码如下:

unsigned char *yuyv_buf = (unsigned char *)malloc(2*1280*720*sizeof(unsigned char));

unsigned char *yuv420_buf = (unsigned char *)malloc(3*1280*720/2*sizeof(unsigned char));
int yuyv_to_yuv420p(const unsigned char *in, unsigned char *out, unsigned int width, unsigned int height)
{
    unsigned char *y = out;
    unsigned char *u = out + width*height;
    unsigned char *v = out + width*height + width*height/4;

    unsigned int i,j;
    unsigned int base_h;
    unsigned int is_y = 1, is_u = 1;
    unsigned int y_index = 0, u_index = 0, v_index = 0;

    unsigned long yuv422_length = 2 * width * height;

    //序列为YU YV YU YV,一个yuv422帧的长度 width * height * 2 个字节
    //丢弃偶数行 u v
    for(i=0; i

参数in代表yuv422文件所在起始位置,out代表转换后yuv420p文件所在起始位置。

你可能感兴趣的:(嵌入式)