[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.

Michael


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 
geq='r=127.5+127.5*cos((X-W/2)*PI/(pow(2,(1+2*Y/H))))',colorchannelmixer=1:0:0:0:1:0:0:0:1:0:0:0,split[h][v];[v]transpose[v];[v][h]hstack 
-frames 1 -y test.png

:: lowpass, highpass, bandpass and notch filtering:

ffmpeg -i test.png -vf 
scale=2*iw:2*ih,fftfilt=dc_Y=0:dc_U=0:dc_V=0:weight_Y='lte(hypot(X/%ARRAY_H%,Y/%ARRAY_V%),2.0/%P%)':weight_U=1:weight_V=1,scale=iw/2:ih/2 
-y lowpass.png

ffmpeg -i test.png -vf 
scale=2*iw:2*ih,fftfilt=dc_Y=128:dc_U=1:dc_V=1:weight_Y='gte(hypot(X/%ARRAY_H%,Y/%ARRAY_V%),2.0/%P%)':weight_U=1:weight_V=1,scale=iw/2:ih/2 
-y highpass.png

ffmpeg -i test.png -vf 
scale=2*iw:2*ih,fftfilt=dc_Y=128:dc_U=1:dc_V=1:weight_Y='between(hypot(X/%ARRAY_H%,Y/%ARRAY_V%),1.8/%P%,2.2/%P%)':weight_U=1:weight_V=1,scale=iw/2:ih/2 
-y bandpass.png

ffmpeg -i test.png -vf 
scale=2*iw:2*ih,fftfilt=dc_Y=0:dc_U=0:dc_V=0:weight_Y='1-between(hypot(X/%ARRAY_H%,Y/%ARRAY_V%),1.8/%P%,2.2/%P%)':weight_U=1:weight_V=1,scale=iw/2:ih/2 
-y notch.png

pause




More information about the ffmpeg-user mailing list