[Libav-user] get_buffer vs get_buffer2, how do I manage/release buffers?

Hendrik Leppkes h.leppkes at gmail.com
Tue Nov 12 09:25:08 CET 2013


On Tue, Nov 12, 2013 at 9:15 AM, Antoine Martin <antoine at nagafix.co.uk> wrote:
> Hi,
>
> Our app uses ffmpeg1.2's "get_buffer" API to manage the lifecycle of the
> video buffers (decoding vpx and x264):
> * it overrides "get_buffer" and "release_buffer"
> * it calls "avcodec_get_buffer" and does its own reference counting
> * it only calls "avcodec_release_buffer" when it is safe to do so (when
> both ffmpeg and our code have finished using the buffer)
>
> I've looked at porting to ffmpeg2's "get_buffer2" API but I do not
> understand how we can achieve the same results.
> How/when do the frames get released? (since "avcodec_release_buffer" is
> no more)
> It seems that "refcounted_frames" and "av_frame_unref" have something to
> do with it, but how?
>

You need to fill AVFrame->buf[] using av_buffer_create when you
allocate a frame, and that function takes a release callback which
will be called once the buffer is unused and should be released.
AVCodecContext->release_buffer is unused in this model.

If all you want is reference counting, you don't need to worry about
implementing your own get_buffer(2) anymore.
You can simply set AVCodecContext->refcounted_frames to 1, and all
frames you get from the decoder are yours to keep, until you call
av_frame_unref or av_frame_free to release it (which you MUST do, or
you leak memory)

- Hendrik


More information about the Libav-user mailing list