-1

I am having trouble encoding a video with the ffmpeg libraries as i am getting segfaults and/or out of bound memory writing when i am writing raw video data to an AVFrame. I therefore just wanted to ask if one of my assumptions was right.

Am i right to assume that the size of AVFrame.data[i] is always equal to AVFrame.linesize[i]*AVFrame.Height? Or could there be scenarios where that is not the case, and if so how can i then reliably calculate the size of AVFrame.data[i]?

2 Answers2

2

It work in most of the cases, but I wouldn't relay on that for all different formats:-

AVFrame.linesize[i] = AVFrame.Width * PixelSize (where PixelSize eg. RGBA = 4bytes)

BufferSize = AVFrame.linesize[i] * AVFrame.Height

The best way, it should be by using FFmpeg's official av_image_get_buffer_size

int buffer_size = av_image_get_buffer_size(AVPixelFormat.AV_PIX_FMT_RGBA, codecCtx->width, codecCtx->height, 1);
SuRGeoNix
  • 482
  • 1
  • 3
  • 10
1

It depends on the pixel format. For example YUV 4:4:4, yes every plane is linesizeheight. But for 4:2:2 it is linesizeheight for the Y plane, but linesize*height/2 for the U and V planes.

szatmary
  • 29,969
  • 8
  • 44
  • 57