带有QT内存泄漏的FFMPEG [英] FFMPEG with QT memory leak

查看:360
本文介绍了带有QT内存泄漏的FFMPEG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我从代码片段开始:

QByteArray ba;
ba.resize(500000);

int encsize = avcodec_encode_video(context, (uint8_t*)ba.data(), 500000, frame.unownedPointer());

我正在做的是对帧中的数据进行编码,然后将数据放入指向QByteArray的缓冲区中.如果我注释掉avcodec_encode_video行,我的内存泄漏就会消失. unownedPointer()看起来像这样:

What I'm doing is encoding the data from frame and putting the data into the buffer pointed at QByteArray. If I comment out the avcodec_encode_video line my memory leak goes away. unownedPointer() looks like this:

 if (this->frame != NULL) return this->frame;
    this->frame =  avcodec_alloc_frame();
    uchar *data = this->img.bits();
    frame->data[0] = (uint8_t *)data;
    frame->data[1] = (uint8_t *)data + 1;
    frame->data[2] = (uint8_t *)data + 2;
    frame->linesize[0] = width * lineSize(this->fmt);
    frame->linesize[1] = width * lineSize(this->fmt);
    frame->linesize[2] = width * lineSize(this->fmt);
    return this->frame;

这里-> frame是AVFrame *,而this-> img是QImage.

Where this->frame is a AVFrame *, and this->img is a QImage.

在大约30fps的编码速率下,我的内存泄漏约为50MB/秒.所以我不确定问题可能是什么.似乎avcodec_encode_video()正在复制内存,并且从不释放内存或其他东西.有什么想法吗?

At a encoding rate of about 30fps, I'm getting a memory leak of about 50MB/sec. So I'm not sure what the issue could be. It seems as if avcodec_encode_video() is copying memory and never freeing it or something. Any ideas?

如果avcodec_encode_video将RGB24数据转换为YUV420P,是否会修改frame.unownedPointer()指向的数据?

If avcodec_encode_video is converting my RGB24 data to YUV420P would it be modifying the data pointed to by frame.unownedPointer()?

推荐答案

看看的代码QtFFmpegwrapper 它使用保存的上下文有效地执行此操作,或者您可以直接使用QtFFMpegwrapper

Take a look at the code for QtFFmpegwrapper it uses a saved context to do this efficently, or you can just use the QtFFMpegwrapper directly

这篇关于带有QT内存泄漏的FFMPEG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