我在这里关注 FFmpeg 视频编码示例,但它制作了一些虚拟 YUV420P 帧,并且我已经从相机捕获了 BGR 图像。
我不知道如何使用frame->data[]
并frame->linesize[]
用我的 BGR 图像填充它们,所以我可以编码 H264 视频。
编辑:
在罗纳德的回答之后,我有以下代码(相机发送的每张新照片都会调用它):
.............
AVFrame *bgrFrame = av_frame_alloc();
bgrFrame->width = originalBGRImage.cols;
bgrFrame->height = originalBGRImage.rows;
ret = av_image_alloc(bgrFrame->data, bgrFrame->linesize, bgrFrame->width, bgrFrame->height, AV_PIX_FMT_BGR24, 32);
/////////////////////////////////////
// This works and prevents memory leak....if I remove it, it consumes all the RAM....but I can't free this memory here, since I will use it later...
av_freep(&bgrFrame->data[0]);
av_frame_free(&bgrFrame);
return;
/////////////////////////////////////
ret = av_image_fill_pointers(bgrFrame->data, AV_PIX_FMT_BGR24, bgrFrame->height, originalBGRImage.data, bgrFrame->linesize);
/////////////////////////////////////
// Here is where I am done using the memory so I will want to free it...but this same code crashes the program.
av_freep(&bgrFrame->data[0]);
av_frame_free(&bgrFrame);
return;
/////////////////////////////////////
因此,如果我删除了av_freep(&bgrFrame->data[0]);
代码末尾的