在第一节FFmpeg开发教程一、FFmpeg 版 Hello world中遇到一个问题,在保存YUV的时候,粗暴的使用:

fwrite(buf, 1, xsize * ysize, f);

方式去拷贝YUV数据是有问题的,得到的图片是这样的:
FFmpeg中AVFrame.linesize的含义
必须通过以下循环才能得到正确的YUV:

static void save_gray_frame(unsigned char *buf, int wrap, int xsize, int ysize, char *filename)
{
    FILE *f = NULL;
    int i = 0;
    f = fopen(filename, "w");
    fprintf(f, "P5\n%d %d\n%d\n", xsize, ysize, 255);
    ![](https://img2018.cnblogs.com/blog/919516/201905/919516-20190510142313623-420164045.jpg)


    for (i = 0; i < ysize; i++) {
        fwrite(buf + wrap * i, 1, xsize, f);
    }
    //fwrite(buf, 1, xsize * ysize, f);
    
    fclose(f);
}

网友解答:Understanding of AVFrame.linesize[]

相关文章:

  • 2022-12-23
  • 2021-08-20
  • 2021-08-06
  • 2021-04-29
  • 2021-06-01
  • 2022-01-23
  • 2021-08-25
  • 2021-12-21
猜你喜欢
相关资源
相似解决方案