FFMPEG: Concatenate and Mix Multiple Inputs using Filter Complex
In this article, we will discuss how to apply concatenation and mixing of multiple inputs using the FFmpeg filter complex in a single command. By using the filter_complex option, you can merge inputs either consecutively or simultaneously.
Prerequisites
To follow along, make sure you have FFmpeg installed on your system. You can download it from the official website: FFmpeg Download.
Concatenate and Mix Multiple Inputs
Suppose you have four inputs (0, 1a, 1b, and 2), and you want to merge them in the middle (1a and 1b). You can achieve this using the following FFmpeg command:
ffmpeg -i 0 -i 1a -i 1b -i 2 -filter_complex "[0:v][1a:v][1b:v]concat=n=3:v=1:a=0[v];[v][2:a]concat=n=2:v=1:a=1" -c:v libx264 -crf 18 -c:a aac -strict experimental output.mp4
In this command, we use the concat filter to merge the video streams (v) and audio streams (a) separately. The filter_complex option allows us to define a filter graph that performs the concatenation and mixing.
Filter Complex in Detail
Let's break down the filter_complex option:
[0:v][1a:v][1b:v]concat=n=3:v=1:a=0[v];[v][2:a]concat=n=2:v=1:a=1
We define two concat filters: one for video streams (v) and another for audio streams (a). The video concat filter has three inputs (n=3), and the audio concat filter has two inputs (n=2). We set v=1 to output a single video stream and a=0 or a=1 to output no audio or a single audio stream, respectively.
Key Concepts
-
Concat: Combines multiple inputs into a single one.
-
Filter Complex: A powerful feature that allows you to chain multiple filters.
-
Streams: Video (v) and audio (a) streams are processed separately.
In this article, we learned how to concatenate and mix multiple inputs using the FFmpeg filter complex in a single command. By understanding the filter_complex option and its components, you can merge inputs either consecutively or simultaneously.
References
-
Books: None.
-
Articles: FFmpeg Filters: concat
-
Online Resources: FFmpeg Filtering Guide