c++ - FFMPEG,C++,内存泄漏,我做错了什么?

标签 c++ memory-leaks ffmpeg

所以我构建了这个应用程序,它使用 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/

相关文章:

unix - 当读取由 null 完成时, `</dev/null ` 到底是什么?

c++ - 在 C++ 中使用 CImg 出现 undefined reference 错误

c++ - OpenGL 优化还是...?

pointers - 使用指针的 Fortran 链表中的内存泄漏

iphone - iphone内存泄漏

node.js - 分离网络服务器和处理服务器

ffmpeg:几秒钟后的新文本,一帧没有同时有两个文本

c++ - 在函数 C++ 中使用字符串数组

c++ - 访问 C++ 程序的代码段

objective-c - autorelease 是否隐藏了 Instruments 中的泄漏?