Reputation: 1575
I am playing with video encoding using LibAV and unable to understand the purpose of linesize
.
For e.g., declaration of av_image_alloc
function in LibAV takes linesizes as arguments:
int av_image_alloc ( uint8_t * pointers[4],
int linesizes[4],
int w,
int h,
enum AVPixelFormat pix_fmt,
int align
)
I am new to LibAV and video encoding. Feel free to provide any link which can also give me little background of video encoding.
Upvotes: 4
Views: 1323
Reputation: 495
linesize array values are dependent on the pixel format.
For NV12 pixel format each frame consists of two planes: Y plane and UV plane (U and V values are interleaved). Therefore linesize[0] = frame_width
and linesize[1]=frame_width
(due to subsampling the number of U-pixels=1/2 of luma pixels and the total number of U-pixels and V-pixels is frame_width).
For RGB24 pixel format each frame consists of single plane and linesize[0]
os relevant only and linesize[0] = 3*frame_width
Upvotes: 0
Reputation: 37598
This function will allocate a buffer large enough to hold image data splitting it into one or more component arrays (planes). Depending on format, size of the line of the each picture component will have its own width (in bytes) (which may be much smaller or much larger than image width) and will also be padded to achieve the specified alignment (16 bytes typically to make vector instructions work). For example with typical YCbCr image with 4:2:0 subsampling there will be 3 planes (that is 3 non-null pointers stored in pointers
) and width of the luma plane line will be (padded) image width, width of the each chroma component lines will be (padded) half image width.
Also note that both pointers
and linesizes
in this function are out pointer parameters, not arrays.
Upvotes: 3
Reputation: 10107
linesize
is the width of your image in memory for each color channel. It may greater or equal to w
, for memory alignment issue.
Check ffmpeg av frame doc:
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.
The linesize may be larger than the size of usable data – there may be extra padding present for performance reasons.
Upvotes: 2