实际音视频开发过程芯片是做了硬件加速的,主要涉及到视频编解码。二次开发过程中需要对SDK做一定的封装使用才行。
写这篇文章的目的和硬编解码无关。 只是如无硬件转换接口的情况下如何对原始数据的转换,以便后续查看。
因为考虑实际原始数据用的比较多的是BGR/YUV之类的,通过枚举ColorConversionCodes可以发现设计这个枚举的思想。
因为有时候我们不知道要转的是yuv420sp还是yuv420p,而且不同的地方叫法都有差异,这是写这篇的重点。
比较简单, 不在叙述。
YV12
,OpenCV头文件imgproc.hpp中COLOR_YUV420p2BGR = COLOR_YUV2BGR_YV12,
//! YUV 4:2:0 family to RGB
COLOR_YUV2RGB_NV12 = 90,
COLOR_YUV2BGR_NV12 = 91,
COLOR_YUV2RGB_NV21 = 92,
COLOR_YUV2BGR_NV21 = 93,
COLOR_YUV420sp2RGB = COLOR_YUV2RGB_NV21,
COLOR_YUV420sp2BGR = COLOR_YUV2BGR_NV21,
COLOR_YUV2RGBA_NV12 = 94,
COLOR_YUV2BGRA_NV12 = 95,
COLOR_YUV2RGBA_NV21 = 96,
COLOR_YUV2BGRA_NV21 = 97,
COLOR_YUV420sp2RGBA = COLOR_YUV2RGBA_NV21,
COLOR_YUV420sp2BGRA = COLOR_YUV2BGRA_NV21,
COLOR_YUV2RGB_YV12 = 98,
COLOR_YUV2BGR_YV12 = 99,
COLOR_YUV2RGB_IYUV = 100,
COLOR_YUV2BGR_IYUV = 101,
COLOR_YUV2RGB_I420 = COLOR_YUV2RGB_IYUV,
COLOR_YUV2BGR_I420 = COLOR_YUV2BGR_IYUV,
COLOR_YUV420p2RGB = COLOR_YUV2RGB_YV12,
COLOR_YUV420p2BGR = COLOR_YUV2BGR_YV12,
COLOR_YUV2RGBA_YV12 = 102,
COLOR_YUV2BGRA_YV12 = 103,
COLOR_YUV2RGBA_IYUV = 104,
COLOR_YUV2BGRA_IYUV = 105,
COLOR_YUV2RGBA_I420 = COLOR_YUV2RGBA_IYUV,
COLOR_YUV2BGRA_I420 = COLOR_YUV2BGRA_IYUV,
COLOR_YUV420p2RGBA = COLOR_YUV2RGBA_YV12,
COLOR_YUV420p2BGRA = COLOR_YUV2BGRA_YV12,
COLOR_YUV2GRAY_420 = 106,
COLOR_YUV2GRAY_NV21 = COLOR_YUV2GRAY_420,
COLOR_YUV2GRAY_NV12 = COLOR_YUV2GRAY_420,
COLOR_YUV2GRAY_YV12 = COLOR_YUV2GRAY_420,
COLOR_YUV2GRAY_IYUV = COLOR_YUV2GRAY_420,
COLOR_YUV2GRAY_I420 = COLOR_YUV2GRAY_420,
COLOR_YUV420sp2GRAY = COLOR_YUV2GRAY_420,
COLOR_YUV420p2GRAY = COLOR_YUV2GRAY_420,
YUV420P一般称plane平面模式
,Y,U,V分别在三个不同平面,它是YUV标准格式,分为YU12和YV12
注意看,OpenCV中没有给出YU12,而使用COLOR_YUV2BGR_I420{android中常用叫法}和 COLOR_YUV2BGR_IYUV 对应
总结: YUV420即为YU12(I420/IYUV), YUV420P即YV12
YUV420SP格式的图像阵列,首先是所有Y值,然后是UV或者VU交替存储,NV12和NV21属于YUV420SP格式,是一种two-plane模式,即Y和UV分为两个plane,但是UV(CbCr)为交错存储,而不是分为三个平面。
cv::Mat image_src(1080*3/2, 1920, CV_8UC1, char *pyuv420_data);
cv::Mat image_dst;
cv::cvtColor(image_src, image_dst, cv::COLOR_YUV2BGR_I420);
cv::cvtColor(image_dst, image_src, cv::COLOR_BGR2YUV_IYUV);
连接1: 图像叠加中文字体