Video editing is a cornerstone of compelling content creation. Whether you’re a YouTuber, marketer, or hobbyist, the ability to merge multiple clips into a seamless final product is essential. FFmpeg, a robust open‑source command‑line tool, makes video concatenation quick, reliable, and quality‑preserving.
Installation on Ubuntu
- Log in to your server via SSH and update the package index:
$ sudo apt update - Install FFmpeg and its dependencies:
$ sudo apt install ffmpeg - Verify the installation:
$ ffmpeg -version
Prerequisites: Matching Video Properties
Before merging, ensure that the source files share consistent encoding parameters—timebase, resolution, codecs, and pixel format. When these match, you can use the fast, re‑encoding‑free methods below. If they differ, you’ll need to re‑encode, which is slower but necessary for compatibility.
Same Codecs – Concat Demuxer (Fast Stream‑Copy)
- Create a text file listing the file paths:
Join_video.txtfile /Users/Video/input1.mp4file /Users/Video/input2.mp4
- Run FFmpeg with the demuxer:
ffmpeg -f concat -safe 0 -i join_video.txt -c copy output_demuxer.mp4
-safe 0 allows any file name; -c copy streams the files without re‑encoding.
Same Codecs – Concat Protocol (Single‑Line Command)
- Execute a one‑liner for compatible formats (e.g., MPEG‑TS):
ffmpeg -i "concat:input1.ts|input2.ts" -c copy output_protocol.ts
- For MP4 (unsupported by the protocol), the command will fail after the first clip, so use the demuxer instead.
Different Codecs or Resolutions – Re‑Encoding with filter_complex
- Specify all input files:
ffmpeg -i file1.mp4 -i file2.mp4 -i file3.mp4 \ - Build a filter graph that selects each file’s video and audio streams:
-filter_complex "[0:v][0:a][1:v][1:a][2:v][2:a] \
- Tell FFmpeg to concatenate the streams (n=3):
concat=n=3:v=1:a=1 [vv][aa]" \ - Map the concatenated streams to the output container:
-map "[vv]" -map "[aa]" mergedVideo.mp4
Re‑encoding is required here; the process is slower but delivers a unified format.
Multiple Audio Streams – Advanced filter_complex Usage
- Define the input files:
ffmpeg -i opening.mkv -i episode.mkv -i ending.mkv -filter_complex - Specify all video and audio streams (one video, two audio per file):
[0:0][0:1][0:2][1:0][1:1][1:2][2:0][2:1][2:2]
- Concatenate with 1 video and 2 audio streams:
concat=n=3:v=1:a=2 [v][a1][a2] - Map the output streams to the final file:
-map "[v]" -map "[a1]" -map "[a2]" output.mkv
Bonus – Quick Merge with Filmora
For users who prefer a graphical interface, Wondershare Filmora offers a drag‑and‑drop workflow that’s ideal for beginners.
- Open Filmora and click New Project.
- Import media: File > Import Media > Import Media Files.
- Drag the desired clips onto the timeline to create a continuous sequence.
- Use the built‑in editing tools (trim, crop, transitions) to polish the video.
- Export the finished product via the Export tab.
Conclusion
FFmpeg delivers unparalleled flexibility for video concatenation, whether you’re working with identical codecs, diverse formats, or multiple audio tracks. Its command‑line precision ensures optimal quality, while the Filmora alternative offers an intuitive shortcut for those less comfortable with scripts. Master these techniques to produce professional‑grade videos efficiently.