Context Navigation

FFmpeg Filtering Guide

FFmpeg has access to many filters and more are added on a regular basis. To see what filters are available with your build see ffmpeg -filters.

Documentation

Refer to the ​FFmpeg documentation (sections "audio/video source/filters/sink") for each filters' documentation and examples. This wiki page is for user contributed examples and tips.

Contributions to this page are encouraged.

Examples

Scaling

Starting with something simple. Resize a 640x480 input to a 320x240 output.

ffmpeg -i input -vf scale=iw/2:-1 output

iw is input width. In this example the input width is 640. 640/2 = 320. The -1 tells the scale filter to preserve the aspect ratio of the output, so in this example the scale filter will choose a value of 240. See the ​FFmpeg documentation for additional information.

Speed up your video

Filtergraph,Chain,Filter relationship

What follows the -vf in an ffmpeg command line is a Filtergraph description. This filtergraph may contain a number of chains, each of which may contain a number of filters.

Whilst a full filtergraph description can be complicated, it is possible to simplify it for simpler graphs provided ambiguity is avoided.

Remembering that filters in a chain are separated by commas "," chains by a semicolon ";" and that if an input or output is not specified it is assumed to come from the preceding or sent to the following item in the chain.

However an alternative, which also allows for white space within the filtergraph, and which may assist in clarity of reading complex graphs, is to enclose the whole filtergraph within double quotes " " thus:-

Scripting your command line parameters

If building complex filtergraphs the command line can get very messy so it can help to break things down into manageable pieces. However one needs to be careful when joining them all together to avoid issues due to your shell and escaped characters.

The following example shows a sample bash script containing a filtergraph of one chain with three filters; yadif, scale and drawtext.

Note that the double quotes " around the whole filtergraph have been escaped \" and the filtergraph spans more than one line, the echo command shows the full command as it is executed. Useful for debugging.

The eval invocation of the $command_line variable is required to avoid loss of the embedded escaped quotes which occurs if it is absent. Other shells may behave differently.

List of Filters

Filters bundled with libavfilter as of 2.79.100 (as configured with --enable-gpl). Filters relying on external libraries, such as frei0r, are not listed here.