NV12ToI420
1.接口定义:
// Convert NV12 to I420.
LIBYUV_API
int NV12ToI420(const uint8* src_y, int src_stride_y,
const uint8* src_uv, int src_stride_uv,
uint8* dst_y, int dst_stride_y,
uint8* dst_u, int dst_stride_u,
uint8* dst_v, int dst_stride_v,
int width, int height);
2.实际使用
首先弄清楚两种图片格式的存储格式:
const uint8 *nv12_y = (const uint8*)image->data;
int nv12_y_stride = image->width;
const uint8 *nv12_uv = nv12_y + nv12_y_stride * image->height;
int nv12_uv_stride = nv12_y_stride;
uint8 *i420_image = NULL;
i420_image = (uint8*)malloc(image->width * image->height * 1.5);
uint8* i420_image_y_ptr = i420_image;
uint8* i420_image_u_ptr = i420_image_y_ptr + (image->width * image->height);
uint8* i420_image_v_ptr = i420_image_u_ptr + (int)(image->width * image->height * 0.25);
libyuv::NV12ToI420(
nv12_y, nv12_y_stride, nv12_uv, nv12_uv_stride,
i420_image_y_ptr, image->width,
i420_image_u_ptr, (image->width >> 1),//由于4个y值共用一个uv,所以可以假设图总共为4个Y,则肯定就一个uv,
//所以dst_stride_y为2,dst_stride_u和dst_stride_v为1,所以需要处除2
i420_image_v_ptr, (image->width >> 1),
image->width, image->height);