[Libav-user] Decoding memory consumption

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[Libav-user] Decoding memory consumption

Asaf Kave
Hello all,
I am using FFmpeg with my software to decode H.264/H.265 videos.
I compare the FFmpeg to alternative, and i see that the memory consumption is too high with FFmpeg.

Is there any way to configure/fine tune the library to reduce the memory?

Thanks,
Asaf

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Decoding memory consumption

Carl Eugen Hoyos-2
Am Do., 27. Juni 2019 um 09:12 Uhr schrieb Asaf Kave <[hidden email]>:

> I am using FFmpeg with my software to decode H.264/H.265 videos.
> I compare the FFmpeg to alternative, and i see that the memory
> consumption is too high with FFmpeg.

Please elaborate!
(This does not sound like a known issue.)

> Is there any way to configure/fine tune the library to reduce the memory?

Use less threads.

Carl Eugen
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Decoding memory consumption

Asaf Kave
I am developing Microsoft Media Foundation Transform , a wrapper on FFmpeg, and my reference is Microsoft H.264 MFT .
In general the first call to "avcodec_send_packet" method produce around 75MB memory overhead compare to the MS decoder, and stay with this difference during the decoding process.

I am using more then one video feed, and the out of memory becoming an issue, so i would like to try to reduce the memory.

Can you share with me the threading configuration?

Thanks,
Asaf



On Thu, Jun 27, 2019 at 2:39 PM Carl Eugen Hoyos <[hidden email]> wrote:
Am Do., 27. Juni 2019 um 09:12 Uhr schrieb Asaf Kave <[hidden email]>:

> I am using FFmpeg with my software to decode H.264/H.265 videos.
> I compare the FFmpeg to alternative, and i see that the memory
> consumption is too high with FFmpeg.

Please elaborate!
(This does not sound like a known issue.)

> Is there any way to configure/fine tune the library to reduce the memory?

Use less threads.

Carl Eugen
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Decoding memory consumption

Venkateswaran.S
Are you using any queue for avpackets and avframe..?


_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Decoding memory consumption

Asaf Kave
i just use one avpacket and one avframe, and reuse them for each new sample.

something impotent that i miss out is that i am using hardware acceleration using DXVA2 to configure the FFmpeg.



On Sun, Jun 30, 2019 at 4:39 PM Venkateswaran.S <[hidden email]> wrote:
Are you using any queue for avpackets and avframe..?

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Decoding memory consumption

Asaf Kave
Hi ,
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.
Is  there any way to configure this number ?


On Mon, Jul 1, 2019 at 9:52 AM Asaf Kave <[hidden email]> wrote:
i just use one avpacket and one avframe, and reuse them for each new sample.

something impotent that i miss out is that i am using hardware acceleration using DXVA2 to configure the FFmpeg.



On Sun, Jun 30, 2019 at 4:39 PM Venkateswaran.S <[hidden email]> wrote:
Are you using any queue for avpackets and avframe..?

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Decoding memory consumption

Carl Eugen Hoyos-2
Am Di., 2. Juli 2019 um 10:58 Uhr schrieb Asaf Kave <[hidden email]>:

> 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.

> Is  there any way to configure this number ?

Edit the source code.

Please find out what top-posting means and avoid it here, Carl Eugen
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Decoding memory consumption

Asaf Kave


On Tue, Jul 2, 2019 at 12:59 PM Carl Eugen Hoyos <[hidden email]> wrote: 
Am Di., 2. Juli 2019 um 10:58 Uhr schrieb Asaf Kave <[hidden email]>:

> 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 well.

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) {
          av_buffer_unref(&m_avContext->hw_frames_ctx);
          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
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".