Concatenate Video Files Using FFMPEG

This article will show you how to concatenate two mpg files into one big file using the CAT and FFMPEG commands. Here was the dilemma. I have two video files that were recorded separately. The recording was accidentally stopped for a brief second or two. The cam created two separate video files. I wanted to stitch and merge the two files into one big file.

To accomplish the feat, I will be using both CAT and FFMPEG commands that is common to most Linux systems. If you use the cat command alone like the in the example below, it will not work. You’ll have timestamp issues. The player also will not go past the end of the first video. It will never play the second and third videos if you have more.

Cat is not enough.

cat abc.mpg def.mpg > ghi.mpg

What you need to do is use CAT and pipe the output using FFMPEG.

The command:

cat abc.mpg def.mpg | ffmpeg -f mpeg -i - -vcodec copy -acodec copy ghi.mpg

You now have a file named ghi.mpg which is the combined output of abc.mpg and def.mpg. You can concatenate 3 or more files if you wish. FFMPEG is such a powerful video converter program capable of converting videos to any video format like avi, wmv, mov, etc. Earlier in the year, I wrote how to install FFMPEG and also another explaining the options.

12 thoughts on “Concatenate Video Files Using FFMPEG

  1. Nice howto, but it doesn’t work for me. I tried to concatenate 10 parts of a movie downloaded from, it starts okay, and then after few seconds I get the following message:

    [NULL @ 0x9617670]error, non monotone timestamps 563083 >= -1931820712
    av_interleaved_write_frame(): Error while opening file

    Any ideas?? TIA

  2. It should be possibile to do something like

    cat imput%d.mpg | ffmpeg -f mpeg -i – -vcodec copy -acodec copy outfile.mpg

    Another solution that maybe make a more compact file is
    mencoder -oac copy -ovc copy -o output.avi input1.avi input2.avi

  3. Thanks for the tip on ffmpeg. Do you know if this would be possible with .wav files?

    Something like? cat 1.wav 3.wav | ffmpeg -f wav -i – -acodec copy combined.wav?

  4. Hi, cool tutorial but I’m having problems when joining files which contain AC3 5.1 audio, the resulting file is totally mute… any suggestions?

  5. you will probably need to concatenate the audio using sox, the video in ffmpeg, and then mux the two together

Comments are closed.