How can I use the filter twice at different times in FFmpeg?

I want to use multiple filters in one go but confused about how to do it. I searched on the internet and get to know about -vf filter but didn’t get success while using the command. Can someone please help me with this?

Welcome back!

To use the filter twice in FFmpeg, you can use the -vf (video filter graph) option multiple times. Each instance of -vf will apply a separate filter.

The -vf parameter in FFmpeg is used to define which video filters should be used while transcoding or processing a video stream. You can change and alter the video frames in a variety of ways.

Here’s an example of how you can apply two filters in FFmpeg:

ffmpeg -i input.mp4 -vf filter1,filter2 output.mp4

  • -i input.mp4: Indicates the input file.
  • output.mp4: Indicated the output file.
  • -vf: The -vf flag is a filter graph, which is a list of one or more filter chains separated by commas.

Or maybe this may help you: How to combine multiple filters in one command?

For more check this:

Can’t we right-write the filters in a separate file and then include that file in the command?

You can use @ symbol to include the file in the command:

ffmpeg -i input.mp4 -vf @filters.txt output.mp4
Where filters.txt contains the filter graph description, with one filter per line.
For example, the filters.txt file might look like this:

  • filter1
  • filter2

You can also specify multiple -vf options in the command line to apply multiple filter graphs:
ffmpeg -i input.mp4 -vf filter1 -vf filter2 output.mp4

This will apply filter1 followed by filter2 to the input video.

Is there any order in which the filters will apply?

It’s possible to specify the order in which the filters are applied by using the -filter_complex option instead of -vf.

This option allows you to specify the input and output streams for each filter, so you have more control over the order in which the filters are applied.

For example:
ffmpeg -i input.mp4 -filter_complex "[0:v]filter1[temp];[temp]filter2[v]" -map "[v]" output.mp4

As per the above example, this will apply filter1 to the input video and save the result to a temporary stream called temp, and then apply filter2 to the temp stream and save the result to the output stream v. The -map option specifies that the output stream v should be used as the video for the output file.

How to use the complex filter graph in FFmpeg to apply filters at different times?

Hey Reena!

In order to use the complex filter graph in FFmpeg to apply filters at different times use the following step-by-step guide given below:

1. Install FFmpeg

The first step is to make sure that FFmpeg is installed on your system.

  1. Install FFmpeg on Windows
  2. Install FFmpeg on Ubuntu
  3. Install FFmpeg on Mac

2. Understanding the Filter Graph Syntax

FFmpeg's complex filter graph uses the `filter_complex` option and adheres to a predetermined syntax. Filters are written as `filter_name=arguments`, and the pipe symbol (`|`) is used to connect them. The `split` filter allows you to divide the video into several streams and apply various filters to each stream individually.

3. Establish the Complex Filter Graph.

Let's say you want to use a `scale` filter for the remaining 10 seconds of the video and a `rotate` filter for the first `10 seconds`. The `filter_complex` argument may appear as follows:

  `ffmpeg -i input.mp4 -filter_complex "[0:v]trim=0:10,rotate=PI/2[rotate];[0:v]trim=10,setpts=PTS-STARTPTS,scale=1280:720[scale];[rotate][scale]concat=n=2:v=1[outv]" -map "[outv]" output.mp4`

Now, execute the command.


  • [0:v] refers to the video stream from the input file (input.mp4).
  • trim=0:10,rotate=PI/2[rotate] is the first filter chain. It trims the video from 0 to 10 seconds, rotates it by 90 degrees clockwise (PI/2 radians), and stores the output in the rotate label.
  • trim=10,setpts=PTS-STARTPTS,scale=1280:720[scale] is the second filter chain. It trims the video from 10 seconds onwards, sets the presentation timestamp to start from 0 (to avoid timestamp issues), and applies a scale filter to resize the video to 1280x720 pixels, storing the output in the scale label.
  • [rotate][scale]concat=n=2:v=1[outv] is the concatenation of the two filtered streams. It takes the rotate and scale labeled outputs and concatenates them into a single output stream labeled outv.

The video will now be filtered, with scale performed after 10 seconds and rotation applied within the first 10. You can adjust the filter’s settings and timestamps to suit your needs.

Thanks Preetpal for this!

One more questions: Is it possible to use FFmpeg to apply numerous filters to a particular area of a video?

Yes, it is possible to apply numerous filters to a particular area of a video using FFmpeg. With the help of FFmpeg’s potent filter_complex feature, you may build intricate filter graphs and use numerous filters simultaneously or sequentially.

Using the trim and setpts filters, you can choose the appropriate portion of a video to apply several filters to before moving on to another section of the video.