FFMPEG with QT memory leak

会有一股神秘感。 提交于 2020-01-06 14:29:06

问题


Let me start with a code clip:

QByteArray ba;
ba.resize(500000);

int encsize = avcodec_encode_video(context, (uint8_t*)ba.data(), 500000, frame.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;

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

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?

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


回答1:


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



来源:https://stackoverflow.com/questions/4201481/ffmpeg-with-qt-memory-leak

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!