ffmpeg -i video1.avi -i video2.avi -filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" output_video.avi
We are using the parameters:
-filter_complex with the filter specification in double quotes (they are needed):
[0:v:0] [0:a:0] [1:v:0] [1:a:0] this part tells the filter to use the video stream from the first file “[0:v:0]”, the audio stream from the first file “[0:a:0]”, the video stream of the second file “[1:v:0]” and the audio stream from the second file “[1:a:0]”.
Note that if any of the files does not have audio or video stream we should not include here.
And also note that if we are merging more than two files we should include the streams from the third, four or n files.
Also note that the first file is 0 (of [0:v:0] indicating 0- first file, v- video stream, and the second zero indicationg the first video stream of that file)concat=n=2:v=1:a=1 [v] [a]
this part is telling first to use the ffmpeg concat filter.
With the n=2 we are telling ffmpeg concat filter that we have 2 input files (so we have to change it if we have more) with one video stream (v=1) and one audio stream (a=1).
Finally we include the [v] and [a] so ffmpeg can use the resulting video ([v]) and audio streams ([a]) for future operations.-map “[v]” -map “[a]”
parameters are telling ffmpeg to use the resulting [v] and [a] streams from the concat filter rather than use the input files for output.output_video.avi is the name of the resulting video. Note that we can include any format or encoding parameter before this. With the concat filter ffmpeg will encode the result so we can transform the files to whatever format and codec we want.
References:
https://www.bugcodemaster.com/article/concatenate-videos-using-ffmpeg
网友评论