Opened 2 years ago

Closed 12 months ago

#10990 closed defect (fixed)

"Assertion best_input >= 0 failed" IFF upsampling AND complex filtergraph

Reported by: Hunter Hogan Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords: resampling
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description (last modified by Hunter Hogan)

Summary of the bug:
If resampler is invoked at the start of the filtergraph to upsample, an error will be thrown at the very end despite the output file being successfully written. Assertion best_input >= 0 failed at src/fftools/ffmpeg_filter.c:2075


[edit] To reproduce, copy/paste

FFmpeg -y -hide_banner -loglevel warning -stats ^
-f lavfi -i anoisesrc=d=533:c=pink:r=44100:a=0.5 ^
-filter_complex [0]aresample=192000,asplit[in1][b0];[b0]atrim=start_sample=146155:end_sample=655680,asetpts=PTS-STARTPTS,afade=in:ns=970:curve=squ[TRIM0];[in1]anullsink;[TRIM0]anull[Z0Z_out] ^
-ar 44100 -map "[Z0Z_out]" -codec:a pcm_f32le ^
"anoisesrc_filtergraph_aresample_44100.wav"

But, no error with:

FFmpeg -f lavfi -i anoisesrc=d=533:c=pink:r=44100:a=0.5 ^
-filter_complex [0]aresample=192000[b0];[b0]atrim=start_sample=146155:end_sample=655680,asetpts=PTS-STARTPTS,afade=in:ns=970:curve=squ[Z0Z_out] ^
-ar 44100 -map "[Z0Z_out]" -codec:a pcm_f32le ^
"anoisesrc_aresample.wav"

Build:

ffmpeg version N-115666-gae00db87ca-g417957ec5e+3 Copyright (c) 2000-2024 the FFmpeg developers
  built with gcc 14.1.0 (Rev3, Built by MSYS2 project)
  configuration:  --pkg-config=pkgconf --cc='ccache gcc' --cxx='ccache g++' --ld='ccache g++' --extra-cxxflags=-fpermissive --extra-cflags=-Wno-int-conversion --disable-autodetect --enable-amf --enable-bzlib --enable-d3d11va --enable-dxva2 --enable-iconv --enable-lzma --enable-zlib --enable-sdl2 --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libdav1d --enable-libaom --disable-debug --enable-libfdk-aac --enable-fontconfig --enable-libass --enable-libfreetype --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libwebp --enable-libxml2 --enable-libzimg --enable-libshine --enable-gpl --enable-avisynth --enable-libxvid --enable-libopenmpt --enable-version3 --enable-librav1e --enable-libsrt --enable-libgsm --enable-libvmaf --enable-libsvtav1 --enable-chromaprint --enable-frei0r --enable-libaribb24 --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfribidi --enable-libgme --enable-libilbc --enable-libsvthevc --enable-libsvtvp9 --enable-libkvazaar --enable-libmodplug --enable-librist --enable-librtmp --enable-librubberband --enable-libtesseract --enable-libxavs --enable-libzmq --enable-libzvbi --enable-openal --enable-libcodec2 --enable-ladspa --enable-libglslang --enable-vulkan --enable-libdavs2 --enable-libxavs2 --enable-libuavs3d --enable-libplacebo --enable-libjxl --enable-opencl --enable-opengl --enable-libopenh264 --enable-libharfbuzz --enable-libfontconfig --enable-openssl --extra-cflags=-DLIBTWOLAME_STATIC --extra-cflags=-DCACA_STATIC --extra-cflags=-DMODPLUG_STATIC --extra-cflags=-DCHROMAPRINT_NODLL --extra-cflags=-DZMQ_STATIC --extra-libs=-lpsapi --extra-cflags=-DLIBXML_STATIC --extra-libs=-liconv --disable-w32threads --extra-cflags=-DKVZ_STATIC_LIB --enable-nonfree --extra-cflags=-DAL_LIBTYPE_STATIC --extra-cflags='-IC:/apps/media-autobuild_suite/local64/include' --extra-cflags='-IC:/apps/media-autobuild_suite/local64/include/AL'
  libavutil      59. 21.100 / 59. 21.100
  libavcodec     61.  7.100 / 61.  7.100
  libavformat    61.  3.104 / 61.  3.104
  libavdevice    61.  2.100 / 61.  2.100
  libavfilter    10.  2.102 / 10.  2.102
  libswscale      8.  2.100 /  8.  2.100
  libswresample   5.  2.100 /  5.  2.100
  libpostproc    58.  2.100 / 58.  2.100

