Monday, March 23, 2015

Few filters from ffmpeg filter library

If you are using WinFF with Display Cmd Line option, then from DVD preset you already know how scaling look like. For example

-vf scale=720:480

That would be width and height of output. With Additional Options activated WinFF will allow you to specify crop values. Unfortunately it will place them in wrong order if you are doing crop and scale. Placing crop in front of scale is preferable.

-vf crop=iw-50-10:ih-20-20:50:20,scale=720:480

Crop parameters are width, height and start point. It calculates it from input with, height and parameters which you have entered. BTW if you need to crop and scale inside complex filter that looks like this:

ffmpeg -i input.mpg -i detail.mpg -filter_complex\
 "[0:v] setpts=PTS-STARTPTS, crop=iw-6-6:ih-0-0:6:0,scale=800x640 [big];\
 [1:v] setpts=PTS-STARTPTS, crop=iw-50-10:ih-20-20:50:20,scale=240x192 [detail];\
 [big][detail] overlay=shortest=1:x=560" -c:v libx264 out.mkv


Filter expressions are separated with coma as in non complex case.
Beside size and crop, commonly used filter is unsharp. With unsharp filter output may be sharper or softer, blured. It accepts six parameters and those are default values:

-vf unsharp=5:5:1.0:5:5:0.0

Parameters are, in order of aperance, luma matrix size, horizontal and vertical, odd integers between 3 and 63. Next we have luma effect strength which is float. Then we have the same but for chroma. Positive values for effect strength will sharpen image, negative will blur it and zero will disable effect. For example scale and make it sharper:

-vf scale=960:540,unsharp=9:9:0.75:9:9:0.75

If we want to blur image we will make floats negative.
Another filter which we may want to use is curves. Those are the same ones which we know from GIMP, Curves Tool under Colors. While describing curves may be somewhat complicated, there is number of presets available and they are:

none
color_negative
cross_process
darker
increase_contrast
lighter
linear_contrast
medium_contrast
negative
strong_contrast
vintage


We can even chain them if required. So, if we want lighter output image:

-vf scale=960:540,curves=lighter

More ambitious users will take a look at man pages and maybe decide to create their own presets. According to documentation ffmpeg can import curves from photoshop but I can not confirm that since I am not using it.

No comments:

Post a Comment