yuv420P数据对AVFrame的赋值

本文介绍了如何使用 FFmpeg 中的 AVFrame 结构体来处理 YUV 格式的图像数据。主要内容包括从文件中读取 YUV 数据并将其填充到 AVFrame 对象中,以及如何分配 AVFrame 和相关缓冲区的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://blog.youkuaiyun.com/chinabinlang/article/details/7804808


 

AVFrame *pict = new AVFrame;

 

   FILE * fyuv = fopen("G:\\352x288.yuv","rb");
  int nfilelen = ( width * height * 3 )/2;
  BYTE * pbuf = new BYTE[nfilelen];
  fread(pbuf,1,nfilelen,fyuv);
  fclose(fyuv);
 
 int size = width * height;
 
  pict->data[0] = pbuf;
  pict->data[1] = pict->data[0] + size;
  pict->data[2] = pict->data[1] + size / 4;
  pict->linesize[0] = width;
  pict->linesize[1] = width / 2;
  pict->linesize[2] = width / 2;

 


AVFrame * alloc_picture(enum PixelFormat pix_fmt, int width, int height)
{
 AVFrame *picture;
 uint8_t *picture_buf;
 int size;

 picture = avcodec_alloc_frame();                     if (!picture){ return NULL;} 
 size    = avpicture_get_size(pix_fmt, width, height);
 picture_buf = (uint8_t *)av_malloc(size);               if (!picture_buf) {av_free(picture); return NULL;}  
 
 avpicture_fill((AVPicture *)picture, picture_buf, pix_fmt, width, height);
 
 return picture;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值