void ConvertYUVFrameToBGRFrame(AVFrame* pYUVFrame, AVFrame* pBGRFrame)
{
int nBGRFrameSize = av_image_get_buffer_size(AV_PIX_FMT_BGR24, pBGRFrame->width, pBGRFrame->height, 1);
uint8_t* pszBGRBuffer = (uint8_t*)av_malloc(nBGRFrameSize);
// The picture buffer pointers pszBGRBuffer pBGRFrame mount frame, it is necessary to manually remove
av_image_fill_arrays (pBGRFrame-> data, pBGRFrame-> linesize, pszBGRBuffer, AV_PIX_FMT_BGR24, pBGRFrame-> width, pBGRFrame-> height, 1);
struct SwsContext *pSwsCtx = sws_getContext(pYUVFrame->width, pYUVFrame->height, AV_PIX_FMT_YUVJ420P,
pBGRFrame->width, pBGRFrame->height, AV_PIX_FMT_BGR24,
SWS_BICUBIC, NULL, NULL, NULL);
0 // Note need to fill srcSliceY, or the call fails
sws_scale (pSwsCtx, pYUVFrame-> Data,
pYUVFrame-> LINESIZE, 0, pYUVFrame-> height,
pBGRFrame-> Data, pBGRFrame-> LINESIZE);
}
Examples of call
AVFrame *pBGRFrame = NULL;
pBGRFrame = av_frame_alloc();
pBGRFrame->width = 1920 / 2;
pBGRFrame->height = 1080 / 2;
pBGRFrame->format = AV_PIX_FMT_BGR24;
pVideoc->ConvertYUVFrameToBGRFrame(pFrame, pBGRFrame);
Description: The size of the image to zoom out, then converts the pixel format BGR24