Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ffmpeg

frame

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?

like image 300
vivienlwt Avatar asked Oct 15 '13 09:10

vivienlwt


1 Answers

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.

like image 134
pogorskiy Avatar answered Oct 01 '22 08:10

pogorskiy