繁体   English   中英

ffmpeg内存增加

[英]ffmpeg memory increase

好吧,我正在使用ffmpeg,当我执行它时,它运行了一个视频示例,嗯,内存开始增加,一个简单的小视频占用了800MB RAM,而Windows Media Player仅占用了50MB来运行该文件,不知道发生了什么,这是循环,问题出在这里(我想...)

while(av_read_frame(formatContext,&framepacket)>= 0){
    pausecontrol.lock();


    if(framepacket.stream_index==gotVideoCodec){
        int framereaded;

        avcodec_decode_video2(videoCodecContext,videoFrame,&framereaded,&framepacket);

        if(framereaded){

            struct SwsContext *ctx = sws_getContext(videoCodecContext->width, videoCodecContext->height, videoCodecContext->pix_fmt, showinWidget->width(),
            showinWidget->height(), PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
            sws_scale(ctx,videoFrame->data,videoFrame->linesize,0,videoCodecContext->height,videoFrame->data,videoFrame->linesize);
            memset(&framecapsule,0,sizeof(QImage));
            framecapsule=QImage(showinWidget->width(),showinWidget->height(),QImage::Format_RGB888);
            for(int y=0;y<showinWidget->height();y++){
                memcpy(framecapsule.scanLine(y),videoFrame->data[0]+y*videoFrame->linesize[0],showinWidget->width()*3);
            }
            emit newFrameReady();
        }
    }
    if(framepacket.stream_index==gotAudioCodec){
        // Audio? Ok
    }
    pausecontrol.unlock();
    av_free_packet(&framepacket);
}

哦,我也在使用QT,但是AVFrame-QImage之间的对话不是问题。

您必须一次创建SwsContext ,而不是循环创建它。 最后,您必须通过调用sws_freeContext释放上下文

struct SwsContext *ctx = sws_getContext(videoCodecContext->width, videoCodecContext->height, videoCodecContext->pix_fmt, showinWidget->width(),
 showinWidget->height(), PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);

 while(av_read_frame(formatContext,&framepacket)>= 0)
 {
   /// .....
 }

sws_freeContext(ctx);

谢谢,我已经解决了(感谢Satuon)。

问题是,我正在变量'framecapsule'变量中创建新图像,memset无法正常工作,因此最后创建的图像在内存中,失去了对其的所有控制。

内存泄漏! 非常感谢你!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM