[Libav-user] How to keep AVFrame data after codec close

wm4 nfxjfg at googlemail.com
Mon Dec 9 19:41:40 CET 2013


On Sat, 7 Dec 2013 22:16:41 -0800
Bruce Wheaton <bruce at spearmorgan.com> wrote:

> On Dec 6, 2013, at 4:39 PM, wm4 <nfxjfg at googlemail.com> wrote:
> 
> > On Thu, 5 Dec 2013 10:53:37 -0800
> > Bruce Wheaton <bruce at spearmorgan.com> wrote:
> > 
> >> On Dec 5, 2013, at 3:41 AM, Paul B Mahol <onemda at gmail.com> wrote:
> >> 
> >>> On 12/5/13, Eric Beuque <eric.beuque at gmail.com> wrote:
> >>>> How i can tell libavcodec that i want to become the owner of the data and
> >>>> be able to free it, to without codec context instance? I was thinking about
> >>>> using get/release_buffer functions, but i don't know how to compute size of
> >>>> the data.
> >>>> 
> >>>> Is data memcpy the only way to do this?
> >>>> 
> >>>> Note, that i also can't upgrade to new version of FFMPEG.
> >>>> 
> >>>> Thanks for your help.
> >>>> 
> >>> 
> >>> Use reference counting system.
> >>> They you need to manually free frame once you will not need it
> >>> (otherwise you leak memory), so you do not need to do copy.
> >> 
> >> 
> >> In my recent experiments, it seemed that closing the codec actually frees all buffers, regardless of reference count. That makes sense - if the codec is gone, what would detect the decreased reference count? 
> > 
> > Did you set AVCodecContext.refcounted_frames to 1? There are other
> > weird requirements to use refcounting, such as allocating AVFrames with
> > av_frame_alloc() instead of avcodec_frame_alloc() (or whatever it was).
> 
> Yes, I followed all the directions I could find, including those two. In the end, memory kept increasing, and I found that I couldn't keep buffers longer than i had the codec and context open.
> 
> It was also quite a memory hog. Saving the copy turned out to have some downsides.

This should not happen. Others (including myself) are using refcounting
successfully. Are you unreffing the AVFrame before passing it do the
decoder? Are you sure you're not using avcodec_free_frame() etc.?


More information about the Libav-user mailing list