+
Filtergraphs
+
Many ffmpeg commands use filters that manipulate the video or audio stream in some way: for example, hflip to horizontally flip a video, or amerge to merge two or more audio tracks into a single stream.
+
The use of a filter is signalled by the flag -vf
(video filter) or -af
(audio filter), followed by the name and options of the filter itself. For example, take the convert colourspace command:
+
ffmpeg -i input_file -c:v libx264 -vf colormatrix=src:dst output_file
+
Here, colormatrix is the filter used, with src and dst representing the source and destination colourspaces. This part following the -vf
is a filtergraph.
+
It is also possible to apply multiple filters to an input, which are sequenced together in the filtergraph. A chained set of filters is called a filter chain, and a filtergraph may include multiple filter chains. Filters in a filterchain are separated from each other by commas (,
), and filterchains are separated from each other by semicolons (;
). For example, take the inverse telecine command:
+
ffmpeg -i input_file -c:v libx264 -vf "fieldmatch,yadif,decimate" output_file
+
Here we have a filtergraph including one filter chain, which is made up of three video filters.
+
It is often prudent to enclose your filtergraph in quotation marks; this means that you can use spaces within the filtergraph. Using the inverse telecine example again, the following filter commands are all valid and equivalent:
+
+ -vf fieldmatch,yadif,decimate
+ -vf "fieldmatch,yadif,decimate"
+ -vf "fieldmatch, yadif, decimate"
+
+ but
-vf fieldmatch, yadif, decimate
is not valid.
+
Straight quotation marks ("like this") rather than curved quotation marks (“like this”) should be used.
+
Note: if the command involves more than one input or output, you must use the flag -filter_complex
instead of -vf
.
+
For more information, check out the ffmpeg wiki Filtering Guide.
+
+