[FFmpeg-trac] #7641(avformat:new): MOV demuxer hogs lots of memory for encrypted files

FFmpeg trac at avcodec.org
Sat Dec 29 05:39:37 EET 2018

#7641: MOV demuxer hogs lots of memory for encrypted files
             Reporter:  Starchild  |                     Type:  defect
               Status:  new        |                 Priority:  normal
            Component:  avformat   |                  Version:  git-master
             Keywords:  mov        |               Blocked By:
             Blocking:             |  Reproduced by developer:  0
Analyzed by developer:  0          |
 Summary of the bug:
 Due to unfrotunate memory management in the mov demuxer, systems with low
 hardware specs run out of memory while playing encrypted MP4 streams.
 This is due to the mov_try_read_block allocating 1 MB blocks regardless of
 the size that was actually required. They are not shrunk to their actual
 size and only freed when the context gets closed.
 Specifically, it happens while processing saiz atoms (auxiliary_info_sizes

 How to reproduce: Process a CENC-encrypted stream with a runtime of 1 hour
 that has around a thousand moof fragments inside the MP4 on a low-spec box
 (say, 150 MB of available memory).

 Possible fix (works for me):
 Change tail of mov_try_read_block to do shrinking. Alternatively don't
 allocate a huge buffer in the first place when a smaller size is known?
     *data = av_realloc(buffer, size);
     if (!*data) {
         return AVERROR(ENOMEM);

Ticket URL: <https://trac.ffmpeg.org/ticket/7641>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker

More information about the FFmpeg-trac mailing list