Hi,

Last couple of days I've been working on a video player using libav. And
because there is no
clean example of how to use AVFormatContext to demux a video file and
process the
frames I've based my code on talks in #libav-devel, the api-example.c and
code I found
when googling.

After being advised to copy the AVCodecContext from the video stream found
in AVFormatContext.streams,
I got a memory leak when closing/free-ing the AVCodecContext. I'm copying
the codec context like this:
https://gist.github.com/roxlu/ed76cd1465bc1cdb16b1#file-avdecoder-cpp-L107-L118

After diving into the source code of libav, I saw that avcodec_copy_context
copies the extradata, but
only frees it when it's an encoder. See the related code here:
https://gist.github.com/roxlu/5f0bbed4da1a52c971c4#file-utils-c-L1464-L1465

The documentation of avcodec_close says:
*"Close a given AVCodecContext and free all the data associated with it
(but not the AVCodecContext itself)."*
*
*
@nevcairiel told me that the source code tells otherwise and that you need
to free the extradata manually:
"** - decoding: Set/allocated/freed by user."*.

Therefore I changed my code and freed the extradata manually. Sadly this
didn't fix the memory leak.

I did found a workaround by manually allocating an AVCodecContext and
copying/freeing the extradata
myself.  I'm not having a memory leak anymore, but I'm still curious if
it's a bug in libav or my code.

Thanks,
roxlu
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to