1

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

使用GitHub 存储库中的FFMPEG.Autogenexample 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;
}
4

0 回答 0