How does FFmpeg calculate linesize alignment?

Viewed 323

I am new to video encoding. I am using FFmpeg library to decode the H.264 frame. I have the below C++ code (full code is here):

AVCodecContext *context = create_codec_context();
AVFrame *decoded_frame = av_frame_alloc();
avcodec_send_packet(context, encoded_packet);
avcodec_receive_frame(context, decoded_frame);

std::cout << decoded_frame->width << "\n"; // prints 1620, as expected
std::cout << decoded_frame->linesize[0] << "\n"; // prints 1664!

What looks strange to me is the linesize of the decoded frame. Although the width of the frame is 1620, the linesize[0] is 1664. According to this answer, the linesize is calculated taking alignment into consideration. In order to get 1664 from 1620, one should apply 64 as an alignment to the initial width.

My question is, where does this 64 alignment come from? Searching through FFmpeg code did not give any results. Does the encoded frame itself already have this information?

If afterwards I decide to "flatten" the decoded frame into a one-dimensional array using av_image_copy_to_buffer(), what alignment should I use? Should it also be 64?

0 Answers
Related