[FFmpeg-trac] #9073(undetermined:new): ffmpeg memory overflow when trimming 4K clips

FFmpeg trac at avcodec.org
Thu Jan 21 07:39:05 EET 2021


#9073: ffmpeg memory overflow when trimming 4K clips
-------------------------------------+-------------------------------------
             Reporter:  andykais     |                     Type:  defect
               Status:  new          |                 Priority:  normal
            Component:               |                  Version:
  undetermined                       |  unspecified
             Keywords:  memory       |               Blocked By:
  filter_complex inputs              |
             Blocking:               |  Reproduced by developer:  0
Analyzed by developer:  0            |
-------------------------------------+-------------------------------------
 Summary of the bug:
 I have discovered that trimming inputs on large 4K files can cause ffmpeg
 to run out of memory computer (which has 16GB of ram). This appears to be
 a bug with input trimming because the command only overflows memory when
 the inputs are trimmed in the same command that contains a
 `-filter_complex`. For comparison, I have ran the same command twice,
 where the first case has inputs trimmed and saved as separate files. This
 does not crash. The second case has a single large input which has its
 inputs trimmed in the same command that renders the final output. This
 does crash. The two commands are shown below, and log files as well as
 memory profile graphs are attached.

 The video input in both cases is
 https://www.youtube.com/watch?v=voprky8BrPw which was downloaded with
 `youtube-dl`.


 The first case (that does not crash):
 {{{
 # create separate inputs beforehand
 for i in $(seq 0 9)
 do
   echo creating output-${i}.mp4
   ffmpeg -v error -ss $(($i * 20)) -t 10 -i './samples/oom-large-4k-
 file/Norway 4K - Winter in Norway - Relaxing Music with AMAZING Beautiful
 Nature and sound-voprky8BrPw.mkv' ./samples/oom-large-4k-
 file/output-${i}.mp4 -y
 done

 # stitch them all together
   ffmpeg \
     -v 9 -loglevel 99 \
     -i './samples/oom-large-4k-file/output-0.mp4' \
     -i './samples/oom-large-4k-file/output-1.mp4' \
     -i './samples/oom-large-4k-file/output-2.mp4' \
     -i './samples/oom-large-4k-file/output-3.mp4' \
     -i './samples/oom-large-4k-file/output-4.mp4' \
     -i './samples/oom-large-4k-file/output-5.mp4' \
     -i './samples/oom-large-4k-file/output-6.mp4' \
     -i './samples/oom-large-4k-file/output-7.mp4' \
     -i './samples/oom-large-4k-file/output-8.mp4' \
     -i './samples/oom-large-4k-file/output-9.mp4' \
     -map '[v_out_9]' -filter_complex
 'color=s=3840x2160:color=black:duration=100.00900000000001[base];
       [0:v] setpts=PTS-STARTPTS, scale=3840:2160 [v_in_0];
       [0:a] asetpts=PTS-STARTPTS, adelay=0:all=1, volume=1[a_in_0];
       [1:v] setpts=PTS+10.001/TB, scale=3840:2160 [v_in_1];
       [1:a] asetpts=PTS-STARTPTS, adelay=10001:all=1, volume=1[a_in_1];
       [2:v] setpts=PTS+20.002/TB, scale=3840:2160 [v_in_2];
       [2:a] asetpts=PTS-STARTPTS, adelay=20002:all=1, volume=1[a_in_2];
       [3:v] setpts=PTS+30.003/TB, scale=3840:2160 [v_in_3];
       [3:a] asetpts=PTS-STARTPTS, adelay=30003:all=1, volume=1[a_in_3];
       [4:v] setpts=PTS+40.004/TB, scale=3840:2160 [v_in_4];
       [4:a] asetpts=PTS-STARTPTS, adelay=40004:all=1, volume=1[a_in_4];
       [5:v] setpts=PTS+50.004999999999995/TB, scale=3840:2160 [v_in_5];
       [5:a] asetpts=PTS-STARTPTS, adelay=50004.99999999999:all=1,
 volume=1[a_in_5];
       [6:v] setpts=PTS+60.00599999999999/TB, scale=3840:2160 [v_in_6];
       [6:a] asetpts=PTS-STARTPTS, adelay=60005.99999999999:all=1,
 volume=1[a_in_6];
       [7:v] setpts=PTS+70.007/TB, scale=3840:2160 [v_in_7];
       [7:a] asetpts=PTS-STARTPTS, adelay=70007:all=1, volume=1[a_in_7];
       [8:v] setpts=PTS+80.00800000000001/TB, scale=3840:2160 [v_in_8];
       [8:a] asetpts=PTS-STARTPTS, adelay=80008.00000000001:all=1,
 volume=1[a_in_8];
       [9:v] setpts=PTS+90.00900000000001/TB, scale=3840:2160 [v_in_9];
       [9:a] asetpts=PTS-STARTPTS, adelay=90009.00000000001:all=1,
 volume=1[a_in_9];
       [base][v_in_0] overlay=x=0:y=0:eof_action=pass [v_out_0];
       [v_out_0][v_in_1] overlay=x=0:y=0:eof_action=pass [v_out_1];
       [v_out_1][v_in_2] overlay=x=0:y=0:eof_action=pass [v_out_2];
       [v_out_2][v_in_3] overlay=x=0:y=0:eof_action=pass [v_out_3];
       [v_out_3][v_in_4] overlay=x=0:y=0:eof_action=pass [v_out_4];
       [v_out_4][v_in_5] overlay=x=0:y=0:eof_action=pass [v_out_5];
       [v_out_5][v_in_6] overlay=x=0:y=0:eof_action=pass [v_out_6];
       [v_out_6][v_in_7] overlay=x=0:y=0:eof_action=pass [v_out_7];
       [v_out_7][v_in_8] overlay=x=0:y=0:eof_action=pass [v_out_8];
       [v_out_8][v_in_9] overlay=x=0:y=0:eof_action=pass [v_out_9];
 [a_in_0][a_in_1][a_in_2][a_in_3][a_in_4][a_in_5][a_in_6][a_in_7][a_in_8][a_in_9]
 amix=inputs=10 [audio]' \
     -map '[audio]' \
     template.mp4 -y \
     2> ffmpeg-separate-inputs-logs.txt

 }}}


 The second case (which does crash)
 {{{
   ffmpeg \
     -v 9 -loglevel 99 \
     -ss 0 -t 10 -i './samples/oom-large-4k-file/Norway 4K - Winter in
 Norway - Relaxing Music with AMAZING Beautiful Nature and sound-
 voprky8BrPw.mkv' \
     -ss 20 -t 10 -i './samples/oom-large-4k-file/Norway 4K - Winter in
 Norway - Relaxing Music with AMAZING Beautiful Nature and sound-
 voprky8BrPw.mkv' \
     -ss 40 -t 10 -i './samples/oom-large-4k-file/Norway 4K - Winter in
 Norway - Relaxing Music with AMAZING Beautiful Nature and sound-
 voprky8BrPw.mkv' \
     -ss 60 -t 10 -i './samples/oom-large-4k-file/Norway 4K - Winter in
 Norway - Relaxing Music with AMAZING Beautiful Nature and sound-
 voprky8BrPw.mkv' \
     -ss 80 -t 10 -i './samples/oom-large-4k-file/Norway 4K - Winter in
 Norway - Relaxing Music with AMAZING Beautiful Nature and sound-
 voprky8BrPw.mkv' \
     -ss 100 -t 10 -i './samples/oom-large-4k-file/Norway 4K - Winter in
 Norway - Relaxing Music with AMAZING Beautiful Nature and sound-
 voprky8BrPw.mkv' \
     -ss 120 -t 10 -i './samples/oom-large-4k-file/Norway 4K - Winter in
 Norway - Relaxing Music with AMAZING Beautiful Nature and sound-
 voprky8BrPw.mkv' \
     -ss 140 -t 10 -i './samples/oom-large-4k-file/Norway 4K - Winter in
 Norway - Relaxing Music with AMAZING Beautiful Nature and sound-
 voprky8BrPw.mkv' \
     -ss 160 -t 10 -i './samples/oom-large-4k-file/Norway 4K - Winter in
 Norway - Relaxing Music with AMAZING Beautiful Nature and sound-
 voprky8BrPw.mkv' \
     -ss 180 -t 10 -i './samples/oom-large-4k-file/Norway 4K - Winter in
 Norway - Relaxing Music with AMAZING Beautiful Nature and sound-
 voprky8BrPw.mkv' \
     -map '[v_out_9]' -filter_complex
 'color=s=3840x2160:color=black:duration=100.00900000000001[base];
       [0:v] setpts=PTS-STARTPTS, scale=3840:2160 [v_in_0];
       [0:a] asetpts=PTS-STARTPTS, adelay=0:all=1, volume=1[a_in_0];
       [1:v] setpts=PTS+10.001/TB, scale=3840:2160 [v_in_1];
       [1:a] asetpts=PTS-STARTPTS, adelay=10001:all=1, volume=1[a_in_1];
       [2:v] setpts=PTS+20.002/TB, scale=3840:2160 [v_in_2];
       [2:a] asetpts=PTS-STARTPTS, adelay=20002:all=1, volume=1[a_in_2];
       [3:v] setpts=PTS+30.003/TB, scale=3840:2160 [v_in_3];
       [3:a] asetpts=PTS-STARTPTS, adelay=30003:all=1, volume=1[a_in_3];
       [4:v] setpts=PTS+40.004/TB, scale=3840:2160 [v_in_4];
       [4:a] asetpts=PTS-STARTPTS, adelay=40004:all=1, volume=1[a_in_4];
       [5:v] setpts=PTS+50.004999999999995/TB, scale=3840:2160 [v_in_5];
       [5:a] asetpts=PTS-STARTPTS, adelay=50004.99999999999:all=1,
 volume=1[a_in_5];
       [6:v] setpts=PTS+60.00599999999999/TB, scale=3840:2160 [v_in_6];
       [6:a] asetpts=PTS-STARTPTS, adelay=60005.99999999999:all=1,
 volume=1[a_in_6];
       [7:v] setpts=PTS+70.007/TB, scale=3840:2160 [v_in_7];
       [7:a] asetpts=PTS-STARTPTS, adelay=70007:all=1, volume=1[a_in_7];
       [8:v] setpts=PTS+80.00800000000001/TB, scale=3840:2160 [v_in_8];
       [8:a] asetpts=PTS-STARTPTS, adelay=80008.00000000001:all=1,
 volume=1[a_in_8];
       [9:v] setpts=PTS+90.00900000000001/TB, scale=3840:2160 [v_in_9];
       [9:a] asetpts=PTS-STARTPTS, adelay=90009.00000000001:all=1,
 volume=1[a_in_9];
       [base][v_in_0] overlay=x=0:y=0:eof_action=pass [v_out_0];
       [v_out_0][v_in_1] overlay=x=0:y=0:eof_action=pass [v_out_1];
       [v_out_1][v_in_2] overlay=x=0:y=0:eof_action=pass [v_out_2];
       [v_out_2][v_in_3] overlay=x=0:y=0:eof_action=pass [v_out_3];
       [v_out_3][v_in_4] overlay=x=0:y=0:eof_action=pass [v_out_4];
       [v_out_4][v_in_5] overlay=x=0:y=0:eof_action=pass [v_out_5];
       [v_out_5][v_in_6] overlay=x=0:y=0:eof_action=pass [v_out_6];
       [v_out_6][v_in_7] overlay=x=0:y=0:eof_action=pass [v_out_7];
       [v_out_7][v_in_8] overlay=x=0:y=0:eof_action=pass [v_out_8];
       [v_out_8][v_in_9] overlay=x=0:y=0:eof_action=pass [v_out_9];
 [a_in_0][a_in_1][a_in_2][a_in_3][a_in_4][a_in_5][a_in_6][a_in_7][a_in_8][a_in_9]
 amix=inputs=10 [audio]' \
     -map '[audio]' \
     template.mp4 -y \
     2> ffmpeg-trimmed-inputs-logs.txt
 }}}

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


More information about the FFmpeg-trac mailing list