首页 > 解决方案 > FFMPEG中lineSize,width,height之间的关系

问题描述

我对 AVFrame 中的linesize,height​​ ,感到困惑。width

根据我的理解,linesize是步幅,理想情况下应该是图像的宽度,对吗?

但是,和的值widthlinesize匹配。

AVFrame pFrame; 
cout<<"PFrame Linesize :"<<pFrame->data.linesize[0]<<endl;
cout<<"PFrame Width :"<<pFrame->width<<endl;

输出 :

PFrame Linesize : 64
PFrame width : 12

我的框架尺寸为 12*12。

根据对这篇文章的回答,linesize 应该与 width 相同。但我无法理解为什么它们在这里不同。

标签: c++11ffmpegcodeclibav

解决方案


我在这里引用文档:

 * For video, size in bytes of each picture line.
 * For audio, size in bytes of each plane.
 *
 * For audio, only linesize[0] may be set. For planar audio, each channel
 * plane must be the same size.
 *
 * For video the linesizes should be multiples of the CPUs alignment
 * preference, this is 16 or 32 for modern desktop CPUs.
 * Some code requires such alignment other code can be slower without
 * correct alignment, for yet other it makes no difference.
 *
 * @note The linesize may be larger than the size of usable data -- there
 * may be extra padding present for performance reasons.

所以视频的 linesize 是

宽度 * 每个像素的字节数 + 行填充

它将您从一行图像/帧数据的开头带到下一行的开头。


推荐阅读