DEV Community

Cover image for Chroma key fringe survives every colorkey tweak? The leak is downstream
LoCo Pro Wrestling LLC
LoCo Pro Wrestling LLC

Posted on

Chroma key fringe survives every colorkey tweak? The leak is downstream

If you have a chroma keyed layer with a stubborn colored fringe around the edges, and retuning colorkey similarity and blend never fully kills it, the key itself is not the problem.

A chroma keyed RGBA image still holds the key color in its RGB channels underneath the alpha=0 region. Any blur, scale, or zoompan applied after the key samples those hidden pixels and smears the key color back out past the subject edge. Tuning colorkey never fixes this, because the leak happens after the key, not at it.

Fix, as an ffmpeg filter chain:

colorkey=0xFF00FF:0.34:0.00,alphaextract,erosion,erosion,alphamerge,premultiply=inplace=1
Enter fullscreen mode Exit fullscreen mode
  1. colorkey=::0.00, blend of 0 for a hard cut. Any nonzero blend creates semi transparent, key colored edge pixels, a second independent source of fringe.
  2. alphaextract,erosion,erosion,alphamerge, shaves the 1 to 2 pixel antialiased ring left at the hard key boundary.
  3. premultiply=inplace=1, run this before any blur or zoompan, not after. It zeroes RGB where alpha is 0, so there is nothing left to smear.
  4. Composite with overlay=...:alpha=premultiplied to match, otherwise edges darken from double multiplying the alpha.

One more thing worth checking: if you generate the source layers with an AI image tool, see whether it supports a native transparent background output. Some do. Generating true alpha at the source skips chroma keying, and this entire class of bug, completely.

Verification note: an automated fringe pixel detector can report zero fringe on a render where the fringe is clearly visible by eye, because it is checking the wrong thing (alpha correctness, not composited RGB after blur). Look at the actual frame, do not trust the metadata.

Full writeup: github.com/locoprowrestling/ffmpeg-tricks

Top comments (0)