#9173 closed defect (fixed)

Underestimated required buffer size (prores 8K)

Reported by: 0kajuna0 Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords: prores
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug: While trying to encode an 8k PNG stream with prores, ffmpeg crashes with "Underestimated required buffer size". This seems to only happen if the PNG stream contains complex images. It seems to be fine if the PNGs are mostly alpha.

This is not an issue with version 4.2.3. Seems to first appear with 4.3.

Tested with multiple Windows machines.

How to reproduce:

% Error: Command failed: ffmpeg -v 9 -loglevel 99 -probesize 472M -f image2pipe -framerate 24000/1001 -i - -c:v prores_ks -y C:\prorestest.MOV
ffmpeg version 2021-03-31-git-61ea0e3191-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10.2.0 (Rev6, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      56. 72.100 / 56. 72.100
  libavcodec     58.135.100 / 58.135.100
  libavformat    58. 77.100 / 58. 77.100
  libavdevice    58. 14.100 / 58. 14.100
  libavfilter     7.111.100 /  7.111.100
  libswscale      5. 10.100 /  5. 10.100
  libswresample   3. 10.100 /  3. 10.100
  libpostproc    55. 10.100 / 55. 10.100
Splitting the commandline.
Reading option '-v' ... matched as option 'v' (set logging level) with argument '9'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument '99'.
Reading option '-probesize' ... matched as AVOption 'probesize' with argument '472M'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'image2pipe'.
Reading option '-framerate' ... matched as AVOption 'framerate' with argument '24000/1001

'.
Reading option '-i' ... matched as input url with argument '-'.
Reading option '-c:v' ... matched as option 'c' (codec name) with argument 'prores_ks'.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option 'C:\prorestest.MOV' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument 9.
Applying option y (overwrite output files) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input url -.
Applying option f (force format) with argument image2pipe.
Successfully parsed a group of options.
Opening an input file: -.
[image2pipe @ 000001defaaa1a00] Opening 'pipe:' for reading
[pipe @ 000001defaaa2a00] Setting default whitelist 'crypto,data'
[image2pipe @ 000001defaaa1a00] Before avformat_find_stream_info() pos: 0 bytes read:65536 seeks:0 nb_streams:1
[image2pipe @ 000001defaaa1a00] Probe buffer size limit of 472000000 bytes reached
[image2pipe @ 000001defaaa1a00] stream 0: start_time: NOPTS duration: NOPTS
[image2pipe @ 000001defaaa1a00] format: start_time: NOPTS duration: NOPTS (estimate from bit rate) bitrate=0 kb/s
[image2pipe @ 000001defaaa1a00] After avformat_find_stream_info() pos: 473280512 bytes read:473345153 seeks:0 frames:110
Input #0, image2pipe, from 'pipe:':
  Duration: N/A, bitrate: N/A
  Stream #0:0, 110, 1001/24000: Video: png, 1 reference frame, rgba(pc), 7680x3840, 0/1, 23.98 fps, 23.98 tbr, 23.98 tbn, 23.98 tbc
Successfully opened the file.
Parsing a group of options: output url C:\prorestest.MOV.
Applying option c:v (codec name) with argument prores_ks.
Successfully parsed a group of options.
Opening an output file: C:\prorestest.MOV.
[file @ 000001defaae64c0] Setting default whitelist 'file,crypto,data'
Successfully opened the file.
detected 8 logical cores
Stream mapping:
  Stream #0:0 -> #0:0 (png (native) -> prores (prores_ks))
cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
    Last message repeated 8 times
[graph 0 input from stream 0:0 @ 000001defaaa5940] Setting 'video_size' to value '7680x3840'
[graph 0 input from stream 0:0 @ 000001defaaa5940] Setting 'pix_fmt' to value '26'
[graph 0 input from stream 0:0 @ 000001defaaa5940] Setting 'time_base' to value '1001/24000'
[graph 0 input from stream 0:0 @ 000001defaaa5940] Setting 'pixel_aspect' to value '0/1'
[graph 0 input from stream 0:0 @ 000001defaaa5940] Setting 'frame_rate' to value '24000/1001'
[graph 0 input from stream 0:0 @ 000001defaaa5940] w:7680 h:3840 pixfmt:rgba tb:1001/24000 fr:24000/1001 sar:0/1
[format @ 000001defaab1640] Setting 'pix_fmts' to value 'yuv422p10le|yuv444p10le|yuva444p10le'
[auto_scaler_0 @ 000001defaad4100] Setting 'flags' to value 'bicubic'
[auto_scaler_0 @ 000001defaad4100] w:iw h:ih flags:'bicubic' interl:0
[format @ 000001defaab1640] auto-inserting filter 'auto_scaler_0' between the filter 'Parsed_null_0' and the filter 'format'
[AVFilterGraph @ 000001defaac6b00] query_formats: 4 queried, 2 merged, 1 already done, 0 delayed
[auto_scaler_0 @ 000001defaad4100] picking yuva444p10le out of 3 ref:rgba alpha:1
[auto_scaler_0 @ 000001defaad4100] w:7680 h:3840 fmt:rgba sar:0/1 -> w:7680 h:3840 fmt:yuva444p10le sar:0/1 flags:0x4
[prores_ks @ 000001defacd8a40] Autoselected 4:4:4:4 profile because of the used input colorspace. It can be overridden through -profile option.
[prores_ks @ 000001defacd8a40] profile 4, 14400 slices, interlacing: no, 28500 bits per MB
[prores_ks @ 000001defacd8a40] frame size upper bound: 476932518
[prores_ks @ 000001defab5eac0] Autoselected 4:4:4:4 profile because of the used input colorspace. It can be overridden through -profile option.
[prores_ks @ 000001defab5eac0] profile 4, 14400 slices, interlacing: no, 28500 bits per MB
[prores_ks @ 000001defab5eac0] frame size upper bound: 476932518
[prores_ks @ 000001defab67080] Autoselected 4:4:4:4 profile because of the used input colorspace. It can be overridden through -profile option.
[prores_ks @ 000001defab67080] profile 4, 14400 slices, interlacing: no, 28500 bits per MB
[prores_ks @ 000001defab67080] frame size upper bound: 476932518
[prores_ks @ 000001defab64780] Autoselected 4:4:4:4 profile because of the used input colorspace. It can be overridden through -profile option.
[prores_ks @ 000001defab64780] profile 4, 14400 slices, interlacing: no, 28500 bits per MB
[prores_ks @ 000001defab64780] frame size upper bound: 476932518
[prores_ks @ 000001defab65e40] Autoselected 4:4:4:4 profile because of the used input colorspace. It can be overridden through -profile option.
[prores_ks @ 000001defab65e40] profile 4, 14400 slices, interlacing: no, 28500 bits per MB
[prores_ks @ 000001defab65e40] frame size upper bound: 476932518
[prores_ks @ 000001defab64c00] Autoselected 4:4:4:4 profile because of the used input colorspace. It can be overridden through -profile option.
[prores_ks @ 000001defab64c00] profile 4, 14400 slices, interlacing: no, 28500 bits per MB
[prores_ks @ 000001defab64c00] frame size upper bound: 476932518
[prores_ks @ 000001defab67500] Autoselected 4:4:4:4 profile because of the used input colorspace. It can be overridden through -profile option.
[prores_ks @ 000001defab67500] profile 4, 14400 slices, interlacing: no, 28500 bits per MB
[prores_ks @ 000001defab67500] frame size upper bound: 476932518
[prores_ks @ 000001defab66c00] Autoselected 4:4:4:4 profile because of the used input colorspace. It can be overridden through -profile option.
[prores_ks @ 000001defab66c00] profile 4, 14400 slices, interlacing: no, 28500 bits per MB
[prores_ks @ 000001defab66c00] frame size upper bound: 476932518
[prores_ks @ 000001defaae4ac0] Autoselected 4:4:4:4 profile because of the used input colorspace. It can be overridden through -profile option.
[prores_ks @ 000001defaae4ac0] profile 4, 14400 slices, interlacing: no, 28500 bits per MB
[prores_ks @ 000001defaae4ac0] frame size upper bound: 476932518
Output #0, mov, to 'C:\prorestest.MOV':
  Metadata:
    encoder         : Lavf58.77.100
  Stream #0:0, 0, 1/24000: Video: prores, 1 reference frame (ap4h / 0x68347061), yuva444p10le(tv, progressive), 7680x3840 (0x0), 0/1, q=2-31, 200 kb/s, 23.98 fps, 24k tbn
    Metadata:
      encoder         : Lavc58.135.100 prores_ks
Clipping frame in rate conversion by 0.000008
frame=    1 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
frame=    2 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
    Last message repeated 1 times
frame=    4 fps=2.5 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
    Last message repeated 1 times
frame=    6 fps=2.5 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
    Last message repeated 1 times
frame=    8 fps=2.4 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
[prores_ks @ 000001defacd8a40] Underestimated required buffer size.
Video encoding failed
[AVIOContext @ 000001defaae65c0] Statistics: 0 seeks, 1 writeouts
[prores_ks @ 000001defab5eac0] Underestimated required buffer size.
[prores_ks @ 000001defab64780] Underestimated required buffer size.
[prores_ks @ 000001defab67080] Underestimated required buffer size.
[prores_ks @ 000001defab65e40] Underestimated required buffer size.
[prores_ks @ 000001defab64c00] Underestimated required buffer size.
[prores_ks @ 000001defab66c00] Underestimated required buffer size.
[prores_ks @ 000001defab67500] Underestimated required buffer size.
[prores_ks @ 000001defacd8a40] Underestimated required buffer size.
[AVIOContext @ 000001defaab2c40] Statistics: 473345153 bytes read, 0 seeks
Conversion failed!

Change History (9)

comment:1 by Carl Eugen Hoyos, 20 months ago

Component: ffmpegavcodec
Keywords: 8k png removed
Priority: importantnormal

comment:2 by mkver, 20 months ago

Can you upload the exact png that leads to this error? (If the file is big, you can upload it here.)

in reply to:  2 comment:3 by 0kajuna0, 20 months ago

Replying to mkver:

Can you upload the exact png that leads to this error? (If the file is big, you can upload it here.)

Edit: Apologies. The crash happens with a single file too. I now uploaded a single PNG. please disregard the previous (very large) ZIP file.

I uploaded a ZIP with several PNG files that produce the crash. In my use case the crash happens when sending the data as a stream, but I just checked that using the PNG files as an input produces the crash too:

ffmpeg -i %03d.png -c:v prores_ks -y test.mov

I could just upload a handful of PNGs if the file is too large. The crash does not always happen on the same frame but it's usually within the first 30. Just wanted to make sure there were enough of them (and I don't know if them being different or the same makes a difference).

