Hello,

I have a simple module in our application that encodes a generated raw image 
and writes the encoded packets to file. The allocated image size is 1920x1080.

Calls to avcodec_encode_video2  are allocating around 500MB of memory which is 
never freed up. I cannot find the source of this leak.

Below I have described the procedure I'm using. Some notes:


1.       if avcodec_encode_video2  does not return a got_pkt, I'm not freeing 
the packet because it was never allocated. Is that correct?


2.  Am I correctly freeing frames with:  av_freep and avcodec_free_frame ?


3.       Does sws_scale simply takes the srcFrame and copies the 
scaled/converted image to the already allocated dstFrame, or is there any 
malloc involved internally? If so, I'm not freeing anything after this call.


Thanks and Regards

Reuben





FUNCTION Start

av_register_all()
avformat_alloc_context(..)
avcodec_find_encoder
avformat_new_stream(..)
avcodec_open2(..)
srcFrame = avcodec_alloc_frame(..)
dstFrame = avcodec_alloc_frame(..)
av_image_alloc(srcFrame, ...)
av_image_alloc(dstFrame, ...)
sws_getContext(..)
avio_open(..)
avformat_write_header(..)

End FUNCTION




FUNCTION WriteLoop

while (..)
{
  fill srcFrame
  av_init_packet(..)
  sws_scale(srcFrame, dstFrame, ...)
  avcodec_encode_video2(.., dstFrame, got_pkt)
  if (got_pkt) WritePacket()
}

End FUNCTION




FUNCTION WritePacket

av_interleaved_write_frame(..)
av_free_packet(..)

End FUNCTION




FUNCTION Stop

got_pkt = 1

while (got_pkt)
{
  avcodec_encode_video2(.., NULL, got_pkt)
  if (got_pkt) WritePacket()
}

av_write_trailer(..)

av_freep(&srcFrame->data[0]);
avcodec_free_frame(&srcFrame);

av_freep(&dstFrame->data[0]);
avcodec_free_frame(&dstFrame);

//free the streams.
av_freep(streams[i]->codec);
av_freep(streams[i]);

avio_close(..);

av_free(avFormatContext);

sws_freeContext(..);


End FUNCTION
_______________________________________________
libav-api mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-api

Reply via email to