Skip to content

Instantly share code, notes, and snippets.

@commshare
Created October 29, 2015 09:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save commshare/b870622281de4c69f721 to your computer and use it in GitHub Desktop.
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