[FFmpeg-devel] libavcodec/rawdec.c and avctx->get_buffer problem

Stefano Sabatini stefano.sabatini-lala
Tue Jan 8 10:10:10 CET 2008

Hi all,

I already posted this to ffmpeg-user without to get a reply, so I'm
reposting it here because it has development implications.

This is the problem I'm facing: in an application I need to do
something everytime a new video frame has been completely decoded.

In order to do this, I define a my_get_buffer() function, which calls
the libavcodec/utils.c:avcodec_default_get_buffer() function, and
which is setted in the avcodec decoder context like this:

avctx->get_buffer= my_get_buffer;

during the initialization stage of the codec context.

This works fine with most decoders, but not with rawdec.c. In this
case the decoder won't just call the avctx->get_buffer function, so
my_get_buffer() won't be executed, resulting in a segfault when a not
initialized struct pointer is accessed later.

As a workaround I tried to patch rawdec.c, simply defining at the end
of this function:

    *data_size = sizeof(AVPicture);
+    avctx->get_buffer(avctx, (AVFrame*)frame);
    return buf_size;

In this way my_get_buffer() gets called, still I get many error messages
[rawvideo @ 0x846ffc0]pic->data[0]!=NULL in avcodec_default_get_buffer

nonetheless the application works, indeed the my_get_buffer calls the
avcodec_default_get_buffer() but ignores the return value, -1 in this

So my question is:
is every decoder supposed to call the avctx->get_buffer function?

If this is the case then is the libavcodec/rawdec.c implementation to
be considered bugged?

Eventually could you suggest a clean fix to this problem?

Many thanks in advance.

More information about the ffmpeg-devel mailing list