From time to time I have the need to combine two or more MP4 video files into a single MP4 file. There are many programs available in the Internet to perform such a task. However, many of them are crappy ‘marketing apps’ or professional and expensive tools. Therefore, I was looking for a solution that produces professional output but doesn’t cost a furtune. I came up with a nice solution using the freely available FFmpeg tool.

FFmpeg is an open-source, command-line-based processing tool for video and audio files. It’s core functionality is also used by a wide range of multimedia applications.

You can download the FFmpeg binary file for 64-bit macOS from here. Scroll down to the section “FFmpeg” and click the green button with the label “ffmpeg-4.0.2.7z”. Note that the version number might be different when you read this.

The file with the ending ‘.7z’ is a compressed archive file, similar to ‘.zip’ or ‘.rar’ files. You can extract the content of the compressed archive file with the help of macOS standard functionality. Right-click the file and choose ‘Decompress’. You will get a file ‘ffmpeg’ (Note: the file doesn’t have a file ending) in the location that you have chosen for extraction.

The following FFmpeg commands will assume that the ‘ffmpeg’ file as well as all MP4 source files are stored on the user’s desktop. Furthermore, the source files are named as ‘input1.mp4’, ‘input2.mp4’, etc. The merged output file will also be saved to the user’s desktop with the name ‘output.mp4’. Temporarily, you will need free space on your harddisk of about 3x times the size of your source files. E.g. if your source files are 5 GB you will temporarily need an additional 15 GB of free harddisk space.

Of course, if you don’t want to use your Desktop as your work folder or if you don’t want to rename your source files, you can also adjust the paths and file names in the commands that will be described next.

Also note that your source files should be of the same format. To be more precise, for ‘Method 1’ described below the used codec need to be the same, the container can be different. For ‘Method 2’ both, codec and container, must be identical for all source files. This also means that with the two methods you can not only merge MP4 files, you can use the same commands to merge files of the type AVI, MKV, etc.

Method 1: FFmpeg concat demuxer

The easiest way is the usage of the ‘FFmpeg concat demuxer’. For this you will have to create a text file containing the file names of your input files. E.g. save a text file with the file name ‘myinput.txt’ on your desktop only containing the following two lines :

If you have more input files, just add additional lines. Thereafter open your ‘Terminal’ and type the following commands:

Depending on the file size of your input files and the power of your CPU the terminal will be busy for a few seconds or minutes. However, after the command has terminated, you will have a new, combined MP4 file with the file name ‘output.mp4’ on your desktop.

Method 2: FFmpeg concat protocol

If you don’t want to create a text file with your source files, you can alternatively use the ‘FFmpeg concat protocol’. With this method you will first losslessly transcode your MP4 files into MPEG-2 transport streams using H.264 video and AAC audio. In a second step the MPEG-2 files will then be concatenated into a single MP4 file. To do so, open your ‘Terminal’ and type the following commands:

Of course, you can also use this methode if you have more than two source files. Just create additional .ts files and add the file names in the concat section of the last command line.

Further reading

More information about the FFmpeg parameters used in this article can be found under ‘FFmpeg video options‘ , ‘FFmpeg bitstream filters‘ and ‘FFmpeg concat‘. If you want to read a good introduction about how to use other functionality of the powerful FFmpeg tool for converting audio and video files, I recommend this article.

Don’t like terminal commands?

If you don’t like use Terminal commands you can alternatively use the open source tool ‘MP4joiner‘ which offers a graphical user interface to merge several MP4 files. It’s also ‘FFmpeg’ that is working under the hood of this tool.

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here