On Oct 16, 2012 2:11 AM, "Quy Pham Sy" <[email protected]> wrote: > > Hi, > > I made a simple console test base on Dranger 's tutorial code by > replace deprecated function by the new versions. > here the full source code: > > https://github.com/phamquy/FFmpeg-tutorial-samples/blob/master/tutorial01.c > > It works fine, but there is a huge memory leak (i use Instrument to > for leak detection). > It seem like the leaks caused by the while loop, > there is no leak after i commented out this part: > > > i=0; > while(av_read_frame(pFormatCtx, &packet)>=0) { > if(packet.stream_index==videoStreamIdx) { > avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet); > > if(frameFinished) { > static struct SwsContext *img_convert_ctx; > int w = pCodecCtx->width; > int h = pCodecCtx->height; > img_convert_ctx = sws_getContext(w, h, pCodecCtx->pix_fmt, > w, h, PIX_FMT_RGB24, > SWS_BICUBIC, NULL, NULL, NULL); > > sws_scale(img_convert_ctx, (const uint8_t * const > *)pFrame->data, > pFrame->linesize, 0, pCodecCtx->height, > pFrameRGB->data, pFrameRGB->linesize); > > if(++i<=5) > SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height, > i); > } > } > av_free_packet(&packet); > } > > > What is wrong with this code?
One thing is that you never release the SwsContext. It's best to just get it once and re-use it, and then release it at the end. It's also possible you're leaking something in SaveFrame. --Michael
_______________________________________________ Libav-user mailing list [email protected] http://ffmpeg.org/mailman/listinfo/libav-user
