[Libav-user] Frames corruption when seeking...

wm4 nfxjfg at googlemail.com
Fri May 30 14:25:55 CEST 2014


On Fri, 30 May 2014 22:02:36 +1000
Jean-Yves Avenard <jyavenard at gmail.com> wrote:

> On 30 May 2014 21:40, wm4 <nfxjfg at googlemail.com> wrote:
> 
> > Then you're probably doing something wrong. It's easily possible that
> > this "wrong" thing was right (or just didn't cause problems) before the
> > recent API changes.
> 
> oh, I'm sure I am... The question is what :)
> 
> I'll keep looking
> 
> 
> 
> > Are you using av_frame_free()? AVFrames are reference counted in the
> > most recent release, so freeing the data isn't as simple as it was.
> > av_frame_free() should take care of this properly.
> 
> with FFmpeg 1.2 I actually didn't allocate the AVFrame.
> 
> I had simply:
>     AVFrame frame;
>     avcodec_get_frame_defaults(&frame);
> 
> and use avcodec_decode_audio4 with a pointer to frame.

At some point, sizeof(AVFrame) was removed from the ABI (i.e, AVFrame
can change any time now). Now you always have to allocate AVFrame with
the provided API functions.

> avcodec_get_frame_defaults being obsolete now, I have changed this to:
>     AVFrame *frame;
>     if (!(frame = av_frame_alloc()))
>     {
>         return AVERROR(ENOMEM);
>     }
> 
>     ret = avcodec_decode_audio4(ctx, frame, &got_frame, pkt);
>     ...
> 
>     av_frame_free(&frame);
> 
> but regardless of the method, the data pointed to within AVFrame is
> never deallocated by either av_frame_free or avcodec_free_frame
> 
> Stepping into the code, it seems that the decoder is managing the
> data, allocating it with get_buffer() and release it later...
> 
> so that makes sense.

In my opinion, the code above is correct. Maybe you could also try to
set the AVCodecContext.refcounted_frames field to 1 before opening the
decoder, and calling av_frame_unref(frame) before calling
avcodec_decode_* (the later was needed with refcounting enabled at
least at some point).

Do you close the decoder correctly? The decoder will keep frame
references internally, and if avcodec_close() isn't called, they won't
be released.

> 
> > I get a mostly black screen with some artifacts when playing your video
> > with vdpau decoding on an older nvidia card with binary drivers.
> 
> ah yes you're right... it's another video that gives me green blocks.
> 
> Maybe I should raise a bug then...
> 
> but seeing I couldn't reproduce it with mplayer, and as the new API
> doesn't cause the issue, I thought the issue was on our side only,..

Can you try with mplayer and "-demuxer lavf"?

> What are you using to play?

mpv, it uses libavformat for demuxing.


More information about the Libav-user mailing list