简体   繁体   中英

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

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

Given avpicture_get_size() is deprecated , this is possible with:

int numBytes = av_image_get_buffer_size(
    enum AVPixelFormat
    int width,
    int height,
    int align
    );

note that for align value of 32 is usually used , I have seen posts using 1 bit might cause distortion on the frame;

Its possible however to fill frame buffer data (ie without size information) with :

int av_image_fill_arrays(uint8_t *dst_data[4], int dst_linesize[4],
                         const uint8_t *src,
                         enum AVPixelFormat pix_fmt, int width, int height, int align);

The avpicture_*<\/code> api is now deprecated. Instead, use av_image_fill_plane_sizes<\/code> to get each plane's size (the size of data[0] array).

int av_image_fill_plane_sizes   (
size_t  size[4],
enum AVPixelFormat  pix_fmt,
int     height,
const ptrdiff_t     linesizes[4] 
)   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM