[Libav-user] Memory allocation and avpicture_fill incorrect?
nkipe at tatapowersed.com
Wed Nov 21 12:42:31 CET 2012
I was trying out the updated tutorial01 code of
since the program crashed unexpectedly at sws_scale with an "Access
violation writing location" error, I was trying to figure out what went
1. I looked into the source for avpicture_get_size and saw a lot of code
that I couldn't understand. Why are such complex operations performed in
the function with data and linesize, when the width, height and pixel
format value multiplication should've easily given you the number of bytes?
2. In avpicture_fill, what exactly are we filling a pFrameRGB with? The
video isn't yet decoded, so what is getting filled there? Looking
through the source just left me confused.
I'm suspecting that the memory allocation is being done incorrectly,
which is why sws_scale is crashing. I've written about this in another
mailing list thread too, titled "get RGB values from ffmpeg frame". But
this question is specific to understanding the allocation and filling.
The code I'm talking about from tutorial01:
pFrameRGB = avcodec_alloc_frame();
if (pFrameRGB==NULL) return -1;
// Determine required buffer size and allocate buffer
numBytes = avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width,
buffer = (uint8_t *) av_malloc(numBytes * sizeof(uint8_t));
sws_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height,
pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, PIX_FMT_RGB24,
SWS_BILINEAR, NULL, NULL, NULL );
// Assign appropriate parts of buffer to image planes in pFrameRGB.
Note that pFrameRGB is an AVFrame, but AVFrame is a superset of AVPicture
avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,
More information about the Libav-user