[Libav-user] Memory leak when using HW accelerated decoding

Andrea Campisi Andrea.Campisi at avolites.com
Thu Mar 7 19:27:39 EET 2024


Hello everyone, I hope that someone can point me into the right direction with this issue.

I have a decoding loop that can optionally use HW acceleration.
The code has been tested on different machines with both Intel and NVIDIA graphic cards and works without issues in most cases.
I'm seeing a memory leak though during a test on a laptop with the following specs:


  *   Intel i7
  *   NVIDIA quadro p520
  *   File being played is a H.264 1920x1080
  *   HW device is AV_HWDEVICE_TYPE_D3D11VA

The leak will eat up all the available memory very quickly and crash the machine.

When running on this machine avcodec_receive_frame(d->avctx, cur_frame) will always return -11 (AVERROR(EAGAIN)) while avcodec_send_packet executes without any issue and it is continuously called even if avcodec_receive_frame is not dequeuing any frame from AVCodecContext*  d->avctx.

av_hwdevice_ctx_create is executed without any problem and creating the context correctly.

cur_frame is not allocated and de-allocated at each step of the decoding loop as in hw_decode.c<https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/hw_decode.c> example but is allocated only once inside a init() function:
d->valid_frame = av_frame_alloc();
d->sw_valid_frame = av_frame_alloc();

and destroyed once in a destroy() function:
av_frame_free(&d->valid_frame);
av_frame_free(&d->sw_valid_frame);
 av_packet_unref(&d->pkt);
 avcodec_free_context(&d->avctx);

The leak seems is not due to any missing de-allocation.
Any help is much appreciated. Thank you!

Andrea
This email and any attachments to it may be confidential and are intended solely for the use of the individual to whom it is addressed.
If you are not the intended recipient of this email, you must neither take any action based upon its contents, nor copy or show it to anyone.
Please contact the sender if you believe you have received this email in error. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20240307/a1e87c5f/attachment.htm>


More information about the Libav-user mailing list