FFMPEG can merge videos, here’s how

Last Updated on March 31, 2023 by Dave Farquhar

Sometimes you need to merge some MP4 video files from the command line. Here’s how to use a command line tool, ffmpeg, to merge video. It may be a little harder to learn than a GUI tool. But it’s much easier to automate, which is helpful if you have a large number of video clips to merge or concatenate together.

Merge videos with FFMPEG

merge video files with ffmpeg
The key to merging video files with ffmpeg is formatting the textfile containing the source files correctly. Most of the other tutorials you find online get the file syntax wrong.

Merging videos with FFMPEG starts with a plain text file. The piece that most people seem to miss, including other tutorials I found on online, is that the text file you create listing the files you want to merge needs a specific format. The text file needs a little more than just a list of the file names you want to merge.

One more caveat. Spaces in filenames are also problematic. In theory, putting the file name in quotes takes care of the spaces. In practice, it doesn’t always work. So I rename my files without spaces ahead of time.

The syntax is the word file followed by your file name. Then you follow that on a new line with the word file and the next file you want to merge. Order the lines in the order you want the video clips to appear in the destination video file.

Here’s an example file:

file video1.mp4
file video2.mp4

Repeat as many times as necessary. Then save the file in the same folder or directory as your videos with a suitable filename you’ll use in the next step.

The format is simple enough you could write a script to populate the text file if you find yourself doing this a lot.

Running the command to merge mp4 files with ffmpeg

Once you have your text file constructed, it’s just a single command to take all those files and mash them together, using ffmpeg’s concat operation.

ffmpeg -f concat -i filelist.txt -c copy destination.mp4

It’s fast and you can automate as much or as little of the process as you want, if you find yourself doing this a lot. Substitute your text file you made in the previous step for filelist.txt. Then substitute whatever you want to call your final file for destination.mp4.

It’s definitely not as intuitive as a GUI editor would be. But once you know how to create the text file that tells ffmpeg what videos to merge and in what order, it’s not difficult.

Command line video editing

I do realize that command line video editing isn’t for everyone. But there are times when it can speed processing along. With GUI tools my rule of thumb has always been an hour of post-production for every minute of video. Using a command line tool can help you get ahead of that curve.

If you need to remove the audio, say, so you can go back and do a voiceover in post-processing, you can do that from the command line as well. I wish we could say we always get our lines right the first time, or that microphones don’t malfunction during recording, but these things happen. And sometimes using the command line to splice together the footage you need is the fastest way to get it done.

And nothing stops you from using a GUI tool like Filmora for part of the job and ffmpeg for other parts.

If you found this post informative or helpful, please share it!