Search code examples
ffmpegphotoshopgimp

Implement Adobe Photoshop's "Levels" feature using ffmpeg


In Adobe photoshop, I used the "Levels" feature to adjust Shadows, Midtones and Highlights of an image. I need an elegant solution using ffmpeg to implement the same effect. A ffmpeg implementation will help me perform the operation programmatically.

I've tried using the colorbalance filter available on ffmpeg.

ffplay -i input -vf colorbalance=rs=-0.75:gs=-0.75:bs=-0.75:rm=-0.875:gm=-0.875:bm=-0.875:rh=-1:gh=-1:bh=-1

In photoshop I'm able to achieve the expected results with the following settings,

Shadows - 199
Midtones - midpoint
Highlights - 255

Solution

  • colorlevels

    Use the colorlevels filter and interpolate the values to match Photoshop:

    enter image description here
    enter image description hereenter image description here
    Original, Photoshop, ffmpeg

    ffmpeg -i input.jpg -vf "colorlevels=rimin=199/255:gimin=199/255:bimin=199/255" -frames:v 1 output.jpg
    

    Since you're only directly adjusting the input black points you only need to adjust *min options as shown in the example.

    curves

    If you're familiar with Curves in Photoshop you can save the preset and load the ACV file with the curves filter:

    ffmpeg -i input.jpg -vf "curves=psfile=file.acv" -frames:v 1 output.jpg