[Libav-user] Is it possible to preallocate memory for AVFrame data when calling avcodec_receive_frame?

ggeng george at visby.io
Mon Dec 17 20:45:19 EET 2018


I am using libav to decode a video (following the demo code available
online), and I am trying to pre-allocate memory that the decoded frame data
will be written to. Ultimately, I would like to have pFrame->data[0] to be
in a region of memory I pre-allocate.

Following examples online, I am able to set pFrame->data as so:

*// Determine required buffer size and allocate buffer*
int numBytes;
numBytes = av_image_get_buffer_size(pixFmt, width, height, 1);
(uint8_t*) dataBuff = (uint8_t*) malloc (numBytes * sizeof(uint8_t));

*// Assign buffer to image planes in pFrame*
av_image_fill_arrays(frame->data, frame->linesize, dataBuff, pixFmt, width,
height, 1);

However, I found that this call:

ret = avcodec_receive_frame(pCodecContext, pFrame)

will always write the decoded frame data to be somewhere else, and allocate
its own memory for pFrame->data, completely ignoring the dataBuffer I set to
pFrame->data before.

Is there a way to get around this? Either by decoding video without a call
to avcodec_receive_frame or a way to set the memory for the data?

Thanks very much for your time.


Sent from: http://libav-users.943685.n4.nabble.com/

More information about the Libav-user mailing list