Fffmpeg:从AVFrame中由YUV获取RGB
Posted 柳鲲鹏
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Fffmpeg:从AVFrame中由YUV获取RGB相关的知识,希望对你有一定的参考价值。
代码:
#define SRC_FORMAT AV_PIX_FMT_YUV420P
#define DEST_FORMAT AV_PIX_FMT_BGR24
static AVPicture g_oPicture = 0;
static struct SwsContext* g_pScxt = NULL;
void yuv2rgb(AVFrame* pFrame, uint8_t* pRgbBuffer)
int width = pFrame->width;
int height = pFrame->height;
if (g_pScxt == NULL)
g_pScxt = sws_getContext(width, height, SRC_FORMAT,
width, height, DEST_FORMAT,
SWS_POINT, NULL, NULL, NULL);
//AVFrame需要填充,还是这个方便。
avpicture_alloc(&g_oPicture, DEST_FORMAT, width, height);
int num_bytes = av_image_get_buffer_size(DEST_FORMAT, width, height, 32);
int retsws = sws_scale(g_pScxt, pFrame->data, pFrame->linesize, 0, height,
g_oPicture.data, g_oPicture.linesize);
//注意,RGB数据是这样复制的
memcpy(pRgbBuffer, g_oPicture.data[0], num_bytes);
//播放完毕后再释放。
//avpicture_free(&g_oPicture);
//sws_freeContext(g_pScxt);
以上是关于Fffmpeg:从AVFrame中由YUV获取RGB的主要内容,如果未能解决你的问题,请参考以下文章