Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ AVFrame buf大小计算_C++_Ffmpeg_Libav_Libavcodec - Fatal编程技术网

C++ AVFrame buf大小计算

C++ AVFrame buf大小计算,c++,ffmpeg,libav,libavcodec,C++,Ffmpeg,Libav,Libavcodec,当我将原始视频数据写入AVFrame时,我在使用ffmpeg库编码视频时遇到问题,因为我正在进行分段错误和/或内存溢出写入。因此,我只想问我的一个假设是否正确 我假设AVFrame.data[i]的大小始终等于AVFrame.linesize[i]*AVFrame.Height,对吗?或者,在某些情况下可能不是这样,如果是这样,我如何才能可靠地计算出AVFrame.data[i]?的大小取决于像素格式。例如YUV 4:4:4,是的,每个平面都是线宽。但是对于4:2:2,Y平面是linesizeh

当我将原始视频数据写入AVFrame时,我在使用ffmpeg库编码视频时遇到问题,因为我正在进行分段错误和/或内存溢出写入。因此,我只想问我的一个假设是否正确


我假设
AVFrame.data[i]
的大小始终等于
AVFrame.linesize[i]*AVFrame.Height
,对吗?或者,在某些情况下可能不是这样,如果是这样,我如何才能可靠地计算出
AVFrame.data[i]

的大小取决于像素格式。例如YUV 4:4:4,是的,每个平面都是线宽。但是对于4:2:2,Y平面是linesizeheight,而对于U和V平面是linesize*height/2。

它在大多数情况下都有效,但对于所有不同的格式,我不会重复这一点:-

AVFrame.linesize[i]=AVFrame.Width*PixelSize(其中PixelSize例如RGBA=4字节)

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

最好的方法是使用FFmpeg的官方

int buffer_size = av_image_get_buffer_size(AVPixelFormat.AV_PIX_FMT_RGBA, codecCtx->width, codecCtx->height, 1);