How to Concatenate Multiple Videos Into a Single Video File

A simple guide on how to merge two or more videos in order into a single video file

When I make tutorial videos, I usually record them in a single take, meaning a topic can be covered in one video file with some parts edited or trimmed.

However, sometimes I need to record two or more clips for a single topic. After trimming and editing each one, I then concatenate them into a single video file.

In this post, I’ll show you how I usually merge those video files.

Not in the mood for reading? Watch the video instead.

For example, let’s say I have the following videos in my current directory:

$ ls
video-01.mp4
video-02.mp4
video-03.mp4

I want to concatenate them all into one video file, in order by number (01 → 02 → 03).

Before we merge them, let’s turn this list of video files into a text file called input-list.txt.

for f in *.mp4; do echo "file '$PWD/$f'" >> input-list.txt; done

Here’s what input-list.txt looks like after running the command:

$ cat input-list.txt
file '/Users/junian/demo/video-01.mp4'
file '/Users/junian/demo/video-02.mp4'
file '/Users/junian/demo/video-03.mp4'

Now, let’s create a single video file that combines all these clips in order using ffmpeg:

ffmpeg -f concat -safe 0 -i input-list.txt -c copy video-output.mp4

A new video file named video-output.mp4 will appear. Open it, and you’ll see it contains all the video content from the input files.

Video

Conclusion

That’s it for today!

Thanks for reading, and see you next time.

References