FFmpeg YUV2RGB

AVFrame* YUV2RGB( AVCodecContext * avctx, AVFrame * frame )
{
	AVFrame* pFrameRGB=NULL;
	pFrameRGB=avcodec_alloc_frame();

	if(pFrameRGB==NULL)
		return NULL;
	// Determine required buffer size and allocate buffer
	
	int numBytes=avpicture_get_size(PIX_FMT_BGR24, avctx->width,avctx->height);

	uint8_t * buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));

	// Assign appropriate parts of buffer to image planes in pFrameRGB
	// Note that pFrameRGB is an AVFrame, but AVFrame is a superset
	// of AVPicture
	avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_BGR24,avctx->width, avctx->height);

	struct SwsContext *img_convert_ctx=NULL;
	img_convert_ctx=sws_getCachedContext(img_convert_ctx,avctx->width,
		avctx->height, avctx->pix_fmt,avctx->width, avctx->height,
		PIX_FMT_RGB24, SWS_BICUBIC,NULL, NULL, NULL);
	if( !img_convert_ctx ) 
	{
		fprintf(stderr, "Cannot initialize sws conversion context\n");
	}
	
	sws_scale(img_convert_ctx, (const uint8_t* const*)frame->data,
		frame->linesize, 0, avctx->height, pFrameRGB->data,
		pFrameRGB->linesize);

	return pFrameRGB;
}

  

pFrameRGB用完要free的
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值