BGR24转换为YUV420函数

void RGBtoYUV(unsigned char* bufferYUV, unsigned char* bufferRGB, unsigned int width, unsigned int height)
{
AVFrame* FrameRGB = av_frame_alloc();
AVFrame* FrameYUV = av_frame_alloc();


avpicture_fill((AVPicture*)FrameRGB, (uint8_t*)bufferRGB, PIX_FMT_BGR24, width, height);
avpicture_fill((AVPicture*)FrameYUV, bufferYUV, PIX_FMT_YUV420P, width, height);


SwsContext* cxt = sws_getContext(width, height, PIX_FMT_BGR24, width, height, PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL);
sws_scale(cxt, FrameRGB->data, FrameRGB->linesize, 0, height, FrameYUV->data, FrameYUV->linesize);


sws_freeContext(cxt);
av_frame_free(&FrameRGB);
av_frame_free(&FrameYUV);
}

猜你喜欢

转载自blog.csdn.net/tong5956/article/details/79219884