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.
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.
Here,
[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 therotate
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 thescale
label.[rotate][scale]concat=n=2:v=1[outv]
is the concatenation of the two filtered streams. It takes therotate
andscale
labeled outputs and concatenates them into a single output stream labeledoutv
.
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.