How to get raw frame data from AVFrame.data[] and AVFrame.linesize[] without specifying the pixel format?

China☆狼群 提交于 2019-12-31 13:13:29

问题


I get the general idea that the frame.data[] is interpreted depending on which pixel format is the video (RGB or YUV). But is there any general way to get all the pixel data from the frame? I just want to compute the hash of the frame data, without interpret it to display the image.

According to AVFrame.h:

uint8_t* AVFrame::data[AV_NUM_DATA_POINTERS]

pointer to the picture/channel planes.

int AVFrame::linesize[AV_NUM_DATA_POINTERS]

For video, size in bytes of each picture line.

Does this mean that if I just extract from data[i] for linesize[i] bytes then I get the full pixel information about the frame?


回答1:


linesize[i] contains stride for the i-th plane.

To obtain the whole buffer, use the function from avcodec.h

/**
 * Copy pixel data from an AVPicture into a buffer, always assume a
 * linesize alignment of 1. */   
int avpicture_layout(const AVPicture* src, enum AVPixelFormat pix_fmt,
                 int width, int height,
                 unsigned char *dest, int dest_size);

Use

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

to calculate the required buffer size.



来源:https://stackoverflow.com/questions/19377938/how-to-get-raw-frame-data-from-avframe-data-and-avframe-linesize-without-spe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!