Reputation: 1260
I am trying to decode the video frame to QImage and display it, but the below code which convert AVFrame to QImage cause memory leak. When I disable the below code the application works fine, but enabling cause to use more RAM and incenses by time.
AVFrame *frameRGB = av_frame_alloc();
int width = frame->width, height = frame->height;
avpicture_alloc( ( AVPicture *) frameRGB, AV_PIX_FMT_RGB24, width,height);
struct SwsContext *convert_ctx=NULL;
enum PixelFormat src_pixfmt = (enum PixelFormat)frame->format;
enum PixelFormat dst_pixfmt = PIX_FMT_RGB24;
convert_ctx = sws_getContext(width, height, src_pixfmt, width, height, dst_pixfmt,
SWS_FAST_BILINEAR, NULL, NULL, NULL);
sws_scale(convert_ctx,frame->data, frame->linesize,0,height, frameRGB->data, frameRGB->linesize);
//decodedQimage = QImage( width, height, QImage::Format_RGB888 );
for( int y = 0; y < height; ++y ){
memcpy( decodedQimage.scanLine(y), frameRGB->data[0]+y * frameRGB->linesize[0], frameRGB->linesize[0] );
}
av_free(frameRGB);
sws_freeContext(convert_ctx);
Here decodedQimage
is QImage type and int it like
decodedQimage = QImage( outputwidth, outputheight, QImage::Format_RGB888 );
Upvotes: 1
Views: 686