Too many inputs specified for the "gradients" filter.
dungtam73 opened this issue · 0 comments
dungtam73 commented
I'm trying to create a video using the gradients filter in FFmpeg. I've tested and succeeded with the FFmpeg command, but when I converted it to Python code using ffmpeg_python, I encountered the error "Too many inputs specified for the "gradients" filter."
. I would appreciate some help troubleshooting this issue.
FFmpeg command:
ffmpeg -i input.mp4 -filter_complex "gradients=c0=white:c1=black:nb_colors=2:s=288x360:speed=1e-05:type=linear:x0=0:x1=0:y0=360:y1=0" output.mp4
Python code:
import ffmpeg #pip install ffmpeg-python
input_file = r"input.mp4"
output_file = r"output.mp4"
# Get the dimensions of the input video
probe = ffmpeg.probe(input_file)
video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
width, height = int(video_stream['width']), int(video_stream['height'])
# Make a gradient filter
input = ffmpeg.input(input_file)
grad = ffmpeg.filter(input,"gradients",s="288x360",type="linear",x0=0,y0=360,x1=0,y1=0,nb_colors=2,c0="white",c1="black",speed=1e-05)
output = grad.output(output_file)
print(output.compile())
ffmpeg.overwrite_output(output).run()
Python logs:
['ffmpeg', '-i', 'input.mp4', '-filter_complex', '[0]gradients=c0=white:c1=black:nb_colors=2:s=288x360:speed=1e-05:type=linear:x0=0:x1=0:y0=360:y1=0[s0]', '-map', '[s0]', 'output.mp4']
ffmpeg version 5.1.2-full_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 12.1.0 (Rev2, 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-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray
--enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --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-libshaderc --enable-vulkan --enable-libplacebo --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 57. 28.100 / 57. 28.100
libavcodec 59. 37.100 / 59. 37.100
libavformat 59. 27.100 / 59. 27.100
libavdevice 59. 7.100 / 59. 7.100
libavfilter 8. 44.100 / 8. 44.100
libswscale 6. 7.100 / 6. 7.100
libswresample 4. 7.100 / 4. 7.100
libpostproc 56. 6.100 / 56. 6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf59.27.100
Duration: 00:00:30.03, start: 0.000000, bitrate: 389 kb/s
Stream #0:0[0x1](eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 288x360 [SAR 1:1 DAR 4:5], 284 kb/s, 30 fps, 30 tbr, 12k tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
encoder : h264
Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 96 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
[AVFilterGraph @ 0000028bd319bfc0] Too many inputs specified for the "gradients" filter.
Error initializing complex filters.
Invalid argument
Command generated by the compile() function from ffmpeg_python:
['ffmpeg', '-i', 'input.mp4', '-filter_complex', '[0]gradients=c0=white:c1=black:nb_colors=2:s=288x360:speed=1e-05:type=linear:x0=0:x1=0:y0=360:y1=0[s0]', '-map', '[s0]', 'output.mp4']
Videos
https://drive.google.com/drive/folders/1JHbPA6kUwMto4yZANLpu6nylVYL_StFo?usp=share_link