Concatenate files of diff codecs
March 13, 2022
10:36 AM
Combining inputs with different codecs:
This example can also combine static images and videos
ffmpeg -loop 1 -r <rate> -t <time> -i [file] -i [file] -f lavfi -t 1 -i anullsrc -filter_complex "[0:v:0] [2:a:0] [1:v:0] [1:a:0] concat=n=2:v=1:a=1" [file]
• -loop 1 an image exclusive command.  If set to 1, loop over the first input. Default value is 0. (omit if not a static image)
• -r <num> set the framerate
• -t <time> how long you want the first input to last for (omit if not a static image)
• -i [file] the first (static image) input
• -f lavfi -t 1 -i anullsrc adds 1 second of empty audio using the anullsrc audio filter.  Required to concat a file with no audio
• -filter_complex "[0:v:0] [2:a:0] [1:v:0] [1:a:0] ... tells ffmpeg which streams to take from the input files, and send as an input to the concat filter.  In this example we are adding an image without audio to the start of a video.  The format is [input_file:type:stream] so [1:v:0] will take input file 1, stream 0, type video
• ... concat=n=2:v=1:a=1" [file] 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 output.  n sets the number if segments (default 2), v the number of video streams per segment (default 1), and a the number of audio streams per segment (default 0)
References and further reading:
• Concatenation of files with different codecs
 ([link]• The concat filter documentation
 ([link]• The null audio source documentation ([link])
Concatenating media files:
Create a [file] containing paths to the files:
# this is a comment
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
Then use the following command:
ffmpeg -f concat -safe 0 -i "[file]" -c copy "output.file"
• -f concat is the filter for concatenating
• -safe 0 is not required if the paths are relative
• -c copy to copy the codecs