Last edited 20 months ago by 0kajuna0 (previous) (diff)

comment:4 by mkver, 20 months ago

  1. I could already reproduce the issue with a different sample. Nevertheless thanks for the effort (have you btw selected FFmpeg as the project? I am asking because the sample hasn't appeared here yet).
  2. The problem is basically here: "frame size upper bound: 476932518". When converted to bits this gives a negative number in a 32bit, leading to nonsense check results.
  3. When I test with an old build of 4.2, the outcome is only slightly different: It does not stops after having encountered an error; instead it just keeps on going, but the frames where the error have been encountered are dropped.

comment:5 by 0kajuna0, 20 months ago

Thank you.

Yes, I'm selecting ffmpeg and introducing the ticket number when uploading. I just uploaded a new PNG. Could it be that the first zip is blocking something due to its size? It was huge. Sorry.

I had not noticed the dropped frames with 4.2
Is there a temporary workaround for this problem? Or some way I could help solve it?

comment:6 by mkver, 20 months ago

You had not noticed the dropped frames, but they occured, didn't they?

No to both. I already know how to solve it.

[Edit]: Your png just appeared.

Last edited 20 months ago by mkver (previous) (diff)

comment:7 by 0kajuna0, 20 months ago

You're right. 4.2.3 gets through but drops the frames.

I really appreciate you solving this.

comment:8 by mkver, 20 months ago

Thanks for the confirmation. Here is the patch btw. If no one objects, I will merge it in a few days.

comment:9 by mkver, 20 months ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.