AVFrame 转 Mat
IYUV(I420)格式
YY | YY | YY | YY |
u | u | u | u |
YY | YY | YY | YY |
v | v | v | v |
YY | YY | YY | YY |
u | u | u | u |
YY | YY | YY | YY |
v | v | v | v |
y = width * height
u(v) = width / 2 * height * 2
伪代码
...
AVFrame *p_frame;//AV_PIX_FMT_YUV420P AV_PIX_FMT_YUVJ420P
...
Mat rgbMat;
Mat yuv_I420;
yuv_I420.create(p_frame->height * 3 / 2, p_frame->width, CV_8UC1);
uint8_t* p_data = yuv_I420.data;
for (int j = 0; j < p_frame->height; j++)
{
memcpy(p_data
, p_frame->data[0] + j * p_frame->linesize[0], p_frame->width);
p_data += p_frame->width;
}
for (int j = 0; j < p_frame->height / 2; j++)
{
memcpy(p_data
, p_frame->data[1] + j * p_frame->linesize[1], p_frame->width / 2);
p_data += p_frame->width / 2;
}
for (int j = 0; j < p_frame->height / 2; j++)
{
memcpy(p_data
, p_frame->data[2] + j * p_frame->linesize[2], p_frame->width / 2);
p_data += p_frame->width / 2;
}
cvtColor(yuv_I420, rgbMat, COLOR_YUV2BGR_I420);
标签:FFMPEG,I420,frame,IYUV,height,YY,width,data
From: https://www.cnblogs.com/blackTree/p/17081403.html