Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use av_frame_unref in ffmpeg?

Tags:

ffmpeg

  1. Can I create one AVFrame and use it for decoding of all frames? So I call av_frame_alloc() once, decode all frames, and then call av_frame_unref() once. Or I should call av_frame_alloc / av_frame_unref for each frame?
  2. When exactly I should call av_frame_unref, before decoding or after decoding?

A.

av_frame_alloc()

av_frame_unref()

(decoding...)

B. Or this variant:

av_frame_alloc()

(decoding...)

av_frame_unref()
like image 877
Igor Avatar asked Oct 17 '25 07:10

Igor


1 Answers

  1. You could only use one AVFrame struct for the entire decoding/encoding process, by calling av_frame_alloc() once.
  2. av_frame_unref() is only needed when you decide to enable reference counting for your encoding/decoding context, called for each frame.
  3. Use av_frame_free() to free the frame struct and all its buffers at the end of your encoding/decoding process.

See ffmpeg's official examples for how to use them: demuxing_decoding

like image 110
halfelf Avatar answered Oct 20 '25 11:10

halfelf