Skip to content

Instantly share code, notes, and snippets.

@commshare
Created October 29, 2015 09:59
Show Gist options
  • Select an option

  • Save commshare/b870622281de4c69f721 to your computer and use it in GitHub Desktop.

Select an option

Save commshare/b870622281de4c69f721 to your computer and use it in GitHub Desktop.
YUV422SP转YUV422P
YUV422SP转YUV422P from git@github.com:commshare/YUVPlayer.git
作者李迟 发布2014-09-08 11:22 分类我的程序代码 标签代码积累, 工程库代码, 编程 阅读1,892 无评论
最近为了测试采集的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博客
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment