【发布时间】:2019-12-29 18:27:04
【问题描述】:
我正在尝试理解 AVFrame,特别是 linesize 属性。
这是我解码的 AVFrame 属性:
width = 640
height= 360
linesize[0] = 640
linesize[1] = 320
linesize[2] = 320
这是一张 YUV 420 平面图像 (AV_PIX_FMT_YUVJ420P)
我正在阅读this code,这是处理 AVFrame 属性的部分:
int linesize = qAbs(m_format.renderFrame->linesize[i]);
AVRational widthRational = params.yuvwidths[i];
AVRational heightRational = params.yuvheights[i];
int width = linesize * widthRational.num / widthRational.den;
int height = m_format.renderFrame->height * heightRational.num / heightRational.den;
glTexImage2D ( GL_TEXTURE_2D, 0, params.yuvInternalformat[i],width ,height, 0, params.yuvGlFormat[i], params.dataType, NULL);
其中,对于 YUV420P,widthRational 和 heightRational 是 1/1 和 1/1 对于 i=0,1/2 和 1/2 对于 i = 1,2。而yuvInternalformat 和yuvGlFormat 总是GL_RED。
在这段代码中有一些我无法理解的东西:
为什么他在linesize 中取绝对值? linesize 可以是负数吗?文档中没有关于负值的内容。我理解他为什么在height 中进行分数乘法,但为什么在linesize 中? linesize不应该是平面图像的实际width,因此不需要乘法吗?
那么linesize是什么,width和height应该如何计算才能使用glTexImage2D?
【问题讨论】: