(FFmpeg) How to use filters (-vf/-af vs -filter_complex)?

Converting between one file format to another is extremely useful and might be all that’s needed for your use of FFMPEG but where the real fun begins is in the filters. Filters are used to manipulate audio and video with the libavfilter library.

A filter might result in a single change to an input file with a new output file or multiple changes to multiple output files or anything in between. Filters follow a sequential order as given by the command.

-vf / -af (video filter / audio filter) is used for simple filtergraphs (one input, one output), and -filter_complex is used for complex filtergraphs (one or more inputs, one or more outputs). Using -filter_complex will allow you omit the movie multimedia source filter and have a shorter command. 

Below is an example of reversing the video and audio of the input with both syntax types:

-vf / -af syntax 

  $ ffmpeg -i input.mp4 -vf reverse -af areverse output.mp4   

-filter_complex syntax

  $ ffmpeg -i input.mp4 -filter_complex "[0:v]reverse;[0:a]areverse" output.mp4  

-filter_complex doesn’t just apply to when chaining manipulation to video and audio. -filter_complex is used when multiple inputs are used or temporary streams are created.

Lastly FFMPEG does have streaming capabilities and filters can be applied and changed at runtime. FFMPEG documentation references these filters as supporting the variables as a command. An example of a filter command is as follows:

 $ ffmpeg -h filter=<name of filter> 

Love FFmpeg? Grab a copy of FFmpeg For Beginners on Kindle or Paperback to learn over 120 ways to master FFmpeg!

buy now on amazon