thebearot
thebearot

Reputation: 43

FFMpeg, AVFrame and AVBuffer

I need help understanding the relationship between AVBuffer and AVFrame. The reason I am getting into this confusion is that I am attempting to make queues of frames and I understand that it can be accomplished via "Reference Counting".

This is what I understand:
- Setting refcounted_frame = 1 in AVCondecContext enables reference counting/passing via avcodec_framde_decode2().
- Everytime avcodec_frame_decode2() is called, I get a new buffer in AVFrame->buf.

What I am confused about:
- Is referenced frame basically 'previous' AVFrame->data??
- If the above is true, how would I reference the counted frames? I suppose via AVFrame->buf[i]?

Any clarification is very much appreciated.

-T

Upvotes: 4

Views: 2214

Answers (1)

Ronald S. Bultje
Ronald S. Bultje

Reputation: 11174

  • Is referenced frame basically 'previous' AVFrame->data??

Well, sort of, but please do note that most modern codecs support multiple references, so the past N AVFrame->data[] are cached internally in the codec to be used as reference frame in inter prediction of subsequent frames.

Also note that although the name is identical, there is no relationship between reference counting and reference frames.

  • If the above is true, how would I reference the counted frames? I suppose via AVFrame->buf[i]?

No, AVFrame->buf[] is just a placeholder for the buffer object that belongs to the planar data in AVFrame->data[]. The frame also holds other buffers, such as for side-data. If you want to get access to previous frames that the decoder might use for as reference frames in inter prediction, you'll have to cache the frames manually as they are returned. Note also that vp9 and hevc have a concept of invisible frames that are never returned to the user and only exist for internal use in coding subsequent frames in the decoder.

Upvotes: 3

Related Questions