I know this is too late, but maybe someone will find it useful. From here I have the key to doing the same conversion, which looks a little shorter.
So, I created a QImage that is reused for each decoded frame:
QImage img( width, height, QImage::Format_RGB888 );
FrameRGB created:
frameRGB = av_frame_alloc(); //Allocate memory for the pixels of a picture and setup the AVPicture fields for it. avpicture_alloc( ( AVPicture *) frameRGB, AV_PIX_FMT_RGB24, width, height);
After the first frame is decoded, I create a SwsContext transform context in this way (it will be used for all of the following frames):
mImgConvertCtx = sws_getContext( codecContext->width, codecContext->height, codecContext->pix_fmt, width, height, AV_PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
And finally, for each decoded frame transform is performed:
if( 1 == framesFinished && nullptr != imgConvertCtx ) { //conversion frame to frameRGB sws_scale(imgConvertCtx, frame->data, frame->linesize, 0, codecContext->height, frameRGB->data, frameRGB->linesize); //setting QImage from frameRGB for( int y = 0; y < height; ++y ) memcpy( img.scanLine(y), frameRGB->data[0]+y * frameRGB->linesize[0], mWidth * 3 ); }
See the link for more details.