Search code examples
c++ffmpegsizeofmemcpy

Determining size of data[0] in AVFrame of FFMPEG


I am trying to allocate AVFrame->data[0] of a video frame to uint8_t* buffer using the following lines of code :

size_t sizeOfFrameData = mpAVFrameInput->linesize[0] * mpAVFrameInput->height;
        
memcpy(mFrameData, mpAVFrameInput->data[0], sizeOfFrameData);

I would like to know if this is a correct way of copying frame data to uint8_t* variable in FFMPEG?


Solution

  • To get the buffer size:

    int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height);
    

    To copy pixel data:

    int avpicture_layout(const AVPicture *src, enum AVPixelFormat pix_fmt,
                         int width, int height,
                         unsigned char *dest, int dest_size);