'linesize 对齐'是什么意思?
我正在关注 http://dranger.com/ffmpeg/tutorial01.html一>.
我刚刚发现 avpicture_get_size
函数已被弃用.
所以我检查了 ffmpeg 的文档(https://www.ffmpeg.org/doxygen/3.0/group__lavu__picture.html#ga24a67963c3ae0054a2a4bab35930e694) 并找到替代品 av_image_get_buffer_size
.
但是我看不懂align
参数的意思是'linesizealignment'......
什么意思?
解决方案FFmpeg 的某些部分,尤其是 libavcodec,需要对齐的 linesizes[],这意味着它需要:
assert(linesize[0] % 32 == 0);断言(行大小 [1] % 32 == 0);断言(行大小 [2] % 32 == 0);
这允许它使用快速/对齐的 SIMD 例程(例如 SSE2/AVX2 movdqa
或 vmovdqa
指令)进行数据访问,而不是它们较慢的未对齐对应物.>
这个av_image_get_buffer_size
函数的align
参数就是这个行对齐方式,你需要它,因为缓冲区的大小受它影响.例如,YUV 缓冲区中 Y 平面的大小实际上不是宽度 * 高度,而是 linesize[0] * height.您会看到(特别是对于不是 16 或 32 的倍数的图像大小),当您将 align
增加到 2 的更高次幂时,返回值会缓慢增加.
实际上,如果您打算将此图片用作调用的输出缓冲区,例如avcodec_decode_video2
,这个应该是32.对于swscale/avfilter,我相信没有绝对的要求,但是建议你还是把它变成32.
I'm following ffmpeg tutorial in http://dranger.com/ffmpeg/tutorial01.html.
I have just found that avpicture_get_size
function is deprecated.
So I have checked ffmpeg's document(https://www.ffmpeg.org/doxygen/3.0/group__lavu__picture.html#ga24a67963c3ae0054a2a4bab35930e694) and found substitute av_image_get_buffer_size
.
But I can't understand align
parameter meaning 'linesize alignment'......
What is it meaning?
解决方案Some parts of FFmpeg, notably libavcodec, require aligned linesizes[], which means that it requires:
assert(linesize[0] % 32 == 0);
assert(linesize[1] % 32 == 0);
assert(linesize[2] % 32 == 0);
This allows it to use fast/aligned SIMD routines (for example SSE2/AVX2 movdqa
or vmovdqa
instructions) for data access instead of their slower unaligned counterparts.
The align
parameter to this av_image_get_buffer_size
function is this line alignment, and you need it because the size of the buffer is affected by it. E.g., the size of a Y plane in a YUV buffer isn't actually width * height, it's linesize[0] * height. You'll see that (especially for image sizes that are not a multiple of 16 or 32), as you increase align
to higher powers of 2, the return value slowly increases.
Practically speaking, if you're going to use this picture as output buffer for calls to e.g. avcodec_decode_video2
, this should be 32. For swscale/avfilter, I believe there is no absolute requirement, but you're recommended to still make it 32.
相关文章