[libav-bugs] [Bug 525] New: Optimize memory management for mp4 muxer

bugzilla-daemon at aruru.libav.org bugzilla-daemon at aruru.libav.org
Sat Jun 1 11:35:01 CEST 2013


https://bugzilla.libav.org/show_bug.cgi?id=525

           Summary: Optimize memory management for mp4 muxer
           Product: Libav
           Version: 9
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: Normal
         Component: libavformat
        AssignedTo: bugzilla at libav.org
        ReportedBy: andysem at mail.ru


Created attachment 416
  --> https://bugzilla.libav.org/attachment.cgi?id=416
The patch optimizes memory management in mp4/mov muxer

I'm using libav 9.6 to write long (many hour) mp4 files in multiple threads of
my application. I've set up the muxer so that it creates fragmented files, but
memory consumption still grows considerably over time. While inspecting libav
code (libavformat/movenc.c in particular) I found out that it constantly
allocates and reallocates memory without attempting to pool and reuse it. This
behavior seems to be causing excessive memory fragmentation with tcmalloc,
which I use as the memory allocator, and as a consequence - memory growth over
time. It is not a leak per se, but rather inefficient behavior.

I prepared a patch that optimizes memory allocations in movenc.c when
fragmented files are written. The patch is two-fold. First, it introduces the
avio_reset_dyn_buf function, which allows to obtain the pointer and size of the
buffer and resets the writing position of the stream to 0. This allows to
acquire the written contents and reuse the buffer (and the allocated memory).
The function can be used in other places as well. Second, this new function is
used within the mp4 muxer to encode and write mov tags. Also, some of the
frequently reallocated buffers in MOVTrack are given the capacity value and
only reallocated when the capacity is not enough.

Overall, with fragmented mp4 files this gives more stable memory consumption
and avoids fragmentation. I see considerably less memory growth with tcmalloc
with this patch applied.

-- 
Configure bugmail: https://bugzilla.libav.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.


More information about the libav-bugs mailing list