Opened 13 months ago

Closed 2 months ago

#10294 closed defect (fixed)

convolution filter's rdiv option ignored

Reported by: Mark Owned by:
Priority: normal Component: avfilter
Version: 6.0 Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:

convolution filter "0rdiv" option seems ignored, instead the default "sum of all matrix elements" value is always used.

Simple example using ffplay below, a 3x3 box blur with an rdiv that should result in the image roughly half as bright as original. I can see the matrix is applied, but the brightness is always the same as original regardless of the 0rdiv value specified.

Result is the same when using ffmpeg to actually produce a new video.

How to reproduce:

% ffplay.exe -i .\in.mp4 -vf "convolution=0m=1 1 1 1 1 1 1 1 1:0rdiv=5"
ffplay version 6.0-full_build-www.gyan.dev Copyright (c) 2003-2023 the FFmpeg developers
  built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-shared --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-libvpl --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      58.  2.100 / 58.  2.100
  libavcodec     60.  3.100 / 60.  3.100
  libavformat    60.  3.100 / 60.  3.100
  libavdevice    60.  1.100 / 60.  1.100
  libavfilter     9.  3.100 /  9.  3.100
  libswscale      7.  1.100 /  7.  1.100
  libswresample   4. 10.100 /  4. 10.100
  libpostproc    57.  1.100 / 57.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '.\in.mp4':q=    0B f=0/0

Regards,
Mark.

Change History (8)

comment:1 by Michael Koch, 13 months ago

I can reproduce this issue.

Also the documentation is unclear:
"Set multiplier for calculated value for each plane. If unset or 0, it will be sum of all matrix elements."
The second example "Apply Blur" suggests that it's indeed a multiplier.
But then the default value should be the _inverse_ of the sum of all elements.

The question remains why a multiplier was given the name "0rdiv".

comment:2 by Mark, 13 months ago

My reply via mail bounced with "550 5.1.1 <trac@avcodec.org>: Recipient address rejected: User unknown in local recipient table", so adding it again here.

I'm not much a programmer, and spent no more the a few minutes looking at the source, but this seemed odd to me:
https://github.com/FFmpeg/FFmpeg/blob/412d43b09a2e21c6c76ca87cc5f05a504a1fee1a/libavfilter/vf_convolution.c#L678

Half guessing at what the init_param function is probably for it seems the rdiv options are always first (re)set to 0, and then a bit further down (around line 741) set to the inverse of the sum of the matrix. Could explain the behavior we see... I think, maybe.

comment:3 by Michael Koch, 13 months ago

Here are 3 command lines for reproducing the issue. Regardless if 0rdiv is unspecified or smaller or larger than 1, the output is always the same.

ffmpeg -f lavfi -i color=black:s=50x50 -vf drawbox=w=1:h=1:x=25:y=25:color=white,format=gray,convolution="1 1 1 1 1 1 1 1 1" -frames 1 -y out.png

ffmpeg -f lavfi -i color=black:s=50x50 -vf drawbox=w=1:h=1:x=25:y=25:color=white,format=gray,convolution="1 1 1 1 1 1 1 1 1":0rdiv=0.2 -frames 1 -y out_rdiv02.png

ffmpeg -f lavfi -i color=black:s=50x50 -vf drawbox=w=1:h=1:x=25:y=25:color=white,format=gray,convolution="1 1 1 1 1 1 1 1 1":0rdiv=5.0 -frames 1 -y out_rdiv50.png

comment:4 by sdc, 3 months ago

Slightly modified repro as above, that I find a little easier to see

ffmpeg -f lavfi -i color=black:s=50x50 -vf drawbox=w=10:h=10:x=25:y=25:color=white,format=gray,convolution="1 1 1 1 1 1 1 1 1" -frames 1 -y out.png

ffmpeg -f lavfi -i color=black:s=50x50 -vf drawbox=w=10:h=10:x=25:y=25:color=white,format=gray,convolution="1 1 1 1 1 1 1 1 1":0rdiv=0.02 -frames 1 -y out_rdiv002.png

ffmpeg -f lavfi -i color=black:s=50x50 -vf drawbox=w=10:h=10:x=25:y=25:color=white,format=gray,convolution="1 1 1 1 1 1 1 1 1":0rdiv=5.0 -frames 1 -y out_rdiv50.png

comment:5 by Marton Balint, 2 months ago

Resolution: fixed
Status: newclosed

comment:6 by Michael Koch, 2 months ago

The documentation of the "rdiv" option is unclear.
"Set multiplier for calculated value for each plane. If unset or 0, it will be sum of all matrix elements."
Is this a multiplier or is the result divided by this value? The second example "Apply Blur" suggests it's indeed a multiplier.
But then the sentence "If unset or 0, it will be sum of all matrix elements" is wrong.
The default value should be the inverse of the sum of all matrix elements.

comment:7 by Michael Koch, 2 months ago

Resolution: fixed
Status: closedreopened

reopened because the documentation of "rdiv" option is wrong

in reply to:  7 comment:8 by Marton Balint, 2 months ago

Resolution: fixed
Status: reopenedclosed

Replying to Michael Koch:

reopened because the documentation of "rdiv" option is wrong

Please open a new ticket, as that is a separate issue.

Note: See TracTickets for help on using tickets.