当前位置: 首页 > 我的程序代码 > 正文

YUV422SP转YUV422P

最近为了测试采集的YUV视频是否正确,不过用YUV播放器看不了YUV422SP的文件。为了让其正确播放,写了个转换函数,当然,没经什么优化。但作为测试手段,已经足够了。
下面给出YUV422SP转YUV422P格式的转换函数,当然,也包括了YUV420SP转YUV420P。代码没什么技术含量,不多说。

/**
yyyy yyyy
uv uv
->
yyyy yyyy
uu
vv
*/
void yuv422sp_to_yuv422p(unsigned char* yuv422sp, unsigned char* yuv422p, int width, int height)
{
    int i, j;
    int y_size;
    int uv_size;
    unsigned char* p_y1;
    unsigned char* p_uv;

    unsigned char* p_y2;
    unsigned char* p_u;
    unsigned char* p_v;

    y_size = uv_size = width * height;

    p_y1 = yuv422sp;
    p_uv = yuv422sp + y_size;

    p_y2 = yuv422p;
    p_u = yuv422p + y_size;
    p_v = p_u + width * height / 2;

    memcpy(p_y2, p_y1, y_size);

    for (j = 0, i = 0; j < uv_size; j+=2, i++)
    {
        p_u[i] = p_uv[j];
        p_v[i] = p_uv[j+1];
    }
}

/**
yyyy yyyy
uv uv
->
yyyy yyyy
uu
vv
*/
void yuv420sp_to_yuv420p(unsigned char* yuv420sp, unsigned char* yuv420p, int width, int height)
{
    int i, j;
    int y_size = width * height;

    unsigned char* y = yuv420sp;
    unsigned char* uv = yuv420sp + y_size;

    unsigned char* y_tmp = yuv420p;
    unsigned char* u_tmp = yuv420p + y_size;
    unsigned char* v_tmp = yuv420p + y_size * 5 / 4;

    // y
    memcpy(y_tmp, y, y_size);

    // u
    for (j = 0, i = 0; j < y_size/2; j+=2, i++)
    {
        u_tmp[i] = uv[j];
        v_tmp[i] = uv[j+1];
    }
}

本文最初于2013-04-15发表在CSDN博客

本文固定链接: http://www.latelee.org/my-library/yuv422sp-to-yuv422p.html

如无特别说明,迟思堂工作室文章均为原创,转载请注明: YUV422SP转YUV422P | 迟思堂工作室
【上一篇】

目前暂无评论

发表评论

*

快捷键:Ctrl+Enter