[Libav-user] Decoding memory consumption

Asaf Kave kaveasaf at gmail.com
Sun Jul 14 17:21:51 EEST 2019

On Tue, Jul 2, 2019 at 12:59 PM Carl Eugen Hoyos <ceffmpeg at gmail.com>

> Am Di., 2. Juli 2019 um 10:58 Uhr schrieb Asaf Kave <kaveasaf at gmail.com>:
> > I track the first call to 'avcodec_send_packet', and i find that the
> majority of
> > the memory consumption is made by call to
> > 'IDirectXVideoAccelerationService_CreateSurface' with initial_pool_size
> == 20.
> 16 is the maximum number of surfaces needed for h264 streams, my guess
> is that the remaining four surfaces come from the number of decoding
> threads.

You are correct, the 16 is from the "dxva2.c" file at
'ff_dxva2_common_frame_params' function, it's surfaces based on number of
possible refs.
The 4 (really 3 + 1) rest of the surfaces come from decode.c at
'ff_decode_get_hw_frames_ctx' function.

> > Is  there any way to configure this number ?
> Edit the source code.

I found the function 'avcodec_get_hw_frames_parameters'  located at
avcodec, that helping me to set the number of the initial_pool_size to
whatever i want, instead changing the hard coded source files.
I am calling that from the get_format callback, and it's work for me very

Now, i want to take this further, and try dynamically find the best value
for the initial_pool_size, for example starting with size of 3 and if
'avcodec_send_packet' is failed with AVERROR(ENOMEM) i will try to increase
it by 1 each time till i will get the limit that needed.
I succeeded to do it for H.264 codec as follow :

ret = avcodec_send_packet(m_avContext, m_avPkt);
if (ret == AVERROR(ENOMEM)) {
    m_avContext->pix_fmt = AV_PIX_FMT_NONE;

    if(m_avContext->hw_frames_ctx != NULL) {
          m_avContext->hw_frames_ctx = NULL;

this work, because at "h264_slice.c" function 'h264_init_ps' there is check
if pix_fmt not initialized, line 1056, then get_format is calling again.

For the HEVC, i didn't succeeded to find equivalent to ignite a new call to
the get_format.
I will be happy to get advise here.

> Please find out what top-posting means and avoid it here, Carl Eugen
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20190714/fef32f01/attachment.html>

More information about the Libav-user mailing list