How to merge multiple video/audio streams using FFmpeg?

Secondly, for merging video streams sequentially, FFmpeg provides a concat filter that takes video and audio streams as input and gives output streams by joining them together one after the other.

The filter works on segments of synchronized video and audio streams. All segments must have the same number of streams of each type, and that will also be the number of streams at the output. Segments are video and audio stream combinations that you map from input files into a concat filter.
Concat filter takes three kinds of parameters,
• n is the number of segments.
• v is the number of output video streams, which is also the number of video streams in each segment.
• a is the number of output audio streams, which is also the number of audio streams in each segment.

Assuming you want to concatenate an opening, an episode, and an ending, all in a bilingual version then you can use the following FFmpeg command.

ffmpeg -i opening.mkv -i episode.mkv -i ending.mkv -filter_complex \ '[0:0] [0:1] [0:2] [1:0] [1:1] [1:2] [2:0] [2:1] [2:2] concat=n=3:v=1:a=2 [v] [a1] [a2]' \ -map '[v]' -map '[a1]' -map '[a2]' output.mkv

For more information refer: