FFmpeg——AVFrame中 的 data

 

AVFrame中 的 data 的定义如下:

typedef struct AVFrame {
#define AV_NUM_DATA_POINTERS 8
    /**
     * pointer to the picture/channel planes.
     * This might be different from the first allocated byte
     *
     * Some decoders access areas outside 0,0 - width,height, please
     * see avcodec_align_dimensions2(). Some filters and swscale can read
     * up to 16 bytes beyond the planes, if these filters are to be used,
     * then 16 extra bytes must be allocated.
     *
     * NOTE: Except for hwaccel formats, pointers not needed by the format
     * MUST be set to NULL.
     */
    uint8_t *data[AV_NUM_DATA_POINTERS];

    // ...
} AVFrame;

 

对于planar模式的YUV:
  • data[0]指向Y分量的开始位置
  • data[1]指向U分量的开始位置
  • data[2]指向V分量的开始位置
 
对于packed模式YUV:
  • data[0]指向数据的开始位置
  • data[1]和data[2]都为NULL
 
对于图像文件来说,如果是plannar模式的图像格式,其存储必然是先存完一张图像所有的所有Y、紧接着再存一张图像的所有U、紧接着存一张图像的所有V。
这刚好和data数组的三个指针的对应的。
 
所以无论是planar还是packed模式,我们直接使用data[0]即可,不用分开读写。

        
 
posted @ 2019-05-09 15:52  MyCPlusPlus  阅读(2013)  评论(0编辑  收藏  举报