Previous ramblings:

How to reproduce:
I reproduced it with a few different wav files, including a white noise file. All were stereo, however. Batch file and 22 logs attached. Only 4 logs have the error. The other logs are to compare changing only one variable but not getting an error.

These quick tests all have filtergraphs loaded from a textfile, and I don't think I tested it without a text file. These tests all use -/complex_filter syntax, but I got the same error with the old syntax.

I did not test downsampling at the start of the filtergraph.

I first encountered this a couple of weeks ago after building version 7. Prior to that, however, I don't think I ever had a filtergraph that included upsampling and multiple input and/or output pads, so I am not claiming the error was recently introduced.

If I recall correctly, originally, FFmpeg would crash, throw the error, and not write a usable file. IIRC, the output file was the size I expected (in bytes), but nothing could read it: ffprobe, ffmpeg, Goldwave all said the file was garbage. I interpreted it to mean that the "headers" were malformed. (By "headers", I probably mean metadata, but I don't know the precise term here.)

I worked around it by scripting:

  1. upsample my input file to a temp output file
  2. filter as I want, output to a new temp
  3. downsample

IIRC, it was necessary for me to downsample in a different filtergraph. But, it now looks like downsampling doesn't throw an error.

Today, I rebuilt, and noticed the differences.

% FFmpeg -hide_banner -loglevel warning -stats 
-i test_input_44100_2ch.wav -/filter_complex test_filter.txt 
-map "[Z0Z_out]" -codec:a pcm_f32le 
"output\\test_input_44100_2ch.wav_filtergraph_192000.wav"

ffmpeg version: media autobuilder suite, built today on Windows

ffmpeg version N-115035-g192f5b58b7-gb7debef3cc+4 Copyright (c) 2000-2024 the FFmpeg developers
built with gcc 13.2.0 (Rev6, Built by MSYS2 project)
configuration:  --pkg-config=pkgconf --cc='ccache gcc' --cxx='ccache g++' --ld='ccache g++' --extra-cxxflags=-fpermissive --extra-cflags=-Wno-int-conversion --disable-autodetect --enable-amf --enable-bzlib --enable-d3d11va --enable-dxva2 --enable-iconv --enable-lzma --enable-zlib --enable-sdl2 --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libdav1d --enable-libaom --disable-debug --enable-libfdk-aac --enable-fontconfig --enable-libass --enable-libfreetype --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libwebp --enable-libxml2 --enable-libzimg --enable-libshine --enable-gpl --enable-avisynth --enable-libxvid --enable-libopenmpt --enable-version3 --enable-librav1e --enable-libgsm --enable-libvmaf --enable-libsvtav1 --enable-chromaprint --enable-frei0r --enable-libaribb24 --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfribidi --enable-libgme --enable-libilbc --enable-libsvthevc --enable-libsvtvp9 --enable-libkvazaar --enable-libmodplug --enable-librtmp --enable-librubberband --enable-libtesseract --enable-libxavs --enable-libzmq --enable-libzvbi --enable-openal --enable-libcodec2 --enable-ladspa --enable-libglslang --enable-vulkan --enable-libdavs2 --enable-libxavs2 --enable-libuavs3d --enable-opengl --enable-libopenh264 --enable-libharfbuzz --enable-libfontconfig --enable-openssl --extra-cflags=-DLIBTWOLAME_STATIC --extra-cflags=-DCACA_STATIC --extra-cflags=-DMODPLUG_STATIC --extra-cflags=-DCHROMAPRINT_NODLL --extra-cflags=-DZMQ_STATIC --extra-libs=-lpsapi --extra-cflags=-DLIBXML_STATIC --extra-libs=-liconv --disable-w32threads --extra-cflags=-DKVZ_STATIC_LIB --enable-nonfree --extra-cflags=-DAL_LIBTYPE_STATIC --extra-cflags='-IC:/apps/media-autobuild_suite/local64/include' --extra-cflags='-IC:/apps/media-autobuild_suite/local64/include/AL'
libavutil      59. 16.101 / 59. 16.101
libavcodec     61.  5.103 / 61.  5.103
libavformat    61.  3.103 / 61.  3.103
libavdevice    61.  2.100 / 61.  2.100
libavfilter    10.  2.101 / 10.  2.101
libswscale      8.  2.100 /  8.  2.100
libswresample   5.  2.100 /  5.  2.100
libpostproc    58.  2.100 / 58.  2.100

Attachments (1)

ffmpeg_reports.zip (114.2 KB ) - added by Hunter Hogan 2 years ago.
reports, loglevel=56, showing error, and reports without error if one variable is changed

Download all attachments as: .zip

Change History (4)

by Hunter Hogan, 2 years ago

Attachment: ffmpeg_reports.zip added

reports, loglevel=56, showing error, and reports without error if one variable is changed

comment:1 by Hunter Hogan, 2 years ago

Description: modified (diff)
Keywords: resampling added

comment:2 by paulgreyson, 13 months ago

I ran into this problem processing a video filtergraph. I worked around it by explicitly setting vframes to just short (I used 30 frames but maybe fewer would work also) of the end of the input video. this filter graph is processing side-by-side stereoscopic video into an anaglyph.

"-filter_complex",                        
                (
                    f"[0:v]crop=iw/2:ih:0:0, crop=iw-{input['crop']}:ih:{input['crop']}:0, scale=2*iw:ih, pad=iw:ih:(ow-iw)/2:0:black[left_base];"
                    f"[0:v]crop=iw/2:ih:iw/2:0, crop=iw-{input['crop']}:ih:0:0, scale=2*iw:ih, pad=iw:ih:(ow-iw)/2:0:black[right_base];"
                    
                    f"[left_base]pad=iw+{input['left_adjust']}:ih+{(16.0/9)*input['left_adjust']}:{input['left_adjust']/2}:{(16.0/9)*input['left_adjust']/2}:black[left_adjusted];"

                    f"[right_base][left_adjusted]scale2ref[right][left];"

                    f"[left]eq=brightness=0.1:contrast=1.2:gamma=1.1[left_filtered];"
                    f"[right]eq=brightness={brightness}:contrast={contrast}:gamma={gamma}[right_filtered];"

                    
                    f"[left_filtered]lutrgb=r=val*{lut}[left_lut];"
                    f"[right_filtered]lutrgb=g=val*{lut}:b=val*{lut}[right_lut];"

                    f"[left_lut]drawtext=fontfile={font}:text='{input['title']}':fontcolor=white:fontsize=48:box=1:boxcolor=black@0.5:boxborderw=5:x={title_depth_offset}+(w-text_w)/2:y=(h-text_h*2):enable='{enable}'[left_final];"
                    f"[right_lut]drawtext=fontfile={font}:text='{input['title']}':fontcolor=white:fontsize=48:box=1:boxcolor=black@0.5:boxborderw=5:x=-{title_depth_offset}+(w-text_w)/2:y=(h-text_h*2):enable='{enable}'[right_final];"

                    f"[left_final][right_final]hstack, stereo3d=sbsl:{stereo3d_mode}, pad=1920:ih:(ow-iw)/2:ih:black, crop=1920:1080:0:1080-ih"
)

comment:3 by Marton Balint, 12 months ago

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