[FFmpeg-devel] [PATCH] delogo filter: new "uglarm" interpolation mode added

Uwe Freese uwe.freese at gmx.de
Wed Dec 26 16:23:58 EET 2018


Hello,

so now I've taken the time to integrate the alternative interpolation 
algorithm 'uglarm' into the delogo filter.

I took the code from ffdshow's logoaway, which took over the code from 
LogoAway for VirtualDub, where I originally added it 2001. :)

I tested the code with several different options and had temporarily 
added many debug outputs (to the console) to see the internally 
calculated values. So I'm pretty confident about the correct functioning 
of the code. I also made some improvements compared to the logoaway 
filter to minimize the lookup tables (which was also a reason for me to 
test it thoroughly).

Of course, it would be nice if the addition will now also find it's way 
into the normal development branch.

The current "xy" mode tends to flicker and show horizontal and vertical 
lines, which sometimes produces an "eye catcher" at the logo area. In 
contrast, the new UGLARM mode IMHO shows a much more non-distracting 
blurred area while keeping the same simple usage (only entering the 
coordinates of the logo).

Can someone please review and add the code? Who would be primarily 
responsible to add this to libavfilter?

You can test the filter (after compiling with the attached patch for 
vf_delogo.c) with the following command to show the old xy mode and the 
new uglarm mode next to each other by:

./ffmpeg -i "yourtestvideo.mkv" -map 0:v:0 -vframes 100 -filter_complex 
"crop=200:200:100:100,split=2[L][R];[L]delogo=x=50:y=50:w=100:h=100[L2];[R]delogo=x=50:y=50:w=100:h=100:mode=uglarm:power=15[R2];[L2][R2]hstack=inputs=2" 
-c:v huffyuv delogotest.mkv && ffplay delogotest.mkv

(power can be from 0 to 30, 15 is default and need not be specified)

Here are some details of what I added and how / why:

- a new parameter "mode" is used to select the mode
   Note: It defaults to the current xy mode.
   Note: I preferred using a string / enum parameter instead of a 
boolean so the parameter could stay backwards compatible in case another 
mode would be added some day.
- a "power" value can be used to set the strength of the effect
   Note: Named "power" (and not "strength") because the distance between 
logo pixels to the border is calculated by using the power of the 
diagonal distance.
   Note: The default value results in exponent 3 (cubic), which 
corresponds to how e.g. a magnetic field is behaving and what I used all 
the years for logoaway.
- Two lookup tables (per plane) are generated at startup (if the new 
mode is set).
- Memory is cleaned up in the new "uninit" function.
- The SAR (sample aspect ratio) is considered to calculate the 
interpolated inner pixels of the logo area.
- As I saw, the filter is applied to three planes, I think it's for Y U 
V, because of the YUV color model.
   Question: How many planes can there be? I used an array of pointers 
to 10 possible lookup tables (one per plane).
   Can there be more? Are 3 enough? Is there a constant to get the max. 
number of planes at compile time?
- Only a band / border of 1 pixel is used for interpolation. This is 
because the "band" option in the delogo filter is planned to be removed 
anyway. It's also not necessary for the new mode.
- I added comments and description as I thought would be useful to 
understand the code. I hope it's ok as it's done.
- I tried to use the same formatting etc. as in the original source 
code. Is there anything I have to change?

I would be really glad for any feedback, comments, improvement 
ideas,..., and of course a review and integration of the code. :)

Of course, I would support adding documentation about the filter as 
well. Just let me know what's needed.

Best Regards,
Uwe

Am 13.12.18 um 07:55 schrieb uwe.freese at gmx.de:
> Hello Kyle,
>> You should also try vf_removelogo. It is supposedly better than the
>> more simple vf_delogo.
>
> I tried (with a box in a PNG mask as logo cover).
>
> That is no alternative both quality wise and from usability point of 
> view:
>
> 1. It gave me blurry borders with several pixels widths from outside 
> to the inner. They were very symmetrical and showed a 45 degree 
> "lines" from the edges to the middle. Hardly the nice blurred box I 
> wanted.
>
> 2. If you want to cover the logo by simple coordinates (a box), it's 
> unnecessary effort to create a PNG mask with that box in it instead of 
> giving the coordinates as parameter.
>
>
> Because removelogo can handle arbitrary masks and the calculation I 
> posted is using a simple rectangular box (and this is my typical use 
> case), I suggested to add it to the "delogo" filter.
>
> So my offer stands, would be nice if someone can add this additional 
> mode.
> [...]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-new-delogo-interpolation-mode-uglarm.patch
Type: text/x-patch
Size: 19910 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20181226/fb4769b9/attachment.bin>


More information about the ffmpeg-devel mailing list