How to Concatenate Multiple Videos Using FFmpeg?

Author: Vita
Publish date
Feb 2, 2024
Best Free Video Merger
  • You might as well try the easiest way to merge videos on PC for free:
  • Download Download Free HD Video Converter Factory;
  • • Open Converter and import your video files;
  • • Merge them into one pack;
  • • Select a format and export the final file.
Quick Navigation
How to Merge Videos with FFmpeg
Optional Method: Merge Videos without Command-line
Facebook
Twitter
Pinterest
Linkedin
Reddit

FFmpeg is a powerful video processing program that helps users change video/audio formats, concatenate files, trim video length, compress video size, etc. This article is focused on FFmpeg merging videos and offers different approaches for that goal. Just keep reading.

Preparation: Download and install the latest FFmpeg on your Windows, Mac, or Linux from the official website: https://ffmpeg.org/download.html
(The version of FFmpeg used in this tutorial is Microsoft Windows v6.0.1.)

How to Concatenate Videos with FFmpeg?

At the core of FFmpeg is the command-line tool. You can use different commands to let FFmpeg merge videos in various cases. Below are some commonly used methods.

1. Combine Videos in Folder/Directory

Step 1: Put all video files in one folder and name it “MP4” (or something like this).
Step 2: Open the MP4 folder and duplicate the FFmpeg.exe application here.
Step 3: Type “CMD” in the address bar to replace the original path.
Step 4: Press “Enter” to open the Command Prompt window.
Step 5: Type this command and press “Enter” to run it:
for %i in (*.mp4) do @echo file '%i') > mylist.txt
The mylist.txt file will contain a list of all the MP4 files.
Step 6: Finally, run the command to make FFmpeg merge videos to MP4:
ffmpeg -f concat -i mylist.txt -c copy output.mp4
Then, you will receive a final merged video named ‘output.mp4’ in the MP4 folder.

Tips: -c copy will copy all the streams. It makes FFmpeg merge videos without re-encoding.

Hot Search: Join Videos without Re-encoding | Merge Videos without Losing Quality

2. Merge Videos with the Same Codecs

Method 1. Use FFmpeg “concat” demuxer

Step 1: In the Command Prompt window, create a .txt file and list the paths of the video files you want to combine, like the example here:
merge_video.txt
File /Users/Video/input1.mp4
File /Users/Video/input2.mp4

You can add two or more video files to the .txt list.
Step 2: Run the FFmpeg command:
ffmpeg -f concat -safe 0 -i join_video.txt -c copy output_demuxer.mp4

Method 2. Use FFmpeg “concat” protocol

The “concat” protocol works only for video formats that support five-level concatenation like MPEG-2 TS:
ffmpeg -i "concat:input1.ts|input2.ts" -c copy output_protocol.ts

3. Merge Videos with Different Formats

Many people want to merge videos of different formats or codecs into an MP4 file, but the methods above don’t work for this case. So, here shows you how to combine an MP4 video and a WMV video using the FFmpeg “concat” filter.
Run this FFmpeg command:
ffmpeg -i input1.mp4 -i input2.wmv -filter_complex "[0:0][0:1][1:0][1:1]concat=n=2:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" output.mp4

Pro-tips:
-filter_complex lets you use the concat filter with multiple inputs and outputs.
[0:0][0:1] and [1:0][1:1] take video stream 0 and audio stream 1 from the first input video and the second input video separately.
n=2 refers to the number of segments (input videos).
v=1 and a=1 are the number of output video streams and audio streams.
[outv] and [outa] are the resulting video and audio streams.

Make sure the videos are in the same dimension and frame rate.
The “concat” filter will re-encode your videos, thus taking a long time to merge them.

4. Concatenate Videos Using Intermediate File Formats

To concatenate MP4 files having intermediate formats, follow the below steps.
Step 1: Name the two videos to the same, except for the file extension.
Step 2: Open the Command Prompt window and run this command:
ffmpeg -i input.mp4 -i input.mkv -c:v copy -c:a copy output.mp4

You can use a similar command to let FFmpeg combine other files with intermediate formats, such as merging MP4 and M4A: ffmpeg -i input.mp4 -i input.m4a -c:v copy -c:a copy output.mp4

5. Merge Videos Side by Side

FFmpeg can also put two videos side by side using the “hstack” filter. Here’s the command:
ffmpeg -i input1.mp4 -i input 2.mp4 –filter_complex "[1:v][0:v]scale2ref[wm][base];[base][wm]hstack=2" output.mp4
FFmpeg hstack filter inputs both videos horizontally. To use this command, all import streams must have the same height.

6. Merge Audio Files

To merge audio in FFmpeg, run this command:
ffmpeg -i audio1.mp3 -i audio2.mp3 -filter_complex "[0:a][1:a]concat=n=2:v=0:a=1" output.mp3
You can add more than two audio files.

How to Merge Videos without Command-line?

FFmpeg converts, records, and streams video and audio files in command lines, and it’s very likely to make mistakes typing those complicated elements. You may meet kinds of errors when processing videos in FFmpeg. Therefore, I recommend you use the easy video combiner – WonderFox Free HD Video Converter Factory.

This software is completely free and allows you to merge videos or audio files from different formats, codecs, resolutions, and frame rates. Whether you are a professional or a beginner in video editing, you can finish the process in several simple clicks!

DownloadDownload the free video merger for Windows and follow the simple steps below.

Free download Download for Free
Free download Download for Free

Step 1: Run Free HD Video Converter Factory and open the “Converter”.
Step 2: Click “Add Files” (or “Add Video Folder”) to import the videos you want to combine.
Step 3: Click the “Merge” button.
Step 4: Select all clips in the Video List and click “Merge”. You can drag the video to adjust the order in the Pack. Then, press the bottom “Merge” button.
Step 5: Choose an output video format from the profile menu (“Video” > “MP4”).
Step 6: Specify an output path and tap “Run” to finalize the process.

How to Merge Videos
How to Merge Videos

Pro-tips: WonderFox Free HD Video Converter Factory has a Pro version. You can upgrade to enjoy more features, such as combining videos side by side, recording, and downloading videos. Get it here:

Similar Articles
Merge TS Files to MP4

Merge TS Files to MP4

Merge MP4 in VLC

Merge MP4 Files VLC

Merge Subtitles with Video

Merge Subtitles with Video

WonderFox HD Video Converter Factory Pro
Full-featured yet Handy Video Converter

WonderFox HD Video Converter Factory Pro is an all-in-one video converter for Windows. It can help you achieve more than the following:

  • Join video/audio files, merge audio and subtitles with video.
  • Convert video and audio to 500+ formats.
  • Put 2 or 3 videos on one screen with different templates.
  • Download movies and songs from 1,000+ websites.
  • Record gameplay, streaming TV, meetings, and audio.
  • Make GIFs, create ringtones, and more…
Free download Download for Free
Free download Download for Free
*

Wrap-up

That is how to concatenate multiple videos using FFmpeg and its alternative. Compared with FFmpeg, WonderFox Free HD Video Converter Factory is much easier without dealing with complex command lines. Get the free software, or try the advanced version now!

Also Read: 5 Best Video Mergers without Watermark

Specialized in multimedia software solutions.
Since 2009

Terms and Conditions | Privacy Policy | License Agreement | Copyright © 2009-2024 WonderFox Soft, Inc.All Rights Reserved

Back to Top