6

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?

genpfault
  • 51,148
  • 11
  • 85
  • 139

3 Answers3

3

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);
aergistal
  • 29,947
  • 5
  • 70
  • 92
1

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 (i.e 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);
genpfault
  • 51,148
  • 11
  • 85
  • 139
Mohammad Kanan
  • 4,452
  • 10
  • 23
  • 47
0

The avpicture_* API is now deprecated. Instead, use av_image_fill_plane_sizes 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] 
)   

Note that the linesizes should be converted to ptrdiff_t (long long*) first.

You can find more here: https://www.ffmpeg.org/doxygen/trunk/group__lavu__picture.html

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
irous
  • 401
  • 3
  • 8