sws_scale 使用前,调用 avpicture_fill 对pAVFrameRGB进行初始化。
static BOOL OutputToBGR24(AVFrame * pAVFrame, int width, int height, BYTE* byOutbuf)
{
struct SwsContext *img_convert_ctx = NULL;
AVFrame *pAVFrameRGB = av_frame_alloc();
if (pAVFrameRGB == NULL)
{
return FALSE;
}
avpicture_fill((AVPicture*)pAVFrameRGB, byOutbuf, AV_PIX_FMT_BGR24, width, height);
img_convert_ctx = sws_getContext(width, height, (AVPixelFormat)pAVFrame->format, width, height, AV_PIX_FMT_BGR24,
SWS_BICUBIC, NULL, NULL, NULL);
sws_scale(img_convert_ctx, pAVFrame->data, pAVFrame->linesize,0, height, pAVFrameRGB->data, pAVFrameRGB->linesize);
av_frame_free(&pAVFrameRGB);
sws_freeContext(img_convert_ctx);
return TRUE;
}