如何使用C ++通过ConvertToI420裁剪NV21?

时间:2019-06-25 09:16:26

标签: libyuv

我从相机获取nv21图像,现在我想通过特殊的矩形对其进行裁剪,我尝试使用ConvertToI420,但似乎失败了。

ConvertToI420

int yuv_crop_image (unsigned char *src_data,unsigned int height ,unsigned int width,unsigned int src_length,
                    unsigned char *dst_data,unsigned int top,unsigned int left,unsigned int dst_width,unsigned int dst_height)                                             
{
    if (left + dst_width > width || top + dst_height > height) 
    {
        return -1;
    }


    if (left % 2 != 0 || top % 2 != 0) {
        return -1;
    }

    unsigned int dst_i420_y_size = dst_width * dst_height;
    unsigned int dst_i420_u_size = (dst_width >> 1) * (dst_height >> 1);

    unsigned char *dst_i420_data   = dst_data;
    unsigned char *dst_i420_y_data = dst_i420_data;
    unsigned char *dst_i420_u_data = dst_i420_data + dst_i420_y_size;
    unsigned char *dst_i420_v_data = dst_i420_data + dst_i420_y_size + dst_i420_u_size;

    int ret = libyuv::ConvertToI420((const unsigned char *) src_data, src_length,
                          (unsigned char *) dst_i420_y_data, dst_width,
                          (unsigned char *) dst_i420_u_data, dst_width >> 1,
                          (unsigned char *) dst_i420_v_data, dst_width >> 1,
                          left, top,
                          width, height,
                          dst_width, dst_height,
                         libyuv::kRotate0, libyuv::FOURCC_NV21);
    printf("!!ret = %d\n",ret);
}

我弄错了

0 个答案:

没有答案