[Libav-user] 32bit transcoding app running out of memory / setting "max_interleave_delta"

Simone Donadini Simone.Donadini at avolites.com
Thu Mar 21 14:46:43 EET 2019


What i am trying to do is to use a ffmpeg to encode files to a custom codec inside a quicktime container, and i have been using the transcode example as reference https://www.ffmpeg.org/doxygen/4.1/transcoding_8c-example.html
I am able to register the codec, read the packages, and write to the output file as expected.

The only thing i am dwelling with at the moment is that some codecs (e.g. ProRes) tend to drain the memory usage.
When transcoding a prores file, looking at the memory profile, i can see that av_interleaved_write_frame() is not freeing the memory allocated during the encoding function.
av_interleaved_write_frame() will start freeing memory just after a "Delay between the first packet and last packet in the muxing queue is 10004900 > 10000000: forcing output" log, and from that point on memory usage during encode_write_frame() will be steady. In both case, reaching or not the "forcing output" point, all the memory will be freed correctly at the end of the transcoding. The problem is that when using high resolution files (>4K) the app, which is 32bit, will run out of memory before getting to the "forcing output" point. I could notice this behavior with quicktime files only, when using h265 for example, av_interleaved_write_frame() will always free the memory.

So if i guess correctly i should find some setting in the muxer to limit memory usage / number of frames in the queue. At the moment i am setting "max_interleave_delta" in the output format context, and it is working fine. I have compared the quicktime header of files exported with and without the "max_interleave_delta", and the only difference i could spot is that the frame chucks are smaller on the latter, besides of that the files are then playing correctly.

But, is this a correct way to limit the muxer queue? or am i missing some other flag to set in the format context?

This is a file i am testing with:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\simone\Videos\bbb_sunflower_2160p_30fps_normal_9sec.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 537199360
    compatible_brands: qt
    creation_time   : 2019-03-20T13:29:43.000000Z
  Duration: 00:00:09.67, start: 0.000000, bitrate: 431795 kb/s
    Stream #0:0(eng), 10, 1/30: Video: prores, 1 reference frame (apch / 0x68637061), yuv422p10le(bt709, progressive), 3840x2160, 0/1, 429391 kb/s, SAR 1:1 DAR 16:9, 30 fps, 30 tbr, 30 tbn, 30 tbc (default)
    Metadata:
      creation_time   : 2019-03-20T13:29:43.000000Z
      handler_name    : Apple Alias Data Handler
      encoder         : Apple ProRes 422 HQ
      timecode        : 00:00:00:00
    Stream #0:1(eng), 0, 1/48000: Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, stereo, s16, 1536 kb/s (default)
    Metadata:
      creation_time   : 2019-03-20T13:29:43.000000Z
      handler_name    : Apple Alias Data Handler
      timecode        : 00:00:00:00
    Stream #0:2(eng), 0, 1/30: Data: none (tmcd / 0x64636D74), 0/1, 0 kb/s (default)
    Metadata:
      creation_time   : 2019-03-20T13:29:43.000000Z
      handler_name    : Apple Alias Data Handler
      timecode        : 00:00:00:00

Output #0, mov, to 'C:\Users\simone\Videos\bbb_sunflower_2160p_30fps_normal_9sec_AiM.mov':
Codec 0x8024 is not in the full list.
    Stream #0:0, 0, 1/30: Video: unknown_codec (aaimv), 1 reference frame (AIVM / 0x4D564941), argb, 3840x2160, 0/1, q=2-31, 200 kb/s, 30 tbn, 30 tbc
    Metadata:
      encoder         : AIM
    Stream #0:1, 0, 1/48000: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
    Stream #0:2, 0, 0/0: Unknown: none


Thanks,
Simone.

________________________________
From: Libav-user [libav-user-bounces at ffmpeg.org] on behalf of Anton Shekhovtsov [shekh.anton at gmail.com]
Sent: Wednesday, March 20, 2019 10:21 AM
To: This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter.
Subject: Re: [Libav-user] 32bit transcoding app running out of memory / setting "max_interleave_delta"



ср, 20 мар. 2019 г. в 12:13, Carl Eugen Hoyos <ceffmpeg at gmail.com<mailto:ceffmpeg at gmail.com>>:
2019-03-20 11:06 GMT+01:00, Simone Donadini <Simone.Donadini at avolites.com<mailto:Simone.Donadini at avolites.com>>:

> we are developing a 32bit transcoder using ffmpeg based on the
> transcoding example
> https://www.ffmpeg.org/doxygen/4.1/transcoding_8c-example.html
> and we are encountering some problem with memory usage
> transcoding files with large resolutions.

Please run massif (or an equivalent tool) to find out where
the memory allocations happen: Everything else includes
guesswork that can easily be avoided.

Please provide "ffmpeg -i" output for both input and output
file so we at least know what you are trying to do.

Carl Eugen
_______________________________________________
Libav-user mailing list
Libav-user at ffmpeg.org<mailto: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<mailto:libav-user-request at ffmpeg.org> with subject "unsubscribe".

"Delay between the first packet and last packet in the muxing queue is 10004900 > 10000000: forcing output"
I can be wrong but does this warning tell the packets are coming in wrong order?
If you mux multiple streams (a+v) you should preinterleave streams packets with enough accuracy, otherwise ffmpeg must buffer everything and this is where memory is wasted.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20190321/05a847d4/attachment.html>


More information about the Libav-user mailing list