Contents

How to Merge Multiple MP4 Files

TL;DR

  1. Install ffmpeg:
    1
    2
    
    sudo apt update
    sudo apt install ffmpeg
    
  2. Merges files:
    1
    
    cd Video-File-Folder
    
    1
    
    ls | while read FILENAME; do echo file \'$FILENAME\'; done | ffmpeg -f concat -safe 0 -protocol_whitelist "file,pipe" -i - -codec copy merged-videos-file.mp4
    

Sources

The Rest of the Story

This might not be the most exciting first post for 2021, but one must start somewhere 😇️

So, you might have some home surveillance video cameras, for example, and those devices tend to break apart the footage into smaller files. I’ve seen some break the footage apart into a file (.mp4) per minute of footage. That means 60 minutes, 60 files.

I find it a bit easier to navigate through one file as opposed to sixty.

Here is how you can use ffmpeg on Linux Mint 20 (or other Debian/Ubuntu-based distribution) to merge all those pesky smaller .mp4 files in a single file.

Steps

Install FFMPEG

You’ll need to have ffmpeg installed on you machine, and you can do that with the following command:

1
2
sudo apt update
sudo apt install ffmpeg

Merge All the Files!

Note: One thing to be aware of, is that your input files must have the same stream types (same formats, timebase, timescale, etc.). If all of the inputs files come from the same device (source), you should be ok.

  1. Start by putting all the files you want to merge into a folder. In the following example the folder I’ll be using will be Video-File-Folder.
  2. Make sure you have changed directory into the folder with all the files
    1
    
    cd Video-File-Folder
    
  3. Run the following command in you terminal:
    1
    
    ls | while read FILENAME; do echo file \'$FILENAME\'; done | ffmpeg -f concat -safe 0 -protocol_whitelist "file,pipe" -i - -codec copy merged-videos-file.mp4
    
  4. The output won’t look to pretty, but when it’s done, you should see a new file in the Video-File-Folder folder called merged-videos-file.mp4

Conclusion

Multiple .mp4 files, should now be one magnificent .mp4 file!

End of Line.