FFMPEGAutogen 示例中可能的内存泄漏

问题描述

我正在使用 https://github.com/Ruslan-B/FFmpeg.AutoGen 库连接到 rtsp 相机流并将帧保存为 png 图像。

使用 GitHub 存储库中存在的 FFMPEG.Autogen's example project 进行测试,没有变化 我注意到 内存 的使用似乎不断增长强>无穷。我已确保在使用后处理所有位图、指针等,但无法查明问题的根源。

它似乎来自他们的 VideoStreamDecoder.TryDecodeNextFrame 方法,如下所示:

public bool TryDecodeNextFrame(out AVFrame frame)
{
    ffmpeg.av_frame_unref(_pFrame);
    ffmpeg.av_frame_unref(_receivedFrame);
    int error;
    do
    {
        try
        {
            do
            {
                error = ffmpeg.av_read_frame(_pformatContext,_pPacket);
                if (error == ffmpeg.AVERROR_EOF)
                {
                    frame = *_pFrame;
                    return false;
                }
                else if(error < 0)
                {
                }
                error.ThrowExceptionIfError();
            } while (_pPacket->stream_index != _streamIndex);

            ffmpeg.avcodec_send_packet(_pCodecContext,_pPacket).ThrowExceptionIfError();
        }
        finally
        {
            ffmpeg.av_packet_unref(_pPacket);
        }

        error = ffmpeg.avcodec_receive_frame(_pCodecContext,_pFrame);
    } while (error == ffmpeg.AVERROR(ffmpeg.EAGAIN));
    error.ThrowExceptionIfError();
    if (_pCodecContext->hw_device_ctx != null)
    {
        ffmpeg.av_hwframe_transfer_data(_receivedFrame,_pFrame,0).ThrowExceptionIfError();
        frame = *_receivedFrame;
    }
    else
    {
        frame = *_pFrame;
    }
    return true;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)