Author:Bernat Guitart - Feb 7th, 2022
What are the FFMPEG filters?
An FFMPEG filter is an editing action that is applied to one or more input sources, resulting in one or more outputs. This editing actions can be things like rotating an input video source, adjusting the volume level, overlaying one video source over another, and a long and long etcetera.
Back in a previous lesson (Video containers and video codecs) we explained that for editing any video or audio, FFMPEG needs to follow a fixed steps:
- Demuxing the data streams in the input files
- Decoding the data streams based on the required codec
- Applying any changes to the data
- Encoding the data again into a data stream; and
- Muxing the data streams into the final output file
The filters are applied in the third step, once the content is decoded and before the content is being encoded again.
We will see later in this lesson that we can chain different filters to apply multiple edititions in the same
FFMPEG command, creating really amazing results. A chain of filters is called a filtergraph.
FFMPEG distinguishes between two types of filtergraphs: simple and complex.
Most common filters
There is almost an infinite list of filters, and you will probably never use half of them. But there are a few that are really common in most of the day to day operations:
scale: resizes the frames of the input source, scaling up or scaling downcrop: trims the canvas size of the framesoverlay: superimposes two inputs, such as two videos, a picture on top of a video or vice versa.loop: loops a stream a number of times or infinitelyconcat: chains audios or videos one after the other
You can also check our guides to:
Filters syntax
As you will notice as we get deeper into the filter usage, the FFMPEG commands can really become very complex and hard to read, so it's important that you learn step by step.
An FFMPEG filter follow the following syntax:
<filter_name>[=<filter_option>=<option_value>][:<filter_option>=<option_value>]
Thus, there is always the filter name, optionally followed by option-value pairs.
The different options-value pairs are separated by a : semicolon character.
Examples of filters:
scale=size=qcifoverlay=x=300:y=200crop=x=0:y=0:width=1920:height=1080
As you see above, there are filters with a single option, others with 2 and others can have 5 or 6.
With the objective of reducing the length of the commands, most of the filter options have shorter versions.
For example, width can usually be abbreviated as w, height as h, etc.
This is an example of equivalent filters:
scale=width=640:height=480scale=w=640:h=480
A step further is ommiting the option name, assuming that the order in which the options are provided follows what the filter expect.
For example, the following commands are the same:
overlay=x=200:y=100overlay=200:100
Chaining filters
FFMPEG filters can be chained together sequentially using a , comma character.
Example:
crop=x=100:y=100:w=400:h=300,scale=w=600:h=400
The example above crops the video and after, it scales up to 600x400.
Filtergraphs
FFMPEG filter_complex examples
Common errors with FFMPEG filters
Self-evaluation
What is a FFMPEG wrapper?
Published on February 7th, 2022