4

I am confused between linesize, height, width in AVFrame.

As per my understanding, linesize is the strides, which ideally should be the width of the image, right ?

However, the value of width and linesize are not matching.

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

Output :

PFrame Linesize : 64
PFrame width : 12

My frame is of dimension 12*12.

According to answers to this post, linesize should be same as width. But I am unable to understand why they are different here.

pseudo_teetotaler
  • 1,485
  • 1
  • 15
  • 35
  • Possible duplicate of [Can anyone help in understanding AVFrame.linesize\[\]?](https://stackoverflow.com/questions/13286022/can-anyone-help-in-understanding-avframe-linesize) – Joshua Waring Dec 18 '18 at 21:46
  • I don't see this as a duplicate of that. According to that post, `linesize` should be same as width. Which is not in my case. – pseudo_teetotaler Dec 18 '18 at 22:06
  • They're not inherently the same, although they are related. The stride is the size in bytes of a row. What is the format of your frame? – Joshua Waring Dec 18 '18 at 22:11
  • I am trying to decode a mpeg file, and want to get the YUV values. I guess the format is YUV_420. – pseudo_teetotaler Dec 18 '18 at 22:13

1 Answers1

-1

EDIT: Why the downvotes? If this is wrong, please correct me.

I'm citing the docs here:

 * 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.

So linesize for video is

width * bytes per pixel + line padding

It takes you from the start of one row of image / frame data to the start of the next row.

Bim
  • 1,008
  • 1
  • 10
  • 29