所以我构建了这个应用程序,它使用 IP 摄像机 rtsp 提要并用它做一些有趣的事情,但是我有一个小的内存泄漏,我现在才确定。
如果我只是运行这个
while (av_read_frame(input_format_context, &input_packet) >= 0) {}
它只会增长'n增长'n增长......所以我错过了什么?
我正在使用 ffmpeg 的 Windows 端口,我的版本是 58.9.100.0
会不会是 FFMPEG 本身的泄漏?
最佳答案
从文档:
If pkt->buf is NULL, then the packet is valid until the next av_read_frame() or until avformat_close_input(). Otherwise the packet is valid indefinitely. In both cases the packet must be freed with av_packet_unref when it is no longer needed.
像这样的东西?
AVPacket *pPacket = av_packet_alloc();
if (!pPacket)
{
logging("failed to allocated memory for AVPacket");
return -1;
}
while (av_read_frame(pFormatContext, pPacket) >= 0)
{
auto response = decode_packet(pPacket, pCodecContext, pFrame);
if (response < 0)
break;
}
av_packet_unref(pPacket);
}
PS:不要成为 cargo 崇拜的受害者,研究源代码。这绝不是一个完整的例子。有使用 ffmpeg 的工作项目。
关于c++ - FFMPEG,C++,内存泄漏,我做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52254202/