yuv420P数据对AVFrame的赋值

来源:互联网 发布:熟悉linux内核 编辑:程序博客网 时间:2024/05/23 00:06

 

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;
}

 

原创粉丝点击