Skip to content
Home » Video » Merge mp4 files with FFMPEG

Merge mp4 files with FFMPEG

Sometimes you need to merge some MP4 video files from the command line. The leading explanation I found for how to do this spends more time trying to sell you another product but it claims is easier. But it’s not a command line tool. So here’s how to use a command line tool, ffmpeg, to merge video. It may be harder to learn, but it’s much easier to automate, which is helpful if you have a large number of video clips to merge or concatenate together.

Merging mp4 files 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.

It 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 containing the files you want to merge needs a specific format. You can’t just put a list of the files you want into a text file.

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 file, and you’re golden.

Here’s an example file:

file video1.mp4
file video2.mp4

Repeat as many times as necessary, then save the file in the same directory with a suitable filename you’ll use in the next step.

Running the command

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

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

It’s fast, and you don’t have to worry about whether you left any gaps when you drag and drop the files in the timeline. Substitute your filelist you made in the last step for filelist.txt and whatever you want to call your final file for destination.mp4.

Command line video editing

I do realize that command line video editing isn’t for everyone. But it can speed processing along.

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!
%d bloggers like this: