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?
If you look at the definition of avpicture_get_size in version 3.2 you see the following code:
It simply calls the suggested function:
av_image_get_buffer_size
with thealign
parameter set to1
. I did not go further to find out the full significance of why1
is used for the depreciated function. As usual with ffmpeg, one can probably figure it out by reading the right code and enough code (with some code experiments).Some parts of FFmpeg, notably libavcodec, require aligned linesizes[], which means that it requires:
This allows it to use fast/aligned SIMD routines (for example SSE2/AVX2
movdqa
orvmovdqa
instructions) for data access instead of their slower unaligned counterparts.The
align
parameter to thisav_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 increasealign
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.My practice:
1.avpicture deprecated problem, I replace avpicture functions with AVFrame & imgutils functions. code sample:
...
...
2.align parameter
first I set align to 32, but for some video streams it did not work, cause distorted images. Then I set it to 16(my environment : mac, Xcode, iPhone6), the some streams works well. But at last i set align to 1, for I have found this