Concatenating videos with FFmpeg

The FFmpeg video handling utility can be used to join videos together into one larger video. If the video files are MPEG-1, MPEG-2, MPEG Program Stream (PS) , or Digital Video (DV) files, you can use a Direct Stream copy method, by issuing a command in the form 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

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:

  1. How to concatenate two MP4 files using FFmpeg? [closed]
    Date accessed: March 12, 2026
    Stack Overflow