我在将原始视频数据写入 AVFrame 时遇到段错误和/或超出范围的内存写入,因此无法使用 ffmpeg 库对视频进行编码。因此,我只想问我的一个假设是否正确。
我是否正确假设 的大小AVFrame.data[i]总是等于AVFrame.linesize[i]*AVFrame.Height?或者是否存在情况并非如此的情况,如果是这样,我如何可靠地计算 的大小AVFrame.data[i]?
我在将原始视频数据写入 AVFrame 时遇到段错误和/或超出范围的内存写入,因此无法使用 ffmpeg 库对视频进行编码。因此,我只想问我的一个假设是否正确。
我是否正确假设 的大小AVFrame.data[i]总是等于AVFrame.linesize[i]*AVFrame.Height?或者是否存在情况并非如此的情况,如果是这样,我如何可靠地计算 的大小AVFrame.data[i]?
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.
它在大多数情况下都有效,但我不会对所有不同的格式进行中继:-
AVFrame.linesize[i] = AVFrame.Width * PixelSize(其中 PixelSize 例如 RGBA = 4bytes)
BufferSize = AVFrame.linesize[i] * AVFrame.Height
最好的办法,应该是使用FFmpeg官方的av_image_get_buffer_size
int buffer_size = av_image_get_buffer_size(AVPixelFormat.AV_PIX_FMT_RGBA, codecCtx->width, codecCtx->height, 1);