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.
Nice howto, but it doesn’t work for me. I tried to concatenate 10 parts of a movie downloaded from youtube.com, 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
Thanks. this really works for me.
For me it worked but no other parameter is possible. thanks
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
I’m using this for MASSIVE DV files, but the output is limited to exactly 1GB. Any ideas?
Not sure why. I’ve heard of 2GB size file limit with 32 bit systems, but not 1GB.
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?
If you are just joining audio instead of video, you might want to try Audacity. Cut and pasting wav files to Audacity is doable.
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?
Dude! You made my day…keep up the good work
you will probably need to concatenate the audio using sox, the video in ffmpeg, and then mux the two together