[FFmpeg-user] fftfilt

Michael Koch astroelectronic at t-online.de
Thu Oct 14 12:25:24 EEST 2021

Am 13.10.2021 um 23:52 schrieb Michael Koch:
> Am 13.10.2021 um 23:09 schrieb Michael Koch:
>> Am 13.10.2021 um 22:57 schrieb Paul B Mahol:
>>> On Wed, Oct 13, 2021 at 10:51 PM Michael Koch 
>>> <astroelectronic at t-online.de>
>>> wrote:
>>>> Am 12.10.2021 um 19:29 schrieb Michael Koch:
>>>>> Am 12.10.2021 um 18:52 schrieb Paul B Mahol:
>>>>>> On Tue, Oct 12, 2021 at 10:55 AM Michael Koch
>>>>>> <astroelectronic at t-online.de>
>>>>>> wrote:
>>>>>>> I have a question about the "fftfilt" filter. What's the default 
>>>>>>> value
>>>>>>> of the weight_U and weight_V options? I'm asking because I get an
>>>>>>> unexpected result.
>>>>>>> This command line creates my input image for testing:
>>>>>>> ffmpeg -f lavfi -i color=black:s=300x50 -lavfi
>>>> drawgrid=c=white:y=-1:w=2:h=51,split[a][b];[b]crop=iw/2:x=0,scale=2*iw:ih:flags=neighbor,split[b][c];[c]crop=iw/2:x=0,scale=2*iw:ih:flags=neighbor,split[c][d];[d]crop=iw/2:x=0,scale=2*iw:ih:flags=neighbor,split[d][e];[e]crop=iw/2:x=0,scale=2*iw:ih:flags=neighbor,split[e][f];[f]crop=iw/2:x=0,scale=2*iw:ih:flags=neighbor[f];[a][b][c][d][e][f]vstack=6,split[h][v];[v]transpose[v];[v][h]hstack 
>>>>>>> -frames 1 -y test.png
>>>>>>> This is the fftfilt lowpass example from the official 
>>>>>>> documentation:
>>>>>>> ffmpeg -i test.png -vf 
>>>>>>> fftfilt=dc_Y=0:weight_Y='squish((Y+X)/100-1)' -y
>>>>>>> out1.png
>>>>>>> Problem: The output has a greenish tint.
>>>>>> Expressions by default for U and V are copied from Y if are unset.
>>>>>> filter works only in YUV or gray space thus in above combination one
>>>>>> gets
>>>>>> green tint.
>>>> I'm trying to make the filter's cutoff frequency independant of the
>>>> image size. But that's not so easy because I don't know the size of 
>>>> the
>>>> FFT array. It's calculated in vf_fftfilt.c lines 185 and 297.
>>>> This calculation is difficult (and slow) to replicate in an 
>>>> expression,
>>>> because either a loop or a logarithm is required.
>>>> Would it be possible to add two new variables so that the FFT array 
>>>> size
>>>> can be used in an expression?
>>>> ARRAY_H = 1 << rdft_hbits
>>>> ARRAY_V = 1 << rdft_vbits
>>>> It the array size is known, things would become much easier.
>>> What are you attempting to do?

Below is a tested example for FFT filtering where the filter frequency 
(or wavelength) isn't a function of image size. The array size is 
calculated by complicated macros. That's why I suggest to make the array 
size available as variables.


set "P=8"             :: filter wavelength = pixels per linepair

set "SIZE_H=460"      :: horizontal size of test image
set "SIZE_V=230"      :: vertical size of test image

set "ARRAY_H=pow(2,ceil(log(ceil(%SIZE_H%*10/9))/log(2)))"    :: macro 
for horizontal fft array size
set "ARRAY_V=pow(2,ceil(log(ceil(%SIZE_V%*10/9))/log(2)))"    :: macro 
for vertical fft array size

:: create test image, wavelength varies continuously from 4 to 8 (in the 
center) to 16 pixels per linepair:

ffmpeg -f lavfi -i color=black:s=%SIZE_V%x%SIZE_V% -lavfi 
-frames 1 -y test.png

:: lowpass, highpass, bandpass and notch filtering:

ffmpeg -i test.png -vf 
-y lowpass.png

ffmpeg -i test.png -vf 
-y highpass.png

ffmpeg -i test.png -vf 
-y bandpass.png

ffmpeg -i test.png -vf 
-y notch.png


More information about the ffmpeg-user mailing list