本文主要是介绍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];
}
}
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];
}
}
这篇关于YUV422SP转YUV422P的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!