ffmpeg -i "concat:input1.mpg|input2.mpg" -c copy
output.mpg. Using ffmpeg for the concatenation operation ensures that
file headers and timestamps are handled correctly, whereas using operating
system commands such as cat on a Linux system or
copy /b on a Microsoft Windows system may produce payback issues.
This method can not be used for
MPEG-4 files, however.
Another method that can be used for MP4 files, as well as the above file types is the Concat Demuxer method, if the files use the same codecs and parameters, such as resolution, framerate, etc. If the files have the same characteristics, you can use a command of the form:
ffmpeg -f concat -safe 0 -i inputFileList.txt
-c copy output.mp4
file, e.g., file inputFile1 - see
example file, which lists five files
named REC-0001-A.mp4, REC-0002-A.mp4, REC-0003-A.mp4, REC-0004-A.mp4, and
REC-0005-A.mp4, which are to be joined into one much larger file.
E.g., if I have a list of MP4 files I wish to join together in the file
Videos2Concatenate.txt and wish to join them into a file
named output.mp4, I could use the command below:
ffmpeg -f concat -safe 0 -i Videos2Concatenate.txt -c copy output.mp4
If the input files aren't the same video file type or don't share the
same parameters, you can use a Concat Filter method, which though slower
due to the need for re-encoding, can handle different codecs, resolutions,
or other parameters. You will need to run the FFmpeg command with
a complex filtergraph, listing all input files with separate
-i flags. E.g.:
ffmpeg -i input1.mp4 -i input2.webm -i input3.mov -filter_complex
"[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[outv][outa]"
-map "[outv]" -map "[outa]" output.mkv
References: